/** * Compute the offset curve for a linestring * * @param list * @param lineString * @param offset * @param bufferParameters */ public static void lineStringOffSetCurve(ArrayList<LineString> list, LineString lineString, double offset, BufferParameters bufferParameters) { list.add(lineString.getFactory().createLineString(new OffsetCurveBuilder(lineString.getPrecisionModel(), bufferParameters).getOffsetCurve(lineString.getCoordinates(), offset))); }
/** * This method handles the degenerate cases of single points and lines, * as well as rings. * * @return a Coordinate array representing the curve * or null if the curve is empty */ public Coordinate[] getRingCurve(Coordinate[] inputPts, int side, double distance) { this.distance = distance; if (inputPts.length <= 2) return getLineCurve(inputPts, distance); // optimize creating ring for for zero distance if (distance == 0.0) { return copyCoordinates(inputPts); } OffsetSegmentGenerator segGen = getSegGen(distance); computeRingBufferCurve(inputPts, side, segGen); return segGen.getCoordinates(); }
OffsetSegmentGenerator segGen = getSegGen(posDistance); if (inputPts.length <= 1) { computePointCurve(inputPts[0], segGen); computeSingleSidedBufferCurve(inputPts, isRightSide, segGen); computeLineBufferCurve(inputPts, segGen);
public Coordinate[] getOffsetCurve(Coordinate[] inputPts, double distance) { this.distance = distance; // a zero width offset curve is empty if (distance == 0.0) return null; boolean isRightSide = distance < 0.0; double posDistance = Math.abs(distance); OffsetSegmentGenerator segGen = getSegGen(posDistance); if (inputPts.length <= 1) { computePointCurve(inputPts[0], segGen); } else { computeOffsetCurve(inputPts, isRightSide, segGen); } Coordinate[] curvePts = segGen.getCoordinates(); // for right side line is traversed in reverse direction, so have to reverse generated line if (isRightSide) CoordinateArrays.reverse(curvePts); return curvePts; }
public static Geometry bufferOffsetCurve(Geometry g, double distance) { OffsetCurveBuilder ocb = new OffsetCurveBuilder( g.getFactory().getPrecisionModel(), new BufferParameters()); Coordinate[] pts = g.getCoordinates(); Coordinate[] curvePts = null; if (g instanceof Polygonal) { curvePts = ocb.getRingCurve(pts, 1, distance); } else { curvePts = ocb.getLineCurve(pts, distance); } Geometry curve = g.getFactory().createLineString(curvePts); return curve; }
public static Geometry singleSidedBufferCurve(Geometry geom, double distance) { BufferParameters bufParam = new BufferParameters(); bufParam.setSingleSided(true); OffsetCurveBuilder ocb = new OffsetCurveBuilder( geom.getFactory().getPrecisionModel(), bufParam ); Coordinate[] pts = ocb.getLineCurve(geom.getCoordinates(), distance); Geometry curve = geom.getFactory().createLineString(pts); return curve; }
/** * Compute the offset curve for a polygon, a point or a collection of geometries * @param list * @param geometry * @param offset * @param bufferParameters */ public static void geometryOffSetCurve(ArrayList<LineString> list, Geometry geometry, double offset, BufferParameters bufferParameters) { final List curves = new OffsetCurveSetBuilder(geometry, offset, new OffsetCurveBuilder(geometry.getFactory().getPrecisionModel(), bufferParameters)).getCurves(); final Iterator<SegmentString> iterator = curves.iterator(); while (iterator.hasNext()) { list.add(geometry.getFactory().createLineString(iterator.next().getCoordinates())); } }
private void addLineString(LineString line) { // a zero or negative width buffer of a line/point is empty if (distance <= 0.0 && ! curveBuilder.getBufferParameters().isSingleSided()) return; Coordinate[] coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates()); Coordinate[] curve = curveBuilder.getLineCurve(coord, distance); addCurve(curve, Location.EXTERIOR, Location.INTERIOR); // TESTING //Coordinate[] curveTrim = BufferCurveLoopPruner.prune(curve); //addCurve(curveTrim, Location.EXTERIOR, Location.INTERIOR); }
/** * Add a Point to the graph. */ private void addPoint(Point p) { // a zero or negative width buffer of a line/point is empty if (distance <= 0.0) return; Coordinate[] coord = p.getCoordinates(); Coordinate[] curve = curveBuilder.getLineCurve(coord, distance); addCurve(curve, Location.EXTERIOR, Location.INTERIOR); }
/** * Adds an offset curve for a polygon ring. * The side and left and right topological location arguments * assume that the ring is oriented CW. * If the ring is in the opposite orientation, * the left and right locations must be interchanged and the side flipped. * * @param coord the coordinates of the ring (must not contain repeated points) * @param offsetDistance the distance at which to create the buffer * @param side the side of the ring on which to construct the buffer line * @param cwLeftLoc the location on the L side of the ring (if it is CW) * @param cwRightLoc the location on the R side of the ring (if it is CW) */ private void addPolygonRing(Coordinate[] coord, double offsetDistance, int side, int cwLeftLoc, int cwRightLoc) { // don't bother adding ring if it is "flat" and will disappear in the output if (offsetDistance == 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) return; int leftLoc = cwLeftLoc; int rightLoc = cwRightLoc; if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && Orientation.isCCW(coord)) { leftLoc = cwRightLoc; rightLoc = cwLeftLoc; side = Position.opposite(side); } Coordinate[] curve = curveBuilder.getRingCurve(coord, side, offsetDistance); addCurve(curve, leftLoc, rightLoc); }
private static Geometry buildCurveSet(Geometry g, double dist, BufferParameters bufParams) { // --- now construct curve OffsetCurveBuilder ocb = new OffsetCurveBuilder( g.getFactory().getPrecisionModel(), bufParams); OffsetCurveSetBuilder ocsb = new OffsetCurveSetBuilder(g, dist, ocb); List curves = ocsb.getCurves(); List lines = new ArrayList(); for (Iterator i = curves.iterator(); i.hasNext(); ) { SegmentString ss = (SegmentString) i.next(); Coordinate[] pts = ss.getCoordinates(); lines.add(g.getFactory().createLineString(pts)); } Geometry curve = g.getFactory().buildGeometry(lines); return curve; }
public static Geometry offsetCurve(Geometry geom, double distance) { BufferParameters bufParams = new BufferParameters(); OffsetCurveBuilder ocb = new OffsetCurveBuilder( geom.getFactory().getPrecisionModel(), bufParams ); Coordinate[] pts = ocb.getOffsetCurve(geom.getCoordinates(), distance); Geometry curve = geom.getFactory().createLineString(pts); return curve; }
OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, bufParams);