Skip to content

Commit

Permalink
Merge branch 'main' of github.com:libgeos/geos into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Jun 8, 2022
2 parents 97de7b3 + 5281ccd commit 8f9b3ab
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Improve `test_geos_unit` application error checking and reporting
- Fix MinimumDiameter getMinimumRectangle for flat input (JTS-875, Martin Davis)
- Fix BufferOp inverted ring check (JTS-878, Martin Davis)
- Fix OverlayNG geomunion to avoid lines in result (Martin Davis)

- Changes:

Expand Down
1 change: 1 addition & 0 deletions src/operation/overlayng/OverlayNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ OverlayNG::geomunion(const Geometry* geom, const PrecisionModel* pm, noding::Nod
{
OverlayNG ov(geom, pm);
ov.setNoder(noder);
ov.setStrictMode(true);
return ov.getResult();
}

Expand Down
73 changes: 73 additions & 0 deletions tests/unit/operation/overlayng/CoverageUnionNGTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Test Suite for geos::operation::coverageunionng::OverlayNG class.

#include <tut/tut.hpp>
#include <utility.h>

// geos
#include <geos/operation/overlayng/CoverageUnion.h>

// std
#include <memory>

using namespace geos::geom;
using namespace geos::operation::overlayng;
using geos::io::WKTReader;
using geos::io::WKTWriter;

namespace tut {
//
// Test Group
//

// Common data used by all tests
struct test_coverageunionng_data {

WKTReader r;
WKTWriter w;

void
checkCoverageUnion(const std::string& wkt, const std::string& wktExpected)
{
std::unique_ptr<Geometry> geom = r.read(wkt);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
std::unique_ptr<Geometry> result = CoverageUnion::geomunion(geom.get());
// std::string wkt_result = w.write(result.get());
// std::cout << std::endl << wkt_result << std::endl;
ensure_equals_geometry(result.get(), expected.get());
}

};

typedef test_group<test_coverageunionng_data> group;
typedef group::object object;

group test_coverageunionng_group("geos::operation::overlayng::CoverageUnionNG");

//
// Test Cases
//

// testFilledHole
template<>
template<>
void object::test<1> ()
{
checkCoverageUnion(
"MULTIPOLYGON (((100 200, 200 200, 200 100, 100 100, 100 200), (120 180, 180 180, 180 120, 120 120, 120 180)), ((180 120, 120 120, 120 180, 180 180, 180 120)))",
"POLYGON ((200 200, 200 100, 100 100, 100 200, 200 200))"
);
}

// test3Squares
template<>
template<>
void object::test<2> ()
{
checkCoverageUnion(
"MULTIPOLYGON (((1 4, 3 4, 3 2, 1 2, 1 4)), ((5 4, 5 2, 3 2, 3 4, 5 4)), ((7 4, 7 2, 5 2, 5 4, 7 4)))",
"POLYGON ((3 4, 5 4, 7 4, 7 2, 5 2, 3 2, 1 2, 1 4, 3 4))"
);
}

} // namespace tut
14 changes: 14 additions & 0 deletions util/geosop/GeomFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include <geos/operation/overlayng/OverlayNG.h>
#include <geos/operation/polygonize/Polygonizer.h>
#include <geos/operation/polygonize/BuildArea.h>
#include <geos/operation/overlayng/CoverageUnion.h>
#include <geos/operation/union/CoverageUnion.h>
#include <geos/precision/GeometryPrecisionReducer.h>
#include <geos/simplify/DouglasPeuckerSimplifier.h>
#include <geos/simplify/TopologyPreservingSimplifier.h>
Expand Down Expand Up @@ -532,6 +534,18 @@ GeomFunction::init()
(void)d; // prevent unused variable warning
return new Result( geom->Union( geomB.get() ) );
});
add("unionCoverageNG", 1, 0, Result::typeGeometry, catOverlay,
"union a polygonal coverage",
[](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
(void)geomB; (void)d; // prevent unused variable warning
return new Result( geos::operation::overlayng::CoverageUnion::geomunion(geom.get()) );
});
add("unionCoverage", 1, 0, Result::typeGeometry, catOverlay,
"union a polygonal coverage",
[](const std::unique_ptr<Geometry>& geom, const std::unique_ptr<Geometry>& geomB, double d)->Result* {
(void)geomB; (void)d; // prevent unused variable warning
return new Result( geos::operation::geounion::CoverageUnion::Union(geom.get()) );
});

add("differenceSR", 2, 1, Result::typeGeometry, catOverlay,
"compute difference of geometry A from B, snap-rounding to a precision scale factor",
Expand Down

0 comments on commit 8f9b3ab

Please sign in to comment.