9#include "gdal/ogr_spatialref.h"
19 static double cos2(
double angle) {
20 return pow(cos((
math::PI / 180) * angle), 2);
24 return pow(angle.
cos(), 2);
27 static double sin2(
double angle) {
28 return pow(sin((
math::PI / 180) * angle), 2);
32 return pow(angle.
sin(), 2);
36 using T = std::remove_cvref_t<
decltype(shape)>;
37 auto centroid = shape.centroid();
38 OGRSpatialReference metric;
39 metric.SetAE(centroid.y, centroid.x, 0, 0);
40 metric.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
42 OGRCoordinateTransformation * toMetric = OGRCreateCoordinateTransformation(&
spatialReference, &metric);
43 if(toMetric ==
nullptr || asOGR.
raw()->transform(toMetric) != OGRERR_NONE)
44 throw std::runtime_error(
"Could not transform geometry to metric");
45 OCTDestroyCoordinateTransformation(OGRCoordinateTransformation::ToHandle(toMetric));
46 return std::move(asOGR).narrowTo<T>().value_or_throw();
49 static inline OGRSpatialReference initWGS84(){
50 OGRSpatialReference wgs84 = OGRSpatialReference();
51 wgs84.importFromEPSG(4326);
52 wgs84.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
57 constexpr static double flattening = 1.0 / 298.257223563;
71 static double distance(
double lambdaA,
double phiA,
double lambdaB,
double phiB,
bool exact =
true) {
75 double S = sin2(G) * cos2(l) + cos2(F) * sin2(l);
76 double C = cos2(G) * cos2(l) + sin2(F) * sin2(l);
82 double T = sqrt(S * C) / w.getAngleValue();
83 double h1 = (3 * T - 1) / (2 * C);
84 double h2 = (3 * T + 1) / (2 * S);
85 double correction = (1 +
flattening * h1 * sin2(F) * cos2(G) -
100 return distance(p.x, p.y, q.x, q.y, exact);
111 return projectToMetric(shape).area();
Utility class for computing distances and areas in metric units for GIS data using the WGS84 Spatial ...
Definition WGS84Ellipsoid.hpp:17
static OGRSpatialReference spatialReference
Definition WGS84Ellipsoid.hpp:59
static double area(fishnet::geometry::Shape auto const &shape)
Definition WGS84Ellipsoid.hpp:110
static constexpr double radiusInMeter
Definition WGS84Ellipsoid.hpp:58
static double distance(double lambdaA, double phiA, double lambdaB, double phiB, bool exact=true)
Definition WGS84Ellipsoid.hpp:71
static double distance(fishnet::geometry::IPoint auto const &p, fishnet::geometry::IPoint auto const &q, bool exact=true) noexcept
Compute the distance between two points in metric units.
Definition WGS84Ellipsoid.hpp:99
static constexpr double flattening
Definition WGS84Ellipsoid.hpp:57
T * raw() const noexcept
Definition OGRAdapterBase.hpp:115
Adapter for an OGRGeometry of statically unknown type, as handed out by a data source.
Definition OGRGeometryAdapter.hpp:83
Degrees implementation of Angle.
Definition Degrees.hpp:11
double sin() const
Definition Degrees.cpp:22
double cos() const
Definition Degrees.cpp:26
Radians implementation of Angle.
Definition Radians.hpp:11
static Radians atan(double tangent)
Definition Radians.cpp:42
Interface for a point.
Definition IPoint.hpp:92
A geometry enclosing an area: a ring, a polygon or a multi-polygon.
Definition IGeometry.hpp:23
static constexpr double PI
Definition Constants.hpp:6
Definition BFSClustering.hpp:5