18#include <geos/export.h>
19#include <geos/geom/Coordinate.h>
26class GEOS_DLL Interpolate {
30 template<geom::Ordinate Ord,
typename CoordType>
32 interpolate(
const geom::CoordinateXY& p,
const CoordType& p1,
const CoordType& p2)
34 double p1z = p1.template get<Ord>();
35 double p2z = p2.template get<Ord>();
37 if (std::isnan(p1z)) {
40 if (std::isnan(p2z)) {
49 double dz = p2z - p1z;
55 double dx = (p2.x - p1.x);
56 double dy = (p2.y - p1.y);
58 double seglen = (dx * dx + dy * dy);
59 double xoff = (p.x - p1.x);
60 double yoff = (p.y - p1.y);
61 double plen = (xoff * xoff + yoff * yoff);
62 double frac = std::sqrt(plen / seglen);
63 double zoff = dz * frac;
64 double zInterpolated = p1z + zoff;
69 template<geom::Ordinate Ord,
typename C1,
typename C2>
71 interpolate(
const geom::CoordinateXY& p,
const C1& p1,
const C1& p2,
const C2& q1,
const C2& q2)
73 double zp = interpolate<Ord>(p, p1, p2);
74 double zq = interpolate<Ord>(p, q1, q2);
83 return (zp + zq) / 2.0;
86 template<geom::Ordinate Ord,
typename C1,
typename C2>
88 get(
const C1& p,
const C2& q)
90 double a = p.template get<Ord>();
91 double b = q.template get<Ord>();
98 template<geom::Ordinate Ord,
typename C1,
typename C2>
100 getOrInterpolate(
const C1& p,
const C2& p1,
const C2& p2)
102 double z = p.template get<Ord>();
103 if (!std::isnan(z))
return z;
104 return interpolate<Ord>(p, p1, p2);
108 interpolate(
const geom::CoordinateXY& p,
const geom::CoordinateXY& p1,
const geom::CoordinateXY& p2)
110 (void) p; (void) p1; (void) p2;
111 return DoubleNotANumber;
116 template<
typename CoordType>
118 zInterpolate(
const geom::CoordinateXY& p,
const CoordType& p1,
const CoordType& p2)
120 return interpolate<geom::Ordinate::Z>(p, p1, p2);
124 template<
typename C1,
typename C2>
126 zInterpolate(
const geom::CoordinateXY& p,
const C1& p1,
const C1& p2,
const C2& q1,
const C2& q2)
128 return interpolate<geom::Ordinate::Z>(p, p1, p2, q1, q2);
132 template<
typename CoordType>
134 mInterpolate(
const geom::CoordinateXY& p,
const CoordType& p1,
const CoordType& p2)
136 return interpolate<geom::Ordinate::M>(p, p1, p2);
140 template<
typename C1,
typename C2>
142 mInterpolate(
const geom::CoordinateXY& p,
const C1& p1,
const C1& p2,
const C2& q1,
const C2& q2)
144 return interpolate<geom::Ordinate::M>(p, p1, p2, q1, q2);
148 template<
typename C1,
typename C2>
150 zGet(
const C1& p,
const C2& q)
152 return get<geom::Ordinate::Z>(p, q);
156 template<
typename C1,
typename C2>
158 mGet(
const C1& p,
const C2& q)
160 return get<geom::Ordinate::M>(p, q);
164 template<
typename C1,
typename C2>
166 zGetOrInterpolate(
const C1& p,
const C2& p1,
const C2& p2)
168 return getOrInterpolate<geom::Ordinate::Z>(p, p1, p2);
172 template<
typename C1,
typename C2>
174 mGetOrInterpolate(
const C1& p,
const C2& p1,
const C2& p2)
176 return getOrInterpolate<geom::Ordinate::M>(p, p1, p2);
Basic namespace for all GEOS functionalities.
Definition geos.h:39