|
| Features (const char *golFile) |
| Creates a collection that contains all features in the given Geographic Object Library.
|
|
| Features (const Features &other) |
| Creates a collection with all the features in the other collection.
|
|
|
| operator bool () const |
| Returns true if this collection contains at least one Feature.
|
|
bool | operator! () const |
| Returns true if this collection is empty.
|
|
bool | contains (const Feature &feature) const |
| Returns true if this collection contains the given Feature.
|
|
|
Features | operator() (const char *query) const |
| Only features that match the given query.
|
|
Nodes | nodes () const |
| Only nodes.
|
|
Nodes | nodes (const char *query) |
| Only nodes that match the given query.
|
|
Ways | ways () const |
| Only ways.
|
|
Ways | ways (const char *query) const |
| Only ways that match the given query.
|
|
Relations | relations () const |
| Only relations.
|
|
Relations | relations (const char *query) const |
| Only relations that match the given query.
|
|
|
std::optional< Feature > | first () const |
| Returns the first Feature in this collection, or std::nullopt if the collection is empty.
|
|
Feature | one () const |
| Returns the one and only Feature in this collection.
|
|
void | addTo (std::vector< Feature > &features) const |
| Appends the Feature objects in this collection to the given std::vector .
|
|
void | addTo (std::vector< FeaturePtr > &features) const |
| Appends the Feature objects in this collection to the given std::vector as FeaturePtr pointers.
|
|
|
uint64_t | count () const |
| Returns the total number of features in this collection.
|
|
double | length () const |
| Calculates the total length (in meters) of the features in this collection.
|
|
double | area () const |
| Calculates the total area (in square meters) of the features in this collection.
|
|
|
Features | operator() (const Box &box) const |
| Only features whose bounding box intersects the given bounding box.
|
|
Features | operator() (Coordinate xy) const |
| Only features whose bounding box contains the given Coordinate.
|
|
Features | operator() (const Feature &feature) const |
| Only features whose geometry intersects with the given Feature (short form of intersecting())
|
|
Features | intersecting (const Feature &feature) const |
| Only features whose geometry intersects with the given Feature.
|
|
Features | within (const Feature &feature) const |
| Only features that lie entirely inside the geometry of the given Feature.
|
|
Features | containing (const Feature &feature) const |
| Only features whose geometry contains the given Feature.
|
|
Features | containing (Coordinate xy) const |
| Only features whose geometry contains the given Coordinate.
|
|
Features | containingLonLat (double lon, double lat) const |
| Only features whose geometry contains the given location.
|
|
Features | crossing (const Feature &feature) const |
| Only features whose geometry crosses the given Feature.
|
|
Features | maxMetersFrom (double distance, Coordinate xy) const |
| Only features whose closest point lies within distance meters of xy .
|
|
Features | maxMetersFrom (double distance, double lon, double lat) const |
| Only features whose closest point lies within distance meters of the given location.
|
|
|
Features | nodesOf (const Feature &feature) const |
| Only nodes that belong to the given Way.
|
|
Features | membersOf (const Feature &feature) const |
| Only features that belong to the given Relation.
|
|
Features | parentsOf (const Feature &feature) const |
| Only features that are parent relations of the given Feature (or parent ways of the given Node).
|
|
Features | connectedTo (const Feature &feature) const |
| Only features that share a common node with the given Feature.
|
|
|
template<typename Predicate > |
Features | filter (Predicate predicate) const |
| Only features that match the given predicate.
|
|
|
FeatureStore * | store () const noexcept |
| Returns a pointer to the FeatureStore which contains the features in this collection.
|
|
A collection of geographic features.
A Features object isn't a classical container; it doesn't actually hold any Feature objects, but merely describes which features should be fetched from a Geographic Object Library. A query is only executed whenever the Features object is iterated, assigned to a container, or when one of its scalar functions (such as count() or length()) is called. This also means that query results are not cached: If you call count() prior to iterating over the Features, two queries will be executed.
Features objects are lightweight and suitable for passing by value. They are threadsafe and can be freely shared among different threads. Their various matchers and filters (and associated resources such as temporary indexes) are shared via refcounting.
To start working with a GOL, simply create a Features
object with the path of its file (the .gol
extension may be omitted):
A collection of geographic features.
Definition Features.h:111
This creates a FeatureStore that manages access to planet.gol
. The world
object now represents a collection of all features stored in the GOL (It is legal to create multiple Features
objects that refer to the same GOL – they will share the same FeatureStore).
To obtain subsets, apply filters using ()
or by calling a named method – or intersect multiple Features
object with &
:
Features hotels = world(
"na[tourism=hotel]");
Features hotelsInParis = hotels & inParis;
Features within(const Feature &feature) const
Only features that lie entirely inside the geometry of the given Feature.
Applying a filter creates a copy of the Features object, with the additional constraint. The original Features object is unaffected.
To retrieve the actual features:
for(Feature hotel : hotelsInParis)
{
std::cout << hotel["name"] << std::endl;
}
std::vector<Feature> hotelList = hotelsInParis;
Feature paris = world("a[boundary=administrative]"
"[admin_level=8][name=Paris]").one();
std::optional<Feature> anyHotel = hotels.
first();
std::optional< Feature > first() const
Returns the first Feature in this collection, or std::nullopt if the collection is empty.
Features has three subclasses: Nodes, Ways and Relations, which contain only Node, Way and Relation objects. Assigning a Features object to a subclass object implicitly filters the collection by type (Assigning a subtype to an incompatible type results in an empty collection):
world("[type=route][route=bus]")
Nodes nodes() const
Only nodes.
Definition Relations.h:11
Upon destruction of last of the Features objects that refer to the same FeatureStore, the Geographic Object Library is automatically closed and all of the FeatureStore's resources are released (This differs from GeoDesk for Java, which requires GOLs to be closed explicitly).
Important: Once a GOL has been closed, all Feature objects retrieved via queries to that GOL are no longer valid; calling any of their methods will result in undefined behavior (The same applies to Tags, Tag, TagValue and StringValue objects).