/** * Computes the buffer of a geometry for a given buffer distance. * * @param g the geometry to buffer * @param distance the buffer distance * @return the buffer of the input geometry */ public static Geometry bufferOp(Geometry g, double distance) { BufferOp gBuf = new BufferOp(g); Geometry geomBuf = gBuf.getResultGeometry(distance); //BufferDebug.saveBuffer(geomBuf); //BufferDebug.runCount++; return geomBuf; }
/** * Calculate the ring buffer * * @param geom * @param bufferSize * @param bufferParameters * @return * @throws SQLException */ public static Geometry runBuffer(final Geometry geom, final double bufferSize, final BufferParameters bufferParameters) throws SQLException { return BufferOp.bufferOp(geom, bufferSize, bufferParameters); } }
private void computeGeometry() { bufferOriginalPrecision(); if (resultGeometry != null) return; PrecisionModel argPM = argGeom.getFactory().getPrecisionModel(); if (argPM.getType() == PrecisionModel.FIXED) bufferFixedPrecision(argPM); else bufferReducedPrecision(); }
/** * Computes the buffer for a geometry for a given buffer distance * and accuracy of approximation. * * @param g the geometry to buffer * @param distance the buffer distance * @param quadrantSegments the number of segments used to approximate a quarter circle * @return the buffer of the input geometry * */ public static Geometry bufferOp(Geometry g, double distance, int quadrantSegments) { BufferOp bufOp = new BufferOp(g); bufOp.setQuadrantSegments(quadrantSegments); Geometry geomBuf = bufOp.getResultGeometry(distance); return geomBuf; }
/** * Computes the buffer for a geometry for a given buffer distance * and accuracy of approximation. * * @param g the geometry to buffer * @param distance the buffer distance * @param quadrantSegments the number of segments used to approximate a quarter circle * @param endCapStyle the end cap style to use * @return the buffer of the input geometry * */ public static Geometry bufferOp(Geometry g, double distance, int quadrantSegments, int endCapStyle) { BufferOp bufOp = new BufferOp(g); bufOp.setQuadrantSegments(quadrantSegments); bufOp.setEndCapStyle(endCapStyle); Geometry geomBuf = bufOp.getResultGeometry(distance); return geomBuf; }
private void bufferReducedPrecision(int precisionDigits) { double sizeBasedScaleFactor = precisionScaleFactor(argGeom, distance, precisionDigits); // System.out.println("recomputing with precision scale factor = " + sizeBasedScaleFactor); PrecisionModel fixedPM = new PrecisionModel(sizeBasedScaleFactor); bufferFixedPrecision(fixedPM); }
private void bufferReducedPrecision() { // try and compute with decreasing precision for (int precDigits = MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) { try { bufferReducedPrecision(precDigits); } catch (TopologyException ex) { // update the saved exception to reflect the new input geometry saveException = ex; // don't propagate the exception - it will be detected by fact that resultGeometry is null } if (resultGeometry != null) return; } // tried everything - have to bail throw saveException; }
/** * Computes the buffer for a geometry for a given buffer distance * and accuracy of approximation. * * @param g the geometry to buffer * @param distance the buffer distance * @param params the buffer parameters to use * @return the buffer of the input geometry * */ public static Geometry bufferOp(Geometry g, double distance, BufferParameters params) { BufferOp bufOp = new BufferOp(g, params); Geometry geomBuf = bufOp.getResultGeometry(distance); return geomBuf; }
/** * Computes a buffer area around this geometry having the given width. The * buffer of a Geometry is the Minkowski sum or difference of the geometry * with a disc of radius <code>abs(distance)</code>. * <p> * Mathematically-exact buffer area boundaries can contain circular arcs. * To represent these arcs using linear geometry they must be approximated with line segments. * The buffer geometry is constructed using 8 segments per quadrant to approximate * the circular arcs. * The end cap style is <code>CAP_ROUND</code>. * <p> * The buffer operation always returns a polygonal result. The negative or * zero-distance buffer of lines and points is always an empty {@link Polygon}. * This is also the result for the buffers of degenerate (zero-area) polygons. * * @param distance * the width of the buffer (may be positive, negative or 0) * @return a polygonal geometry representing the buffer region (which may be * empty) * * @throws TopologyException * if a robustness error occurs * * @see #buffer(double, int) * @see #buffer(double, int, int) */ public Geometry buffer(double distance) { return BufferOp.bufferOp(this, distance); }
@Override public <P extends C2D> Geometry<P> buffer(final Geometry<P> geometry, final double distance) { final BufferOp op = new BufferOp(JTS.to(geometry)); return JTS.from(op.getResultGeometry(distance), geometry.getCoordinateReferenceSystem()); }
return BufferOp.bufferOp(this, distance, quadrantSegments);
public Shape buffer(Shape shape, Double distance, Map<String, Object> params) { Geometry geometry = toGeometry(shape); BufferParameters parameters = new BufferParameters(); if (params != null) { bindParameters(parameters, params); } BufferOp ops = new BufferOp(geometry, parameters); return toShape(ops.getResultGeometry(distance)); }
return BufferOp.bufferOp(this, distance, quadrantSegments, endCapStyle);
void run6() throws Exception { // polygon with two vertices very close - mitred negative buffer lies outside input String wkt = "POLYGON ((589081.1515112884 4518509.334764771, 589103.7370954598 4518497.015419995, 589099.8017397423 4518490.719003885, 589097.1198886324 4518486.20858194, 589090.9424687021 4518475.819013388, 589081.1515112884 4518509.334764771))"; Geometry g = rdr.read(wkt); BufferParameters params = new BufferParameters(8, BufferParameters.CAP_ROUND, BufferParameters.JOIN_MITRE, 5); Geometry buf = new BufferOp(g, params).getResultGeometry(-5); System.out.println(buf); };
/** * Compute the buffer * @param geometry * @param distance * @param bufferParameters * @return */ private static Geometry computeSingleSideBuffer(Geometry geometry, double distance, BufferParameters bufferParameters){ bufferParameters.setSingleSided(true); return BufferOp.bufferOp(geometry, distance, bufferParameters); } }
void run5() throws Exception { // polygon with two vertices very close - mitred negative buffer lies outside input String wkt = "POLYGON ((588722.7612465625 4518964.956739423, 588755.2073151038 4518948.2420851765, 588750.2892019567 4518938.490656119, 588750.2892047082 4518938.490654858, 588741.1098934844 4518920.290260831, 588722.7612465625 4518964.956739423))"; Geometry g = rdr.read(wkt); BufferParameters params = new BufferParameters(8, BufferParameters.CAP_ROUND, BufferParameters.JOIN_MITRE, 5); Geometry buf = new BufferOp(g, params).getResultGeometry(-5); System.out.println(buf); };
public static Geometry bufferWithSimplify(Geometry g, Double distance, @Metadata(title="Simplify factor") Double simplifyFactor) { double dist = 0; if (distance != null) dist = distance.doubleValue(); BufferParameters bufParams = new BufferParameters(); if (simplifyFactor != null) bufParams.setSimplifyFactor(simplifyFactor.doubleValue()); return BufferOp.bufferOp(g, dist, bufParams); }
void run4() throws Exception { // String wkt = "LINESTRING (1872699.676 530329.155, 1872712.232 530255.793, 1872724.601 530183.526, 1872737.157 530110.164, 1872749.713 530036.802, 1872762.082 529964.535, 1872774.638 529891.173, 1872787.194 529817.811, 1872799.563 529745.545, 1872812.119 529672.183, 1872824.675 529598.821, 1872837.044 529526.555, 1872849.6 529453.194, 1872862.156 529379.832, 1872874.524 529307.566, 1872887.08 529234.205, 1872899.636 529160.844, 1872912.005 529088.578, 1872924.561 529015.217, 1872937.117 528941.856, 1872949.486 528869.59, 1872962.042 528796.23)"; // String wkt = "LINESTRING(1872762.082 529964.535, 1872774.638 529891.173, 1872787.194 529817.811)"; String wkt = "LINESTRING (1872612.157 530840.503, 1872624.713 530767.14, 1872637.269 530693.777)"; Geometry g = rdr.read(wkt); BufferParameters params = new BufferParameters(10, BufferParameters.CAP_SQUARE, BufferParameters.JOIN_MITRE, 10); Geometry buf = new BufferOp(g, params).getResultGeometry(200); System.out.println(buf); };
public static Geometry bufferMitredJoin(Geometry g, double distance) { BufferParameters bufParams = new BufferParameters(); bufParams.setJoinStyle(BufferParameters.JOIN_MITRE); return BufferOp.bufferOp(g, distance, bufParams); }
BufferOp bufOp = new BufferOp(geom, bufferParameters); return bufOp.getResultGeometry(distance); BufferOp bufOp = new BufferOp(geom, new BufferParameters(value.getInt())); return bufOp.getResultGeometry(distance);