GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
Features.h
Go to the documentation of this file.
1// Copyright (c) 2024 Clarisma / GeoDesk contributors
2// SPDX-License-Identifier: LGPL-3.0-only
3
4#pragma once
5
6#include <vector>
9#include <geodesk/geom/Box.h>
10
11namespace geodesk
12{
13class Feature;
14class Nodes;
15class Ways;
16class Relations;
17}
18
19class GEOSGeometry;
20class GEOSContextHandle_t;
21class OGRGeometry;
22
23namespace geodesk {
24
123{
124public:
130 Features(const char* golFile);
131
135 Features(const Features& other);
136
139
143 operator bool() const;
144
147 bool operator!() const;
148
151 bool isEmpty() const;
152
155 bool contains(const Feature& feature) const;
156
160
167 Features operator()(const char* query) const;
168
172 Nodes nodes() const;
173
181 Nodes nodes(const char* query) const;
182
186 Ways ways() const;
187
195 Ways ways(const char* query) const;
196
201
209 Relations relations(const char* query) const;
210
214
223 std::optional<Feature> first() const;
224
232 Feature one() const;
233
236 operator std::vector<Feature>() const;
237
242 operator std::vector<FeaturePtr>() const;
243
246 void addTo(std::vector<Feature>& features) const;
247
251 void addTo(std::vector<FeaturePtr>& features) const;
252
256
259 uint64_t count() const;
260
267 double length() const;
268
275 double area() const;
276
280
285 Features operator()(const Box& box) const;
286
292
296 Features operator()(const Feature& feature) const;
297
304 Features intersecting(const Feature& feature) const;
305
314 Features intersecting(GEOSContextHandle_t context, const GEOSGeometry* geom) const;
315
322 Features within(const Feature& feature) const;
323
332 Features within(GEOSContextHandle_t context, const GEOSGeometry* geom) const;
333
340 Features containing(const Feature& feature) const;
341
351 Features containing(GEOSContextHandle_t context, const GEOSGeometry* geom) const;
352
357
364 Features containingLonLat(double lon, double lat) const;
365
372 Features crossing(const Feature& feature) const;
373
382 Features crossing(GEOSContextHandle_t context, const GEOSGeometry* geom) const;
383
390 Features maxMetersFrom(double distance, Coordinate xy) const;
391
399 Features maxMetersFrom(double distance, double lon, double lat) const;
400
404
407 Features nodesOf(const Feature& feature) const;
408
411 Features membersOf(const Feature& feature) const;
412
416 Features parentsOf(const Feature& feature) const;
417
421 Features connectedTo(const Feature& feature) const;
422
426
445 template <typename Predicate>
446 Features filter(Predicate predicate) const;
447
451
458 Key key(std::string_view k) const;
459
463
467 FeatureStore* store() const noexcept;
468
470};
471
474class Nodes : public Features
475{
476};
477
480class Ways : public Features
481{
482};
483
486class Relations : public Features
487{
488};
489
490} // namespace geodesk
491
492
493
An axis-aligned bounding box.
Definition Box.h:40
A pair of Cartesian coordinate values.
Definition Coordinate.h:17
A geographic feature.
Definition Feature.h:28
A collection of geographic features.
Definition Features.h:123
Features(const char *golFile)
Creates a collection that contains all features in the given Geographic Object Library.
Ways ways() const
Only ways.
Features intersecting(GEOSContextHandle_t context, const GEOSGeometry *geom) const
Only features whose geometry intersects geom.
Ways ways(const char *query) const
Only ways that match the given query.
Features containingLonLat(double lon, double lat) const
Only features whose geometry contains the given location.
double length() const
Computes the total length (in meters) of the features in this collection.
Features containing(const Feature &feature) const
Only features whose geometry contains the given Feature.
Features maxMetersFrom(double distance, double lon, double lat) const
Only features whose closest point lies within distance meters of the given location.
bool contains(const Feature &feature) const
Checks if the specified Feature exists in this collection.
Features nodesOf(const Feature &feature) const
Only nodes that belong to the given Way.
Features containing(GEOSContextHandle_t context, const GEOSGeometry *geom) const
Only features whose geometry contains geom.
void addTo(std::vector< FeaturePtr > &features) const
Appends the Feature objects in this collection to the given std::vector as FeaturePtr pointers.
FeatureStore * store() const noexcept
Returns a pointer to the FeatureStore which contains the features in this collection.
Features crossing(const Feature &feature) const
Only features whose geometry crosses the given Feature.
Features membersOf(const Feature &feature) const
Only features that belong to the given Relation.
Relations relations() const
Only relations.
Features filter(Predicate predicate) const
Only features that match the given predicate.
Feature one() const
Returns the one and only Feature in this collection.
Features within(const Feature &feature) const
Only features that lie entirely inside the geometry of the given Feature.
Relations relations(const char *query) const
Only relations that match the given query.
Features within(GEOSContextHandle_t context, const GEOSGeometry *geom) const
Only features that lie entirely inside geom.
void addTo(std::vector< Feature > &features) const
Appends the Feature objects in this collection to the given std::vector.
Features parentsOf(const Feature &feature) const
Only features that are parent relations of the given Feature (or parent ways of the given Node).
std::optional< Feature > first() const
Returns the first Feature in this collection, or std::nullopt if the collection is empty.
Features operator()(const char *query) const
Only features that match the given query.
Nodes nodes() const
Only nodes.
double area() const
Computes the total area (in square meters) of the features in this collection.
Features(const Features &other)
Creates a collection with all the features in the other collection.
Features operator()(const Box &box) const
Only features whose bounding box intersects the given bounding box.
uint64_t count() const
Returns the total number of features in this collection.
Features intersecting(const Feature &feature) const
Only features whose geometry intersects the given Feature.
Features crossing(GEOSContextHandle_t context, const GEOSGeometry *geom) const
Only features whose geometry crosses geom.
Key key(std::string_view k) const
Obtains a Key for the given string, which can be used for faster tag-value lookups.
Features operator()(const Feature &feature) const
Only features whose geometry intersects the given Feature (short form of intersecting())
bool operator!() const
Returns true if this collection contains no features.
Features operator()(Coordinate xy) const
Only features whose bounding box contains the given Coordinate.
Features maxMetersFrom(double distance, Coordinate xy) const
Only features whose closest point lies within distance meters of xy.
bool isEmpty() const
Returns true if this collection contains no features.
Features connectedTo(const Feature &feature) const
Only features that share a common node with the given Feature.
Nodes nodes(const char *query) const
Only nodes that match the given query.
Features containing(Coordinate xy) const
Only features whose geometry contains the given Coordinate.
A lightweight wrapper for a key string.
Definition Key.h:44
A collection containing only Node features.
Definition Features.h:475
A collection containing only Relation features.
Definition Features.h:487
A collection containing only Way features.
Definition Features.h:481
Definition Feature.h:11