Skip to content

Commit

Permalink
Improve BufferByUnion functions
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
  • Loading branch information
dr-jts committed Jun 4, 2021
1 parent 15c0159 commit 93d804d
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.locationtech.jts.geom.GeometryCollection;
import org.locationtech.jts.geom.GeometryCollectionIterator;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.operation.overlayng.OverlayNG;
import org.locationtech.jts.operation.overlayng.OverlayNGRobust;
import org.locationtech.jtstest.geomfunction.Metadata;


Expand Down Expand Up @@ -59,17 +61,29 @@ public static Geometry bufferBySegments(Geometry g, double distance)
return g.union(segBuf);
}

public static Geometry bufferByChains(Geometry g, double distance,
@Metadata(title="Max Chain Size")
public static Geometry bufferBySections(Geometry g, double distance,
@Metadata(title="Section Size")
int maxChainSize)
{
if (maxChainSize <= 0)
throw new IllegalArgumentException("Maximum Chain Size must be specified as an input parameter");
throw new IllegalArgumentException("Section Size must be specified as an input parameter");
Geometry segs = LineHandlingFunctions.extractChains(g, maxChainSize);
double posDist = Math.abs(distance);
Geometry segBuf = bufferByComponents(segs, posDist);
if (distance < 0.0)
return g.difference(segBuf);
return g.union(segBuf);
return OverlayNGRobust.overlay(g, segBuf, OverlayNG.DIFFERENCE);
return OverlayNGRobust.overlay(g, segBuf, OverlayNG.UNION);
}

public static Geometry sectionBuffers(Geometry g, double distance,
@Metadata(title="Section Size")
int maxChainSize)
{
if (maxChainSize <= 0)
throw new IllegalArgumentException("Section Size must be specified as an input parameter");
Geometry segs = LineHandlingFunctions.extractChains(g, maxChainSize);
double posDist = Math.abs(distance);
Geometry segBuf = componentBuffers(segs, posDist);
return segBuf;
}
}

0 comments on commit 93d804d

Please sign in to comment.