Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions capi/geos_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,5 +2061,15 @@ extern "C" {
return GEOSCoverageSimplifyVW_r(handle, input, tolerance, preserveBoundary);
}

Geometry*
GEOSCoverageSimplifyVWWithProgress(const Geometry* input, double tolerance,
int preserveBoundary,
GEOSProgressCallback_r progressFunc,
void* progressUserData)
{
return GEOSCoverageSimplifyVWWithProgress_r(
handle, input, tolerance, preserveBoundary, progressFunc, progressUserData);
}


} /* extern "C" */
68 changes: 67 additions & 1 deletion capi/geos_c.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ typedef void (*GEOSMessageHandler)(GEOS_PRINTF_FORMAT const char *fmt, ...)
*/
typedef void (*GEOSMessageHandler_r)(const char *message, void *userdata);


/**
* A GEOS progression callback function.
*
* Such function takes a progression ratio, and an optional message.
*
* \param progressRatio Progression ratio (between 0 and 1)
* \param message Information message (can be NULL)
* \param userdata the user data pointer that was passed to GEOS together with
* this callback.
*/
typedef void (*GEOSProgressCallback_r)(double progressRatio,
const char* message, void* userdata);


/*
* When we're included by geos_c.cpp, these types are #defined to the
* C++ definitions via preprocessor. We don't touch them to allow the
Expand Down Expand Up @@ -886,6 +901,16 @@ GEOSCoverageSimplifyVW_r(
double tolerance,
int preserveBoundary);

/** \see GEOSCoverageSimplifyVWWithProgress */
extern GEOSGeometry GEOS_DLL *
GEOSCoverageSimplifyVWWithProgress_r(
GEOSContextHandle_t extHandle,
const GEOSGeometry* input,
double tolerance,
int preserveBoundary,
GEOSProgressCallback_r progressFunc,
void* progressUserData);

