Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GEOSCoverageUnion #158

Merged
merged 14 commits into from
May 29, 2019
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# by the Free Software Foundation.
# See the COPYING file for more information.
#
dist: trusty
dist: xenial
sudo: false

language: cpp
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ Changes in 3.8.0
- CAPI: GEOSBuildArea (#952, Even Rouault)
- CAPI: GEOSMakeValid (#952, Even Rouault)
- CAPI: GEOSPolygonize_valid (#727, Dan Baston)
- CAPI: GEOSCoverageUnion (Dan Baston)

- Improvements:
- Improve performance and robustness of GEOSPointOnSurface (Martin Davis)
- Improve performance of GEOSPolygonize for cases with many potential
holes (#748, Dan Baston)
- Improve performance of GEOSPolygonize for cases with many or complex
shells (Dan Baston, Martin Davis)


Changes in 3.7.2
Expand Down
6 changes: 6 additions & 0 deletions capi/geos_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ extern "C" {
return GEOSUnaryUnion_r(handle, g);
}

Geometry*
GEOSCoverageUnion(const Geometry* g)
{
return GEOSCoverageUnion_r(handle, g);
}

Geometry*
GEOSNode(const Geometry* g)
{
Expand Down
10 changes: 10 additions & 0 deletions capi/geos_c.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
const GEOSGeometry* g2);
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
const GEOSGeometry* g);
/* GEOSCoverageUnion is an optimized union algorithm for polygonal inputs that are correctly
* noded and do not overlap. It will not generate an error (return NULL) for inputs that
* do not satisfy this constraint. */
extern GEOSGeometry GEOS_DLL *GEOSCoverageUnion_r(GEOSContextHandle_t handle,
const GEOSGeometry* g);
/* @deprecated in 3.3.0: use GEOSUnaryUnion_r instead */
extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle,
const GEOSGeometry* g);
Expand Down Expand Up @@ -1603,6 +1608,11 @@ extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);

/* GEOSCoverageUnion is an optimized union algorithm for polygonal inputs that are correctly
* noded and do not overlap. It will not generate an error (return NULL) for inputs that
* do not satisfy this constraint. */
extern GEOSGeometry GEOS_DLL *GEOSCoverageUnion(const GEOSGeometry *g);

/* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
Expand Down
27 changes: 27 additions & 0 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include <geos/operation/relate/RelateOp.h>
#include <geos/operation/sharedpaths/SharedPathsOp.h>
#include <geos/operation/union/CascadedPolygonUnion.h>
#include <geos/operation/union/CoverageUnion.h>
#include <geos/operation/valid/IsValidOp.h>
#include <geos/operation/valid/MakeValid.h>
#include <geos/precision/GeometryPrecisionReducer.h>
Expand Down Expand Up @@ -2145,6 +2146,32 @@ extern "C" {
return NULL;
}

Geometry*
GEOSCoverageUnion_r(GEOSContextHandle_t extHandle, const Geometry* g)
{
if(0 == extHandle) {
return NULL;
}

GEOSContextHandleInternal_t* handle = 0;
handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
if(0 == handle->initialized) {
return NULL;
}

try {
return geos::operation::geounion::CoverageUnion::Union(g).release();
}
catch(const std::exception& e) {
handle->ERROR_MESSAGE("%s", e.what());
}
catch(...) {
handle->ERROR_MESSAGE("Unknown exception thrown");
}

return NULL;
}

Geometry*
GEOSUnaryUnion_r(GEOSContextHandle_t extHandle, const Geometry* g)
{
Expand Down
9 changes: 9 additions & 0 deletions include/geos/geom/LineSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <geos/inline.h>

#include <iostream> // for ostream
#include <functional> // for std::hash
#include <memory> // for unique_ptr

// Forward declarations
Expand Down Expand Up @@ -366,6 +367,14 @@ class GEOS_DLL LineSegment {
*/
std::unique_ptr<LineString> toGeometry(const GeometryFactory& gf) const;

struct HashCode {
size_t operator()(const LineSegment & s) const {
size_t h = std::hash<double>{}(s.p0.x);
h ^= (std::hash<double>{}(s.p0.y) << 1);
h ^= (std::hash<double>{}(s.p1.x) << 1);
return h ^ (std::hash<double>{}(s.p1.y) << 1);
}
};
};

std::ostream& operator<< (std::ostream& o, const LineSegment& l);
Expand Down
Loading