Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
OGRFieldAdapter.hpp
Go to the documentation of this file.
1#pragma once
2#include <gdal/ogr_feature.h>
4#include <typeindex>
7namespace fishnet{
13public:
14 static OGRFieldType fromTypeIndex(const std::type_index & type) noexcept {
15 if (typeid(double) == type || typeid(float) == type)
16 return OFTReal;
17 if(typeid(int) == type)
18 return OFTInteger;
19 if (typeid(long) == type || typeid(size_t) == type)
20 return OFTInteger64;
21 return OFTString;
22 }
23
24 template<typename T>
25 static void setFieldValue(OGRFeature * feature, const std::string & fieldName, const T & value) noexcept {
26 const char * name = fieldName.c_str();
27 if constexpr(std::same_as<T,int>)
28 feature->SetField(name, value);
29 else if constexpr(std::integral<T>)
30 feature->SetField(name, GIntBig((static_cast<int64_t>(value))));
31 else if constexpr (std::floating_point<T>)
32 feature->SetField(name, static_cast<double>(value));
33 else if constexpr (std::same_as<T,std::string>)
34 feature->SetField(name, value.c_str());
35 else
36 feature->SetField(name, value);
37 }
38};
39
40uint64_t normalizeToShpFileIntField(std::integral auto number) noexcept {
41 const uint64_t SHP_MAX_VALUE = 1000000000000000000ULL;
42 return fishnet::math::normalize(number,SHP_MAX_VALUE);
43}
44
45}
Static Adaptor class for OGRFields.
Definition OGRFieldAdapter.hpp:12
static void setFieldValue(OGRFeature *feature, const std::string &fieldName, const T &value) noexcept
Definition OGRFieldAdapter.hpp:25
static OGRFieldType fromTypeIndex(const std::type_index &type) noexcept
Definition OGRFieldAdapter.hpp:14
static auto normalize(const ValueType value, BoundType upperBound)
Normalizes any value into the range: [0,upperBound)
Definition Normalize.hpp:19
Definition BFSClustering.hpp:5
uint64_t normalizeToShpFileIntField(std::integral auto number) noexcept
Definition OGRFieldAdapter.hpp:40