GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
geodesk::Feature Class Reference

A geographic feature. More...

#include <Feature.h>

Inheritance diagram for geodesk::Feature:
geodesk::Node geodesk::Relation geodesk::Way

Public Member Functions

 Feature (FeatureStore *store, FeaturePtr ptr)
 
Type & Identity
FeatureType type () const noexcept
 The Feature's type.
 
int64_t id () const noexcept
 The ID of this Feature.
 
bool isNode () const noexcept
 true if this Feature is a Node.
 
bool isAnonymousNode () const noexcept
 true if this Feature is an anonymous node.
 
bool isWay () const noexcept
 true if this Feature is a Way.
 
bool isRelation () const noexcept
 true if this Feature is a Relation.
 
bool isArea () const noexcept
 true if this Feature is an area (represented by either a Way or Relation).
 
bool belongsToRelation () const noexcept
 true if this Feature belongs to at least one Relation.
 
StringValue role () const noexcept
 The Feature's role in its Relation, if it was returned via members() or Features::membersOf(), otherwise an empty string.
 
Display
const char * typeName () const noexcept
 "node", "way" or "relation"
 
char * format (char *buf) const noexcept
 Formats the string representation (e.g. "node/123456") of this Feature into the provided buffer.
 
std::string toString () const
 Creates a std::string with the Feature's type and ID.
 
std::string label () const
 Creates a short descriptive label.
 
Tags
TagValue operator[] (std::string_view key) const noexcept
 Obtains the tag value for the given key.
 
Tags tags () const noexcept
 A collection of the Feature's tags.
 
bool hasTag (std::string_view k) const noexcept
 Checks if this Feature has a tag with the given key.
 
bool hasTag (std::string_view k, std::string_view v) const noexcept
 Checks if this Feature has a tag with the given key and value.
 
Geometry
Box bounds () const noexcept
 The bounding box of this Feature.
 
Coordinate xy () const noexcept
 The Mercator-projected x/y coordinate of a Node, or the center point of the bounding box for a Way or Relation.
 
int32_t x () const noexcept
 The Mercator-projected x-coordinate of a Node, or the horizontal midpoint of the bounding box for a Way or Relation.
 
int32_t y () const noexcept
 The Mercator-projected y-coordinate of a Node, or the vertical midpoint of the bounding box for a Way or Relation.
 
double lon () const noexcept
 The longitude of this feature (in WGS-84 degrees).
 
double lat () const noexcept
 The latitude of this feature (in WGS-84 degrees).
 
Coordinate centroid () const
 Computes the centroid of this Feature.
 
double area () const
 Measures the area of this Feature.
 
double length () const
 Measures the length of this Feature.
 
GEOSGeometry * toGeometry (GEOSContextHandle_t geosContext) const
 Creates a GEOSGeometry based on this Feature's geometry.
 
Related Features
Nodes nodes () const
 The nodes of this Way.
 
Nodes nodes (const char *query) const
 The nodes of this Way that match the given query.
 
Features members () const
 The members of this Relation.
 
Features members (const char *query) const
 The members of this Relation that match the given query.
 
Features parents () const
 The parent relations of this Feature (and the parent ways for a Node).
 
Features parents (const char *query) const
 The parent relations of this Feature (and the parent ways for a Node) that match the given query.
 
Access to the Low-Level API
FeaturePtr ptr () const noexcept
 Pointer to the stored data of this Feature.
 
FeatureStorestore () const noexcept
 Pointer to the FeatureStore which contains this Feature.
 

Detailed Description

A geographic feature.

Constructor & Destructor Documentation

◆ Feature()

geodesk::Feature::Feature ( FeatureStore * store,
FeaturePtr ptr )

Member Function Documentation

◆ area()

double geodesk::Feature::area ( ) const

Measures the area of this Feature.

Returns
area (in square meters), or 0 if the feature is not polygonal
Exceptions
QueryExceptionif one or more tiles that contain the geometry of a Relation are missing

◆ belongsToRelation()

bool geodesk::Feature::belongsToRelation ( ) const
noexcept

true if this Feature belongs to at least one Relation.

◆ bounds()

Box geodesk::Feature::bounds ( ) const
noexcept

The bounding box of this Feature.

Returns
The Feature's bounding box (in Mercator projection)

◆ centroid()

Coordinate geodesk::Feature::centroid ( ) const

Computes the centroid of this Feature.

Returns
the Feature's centroid (in Mercator projection)
Exceptions
QueryExceptionif one or more tiles that contain the geometry of a Relation are missing

◆ format()

char * geodesk::Feature::format ( char * buf) const
noexcept

Formats the string representation (e.g. "node/123456") of this Feature into the provided buffer.

Appends a null-terminator at the end of the output, and returns a pointer to the null-terminator, allowing easy concatenation.

Parameters
bufpointer to a char array of sufficient size
Returns
a pointer to the null-terminator of the string in buf

◆ hasTag() [1/2]

bool geodesk::Feature::hasTag ( std::string_view k) const
noexcept

Checks if this Feature has a tag with the given key.

◆ hasTag() [2/2]

bool geodesk::Feature::hasTag ( std::string_view k,
std::string_view v ) const
noexcept

Checks if this Feature has a tag with the given key and value.

◆ id()

int64_t geodesk::Feature::id ( ) const
noexcept

The ID of this Feature.

Returns
the ID of the Feature

