IsValidOp.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright (C) 2021 Martin Davis
*
* 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.
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/operation/valid/PolygonTopologyAnalyzer.h>
#include <geos/operation/valid/TopologyValidationError.h>
#include <geos/util.h>
// Forward declarations
namespace geos {
namespace geom {
class CoordinateXY;
class Geometry;
class Point;
class MultiPoint;
class LineString;
class LinearRing;
class Polygon;
class MultiPolygon;
class GeometryCollection;
}
namespace algorithm {
namespace locate {
class IndexedPointInAreaLocator;
}
}
}
namespace geos { // geos.
namespace operation { // geos.operation
namespace valid { // geos.operation.valid
class GEOS_DLL IsValidOp {
using CoordinateXY = geos::geom::CoordinateXY;
private:
static constexpr int MIN_SIZE_LINESTRING = 2;
static constexpr int MIN_SIZE_RING = 4;
const geom::Geometry* inputGeometry;
bool isInvertedRingValid = false;
std::unique_ptr<TopologyValidationError> validErr;
bool hasInvalidError()
{
return validErr != nullptr;
}
void logInvalid(int code, const geom::CoordinateXY& pt);
bool isValidGeometry(const geom::Geometry* g);
bool isValid(const geom::Point* g);
bool isValid(const geom::MultiPoint* g);
bool isValid(const geom::LineString* g);
bool isValid(const geom::LinearRing* g);
bool isValid(const geom::Polygon* g);
bool isValid(const geom::MultiPolygon* g);
bool isValid(const geom::GeometryCollection* gc);
void checkCoordinatesValid(const geom::CoordinateSequence* coords);
void checkCoordinatesValid(const geom::Polygon* poly);
void checkRingClosed(const geom::LinearRing* ring);
void checkRingsClosed(const geom::Polygon* poly);
void checkRingsPointSize(const geom::Polygon* poly);
void checkRingPointSize(const geom::LinearRing* ring);
void checkTooFewPoints(const geom::LineString* line, std::size_t minSize);
bool isNonRepeatedSizeAtLeast(const geom::LineString* line, std::size_t minSize);
void checkAreaIntersections(PolygonTopologyAnalyzer& areaAnalyzer);
void checkRingSimple(const geom::LinearRing* ring);
void checkHolesInShell(const geom::Polygon* poly);
const CoordinateXY* findHoleOutsideShellPoint(
const geom::LinearRing* hole,
const geom::LinearRing* shell);
void checkHolesNotNested(const geom::Polygon* poly);
void checkShellsNotNested(const geom::MultiPolygon* mp);
void checkInteriorConnected(PolygonTopologyAnalyzer& areaAnalyzer);
public:
IsValidOp(const geom::Geometry* p_inputGeometry)
: inputGeometry(p_inputGeometry)
, validErr(nullptr)
{};
void setSelfTouchingRingFormingHoleValid(bool p_isValid)
{
isInvertedRingValid = p_isValid;
};
static bool isValid(const geom::Geometry* geom)
{
IsValidOp ivo(geom);
return ivo.isValid();
};
static bool isValid(const geom::CoordinateXY& coord)
{
return isValid(&coord);
}
bool isValid();
static bool isValid(const geom::CoordinateXY* coord);
const TopologyValidationError* getValidationError();
};
} // namespace geos.operation.valid
} // namespace geos.operation
} // namespace geos
geos::algorithm::locate::IndexedPointInAreaLocator
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition IndexedPointInAreaLocator.h:54
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::GeometryCollection
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::LineString
Definition LineString.h:66
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::geom::MultiPoint
Definition MultiPoint.h:50
geos::geom::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Point
Definition Point.h:61
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::operation::valid::IsValidOp::IsValidOp
IsValidOp(const geom::Geometry *p_inputGeometry)
Definition IsValidOp.h:222
geos::operation::valid::IsValidOp::isValid
static bool isValid(const geom::CoordinateXY *coord)
geos::operation::valid::IsValidOp::isValid
bool isValid()
geos::operation::valid::IsValidOp::getValidationError
const TopologyValidationError * getValidationError()
geos::operation::valid::IsValidOp::setSelfTouchingRingFormingHoleValid
void setSelfTouchingRingFormingHoleValid(bool p_isValid)
Definition IsValidOp.h:254
geos::operation::valid::IsValidOp::isValid
static bool isValid(const geom::Geometry *geom)
Definition IsValidOp.h:264
geos::operation::valid::TopologyValidationError
Contains information about the nature and location of a geom::Geometry validation error.
Definition TopologyValidationError.h:39
geos::algorithm::locate
Classes which determine the Location of points in geometries.
Definition IndexedPointInAreaLocator.h:40
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos::operation::valid
Provides classes for testing the validity of geometries.
Definition namespaces.h:289
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38