GEOS 3.14.0dev
ElevationModel.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Sandro Santilli <strk@kbt.io>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last Port: operation/overlayng/ElevationModel.java 4c88fea52
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22
23#include <geos/geom/Envelope.h> // for composition
24
25// Forward declarations
26namespace geos {
27 namespace geom {
28 class Geometry;
29 }
30}
31
32namespace geos { // geos.
33namespace operation { // geos.operation
34namespace overlayng { // geos.operation.overlayng
35
36
65class GEOS_DLL ElevationModel {
66
67private:
68
69 class ElevationCell {
70 private:
71
72 int numZ = 0;
73 double sumZ = 0.0;
74 double avgZ;
75
76 public:
77
78 bool isNull() const
79 {
80 return numZ == 0;
81 }
82
83 void add(double z)
84 {
85 ++numZ;
86 sumZ += z;
87 }
88
89 void compute()
90 {
91 avgZ = DoubleNotANumber;
92 if (numZ > 0)
93 avgZ = sumZ / numZ;
94 }
95
96 double getZ() const
97 {
98 return avgZ;
99 }
100 };
101
102
103 static const int DEFAULT_CELL_NUM;
104 geom::Envelope extent;
105 int numCellX;
106 int numCellY;
107 double cellSizeX;
108 double cellSizeY;
109 std::vector<ElevationCell> cells;
110 bool isInitialized = false;
111 bool hasZValue = false;
112 double averageZ = DoubleNotANumber;
113
114 void init();
115
116 ElevationCell& getCell(double x, double y); //, bool isCreateIfMissing);
117
118 int getCellOffset(int ix, int iy) {
119 return (numCellX * iy + ix);
120 }
121
122protected:
123
124 void add(double x, double y, double z);
125
126
127public:
128
129 static std::unique_ptr<ElevationModel> create(const geom::Geometry& geom1,
130 const geom::Geometry& geom2);
131
132 static std::unique_ptr<ElevationModel> create(const geom::Geometry& geom1);
133
134 ElevationModel(const geom::Envelope& extent, int numCellX, int numCellY);
135
136 void add(const geom::Geometry& geom);
137
138
150 double getZ(double x, double y);
151
152
164
165
166};
167
168} // namespace geos.operation.overlayng
169} // namespace geos.operation
170} // namespace geos
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
A simple elevation model used to populate missing Z values in overlay results.
Definition ElevationModel.h:65
void populateZ(geom::Geometry &geom)
Computes Z values for any missing Z values in a geometry, using the computed model.
Basic namespace for all GEOS functionalities.
Definition geos.h:39