ElevationModel.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2020 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last Port: operation/overlayng/ElevationModel.java 4c88fea52
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Envelope.h> // for composition
// Forward declarations
namespace geos {
namespace geom {
class Geometry;
}
}
namespace geos { // geos.
namespace operation { // geos.operation
namespace overlayng { // geos.operation.overlayng
class GEOS_DLL ElevationModel {
private:
class ElevationCell {
private:
int numZ = 0;
double sumZ = 0.0;
double avgZ;
public:
bool isNull() const
{
return numZ == 0;
}
void add(double z)
{
++numZ;
sumZ += z;
}
void compute()
{
avgZ = DoubleNotANumber;
if (numZ > 0)
avgZ = sumZ / numZ;
}
double getZ() const
{
return avgZ;
}
};
static const int DEFAULT_CELL_NUM;
geom::Envelope extent;
int numCellX;
int numCellY;
double cellSizeX;
double cellSizeY;
std::vector<ElevationCell> cells;
bool isInitialized = false;
bool hasZValue = false;
double averageZ = DoubleNotANumber;
void init();
ElevationCell& getCell(double x, double y); //, bool isCreateIfMissing);
int getCellOffset(int ix, int iy) {
return (numCellX * iy + ix);
}
protected:
void add(double x, double y, double z);
public:
static std::unique_ptr<ElevationModel> create(const geom::Geometry& geom1,
const geom::Geometry& geom2);
static std::unique_ptr<ElevationModel> create(const geom::Geometry& geom1);
ElevationModel(const geom::Envelope& extent, int numCellX, int numCellY);
void add(const geom::Geometry& geom);
double getZ(double x, double y);
void populateZ(geom::Geometry& geom);
};
} // namespace geos.operation.overlayng
} // namespace geos.operation
} // namespace geos
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::operation::overlayng::ElevationModel::getZ
double getZ(double x, double y)
geos::operation::overlayng::ElevationModel::populateZ
void populateZ(geom::Geometry &geom)
Computes Z values for any missing Z values in a geometry, using the computed model.
geos::geom
Definition Angle.h:26
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38