8000 Add CascadedPolygonUnion bufferUnion by dr-jts · Pull Request #470 · locationtech/jts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add CascadedPolygonUnion bufferUnion #470

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 8000 GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineSegment;
import org.locationtech.jts.geom.TopologyException;
import org.locationtech.jts.geom.util.GeometryCombiner;

/**
Expand Down Expand Up @@ -196,10 +197,35 @@ private Geometry extractByEnvelope(Envelope env, Geometry geom,
}

private Geometry unionFull(Geometry geom0, Geometry geom1) {
Geometry union = geom0.union(geom1);
return union;
try {
return geom0.union(geom1);
}
catch (TopologyException ex) {
/**
* If the overlay union fails,
* try a buffer union, which often succeeds
*/
return unionBuffer(geom0, geom1);
}
}

/**
* Implements union using the buffer-by-zero trick.
* This seems to be more robust than overlay union,
* for reasons somewhat unknown.
*
* @param g0 a geometry
* @param g1 a geometry
* @return the union of the geometries
*/
private static Geometry unionBuffer(Geometry g0, Geometry g1)
{
GeometryFactory factory = g0.getFactory();
Geometry gColl = factory.createGeometryCollection(new Geometry[] { g0, g1 } );
Geometry union = gColl.buffer(0.0);
return union;
}

private boolean isBorderSegmentsSame(Geometry result, Envelope env) {
List<LineSegment> segsBefore = extractBorderSegments(g0, g1, env);

Expand Down
0