/** \see GEOSCoverageCleanParams_create */
extern GEOSCoverageCleanParams GEOS_DLL *
GEOSCoverageCleanParams_create_r(
Expand Down Expand Up @@ -1076,6 +1101,13 @@ extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(
GEOSContextHandle_t handle,
const GEOSGeometry* g);

/** \see GEOSUnaryUnion */
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnionWithProgress_r(
GEOSContextHandle_t handle,
const GEOSGeometry* g,
GEOSProgressCallback_r progressFunc,
void* progressUserData);

/** \see GEOSUnaryUnionPrec */
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnionPrec_r(
GEOSContextHandle_t handle,
Expand Down Expand Up @@ -4321,6 +4353,40 @@ extern GEOSGeometry GEOS_DLL * GEOSCoverageSimplifyVW(
double tolerance,
int preserveBoundary);

/**
* Operates on a coverage (represented as a list of polygonal geometry
* with exactly matching edge geometry) to apply a Visvalingam–Whyatt
* simplification to the edges, reducing complexity in proportion with
* the provided tolerance, while retaining a valid coverage (no edges
* will cross or touch after the simplification).
* Geometries never disappear, but they may be simplified down to just
* a triangle. Also, some invalid geoms (such as Polygons which have too
* few non-repeated points) will be returned unchanged.
* If the input dataset is not a valid coverage due to overlaps,
* it will still be simplified, but invalid topology such as crossing
* edges will still be invalid.
*
* \param input The polygonal coverage to access,
* stored in a geometry collection. All members must be POLYGON
* or MULTIPOLYGON.
* \param tolerance A tolerance parameter in linear units.
* \param preserveBoundary Use 1 to preserve the outside edges
* of the coverage without simplification,
* 0 to allow them to be simplified.
* \param progressFunc Progress callback (or null)
* \param progressUserData User data passed to progress callback (can be null)
* \return A collection containing the simplified geometries, or null
* on error.
*
* \since 3.14
*/
extern GEOSGeometry GEOS_DLL * GEOSCoverageSimplifyVWWithProgress(
const GEOSGeometry* input,
double tolerance,
int preserveBoundary,
GEOSProgressCallback_r progressFunc,
void* progressUserData);

/**
* Create a default GEOSCoverageCleanParams object for controlling
* the way invalid polygon interactions are repaird by \ref GEOSCoverageCleanWithParams.
Expand Down Expand Up @@ -5328,7 +5394,7 @@ extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry*
extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);

/**
* Tests if geometry g1 is completely within g2,
* Tests if geometry g1 is completely within g2,
* but not wholly contained in the boundary of g2.
* \param g1 Input geometry
* \param g2 Input geometry
Expand Down
42 changes: 40 additions & 2 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
#include <geos/util/Interrupt.h>
#include <geos/util/UniqueCoordinateArrayFilter.h>
#include <geos/util/Machine.h>
#include <geos/util/Progress.h>
#include <geos/version.h>

// This should go away
Expand Down Expand Up @@ -1666,6 +1667,24 @@
});
}

Geometry*
GEOSUnaryUnionWithProgress_r(GEOSContextHandle_t extHandle, const Geometry* g,

Check warning on line 1671 in capi/geos_ts_c.cpp

View check run for this annotation

Codecov / codecov/patch

capi/geos_ts_c.cpp#L1671

Added line #L1671 was not covered by tests
GEOSProgressCallback_r progressFunc,
void* progressUserData)
{
geos::util::ProgressFunction progressFunction(
[progressFunc, progressUserData](double progress, const char* message)

Check warning on line 1676 in capi/geos_ts_c.cpp

View check run for this annotation

Codecov / codecov/patch

capi/geos_ts_c.cpp#L1676

Added line #L1676 was not covered by tests
{
progressFunc(progress, message, progressUserData);
});

Check warning on line 1679 in capi/geos_ts_c.cpp

View check run for this annotation

Codecov / codecov/patch

capi/geos_ts_c.cpp#L1678-L1679

Added lines #L1678 - L1679 were not covered by tests

return execute(extHandle, [&]() {
std::unique_ptr<Geometry> g3(g->Union(&progressFunction));
g3->setSRID(g->getSRID());
return g3.release();
});
}

Check warning on line 1686 in capi/geos_ts_c.cpp

View check run for this annotation

Codecov / codecov/patch

capi/geos_ts_c.cpp#L1681-L1686

Added lines #L1681 - L1686 were not covered by tests

Geometry*
GEOSUnaryUnionPrec_r(GEOSContextHandle_t extHandle, const Geometry* g1, double gridSize)
{
Expand Down Expand Up @@ -4522,6 +4541,25 @@
double tolerance,
int preserveBoundary)
{
return GEOSCoverageSimplifyVWWithProgress_r(extHandle, input, tolerance,
preserveBoundary,
nullptr, nullptr);
}

Geometry*
GEOSCoverageSimplifyVWWithProgress_r(GEOSContextHandle_t extHandle,
const Geometry* input,
double tolerance,
int preserveBoundary,
GEOSProgressCallback_r progressFunc,
void* progressUserData)
{
geos::util::ProgressFunction progressFunction(
[progressFunc, progressUserData](double progress, const char* message)

Check warning on line 4558 in capi/geos_ts_c.cpp

View check run for this annotation

Codecov / codecov/patch

capi/geos_ts_c.cpp#L4558

Added line #L4558 was not covered by tests
{
progressFunc(progress, message, progressUserData);
});

using geos::coverage::CoverageSimplifier;

return execute(extHandle, [&]() -> Geometry* {
Expand All @@ -4536,10 +4574,10 @@
CoverageSimplifier cov(coverage);
std::vector<std::unique_ptr<Geometry>> simple;
if (preserveBoundary == 1) {
simple = cov.simplifyInner(tolerance);
simple = cov.simplifyInner(tolerance, progressFunc ? progressFunction : geos::util::defaultProgress);
}
else if (preserveBoundary == 0) {
simple = cov.simplify(tolerance);
simple = cov.simplify(tolerance, progressFunc ? progressFunction : geos::util::defaultProgress);
}
else return nullptr;

Expand Down
5 changes: 4 additions & 1 deletion include/geos/coverage/CoverageBoundarySegmentFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <geos/geom/Coordinate.h>
#include <geos/geom/LineSegment.h>
#include <geos/export.h>
#include <geos/util/Progress.h>

namespace geos {
namespace geom {
Expand Down Expand Up @@ -57,7 +58,9 @@ class CoverageBoundarySegmentFinder : public geos::geom::CoordinateSequenceFilte


static LineSegment::UnorderedSet
findBoundarySegments(const std::vector<const Geometry*>& geoms);
findBoundarySegments(const std::vector<const Geometry*>& geoms,
const util::ProgressFunction& progressFunction = util::defaultProgress);


static bool isBoundarySegment(
const LineSegment::UnorderedSet& boundarySegs,
Expand Down
4 changes: 3 additions & 1 deletion include/geos/coverage/CoverageEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/LineSegment.h>
#include <geos/util.h>
#include <geos/util/Progress.h>

// Forward declarations
namespace geos {
Expand Down Expand Up @@ -116,7 +117,8 @@ class GEOS_DLL CoverageEdge {

static std::unique_ptr<MultiLineString> createLines(
const std::vector<CoverageEdge*>& edges,
const GeometryFactory* geomFactory);
const GeometryFactory* geomFactory,
const util::ProgressFunction& progressFunction = util::defaultProgress);

std::unique_ptr<LineString> toLineString(
const GeometryFactory* geomFactory);
Expand Down
17 changes: 11 additions & 6 deletions include/geos/coverage/CoverageRingEdges.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <geos/geom/Coordinate.h>
#include <geos/geom/LineSegment.h>
#include <geos/coverage/CoverageEdge.h> // to materialize CoverageEdge
#include <geos/util/Progress.h>

#include <set>
#include <map>
Expand Down Expand Up @@ -72,10 +73,11 @@

public:

CoverageRingEdges(const std::vector<const Geometry*>& coverage)
CoverageRingEdges(const std::vector<const Geometry*>& coverage,

Check warning on line 76 in include/geos/coverage/CoverageRingEdges.h

View check run for this annotation

Codecov / codecov/patch

include/geos/coverage/CoverageRingEdges.h#L76

Added line #L76 was not covered by tests
const util::ProgressFunction& progressFunction = util::defaultProgress)
: m_coverage(coverage)
{
build();
build(progressFunction);

Check warning on line 80 in include/geos/coverage/CoverageRingEdges.h

View check run for this annotation

Codecov / codecov/patch

include/geos/coverage/CoverageRingEdges.h#L80

Added line #L80 was not covered by tests
};


Expand All @@ -96,14 +98,15 @@
/**
* Recreates the polygon coverage from the current edge values.
*
* @param progressFunction Progress function or null
* @return an array of polygonal geometries representing the coverage
*/
std::vector<std::unique_ptr<Geometry>> buildCoverage() const;
std::vector<std::unique_ptr<Geometry>> buildCoverage(const util::ProgressFunction& progressFunction = util::defaultProgress) const;


private:

void build();
void build(const util::ProgressFunction& progressFunction = util::defaultProgress);

void addRingEdges(
const LinearRing* ring,
Expand Down Expand Up @@ -140,10 +143,12 @@
const CoordinateSequence& ring);

Coordinate::UnorderedSet findMultiRingNodes(
const std::vector<const Geometry*>& coverage);
const std::vector<const Geometry*>& coverage,
const util::ProgressFunction& progressFunction = util::defaultProgress);

Coordinate::UnorderedSet findBoundaryNodes(
LineSegment::UnorderedSet& lineSegments);
LineSegment::UnorderedSet& lineSegments,
const util::ProgressFunction& progressFunction = util::defaultProgress);