◆ isAnonymousNode()

bool geodesk::Feature::isAnonymousNode ( ) const
noexcept

true if this Feature is an anonymous node.

An anonymous node is a Node that has no tags and does not belong to any relation; it merely exists as a vertex of a Way. Its ID is always 0 and its FeaturePtr is nullptr.

◆ isArea()

bool geodesk::Feature::isArea ( ) const
noexcept

true if this Feature is an area (represented by either a Way or Relation).

◆ isNode()

bool geodesk::Feature::isNode ( ) const
noexcept

true if this Feature is a Node.

◆ isRelation()

bool geodesk::Feature::isRelation ( ) const
noexcept

true if this Feature is a Relation.

◆ isWay()

bool geodesk::Feature::isWay ( ) const
noexcept

true if this Feature is a Way.

◆ label()

std::string geodesk::Feature::label ( ) const

Creates a short descriptive label.

This is usually a combination of the type and name, such as hotel "Four Seasons".

◆ lat()

double geodesk::Feature::lat ( ) const
noexcept

The latitude of this feature (in WGS-84 degrees).

For a Way or Relation, this is the vertical midpoint of its bounding box.

◆ length()

double geodesk::Feature::length ( ) const

Measures the length of this Feature.

Returns
length (in meters), or 0 if the feature is not lineal
Exceptions
QueryExceptionif one or more tiles that contain the geometry of a Relation are missing

◆ lon()

double geodesk::Feature::lon ( ) const
noexcept

The longitude of this feature (in WGS-84 degrees).

For a Way or Relation, this is the horizontal midpoint of its bounding box.

◆ members() [1/2]

Features geodesk::Feature::members ( ) const

The members of this Relation.

Returns
an ordered collection of Feature objects

◆ members() [2/2]

Features geodesk::Feature::members ( const char * query) const

The members of this Relation that match the given query.

Parameters
querya query in GOQL format
Returns
an ordered collection of Feature objects
Exceptions
QueryExceptionif the query is malformed.

◆ nodes() [1/2]

Nodes geodesk::Feature::nodes ( ) const

The nodes of this Way.

Returns
an ordered collection of Node objects

◆ nodes() [2/2]

Nodes geodesk::Feature::nodes ( const char * query) const

The nodes of this Way that match the given query.

Parameters
querya query in GOQL format
Returns
an ordered collection of Node objects
Exceptions
QueryExceptionif the query is malformed.

◆ operator[]()

TagValue geodesk::Feature::operator[] ( std::string_view key) const
noexcept

Obtains the tag value for the given key.

Returns
the tag's value (or an empty string if the feature doesn't have a tag with this key)

◆ parents() [1/2]

Features geodesk::Feature::parents ( ) const

The parent relations of this Feature (and the parent ways for a Node).

Returns
a collection of Relation objects (Way and Relation for Node)

◆ parents() [2/2]

Features geodesk::Feature::parents ( const char * query) const

The parent relations of this Feature (and the parent ways for a Node) that match the given query.

Parameters
querya query in GOQL format
Returns
a collection of Relation objects (Way and Relation for Node)
Exceptions
QueryExceptionif the query is malformed.

◆ ptr()

FeaturePtr geodesk::Feature::ptr ( ) const
noexcept

Pointer to the stored data of this Feature.

If this Feature is an anonymous node, the FeaturePtr will be a nullptr

◆ role()

StringValue geodesk::Feature::role ( ) const
noexcept

The Feature's role in its Relation, if it was returned via members() or Features::membersOf(), otherwise an empty string.

Returns
the Feature's role (or an empty string)

◆ store()

FeatureStore * geodesk::Feature::store ( ) const
noexcept

Pointer to the FeatureStore which contains this Feature.

◆ tags()

Tags geodesk::Feature::tags ( ) const
noexcept

A collection of the Feature's tags.

◆ toGeometry()

GEOSGeometry * geodesk::Feature::toGeometry ( GEOSContextHandle_t geosContext) const

Creates a GEOSGeometry based on this Feature's geometry.

Coordinates will be in Mercator projection. The caller assumes ownership of the newly created GEOSGeometry and is responsible for its cleanup.

This method is only available if build option GEODESK_WITH_GEOS is enabled (off by default).

Parameters
geosContextThe GEOS context o use
Returns
the pointer to the newly-created GEOSGeometry

◆ toString()

std::string geodesk::Feature::toString ( ) const

Creates a std::string with the Feature's type and ID.

Returns
a std::string (e.g. "node/123456")

◆ type()

FeatureType geodesk::Feature::type ( ) const
noexcept

The Feature's type.

Returns
NODE, WAY or RELATION

◆ typeName()

const char * geodesk::Feature::typeName ( ) const
noexcept

"node", "way" or "relation"

Returns
pointer null-terminated constant string

◆ x()

int32_t geodesk::Feature::x ( ) const
noexcept

The Mercator-projected x-coordinate of a Node, or the horizontal midpoint of the bounding box for a Way or Relation.

◆ xy()

Coordinate geodesk::Feature::xy ( ) const
noexcept

The Mercator-projected x/y coordinate of a Node, or the center point of the bounding box for a Way or Relation.

◆ y()

int32_t geodesk::Feature::y ( ) const
noexcept

The Mercator-projected y-coordinate of a Node, or the vertical midpoint of the bounding box for a Way or Relation.


The documentation for this class was generated from the following file: