public virtual void TestBufferPoint() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Point inputGeom = new com.epl.geometry.Point(12, 120); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)result; int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 100.0) < 10); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 80) < 0.01 && System.Math.Abs(env2D.GetHeight() - 80) < 0.01); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 12) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 120) < 0.001); com.epl.geometry.NonSimpleResult nsr = new com.epl.geometry.NonSimpleResult(); bool is_simple = simplify.IsSimpleAsFeature(result, sr, true, nsr, null); NUnit.Framework.Assert.IsTrue(is_simple); { result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -1, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } }
/// <summary> /// Calculates a buffer polygon for each geometry at each of the /// corresponding specified distances. /// </summary> /// <remarks> /// Calculates a buffer polygon for each geometry at each of the /// corresponding specified distances. It is assumed that all geometries have /// the same spatial reference. There is an option to union the /// returned geometries. /// See OperatorBuffer. /// </remarks> /// <param name="geometries">An array of geometries to be buffered.</param> /// <param name="spatialReference">The spatial reference of the geometries.</param> /// <param name="distances">The corresponding distances for the input geometries to be buffered.</param> /// <param name="toUnionResults">TRUE if all geometries buffered at a given distance are to be unioned into a single polygon.</param> /// <returns>The buffer of the geometries.</returns> public static com.epl.geometry.Polygon[] Buffer(com.epl.geometry.Geometry[] geometries, com.epl.geometry.SpatialReference spatialReference, double[] distances, bool toUnionResults) { // initially assume distances are in unit of spatial reference double[] bufferDistances = distances; com.epl.geometry.OperatorBuffer op = (com.epl.geometry.OperatorBuffer)factory.GetOperator(com.epl.geometry.Operator.Type.Buffer); if (toUnionResults) { com.epl.geometry.SimpleGeometryCursor inputGeometriesCursor = new com.epl.geometry.SimpleGeometryCursor(geometries); com.epl.geometry.GeometryCursor result = op.Execute(inputGeometriesCursor, spatialReference, bufferDistances, toUnionResults, null); System.Collections.Generic.List <com.epl.geometry.Polygon> resultGeoms = new System.Collections.Generic.List <com.epl.geometry.Polygon>(); com.epl.geometry.Geometry g; while ((g = result.Next()) != null) { resultGeoms.Add((com.epl.geometry.Polygon)g); } com.epl.geometry.Polygon[] buffers = resultGeoms.ToArray(); return(buffers); } else { com.epl.geometry.Polygon[] buffers = new com.epl.geometry.Polygon[geometries.Length]; for (int i = 0; i < geometries.Length; i++) { buffers[i] = (com.epl.geometry.Polygon)op.Execute(geometries[i], spatialReference, bufferDistances[i], null); } return(buffers); } }
/// <summary> /// Calculates a buffer polygon of the geometry as specified by the /// distance input. /// </summary> /// <remarks> /// Calculates a buffer polygon of the geometry as specified by the /// distance input. The buffer is implemented in the xy-plane. /// See OperatorBuffer /// </remarks> /// <param name="geometry">Geometry to be buffered.</param> /// <param name="spatialReference">The spatial reference of the geometry.</param> /// <param name="distance">The specified distance for buffer. Same units as the spatial reference.</param> /// <returns>The buffer polygon at the specified distances.</returns> public static com.epl.geometry.Polygon Buffer(com.epl.geometry.Geometry geometry, com.epl.geometry.SpatialReference spatialReference, double distance) { double bufferDistance = distance; com.epl.geometry.OperatorBuffer op = (com.epl.geometry.OperatorBuffer)factory.GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.Geometry result = op.Execute(geometry, spatialReference, bufferDistance, null); return((com.epl.geometry.Polygon)result); }
public virtual com.epl.geometry.ogc.OGCGeometry Buffer(double distance) { com.epl.geometry.OperatorBuffer op = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); if (distance == 0) { // when distance is 0, return self (maybe we should // create a copy instead). return(this); } double[] d = new double[] { distance }; com.epl.geometry.GeometryCursor cursor = op.Execute(GetEsriGeometryCursor(), GetEsriSpatialReference(), d, true, null); return(com.epl.geometry.ogc.OGCGeometry.CreateFromEsriGeometry(cursor.Next(), esriSR)); }
public virtual void TestBufferPolygon() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polygon inputGeom = new com.epl.geometry.Polygon(); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result == inputGeom); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 10, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 20 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 20 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 104.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.epl.geometry.SpatialReference.Create(4326); inputGeom = new com.epl.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -10, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 15.85) < 0.1 && System.Math.Abs(env2D.GetHeight() - 15.85) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 32.07) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 17.93) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.epl.geometry.SpatialReference.Create(4326); inputGeom = new com.epl.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(0, 50); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); inputGeom.StartPath(10, 10); inputGeom.LineTo(40, 10); inputGeom.LineTo(40, 40); inputGeom.LineTo(10, 40); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -2, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() + 4 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() + 4 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 2); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 108) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
public virtual void TestBufferPolyline() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polyline inputGeom = new com.epl.geometry.Polyline(); com.epl.geometry.OperatorBuffer buffer = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer); com.epl.geometry.OperatorSimplify simplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); inputGeom.LineTo(0, 50); { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -1, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 80 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 80 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 171.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 2); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 186.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { inputGeom = new com.epl.geometry.Polyline(); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.StartPath(50, 0); inputGeom.LineTo(0, 50); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon); com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)(result); com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 208.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { inputGeom = new com.epl.geometry.Polyline(); inputGeom.StartPath(1.762614, 0.607368); inputGeom.LineTo(1.762414, 0.606655); inputGeom.LineTo(1.763006, 0.607034); inputGeom.LineTo(1.762548, 0.607135); com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0.005, null); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }