17#include <gdal/ogr_spatialref.h>
27template<geometry::AnyGeometry G>
30 OGRSpatialReference spatialRef;
31 std::vector<Feature<G>> features;
37 std::unordered_map<std::string,FieldDefinitionVariant> fields;
39 using error_type = std::string;
47 const auto removed = std::ranges::remove_if(this->features,predicate);
48 this->features.erase(removed.begin(),removed.end());
51 template<geometry::AnyGeometry T>
69 explicit VectorLayer(OGRSpatialReference spatialReference):spatialRef(
std::move(spatialReference)){}
71 constexpr size_t size() const noexcept {
72 return this->features.size();
76 return this->
size() == 0;
80 return std::views::all(features) | std::views::transform([](
const auto & feature){
return feature.getGeometry();});
84 return std::views::all(features);
88 return std::views::all(features);
92 return this->spatialRef;
96 this->spatialRef = spatialReference;
108 for(
auto && geometry:geometries){
121 return std::ranges::find_if(this->features,[&g](
const auto & feature){
return feature.getGeometry() == g;}) != std::ranges::end(this->features);
126 remove( [&g](
const auto & feature){
return feature.getGeometry() == g;});
130 features.push_back(std::forward<
Feature<G>>(feature));
134 features.push_back(feature);
138 for(
auto && feature:features){
144 return std::ranges::contains(this->features, feature);
148 remove([&feature](
const auto & f){
return f==feature;});
159 template<FieldValueType T>
161 if(fieldName.length() > 10){
162 return std::unexpected(
"Field name \""+ fieldName+
"\" must not exceed a length of 10 characters");
164 if(this->fields.contains(fieldName))
165 return std::unexpected(
"Field \"" + fieldName +
"\" already exists");
168 this->fields.emplace(fieldName, field);
173 return addField<int>(fieldName,fieldID);
177 return addField<double>(fieldName,fieldID);
181 return addField<std::string>(fieldName,fieldID);
185 return addField<size_t>(fieldName,fieldID);
188 constexpr bool hasField(
const std::string & fieldName)
const noexcept {
189 return this->fields.contains(fieldName);
192 constexpr void removeField(
const std::string & fieldName)
noexcept {
193 this->fields.erase(fieldName);
200 template<geometry::AnyGeometry T>
202 for(
auto [fieldName,fieldVariant]:fields){
203 other.fields.try_emplace(fieldName,fieldVariant);
207 template<FieldValueType T>
210 if(not fields.contains(fieldName)) {
214 std::visit([&optFieldDef](
auto && fieldVariant){
215 using U =
typename std::decay_t<
decltype(fieldVariant)>::value_type;
216 if constexpr(std::same_as<T,U>){
217 optFieldDef = fieldVariant;
219 },fields.at(fieldName));
224 return getField<double>(fieldName);
228 return getField<int>(fieldName);
232 return getField<size_t>(fieldName);
236 return getField<std::string>(fieldName);
239 constexpr const std::unordered_map<std::string,FieldDefinitionVariant> &
getFieldsMap() const noexcept {
Feature implementation storing a geometry and associated attributes.
Definition Feature.hpp:51
Field definition implementation. Defines name, id and data type of a field.
Definition FieldDefinition.hpp:43
Stores the geometries, wrapped in features (which hold the field values / attributes) Keeps track of ...
Definition VectorLayer.hpp:28
constexpr void setSpatialReference(const OGRSpatialReference &spatialReference) noexcept
Definition VectorLayer.hpp:95
constexpr fishnet::Either< FieldDefinition< T >, error_type > addField(const std::string &fieldName, const std::optional< int > &fieldID=std::nullopt) noexcept
Add a field of generic type T to the layer. A field is referenced exclusively by its name.
Definition VectorLayer.hpp:160
constexpr void addAllGeometry(util::forward_range_of< G > auto &&geometries) noexcept
Definition VectorLayer.hpp:107
constexpr fishnet::Either< FieldDefinition< T >, error_type > getField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:208
constexpr bool isEmpty() const noexcept
Definition VectorLayer.hpp:75
constexpr fishnet::Either< FieldDefinition< std::string >, error_type > addTextField(const std::string &fieldName, const std::optional< int > &fieldID=std::nullopt) noexcept
Definition VectorLayer.hpp:180
constexpr void removeFeature(const Feature< G > &feature) noexcept
Definition VectorLayer.hpp:147
constexpr void removeGeometry(const G &g) noexcept
Definition VectorLayer.hpp:125
G geometry_type
Definition VectorLayer.hpp:55
constexpr util::view_of< G > auto getGeometries() const noexcept
Definition VectorLayer.hpp:79
constexpr void clearFields() noexcept
Definition VectorLayer.hpp:196
constexpr bool hasField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:188
constexpr fishnet::Either< FieldDefinition< size_t >, error_type > addSizeField(const std::string &fieldName, const std::optional< int > &fieldID=std::nullopt) noexcept
Definition VectorLayer.hpp:184
constexpr fishnet::Either< FieldDefinition< double >, error_type > addDoubleField(const std::string &fieldName, const std::optional< int > &fieldID=std::nullopt) noexcept
Definition VectorLayer.hpp:176
constexpr fishnet::Either< FieldDefinition< size_t >, error_type > getSizeField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:231
constexpr size_t size() const noexcept
Definition VectorLayer.hpp:71
constexpr const OGRSpatialReference & getSpatialReference() const noexcept
Definition VectorLayer.hpp:91
constexpr void addGeometry(G &&g) noexcept
Definition VectorLayer.hpp:103
constexpr void addFeature(Feature< G > &&feature) noexcept
Definition VectorLayer.hpp:129
constexpr void addFeatures(util::forward_range_of< Feature< G > > auto &&features) noexcept
Definition VectorLayer.hpp:137
constexpr util::view_of< Feature< G > > auto getFeatures() noexcept
Definition VectorLayer.hpp:87
constexpr const std::unordered_map< std::string, FieldDefinitionVariant > & getFieldsMap() const noexcept
Definition VectorLayer.hpp:239
constexpr void addGeometry(const G &g) noexcept
Definition VectorLayer.hpp:99
constexpr fishnet::Either< FieldDefinition< int >, error_type > addIntegerField(const std::string &fieldName, const std::optional< int > &fieldID=std::nullopt) noexcept
Definition VectorLayer.hpp:172
constexpr fishnet::Either< FieldDefinition< int >, error_type > getIntegerField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:227
constexpr bool containsFeature(const Feature< G > &feature) noexcept
Definition VectorLayer.hpp:143
constexpr bool containsGeometry(const G &g) const noexcept
checks if any geometry is equal to the passed geometry WARNING: this method might be slow,...
Definition VectorLayer.hpp:120
constexpr fishnet::Either< FieldDefinition< double >, error_type > getDoubleField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:223
constexpr void removeField(const std::string &fieldName) noexcept
Definition VectorLayer.hpp:192
constexpr fishnet::Either< FieldDefinition< std::string >, error_type > getTextField(const std::string &fieldName) const noexcept
Definition VectorLayer.hpp:235
VectorLayer()=default
Construct a new incomplete Vector Layer object.
constexpr void addFeature(const Feature< G > &feature) noexcept
Definition VectorLayer.hpp:133
constexpr void copyFields(VectorLayer< T > &other) const noexcept
Definition VectorLayer.hpp:201
constexpr util::view_of< Feature< G > > auto getFeatures() const noexcept
Definition VectorLayer.hpp:83
VectorLayer(OGRSpatialReference spatialReference)
Construct a new empty Vector Layer object.
Definition VectorLayer.hpp:69
Definition FunctionalConcepts.hpp:36
Definition CollectionConcepts.hpp:27
Definition CollectionConcepts.hpp:45
Definition BFSClustering.hpp:5