diff --git a/src/main/java/com/esri/core/geometry/GeometryEngine.java b/src/main/java/com/esri/core/geometry/GeometryEngine.java index 99466fd2..d10d5410 100644 --- a/src/main/java/com/esri/core/geometry/GeometryEngine.java +++ b/src/main/java/com/esri/core/geometry/GeometryEngine.java @@ -24,7 +24,6 @@ package com.esri.core.geometry; -import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; @@ -658,6 +657,13 @@ public static Geometry[] cut(Geometry cuttee, Polyline cutter, return cutsList.toArray(new Geometry[0]); } + + public static Polygon[] buffer(Geometry[] geometries, + SpatialReference spatialReference, double[] distances, + boolean toUnionResults) { + return buffer(geometries, spatialReference, distances, 0, toUnionResults); + } + /** * Calculates a buffer polygon for each geometry at each of the * corresponding specified distances. It is assumed that all geometries have @@ -669,11 +675,12 @@ public static Geometry[] cut(Geometry cuttee, Polyline cutter, * @param geometries An array of geometries to be buffered. * @param spatialReference The spatial reference of the geometries. * @param distances The corresponding distances for the input geometries to be buffered. + * @param max_vertices_in_full_circle Max vertices of circle for buffer edge. * @param toUnionResults TRUE if all geometries buffered at a given distance are to be unioned into a single polygon. * @return The buffer of the geometries. */ public static Polygon[] buffer(Geometry[] geometries, - SpatialReference spatialReference, double[] distances, + SpatialReference spatialReference, double[] distances, int max_vertices_in_full_circle, boolean toUnionResults) { // initially assume distances are in unit of spatial reference double[] bufferDistances = distances; @@ -685,7 +692,7 @@ public static Polygon[] buffer(Geometry[] geometries, SimpleGeometryCursor inputGeometriesCursor = new SimpleGeometryCursor( geometries); GeometryCursor result = op.execute(inputGeometriesCursor, - spatialReference, bufferDistances, toUnionResults, null); + spatialReference, bufferDistances, max_vertices_in_full_circle, toUnionResults, null); ArrayList resultGeoms = new ArrayList(); Geometry g; @@ -698,12 +705,17 @@ public static Polygon[] buffer(Geometry[] geometries, Polygon[] buffers = new Polygon[geometries.length]; for (int i = 0; i < geometries.length; i++) { buffers[i] = (Polygon) op.execute(geometries[i], - spatialReference, bufferDistances[i], null); + spatialReference, bufferDistances[i], max_vertices_in_full_circle, null); } return buffers; } } + public static Polygon buffer(Geometry geometry, + SpatialReference spatialReference, double distance) { + return buffer(geometry, spatialReference, 0, distance); + } + /** * Calculates a buffer polygon of the geometry as specified by the * distance input. The buffer is implemented in the xy-plane. @@ -713,16 +725,18 @@ public static Polygon[] buffer(Geometry[] geometries, * @param geometry Geometry to be buffered. * @param spatialReference The spatial reference of the geometry. * @param distance The specified distance for buffer. Same units as the spatial reference. + * @param max_vertices_in_full_circle Max vertices of circle for buffer edge. * @return The buffer polygon at the specified distances. */ public static Polygon buffer(Geometry geometry, - SpatialReference spatialReference, double distance) { + SpatialReference spatialReference, int max_vertices_in_full_circle, double distance) { double bufferDistance = distance; OperatorBuffer op = (OperatorBuffer) factory .getOperator(Operator.Type.Buffer); Geometry result = op.execute(geometry, spatialReference, - bufferDistance, null); + bufferDistance, max_vertices_in_full_circle, null + ); return (Polygon) result; } diff --git a/src/main/java/com/esri/core/geometry/OperatorBuffer.java b/src/main/java/com/esri/core/geometry/OperatorBuffer.java index 93c71b02..0b4da792 100644 --- a/src/main/java/com/esri/core/geometry/OperatorBuffer.java +++ b/src/main/java/com/esri/core/geometry/OperatorBuffer.java @@ -24,8 +24,6 @@ package com.esri.core.geometry; -import com.esri.core.geometry.Operator.Type; - /** *Creates buffer polygons around geometries. */ @@ -41,10 +39,11 @@ public Type getType() { *@param inputGeometries The geometries to buffer. *@param sr The SpatialReference of the Geometries. *@param distances The buffer distances for the Geometries. If the size of the distances array is less than the number of geometries in the inputGeometries, the last distance value is used for the rest of geometries. + *@param max_vertices_in_full_circle Max vertices of circle for buffer edge. *@param bUnion If True, the buffered geometries will be unioned, otherwise they wont be unioned. */ public abstract GeometryCursor execute(GeometryCursor inputGeometries, - SpatialReference sr, double[] distances, boolean bUnion, + SpatialReference sr, double[] distances, int max_vertices_in_full_circle, boolean bUnion, ProgressTracker progressTracker); /** @@ -53,9 +52,10 @@ public abstract GeometryCursor execute(GeometryCursor inputGeometries, *@param inputGeometry The geometry to buffer. *@param sr The SpatialReference of the Geometry. *@param distance The buffer distance for the Geometry. + *@param max_vertices_in_full_circle Max vertices of circle for buffer edge. */ public abstract Geometry execute(Geometry inputGeometry, - SpatialReference sr, double distance, + SpatialReference sr, double distance, int max_vertices_in_full_circle, ProgressTracker progressTracker); /** diff --git a/src/main/java/com/esri/core/geometry/OperatorBufferLocal.java b/src/main/java/com/esri/core/geometry/OperatorBufferLocal.java index 8c44225f..f7b20de6 100644 --- a/src/main/java/com/esri/core/geometry/OperatorBufferLocal.java +++ b/src/main/java/com/esri/core/geometry/OperatorBufferLocal.java @@ -28,21 +28,24 @@ class OperatorBufferLocal extends OperatorBuffer { @Override public GeometryCursor execute(GeometryCursor inputGeometries, - SpatialReference sr, double[] distances, boolean bUnion, + SpatialReference sr, double[] distances, int max_vertices_in_full_circle, boolean bUnion, ProgressTracker progressTracker) { return execute(inputGeometries, sr, distances, NumberUtils.NaN(), 96, bUnion, progressTracker); } @Override - public Geometry execute(Geometry inputGeometry, SpatialReference sr, - double distance, ProgressTracker progressTracker) { + public Geometry execute( + Geometry inputGeometry, SpatialReference sr, + double distance, int max_vertices_in_full_circle, ProgressTracker progressTracker + ) { SimpleGeometryCursor inputCursor = new SimpleGeometryCursor( inputGeometry); double[] distances = new double[1]; distances[0] = distance; GeometryCursor outputCursor = execute(inputCursor, sr, distances, - false, progressTracker); + max_vertices_in_full_circle, false, progressTracker + ); return outputCursor.next(); } diff --git a/src/main/java/com/esri/core/geometry/ogc/OGCGeometry.java b/src/main/java/com/esri/core/geometry/ogc/OGCGeometry.java index 17ef2f8f..8b0dcbc5 100644 --- a/src/main/java/com/esri/core/geometry/ogc/OGCGeometry.java +++ b/src/main/java/com/esri/core/geometry/ogc/OGCGeometry.java @@ -452,6 +452,10 @@ private OGCGeometry simplifyBunch_(GeometryCursor gc) { } public OGCGeometry buffer(double distance) { + return buffer(distance, 0); // use default which is 96 currently + } + + public OGCGeometry buffer(double distance, int max_vertices_in_full_circle) { OperatorBuffer op = (OperatorBuffer) OperatorFactoryLocal.getInstance() .getOperator(Operator.Type.Buffer); if (distance == 0) {// when distance is 0, return self (maybe we should @@ -461,7 +465,7 @@ public OGCGeometry buffer(double distance) { double d[] = { distance }; com.esri.core.geometry.GeometryCursor cursor = op.execute( - getEsriGeometryCursor(), getEsriSpatialReference(), d, true, + getEsriGeometryCursor(), getEsriSpatialReference(), d, max_vertices_in_full_circle, true, null); return OGCGeometry.createFromEsriGeometry(cursor.next(), esriSR); } diff --git a/src/test/java/com/esri/core/geometry/TestBuffer.java b/src/test/java/com/esri/core/geometry/TestBuffer.java index 341751f5..7e675fcc 100755 --- a/src/test/java/com/esri/core/geometry/TestBuffer.java +++ b/src/test/java/com/esri/core/geometry/TestBuffer.java @@ -46,7 +46,7 @@ public void testBufferPoint() { .getInstance().getOperator(Operator.Type.Buffer); OperatorSimplify simplify = (OperatorSimplify) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.Simplify); - Geometry result = buffer.execute(inputGeom, sr, 40.0, null); + Geometry result = buffer.execute(inputGeom, sr, 40.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) result; int pathCount = poly.getPathCount(); @@ -65,13 +65,13 @@ public void testBufferPoint() { assertTrue(is_simple); { - result = buffer.execute(inputGeom, sr, 0, null); + result = buffer.execute(inputGeom, sr, 0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -1, null); + result = buffer.execute(inputGeom, sr, -1, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } @@ -85,7 +85,7 @@ public void testBufferEnvelope() { .getInstance().getOperator(Operator.Type.Buffer); OperatorSimplify simplify = (OperatorSimplify) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.Simplify); - Geometry result = buffer.execute(inputGeom, sr, 40.0, null); + Geometry result = buffer.execute(inputGeom, sr, 40.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -102,25 +102,25 @@ public void testBufferEnvelope() { assertTrue(simplify.isSimpleAsFeature(result, sr, true, nsr, null)); { - result = buffer.execute(inputGeom, sr, -200.0, null); + result = buffer.execute(inputGeom, sr, -200.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -200.0, null); + result = buffer.execute(inputGeom, sr, -200.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -199 / 2.0, null); + result = buffer.execute(inputGeom, sr, -199 / 2.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -50.0, null); + result = buffer.execute(inputGeom, sr, -50.0, 0, null); poly = (Polygon) (result); result.queryEnvelope2D(env2D); assertTrue(Math.abs(env2D.getWidth() - (199 - 100)) < 0.001 @@ -145,7 +145,7 @@ public void testBufferMultiPoint() { MultiPoint inputGeom = new MultiPoint(); inputGeom.add(12, 120); inputGeom.add(20, 120); - Geometry result = buffer.execute(inputGeom, sr, 40.0, null); + Geometry result = buffer.execute(inputGeom, sr, 40.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -161,13 +161,13 @@ public void testBufferMultiPoint() { assertTrue(simplify.isSimpleAsFeature(result, sr, null)); { - result = buffer.execute(inputGeom, sr, 0, null); + result = buffer.execute(inputGeom, sr, 0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -1, null); + result = buffer.execute(inputGeom, sr, -1, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } @@ -181,7 +181,7 @@ public void testBufferLine() { .getInstance().getOperator(Operator.Type.Buffer); OperatorSimplify simplify = (OperatorSimplify) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.Simplify); - Geometry result = buffer.execute(inputGeom, sr, 40.0, null); + Geometry result = buffer.execute(inputGeom, sr, 40.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -197,13 +197,13 @@ public void testBufferLine() { assertTrue(simplify.isSimpleAsFeature(result, sr, null)); { - result = buffer.execute(inputGeom, sr, 0, null); + result = buffer.execute(inputGeom, sr, 0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - result = buffer.execute(inputGeom, sr, -1, null); + result = buffer.execute(inputGeom, sr, -1, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } @@ -223,19 +223,19 @@ public void testBufferPolyline() { inputGeom.lineTo(0, 50); { - Geometry result = buffer.execute(inputGeom, sr, 0, null); + Geometry result = buffer.execute(inputGeom, sr, 0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - Geometry result = buffer.execute(inputGeom, sr, -1, null); + Geometry result = buffer.execute(inputGeom, sr, -1, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result.isEmpty()); } { - Geometry result = buffer.execute(inputGeom, sr, 40.0, null); + Geometry result = buffer.execute(inputGeom, sr, 40.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -252,7 +252,7 @@ public void testBufferPolyline() { } { - Geometry result = buffer.execute(inputGeom, sr, 4.0, null); + Geometry result = buffer.execute(inputGeom, sr, 4.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -275,7 +275,7 @@ public void testBufferPolyline() { inputGeom.startPath(50, 0); inputGeom.lineTo(0, 50); - Geometry result = buffer.execute(inputGeom, sr, 4.0, null); + Geometry result = buffer.execute(inputGeom, sr, 4.0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -298,7 +298,7 @@ public void testBufferPolyline() { inputGeom.lineTo(1.763006,0.607034); inputGeom.lineTo(1.762548,0.607135); - Geometry result = buffer.execute(inputGeom, sr, 0.005, null); + Geometry result = buffer.execute(inputGeom, sr, 0.005, 0, null); assertTrue(simplify.isSimpleAsFeature(result, sr, null)); } } @@ -316,13 +316,13 @@ public void testBufferPolygon() { inputGeom.lineTo(50, 0); { - Geometry result = buffer.execute(inputGeom, sr, 0, null); + Geometry result = buffer.execute(inputGeom, sr, 0, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); assertTrue(result == inputGeom); } { - Geometry result = buffer.execute(inputGeom, sr, 10, null); + Geometry result = buffer.execute(inputGeom, sr, 10, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -345,7 +345,7 @@ public void testBufferPolygon() { inputGeom.lineTo(50, 50); inputGeom.lineTo(50, 0); - Geometry result = buffer.execute(inputGeom, sr, -10, null); + Geometry result = buffer.execute(inputGeom, sr, -10, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D(); @@ -373,7 +373,7 @@ public void testBufferPolygon() { inputGeom.lineTo(40, 40); inputGeom.lineTo(10, 40); - Geometry result = buffer.execute(inputGeom, sr, -2, null); + Geometry result = buffer.execute(inputGeom, sr, -2, 0, null); assertTrue(result.getType().value() == Geometry.GeometryType.Polygon); Polygon poly = (Polygon) (result); Envelope2D env2D = new Envelope2D();