std::unique_ptr<Geometry> buildPolygonal(
const Geometry* geom) const;
Expand Down
24 changes: 17 additions & 7 deletions include/geos/coverage/CoverageSimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>
#include <memory>
#include <geos/export.h>
#include <geos/util/Progress.h>


namespace geos {
Expand Down Expand Up @@ -87,15 +88,18 @@ class GEOS_DLL CoverageSimplifier {
*
* @param coverage a set of polygonal geometries forming a coverage
* @param tolerance the simplification tolerance
* @param progressFunction Progress function
* @return the simplified polygons
*/
static std::vector<std::unique_ptr<Geometry>> simplify(
std::vector<const Geometry*>& coverage,
double tolerance);
double tolerance,
const util::ProgressFunction& progressFunction = util::defaultProgress);

static std::vector<std::unique_ptr<Geometry>> simplify(
const std::vector<std::unique_ptr<Geometry>>& coverage,
double tolerance);
double tolerance,
const util::ProgressFunction& progressFunction = util::defaultProgress);

/**
* Simplifies the inner boundaries of a set of polygonal geometries forming a coverage,
Expand All @@ -104,35 +108,40 @@ class GEOS_DLL CoverageSimplifier {
*
* @param coverage a set of polygonal geometries forming a coverage
* @param tolerance the simplification tolerance
* @param progressFunction Progress function
* @return the simplified polygons
*/
static std::vector<std::unique_ptr<Geometry>> simplifyInner(
std::vector<const Geometry*>& coverage,
double tolerance);
double tolerance,
const util::ProgressFunction& progressFunction = util::defaultProgress);

static std::vector<std::unique_ptr<Geometry>> simplifyInner(
const std::vector<std::unique_ptr<Geometry>>& coverage,
double tolerance);
double tolerance,
const util::ProgressFunction& progressFunction = util::defaultProgress);

/**
* Computes the simplified coverage, preserving the coverage topology.
*
* @param tolerance the simplification tolerance
* @param progressFunction Progress function
* @return the simplified polygons
*/
std::vector<std::unique_ptr<Geometry>> simplify(
double tolerance);
double tolerance, const util::ProgressFunction& progressFunction = util::defaultProgress);

/**
* Computes the inner-boundary simplified coverage,
* preserving the coverage topology,
* and leaving outer boundary edges unchanged.
*
* @param tolerance the simplification tolerance
* @param progressFunction Progress function
* @return the simplified polygons
*/
std::vector<std::unique_ptr<Geometry>> simplifyInner(
double tolerance);
double tolerance, const util::ProgressFunction& progressFunction = util::defaultProgress);


private:
Expand All @@ -145,7 +154,8 @@ class GEOS_DLL CoverageSimplifier {
void simplifyEdges(
std::vector<CoverageEdge*> edges,
const MultiLineString* constraints,
double tolerance);
double tolerance,
const util::ProgressFunction& progressFunction);

void setCoordinates(
std::vector<CoverageEdge*>& edges,
Expand Down
Loading