public virtual void testEnvelopeGeometryEngine() { com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); e.setCoords(-180.0, -90.0, 180.0, 90.0); string result = com.esri.core.geometry.GeometryEngine.geometryToGeoJson(e); NUnit.Framework.Assert.AreEqual("{\"bbox\":[-180.0,-90.0,180.0,90.0]}", result); }
public virtual void testTouchesOnPolygonAndEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Polygon basePl = new com.esri.core.geometry.Polygon(); basePl.startPath(new com.esri.core.geometry.Point(-117, 20)); basePl.lineTo(new com.esri.core.geometry.Point(-100, 20)); basePl.lineTo(new com.esri.core.geometry.Point(-100, 10)); basePl.lineTo(new com.esri.core.geometry.Point(-117, 10)); // Envelope env = new Envelope(new Point(-117,20), 12, 12);//not touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(-100, 20 , -80, 30); // touched bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.touches(basePl, env, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public static void TestImportExportShapePolyline() { com.esri.core.geometry.OperatorExportToESRIShape exporterShape = (com.esri.core.geometry.OperatorExportToESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToESRIShape); com.esri.core.geometry.OperatorImportFromESRIShape importerShape = (com.esri.core.geometry.OperatorImportFromESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromESRIShape); com.esri.core.geometry.Polyline polyline = MakePolyline(); // Test Import Polyline from Polyline System.IO.MemoryStream polylineShapeBuffer = exporterShape.Execute(0, polyline); com.esri.core.geometry.Geometry polylineShapeGeometry = importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Polyline, polylineShapeBuffer); // TODO test this //com.esri.core.geometry.TestCommonMethods.CompareGeometryContent((com.esri.core.geometry.MultiPath)polylineShapeGeometry, polyline); // Test Import Envelope from Polyline; com.esri.core.geometry.Geometry envelopeShapeGeometry = importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Envelope, polylineShapeBuffer); com.esri.core.geometry.Envelope envelope = (com.esri.core.geometry.Envelope)envelopeShapeGeometry; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope otherenv = new com.esri.core.geometry.Envelope(); envelope.QueryEnvelope(env); polyline.QueryEnvelope(otherenv); NUnit.Framework.Assert.IsTrue(env.GetXMin() == otherenv.GetXMin()); NUnit.Framework.Assert.IsTrue(env.GetXMax() == otherenv.GetXMax()); NUnit.Framework.Assert.IsTrue(env.GetYMin() == otherenv.GetYMin()); NUnit.Framework.Assert.IsTrue(env.GetYMax() == otherenv.GetYMax()); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D otherinterval; interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); otherinterval = polyline.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(interval.vmin == otherinterval.vmin); NUnit.Framework.Assert.IsTrue(interval.vmax == otherinterval.vmax); }
public virtual void testCenterXY() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(-130, 30 , -70, 50); NUnit.Framework.Assert.AreEqual(env.getCenterX(), 0, -100); NUnit.Framework.Assert.AreEqual(env.getCenterY(), 0, 40); }
public virtual void testEnvelope2000() { com.esri.core.geometry.Point[] points = new com.esri.core.geometry.Point[2000]; java.util.Random random = new java.util.Random(69); for (int i = 0; i < 2000; i++) { points[i] = new com.esri.core.geometry.Point(); points[i].setX(random.nextDouble() * 100); points[i].setY(random.nextDouble() * 100); } for (int iter = 0; iter < 2; iter++) { long startTime = Sharpen.Runtime.nanoTime(); com.esri.core.geometry.Envelope geomExtent = new com.esri.core.geometry.Envelope( ); com.esri.core.geometry.Envelope fullExtent = new com.esri.core.geometry.Envelope( ); for (int i_1 = 0; i_1 < 2000; i_1++) { points[i_1].queryEnvelope(geomExtent); fullExtent.merge(geomExtent); } long endTime = Sharpen.Runtime.nanoTime(); } }
public static void compareGeometryContent(com.esri.core.geometry.MultiPoint geom1 , com.esri.core.geometry.MultiPoint geom2) { // Geometry types NUnit.Framework.Assert.IsTrue(geom1.getType().value() == geom2.getType().value()); // Envelopes com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(); geom1.queryEnvelope(env1); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(); geom2.queryEnvelope(env2); NUnit.Framework.Assert.IsTrue(env1.getXMin() == env2.getXMin() && env1.getXMax() == env2.getXMax() && env1.getYMin() == env2.getYMin() && env1.getYMax() == env2. getYMax()); // Point count int pointCount1 = geom1.getPointCount(); int pointCount2 = geom2.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2); com.esri.core.geometry.Point point1; com.esri.core.geometry.Point point2; for (int i = 0; i < pointCount1; i++) { point1 = geom1.getPoint(i); point2 = geom2.getPoint(i); double x1 = point1.getX(); double x2 = point2.getX(); NUnit.Framework.Assert.IsTrue(x1 == x2); double y1 = point1.getY(); double y2 = point2.getY(); NUnit.Framework.Assert.IsTrue(y1 == y2); } }
public static void TestDistanceBetweenPointAndEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(23, 23, 23, 23); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(30, 30); double dist = com.esri.core.geometry.GeometryEngine.Distance(env, pt, null); // expect just under 10. NUnit.Framework.Assert.IsTrue(System.Math.Abs(dist - 9.8994949) < 0.0001); }
public static com.esri.core.geometry.Envelope makeEnvelope3() { com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.setCoords(5, 5, 6, 6); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env ); return(envelope); }
public virtual void testEmptyEnvelope() { com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.OperatorExportToGeoJson exporter = (com.esri.core.geometry.OperatorExportToGeoJson )factory.getOperator(com.esri.core.geometry.Operator.Type.ExportToGeoJson); string result = exporter.execute(e); NUnit.Framework.Assert.AreEqual("{\"bbox\":null}", result); }
public static void testClipIssue258243() { com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); poly1.startPath(21.476191371901479, 41.267022001907215); poly1.lineTo(59.669186665158051, 36.62700518555863); poly1.lineTo(20.498578117352313, 30.363180148246094); poly1.lineTo(18.342565836615044, 46.303295352085627); poly1.lineTo(17.869569458621626, 23.886816966894159); poly1.lineTo(19.835465558090434, 20); poly1.lineTo(18.83911285048551, 43.515995498114791); poly1.lineTo(20.864485260298004, 20.235921201027757); poly1.lineTo(18.976127544787012, 20); poly1.lineTo(34.290201277718218, 61.801369014954794); poly1.lineTo(20.734727419368866, 20); poly1.lineTo(18.545865698148113, 20); poly1.lineTo(19.730260558565515, 20); poly1.lineTo(19.924806216827005, 23.780315893949187); poly1.lineTo(21.675168105421452, 36.699924873001258); poly1.lineTo(22.500527828912158, 43.703424859922983); poly1.lineTo(42.009527116514818, 36.995486982256089); poly1.lineTo(24.469729873835782, 58.365871758247039); poly1.lineTo(24.573736036545878, 36.268390409195824); poly1.lineTo(22.726502169802746, 20); poly1.lineTo(23.925834885228145, 20); poly1.lineTo(25.495346880936729, 20); poly1.lineTo(23.320941499288317, 20); poly1.lineTo(24.05655665646276, 28.659578774758632); poly1.lineTo(23.205940789341135, 38.491506888710504); poly1.lineTo(21.472847203385509, 53.057228182018044); poly1.lineTo(25.04257681654104, 20); poly1.lineTo(25.880572351149542, 25.16102863979474); poly1.lineTo(26.756283333879658, 20); poly1.lineTo(21.476191371901479, 41.267022001907215); com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.setCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793 ); try { com.esri.core.geometry.Geometry output_geom = com.esri.core.geometry.OperatorClip .local().execute(poly1, env, com.esri.core.geometry.SpatialReference.create(4326 ), null); com.esri.core.geometry.Envelope envPoly = new com.esri.core.geometry.Envelope(); poly1.queryEnvelope(envPoly); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(env); e.intersect(envPoly); com.esri.core.geometry.Envelope clippedEnv = new com.esri.core.geometry.Envelope( ); output_geom.queryEnvelope(clippedEnv); NUnit.Framework.Assert.IsTrue(System.Math.abs(clippedEnv.getXMin() - e.getXMin()) < 1e-10 && System.Math.abs(clippedEnv.getYMin() - e.getYMin()) < 1e-10 && System.Math .abs(clippedEnv.getXMax() - e.getXMax()) < 1e-10 && System.Math.abs(clippedEnv.getYMax () - e.getYMax()) < 1e-10); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue(false); } }
public RandomCoordinateGenerator(int count, com.esri.core.geometry.Envelope e, double tol) { env = e; maxlen = (env.GetWidth() + env.GetHeight()) / 2 * 0.1; points = new System.Collections.Generic.List<com.esri.core.geometry.Point>(); points.Capacity = count; tolerance = tol; maxcount = count; }
public static void testDistanceBetweenPointAndEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(23, 23, 23, 23); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(30, 30); double dist = com.esri.core.geometry.GeometryEngine.distance(env, pt, null); // expect just under 10. NUnit.Framework.Assert.IsTrue(System.Math.abs(dist - 9.8994949) < 0.0001); }
public static void TestUnion_() { com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(10, 20); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(); pt2.SetXY(10, 10); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(10, 10, 30, 50); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(30, 10, 60, 50); com.esri.core.geometry.Geometry[] geomArray = new com.esri.core.geometry.Geometry[] { env1, env2 }; com.esri.core.geometry.SimpleGeometryCursor inputGeometries = new com.esri.core.geometry.SimpleGeometryCursor(geomArray); com.esri.core.geometry.OperatorUnion union = (com.esri.core.geometry.OperatorUnion)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Union); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.GeometryCursor outputCursor = union.Execute(inputGeometries, sr, null); com.esri.core.geometry.Geometry result = outputCursor.Next(); }
public virtual void TestIntersection1() { // OperatorFactoryLocal projEnv = OperatorFactoryLocal.getInstance(); // int codeIn = 26910;//NAD_1983_UTM_Zone_10N : GCS 6269 // int codeOut = 32610;//WGS_1984_UTM_Zone_10N; : GCS 4326 // int codeIn = SpatialReference::PCS_WGS_1984_UTM_10N; // int codeOut = SpatialReference::PCS_WORLD_MOLLWEIDE; // int codeOut = 102100; inputSR = com.esri.core.geometry.SpatialReference.Create(codeIn); NUnit.Framework.Assert.IsTrue(inputSR.GetID() == codeIn); outputSR = com.esri.core.geometry.SpatialReference.Create(codeOut); NUnit.Framework.Assert.IsTrue(outputSR.GetID() == codeOut); com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(855277, 3892059, 855277 + 100, 3892059 + 100); // Envelope env1 = new Envelope(-1000000, -1000000, 1000000, 1000000); // env1.SetCoords(-8552770, -3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(855277 + 1, 3892059 + 1, 855277 + 30, 3892059 + 20); poly2.AddEnvelope(env2, false); com.esri.core.geometry.GeometryCursor cursor1 = new com.esri.core.geometry.SimpleGeometryCursor(poly1); com.esri.core.geometry.GeometryCursor cursor2 = new com.esri.core.geometry.SimpleGeometryCursor(poly2); com.esri.core.geometry.GeometryCursor outputGeoms = operatorIntersection.Execute(cursor1, cursor2, inputSR, null); com.esri.core.geometry.Geometry geomr = outputGeoms.Next(); NUnit.Framework.Assert.IsNotNull(geomr); NUnit.Framework.Assert.IsTrue(geomr.GetType() == com.esri.core.geometry.Geometry.Type.Polygon); com.esri.core.geometry.Polygon geom = (com.esri.core.geometry.Polygon)geomr; NUnit.Framework.Assert.IsTrue(geom.GetPointCount() == 4); // com.esri.core.geometry.Point[] points = com.esri.core.geometry.TestCommonMethods.PointsFromMultiPath(geom); // // SPtrOfArrayOf(Point2D) // // pts = // // geom.get.getCoordinates2D(); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetX() - 855278.000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetY() - 3892060.0000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetX() - 855307.00000000093) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetY() - 3892079.0000000000) < 1e-7); // geomr = operatorIntersection.Execute(poly1, poly2, inputSR, null); // NUnit.Framework.Assert.IsNotNull(geomr); // NUnit.Framework.Assert.IsTrue(geomr.GetType() == com.esri.core.geometry.Geometry.Type.Polygon); // com.esri.core.geometry.Polygon outputGeom = (com.esri.core.geometry.Polygon)geomr; // NUnit.Framework.Assert.IsTrue(outputGeom.GetPointCount() == 4); // points = com.esri.core.geometry.TestCommonMethods.PointsFromMultiPath(outputGeom); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetX() - 855278.000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[0].GetY() - 3892060.0000000000) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetX() - 855307.00000000093) < 1e-7); // NUnit.Framework.Assert.IsTrue(System.Math.Abs(points[2].GetY() - 3892079.0000000000) < 1e-7); }
public virtual void TestBufferEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Envelope inputGeom = new com.esri.core.geometry.Envelope(1, 0, 200, 400); com.esri.core.geometry.OperatorBuffer buffer = (com.esri.core.geometry.OperatorBuffer)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Buffer); com.esri.core.geometry.OperatorSimplify simplify = (com.esri.core.geometry.OperatorSimplify)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Simplify); com.esri.core.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.esri.core.geometry.Geometry.GeometryType.Polygon); com.esri.core.geometry.Polygon poly = (com.esri.core.geometry.Polygon)(result); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - (80 + 199)) < 0.001 && System.Math.Abs(env2D.GetHeight() - (80 + 400)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 201.0 / 2) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 400 / 2.0) < 0.001); 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); com.esri.core.geometry.NonSimpleResult nsr = new com.esri.core.geometry.NonSimpleResult(); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, true, nsr, null)); { result = buffer.Execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.esri.core.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.esri.core.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -199 / 2.0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.esri.core.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result.IsEmpty()); } { result = buffer.Execute(inputGeom, sr, -50.0, null); poly = (com.esri.core.geometry.Polygon)(result); result.QueryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - (199 - 100)) < 0.001 && System.Math.Abs(env2D.GetHeight() - (400 - 100)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 201.0 / 2) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 400 / 2.0) < 0.001); pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 4.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
public virtual void testSerializeEnvelope() { try { java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream oo = new java.io.ObjectOutputStream(streamOut); com.esri.core.geometry.Envelope pt = new com.esri.core.geometry.Envelope(10, 10, 400, 300); oo.writeObject(pt); java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut .toByteArray()); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(streamIn); com.esri.core.geometry.Envelope ptRes = (com.esri.core.geometry.Envelope)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt)); } catch (System.Exception) { fail("Envelope serialization failure"); } // try // { // FileOutputStream streamOut = new FileOutputStream(m_thisDirectory + // "savedEnvelope.txt"); // ObjectOutputStream oo = new ObjectOutputStream(streamOut); // Envelope pt = new Envelope(10, 10, 400, 300); // oo.writeObject(pt); // } // catch(Exception ex) // { // fail("Envelope serialization failure"); // } try { java.io.InputStream s = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization )).getResourceAsStream("savedEnvelope.txt"); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(s); com.esri.core.geometry.Envelope ptRes = (com.esri.core.geometry.Envelope)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.getXMax() == 400); } catch (System.Exception) { fail("Envelope serialization failure"); } }
public virtual void TestEqualsOnEnvelopes() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Point p = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(p, 12, 12); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(-136, 4, -124, 16); bool isEqual; try { isEqual = com.esri.core.geometry.GeometryEngine.Equals(env, env2, sr); } catch (System.ArgumentException) { isEqual = false; } NUnit.Framework.Assert.IsTrue(isEqual); }
public virtual void testReplaceNaNs() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(); pt.setXY(1, 2); pt.setZ(double.NaN); pt.queryEnvelope(env); pt.replaceNaNs(com.esri.core.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(pt.Equals(new com.esri.core.geometry.Point(1, 2, 5) )); NUnit.Framework.Assert.IsTrue(env.hasZ()); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).isEmpty()); env.replaceNaNs(com.esri.core.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).Equals(new com.esri.core.geometry.Envelope1D(5, 5))); }
public virtual void TestEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.SetCoords(100, 200, 250, 300); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).IsEmpty()); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 1, 2); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmax == 2); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 0); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 3, 4); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID); NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 0); env.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 5, 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0).vmax == 2); env.DropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsFalse(env.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(); env.CopyTo(env1); NUnit.Framework.Assert.IsFalse(env1.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env1.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).vmax == 4); }
public virtual void TestCreation1() { // Simple area and length calcul test com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); int number = poly.GetStateFlag(); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(1000, 2000, 1010, 2010); env.ToString(); poly.AddEnvelope(env, false); poly.ToString(); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() - 100) < 1e-12); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateLength2D() - 40) < 1e-12); poly.SetEmpty(); number = poly.GetStateFlag(); poly.AddEnvelope(env, true); number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(poly.CalculateArea2D() + 100) < 1e-12); number = poly.GetStateFlag(); }
public virtual void testTouchesOnPointAndEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Point p = new com.esri.core.geometry.Point(-130, 10); // Envelope env = new Envelope(p, 12, 12);//not touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(-130, 10 , -110, 20); // touched bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.touches(p, env, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public virtual void testEqualsOnEnvelopes() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Point p = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(p, 12, 12); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(-136, 4, -124, 16); bool isEqual; try { isEqual = com.esri.core.geometry.GeometryEngine.equals(env, env2, sr); } catch (System.ArgumentException) { isEqual = false; } NUnit.Framework.Assert.IsTrue(isEqual); }
public static void testUnion() { com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(10, 20); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(); pt2.setXY(10, 10); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(10, 10 , 30, 50); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(30, 10 , 60, 50); com.esri.core.geometry.Geometry[] geomArray = new com.esri.core.geometry.Geometry [] { env1, env2 }; com.esri.core.geometry.SimpleGeometryCursor inputGeometries = new com.esri.core.geometry.SimpleGeometryCursor (geomArray); com.esri.core.geometry.OperatorUnion union = (com.esri.core.geometry.OperatorUnion )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .Union); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.GeometryCursor outputCursor = union.execute(inputGeometries , sr, null); com.esri.core.geometry.Geometry result = outputCursor.next(); }
public virtual void testProximity2D_2() { com.esri.core.geometry.Point point1 = new com.esri.core.geometry.Point(3, 2); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(2, 4); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); envelope.setCoords(4, 3, 7, 6); com.esri.core.geometry.Polygon polygonToTest = new com.esri.core.geometry.Polygon (); polygonToTest.addEnvelope(envelope, false); com.esri.core.geometry.Proximity2DResult prxResult1 = com.esri.core.geometry.GeometryEngine .getNearestVertex(envelope, point1); com.esri.core.geometry.Proximity2DResult prxResult2 = com.esri.core.geometry.GeometryEngine .getNearestVertex(polygonToTest, point1); com.esri.core.geometry.Proximity2DResult prxResult3 = com.esri.core.geometry.GeometryEngine .getNearestCoordinate(envelope, point2, false); com.esri.core.geometry.Proximity2DResult prxResult4 = com.esri.core.geometry.GeometryEngine .getNearestCoordinate(polygonToTest, point2, false); com.esri.core.geometry.Point result1 = prxResult1.getCoordinate(); com.esri.core.geometry.Point result2 = prxResult2.getCoordinate(); NUnit.Framework.Assert.IsTrue(result1.getX() == result2.getX()); com.esri.core.geometry.Point result3 = prxResult3.getCoordinate(); com.esri.core.geometry.Point result4 = prxResult4.getCoordinate(); NUnit.Framework.Assert.IsTrue(result3.getX() == result4.getX()); }
public virtual void testTouchOnEnvelopes() { // case1, not touched // Envelope env = new Envelope(new Point(-117,20), 12, 12); // Envelope env2 = new Envelope(-100,20,-80,30); // case2 touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(new com.esri.core.geometry.Point (-117, 20), 12, 12); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(-117, 26, -80, 30); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.touches(env, env2, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public static void testIntervalTreeRandomConstruction() { int pointcount = 0; int passcount = 1000; int figureSize = 50; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.setCoords(-10000, -10000, 10000, 10000); com.esri.core.geometry.RandomCoordinateGenerator generator = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), env, 0.001); java.util.Random random = new java.util.Random(2013); int rand_max = 98765; System.Collections.Generic.List <com.esri.core.geometry.Envelope1D> intervals = new System.Collections.Generic.List <com.esri.core.geometry.Envelope1D>(); com.esri.core.geometry.AttributeStreamOfInt8 intervalsFound = new com.esri.core.geometry.AttributeStreamOfInt8 (0); for (int i = 0; i < passcount; i++) { int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator.GetRandomCoord(); if (j == 0 || bRandomNew) { poly.startPath(pt); } else { poly.lineTo(pt); } } { intervals.clear(); com.esri.core.geometry.SegmentIterator seg_iter = poly.querySegmentIterator(); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D range = poly.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .POSITION, 0); range.vmin -= 0.01; range.vmax += 0.01; while (seg_iter.nextPath()) { while (seg_iter.hasNextSegment()) { com.esri.core.geometry.Segment segment = seg_iter.nextSegment(); interval = segment.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .POSITION, 0); intervals.add(interval); } } intervalsFound.resize(intervals.Count, 0); // Just test construction for assertions com.esri.core.geometry.IntervalTreeImpl intervalTree = new com.esri.core.geometry.IntervalTreeImpl (true); construct(intervalTree, intervals); for (int j_1 = 0; j_1 < intervals.Count; j_1++) { intervalTree.insert(j_1); } com.esri.core.geometry.IntervalTreeImpl.IntervalTreeIteratorImpl iterator = intervalTree .getIterator(range, 0.0); int count = 0; int handle; while ((handle = iterator.next()) != -1) { count++; intervalsFound.write(handle, unchecked ((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count); for (int j_2 = 0; j_2 < intervalsFound.size(); j_2++) { interval = intervals[j_2]; NUnit.Framework.Assert.IsTrue(intervalsFound.read(j_2) == 1); } for (int j_3 = 0; j_3 < intervals.Count >> 1; j_3++) { intervalTree.remove(j_3); } iterator.resetIterator(range, 0.0); count = 0; while ((handle = iterator.next()) != -1) { count++; intervalsFound.write(handle, unchecked ((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count - (intervals.Count >> 1)); for (int j_4 = (intervals.Count >> 1); j_4 < intervals.Count; j_4++) { intervalTree.remove(j_4); } } } }
public static void testPointTypes() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorDifference difference = (com.esri.core.geometry.OperatorDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.Difference); com.esri.core.geometry.OperatorSymmetricDifference sym_difference = (com.esri.core.geometry.OperatorSymmetricDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference); { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.000000009, 0.000000009); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.setXY(0, 0); point_2.setXY(0.00000002, 0.00000002); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, point_2, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, point_1, com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_2.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.isEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.getXY(0).x == 0 && sym_differenced. getXY(0).y == 0); NUnit.Framework.Assert.IsTrue(sym_differenced.getXY(1).x == 0.00000002 && sym_differenced .getXY(1).y == 0.00000002); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(1, 1); point_2.setXY(0.000000009, 0.000000009); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.getPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.getXY(0).x == 1 && differenced_1.getXY (0).y == 1); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.create( 4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.isEmpty()); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(1, 1); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.getXY(0).x == 1.0 && differenced_1.getXY (0).y == 1.0); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference .execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.create( 4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.isEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.getPointCount() == 1); NUnit.Framework.Assert.IsTrue(sym_differenced.getXY(0).x == 1 && sym_differenced. getXY(0).y == 1); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.add(0, 0); multi_point_1.add(0, 0); point_2.setXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint )(sym_difference.execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.isEmpty()); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.add(0, 0); multi_point_1.add(0, 0); multi_point_1.add(2, 2); polygon_2.startPath(-1, -1); polygon_2.lineTo(-1, 1); polygon_2.lineTo(1, 1); polygon_2.lineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.getPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.getXY(0).x == 2 && differenced_1.getXY (0).y == 2); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.add(0, 0); multi_point_1.add(0, 0); multi_point_1.add(1, 1); polygon_2.startPath(-1, -1); polygon_2.lineTo(-1, 1); polygon_2.lineTo(1, 1); polygon_2.lineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); } { // multi_point/envelope com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.geometry.Envelope( ); multi_point_1.add(-2, 0); multi_point_1.add(0, 2); multi_point_1.add(2, 0); multi_point_1.add(0, -2); envelope_2.setCoords(-1, -1, 1, 1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, envelope_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty() && differenced_1 == multi_point_1 ); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.add(2, 2); multi_point_1.add(2, 2); multi_point_1.add(-2, -2); polygon_2.startPath(-1, -1); polygon_2.lineTo(-1, 1); polygon_2.lineTo(1, 1); polygon_2.lineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint )(difference.execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference .create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty() && differenced_1 == multi_point_1 ); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); point_1.setXY(0, 0); polygon_2.startPath(-1, -1); polygon_2.lineTo(-1, 1); polygon_2.lineTo(1, 1); polygon_2.lineTo(1, -1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.create(4326 ), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); polygon_2.setEmpty(); polygon_2.startPath(1, 1); polygon_2.lineTo(1, 2); polygon_2.lineTo(2, 2); polygon_2.lineTo(2, 1); differenced_1 = (com.esri.core.geometry.Point)(difference.execute(point_1, polygon_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); point_1.setXY(0, 0); polygon_2.startPath(1, 0); polygon_2.lineTo(0, 1); polygon_2.lineTo(1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.create(4326 ), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); point_1.setEmpty(); point_1.setXY(0.5, 0.5); polygon_2.setEmpty(); polygon_2.startPath(1, 0); polygon_2.lineTo(0, 1); polygon_2.lineTo(1, 1); differenced_1 = (com.esri.core.geometry.Point)(difference.execute(point_1, polygon_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); } { // point/envelope com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.geometry.Envelope( ); point_1.setXY(0, 0); envelope_2.setCoords(-1, -1, 1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, envelope_2, com.esri.core.geometry.SpatialReference.create(4326 ), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); envelope_2.setEmpty(); envelope_2.setCoords(1, 1, 2, 2); differenced_1 = (com.esri.core.geometry.Point)(difference.execute(point_1, envelope_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polyline com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polyline polyline_2 = new com.esri.core.geometry.Polyline( ); point_1.setXY(0, 0); polyline_2.startPath(-1, 0); polyline_2.lineTo(1, 0); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference .execute(point_1, polyline_2, com.esri.core.geometry.SpatialReference.create(4326 ), null)); NUnit.Framework.Assert.IsTrue(differenced_1.isEmpty()); polyline_2.setEmpty(); polyline_2.startPath(1, 0); polyline_2.lineTo(2, 0); differenced_1 = (com.esri.core.geometry.Point)(difference.execute(point_1, polyline_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); polyline_2.setEmpty(); polyline_2.startPath(-1, -1); polyline_2.lineTo(-1, 1); polyline_2.lineTo(1, 1); polyline_2.lineTo(1, -1); differenced_1 = (com.esri.core.geometry.Point)(difference.execute(point_1, polyline_2 , com.esri.core.geometry.SpatialReference.create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.isEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } }
public static com.esri.core.geometry.Envelope MakeEnvelope() { com.esri.core.geometry.Envelope envelope; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(0.0, 0.0, 5.0, 5.0); envelope = env; com.esri.core.geometry.Envelope1D interval = new com.esri.core.geometry.Envelope1D(); interval.vmin = -3.0; interval.vmax = -7.0; envelope.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, interval); interval.vmin = 16.0; interval.vmax = 32.0; envelope.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, interval); interval.vmin = 5.0; interval.vmax = 11.0; envelope.SetInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, interval); return envelope; }
public virtual void TestProximity2D_2() { com.esri.core.geometry.Point point1 = new com.esri.core.geometry.Point(3, 2); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(2, 4); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); envelope.SetCoords(4, 3, 7, 6); com.esri.core.geometry.Polygon polygonToTest = new com.esri.core.geometry.Polygon(); polygonToTest.AddEnvelope(envelope, false); com.esri.core.geometry.Proximity2DResult prxResult1 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(envelope, point1); com.esri.core.geometry.Proximity2DResult prxResult2 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(polygonToTest, point1); com.esri.core.geometry.Proximity2DResult prxResult3 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(envelope, point2, false); com.esri.core.geometry.Proximity2DResult prxResult4 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(polygonToTest, point2, false); com.esri.core.geometry.Point result1 = prxResult1.GetCoordinate(); com.esri.core.geometry.Point result2 = prxResult2.GetCoordinate(); NUnit.Framework.Assert.IsTrue(result1.GetX() == result2.GetX()); com.esri.core.geometry.Point result3 = prxResult3.GetCoordinate(); com.esri.core.geometry.Point result4 = prxResult4.GetCoordinate(); NUnit.Framework.Assert.IsTrue(result3.GetX() == result4.GetX()); }
public virtual void TestTouchesOnPolygonAndEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Polygon basePl = new com.esri.core.geometry.Polygon(); basePl.StartPath(new com.esri.core.geometry.Point(-117, 20)); basePl.LineTo(new com.esri.core.geometry.Point(-100, 20)); basePl.LineTo(new com.esri.core.geometry.Point(-100, 10)); basePl.LineTo(new com.esri.core.geometry.Point(-117, 10)); // Envelope env = new Envelope(new Point(-117,20), 12, 12);//not touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(-100, 20, -80, 30); // touched bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.Touches(basePl, env, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public virtual void TestFromProjection() { com.esri.core.geometry.MultiPoint multiPointInitial = new com.esri.core.geometry.MultiPoint(); multiPointInitial.Add(-20037508.342789244, 3360107.7777777780); multiPointInitial.Add(-18924313.434856508, 3360107.7777777780); multiPointInitial.Add(-18924313.434856508, -3360107.7777777780); multiPointInitial.Add(-20037508.342789244, -3360107.7777777780); com.esri.core.geometry.Geometry geom1 = ((com.esri.core.geometry.MultiPoint)multiPointInitial); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(102100); com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(-20037508.342788246, -30240971.958386172, 20037508.342788246, 30240971.958386205); /* xmin */ /* ymin */ /* xmax */ /* ymax */ // /*xmin*/ -20037508.342788246 // /*ymin*/ -30240971.958386172 // /*xmax*/ 20037508.342788246 // /*ymax*/ 30240971.958386205 com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(env.xmin, env.ymin); poly.LineTo(env.xmin, env.ymax); poly.LineTo(env.xmax, env.ymax); poly.LineTo(env.xmax, env.ymin); com.esri.core.geometry.Geometry geom2 = new com.esri.core.geometry.Envelope(env); // Geometry geom2 = poly; com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.MultiPoint multiPointOut = (com.esri.core.geometry.MultiPoint)(operatorIntersection.Execute(geom1, geom2, sr, null)); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D().Length == 2); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[0].x == -18924313.434856508); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[0].y == 3360107.7777777780); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[1].x == -18924313.434856508); NUnit.Framework.Assert.IsTrue(multiPointOut.GetCoordinates2D()[1].y == -3360107.7777777780); }
public static void TestPointTypes() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.OperatorDifference difference = (com.esri.core.geometry.OperatorDifference)engine.GetOperator(com.esri.core.geometry.Operator.Type.Difference); com.esri.core.geometry.OperatorSymmetricDifference sym_difference = (com.esri.core.geometry.OperatorSymmetricDifference)engine.GetOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference); { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.000000009, 0.000000009); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.IsEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.000000009, 0.0); com.esri.core.geometry.Point differenced = (com.esri.core.geometry.Point)(difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced.IsEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // point/point com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); point_1.SetXY(0, 0); point_2.SetXY(0.00000002, 0.00000002); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference.Execute(point_2, point_1, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_2.IsEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint)(sym_difference.Execute(point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.IsEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(0).x == 0 && sym_differenced.GetXY(0).y == 0); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(1).x == 0.00000002 && sym_differenced.GetXY(1).y == 0.00000002); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); point_2.SetXY(0.000000009, 0.000000009); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 1 && differenced_1.GetXY(0).y == 1); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference.Execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.IsEmpty()); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); point_2.SetXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 1.0 && differenced_1.GetXY(0).y == 1.0); com.esri.core.geometry.Point differenced_2 = (com.esri.core.geometry.Point)(difference.Execute(point_2, multi_point_1, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_2.IsEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint)(sym_difference.Execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!sym_differenced.IsEmpty()); NUnit.Framework.Assert.IsTrue(sym_differenced.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(sym_differenced.GetXY(0).x == 1 && sym_differenced.GetXY(0).y == 1); } { // multi_point/point com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); point_2.SetXY(0.000000009, 0.0); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); com.esri.core.geometry.MultiPoint sym_differenced = (com.esri.core.geometry.MultiPoint)(sym_difference.Execute(multi_point_1, point_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(sym_differenced.IsEmpty()); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); multi_point_1.Add(2, 2); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1.GetPointCount() == 1); NUnit.Framework.Assert.IsTrue(differenced_1.GetXY(0).x == 2 && differenced_1.GetXY(0).y == 2); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.Add(0, 0); multi_point_1.Add(0, 0); multi_point_1.Add(1, 1); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); } { // multi_point/envelope com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.geometry.Envelope(); multi_point_1.Add(-2, 0); multi_point_1.Add(0, 2); multi_point_1.Add(2, 0); multi_point_1.Add(0, -2); envelope_2.SetCoords(-1, -1, 1, 1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, envelope_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty() && differenced_1 == multi_point_1); } { // multi_point/polygon com.esri.core.geometry.MultiPoint multi_point_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); multi_point_1.Add(2, 2); multi_point_1.Add(2, 2); multi_point_1.Add(-2, -2); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.esri.core.geometry.MultiPoint differenced_1 = (com.esri.core.geometry.MultiPoint)(difference.Execute(multi_point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty() && differenced_1 == multi_point_1); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); point_1.SetXY(0, 0); polygon_2.StartPath(-1, -1); polygon_2.LineTo(-1, 1); polygon_2.LineTo(1, 1); polygon_2.LineTo(1, -1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); polygon_2.SetEmpty(); polygon_2.StartPath(1, 1); polygon_2.LineTo(1, 2); polygon_2.LineTo(2, 2); polygon_2.LineTo(2, 1); differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polygon com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polygon polygon_2 = new com.esri.core.geometry.Polygon(); point_1.SetXY(0, 0); polygon_2.StartPath(1, 0); polygon_2.LineTo(0, 1); polygon_2.LineTo(1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); point_1.SetEmpty(); point_1.SetXY(0.5, 0.5); polygon_2.SetEmpty(); polygon_2.StartPath(1, 0); polygon_2.LineTo(0, 1); polygon_2.LineTo(1, 1); differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polygon_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); } { // point/envelope com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Envelope envelope_2 = new com.esri.core.geometry.Envelope(); point_1.SetXY(0, 0); envelope_2.SetCoords(-1, -1, 1, 1); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, envelope_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); envelope_2.SetEmpty(); envelope_2.SetCoords(1, 1, 2, 2); differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, envelope_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } { // point/polyline com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(); com.esri.core.geometry.Polyline polyline_2 = new com.esri.core.geometry.Polyline(); point_1.SetXY(0, 0); polyline_2.StartPath(-1, 0); polyline_2.LineTo(1, 0); com.esri.core.geometry.Point differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polyline_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(differenced_1.IsEmpty()); polyline_2.SetEmpty(); polyline_2.StartPath(1, 0); polyline_2.LineTo(2, 0); differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polyline_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); polyline_2.SetEmpty(); polyline_2.StartPath(-1, -1); polyline_2.LineTo(-1, 1); polyline_2.LineTo(1, 1); polyline_2.LineTo(1, -1); differenced_1 = (com.esri.core.geometry.Point)(difference.Execute(point_1, polyline_2, com.esri.core.geometry.SpatialReference.Create(4326), null)); NUnit.Framework.Assert.IsTrue(!differenced_1.IsEmpty()); NUnit.Framework.Assert.IsTrue(differenced_1 == point_1); } }
public static void TestImportExportWktMultiPolygon() { com.esri.core.geometry.OperatorImportFromWkt importerWKT = (com.esri.core.geometry.OperatorImportFromWkt)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromWkt); com.esri.core.geometry.OperatorExportToWkt exporterWKT = (com.esri.core.geometry.OperatorExportToWkt)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToWkt); com.esri.core.geometry.Polygon polygon; string wktString; com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D(); com.esri.core.geometry.WktParser wktParser = new com.esri.core.geometry.WktParser(); // Test Import from MultiPolygon wktString = "Multipolygon M empty"; polygon = (com.esri.core.geometry.Polygon)importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.IsEmpty()); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); polygon = (com.esri.core.geometry.Polygon)com.esri.core.geometry.GeometryEngine.GeometryFromWkt(wktString, 0, com.esri.core.geometry.Geometry.Type.Unknown); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.IsEmpty()); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.M)); wktString = exporterWKT.Execute(0, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON M EMPTY")); wktString = com.esri.core.geometry.GeometryEngine.GeometryToWkt(polygon, 0); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON M EMPTY")); wktString = "Multipolygon Z (empty, (empty, (10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3), empty, (10 10 1, 12 12 1)), empty, ((90 90 88, 60 90 7, 60 60 7), empty, (70 70 7, 80 80 7, 70 80 7, 70 70 7)), empty)"; polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); polygon.QueryEnvelope2D(envelope); NUnit.Framework.Assert.IsTrue(envelope.xmin == 10 && envelope.xmax == 90 && envelope.ymin == 10 && envelope.ymax == 90); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 14); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 5); // assertTrue(polygon.calculate_area_2D() > 0.0); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); double z = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0); NUnit.Framework.Assert.IsTrue(z == 5); // Test Export to WKT MultiPolygon wktString = exporterWKT.Execute(0, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3, 12 12 3, 12 12 3), (10 10 1, 12 12 1, 10 10 1)), ((90 90 88, 60 90 7, 60 60 7, 90 90 88), (70 70 7, 70 80 7, 80 80 7, 70 70 7)))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } // Test import Polygon wktString = "POLYGON z (EMPTY, EMPTY, (10 10 5, 10 20 5, 20 20 5, 20 10 5), (12 12 3), EMPTY, (10 10 1, 12 12 1), EMPTY, (60 60 7, 60 90 7, 90 90 7, 60 60 7), EMPTY, (70 70 7, 70 80 7, 80 80 7), EMPTY)"; polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 14); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 5); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); // Test Export to WKT Polygon wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportPolygon, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z ((10 10 5, 20 10 5, 20 20 5, 10 20 5, 10 10 5), (12 12 3, 12 12 3, 12 12 3), (10 10 1, 12 12 1, 10 10 1), (60 60 7, 60 90 7, 90 90 7, 60 60 7), (70 70 7, 70 80 7, 80 80 7, 70 70 7))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); polygon.QueryEnvelope(env); wktString = exporterWKT.Execute(0, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z ((10 10 1, 90 10 7, 90 90 1, 10 90 7, 10 10 1))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((10 10 1, 90 10 7, 90 90 1, 10 90 7, 10 10 1)))")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } env.SetEmpty(); wktString = exporterWKT.Execute(0, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("POLYGON Z EMPTY")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, env, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z EMPTY")); wktParser.ResetParser(wktString); while (wktParser.NextToken() != com.esri.core.geometry.WktParser.WktToken.not_available) { } wktString = "MULTIPOLYGON (((5 10, 8 10, 10 10, 10 0, 0 0, 0 10, 2 10, 5 10)))"; // ring // is // oriented // clockwise polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.CalculateArea2D() > 0); wktString = "MULTIPOLYGON Z (((90 10 7, 10 10 1, 10 90 7, 90 90 1, 90 10 7)))"; // ring // is // oriented // clockwise polygon = (com.esri.core.geometry.Polygon)(importerWKT.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, wktString, null)); NUnit.Framework.Assert.IsTrue(polygon != null); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() == 4); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(polygon.HasAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(polygon.CalculateArea2D() > 0); wktString = exporterWKT.Execute(com.esri.core.geometry.WktExportFlags.wktExportMultiPolygon, polygon, null); NUnit.Framework.Assert.IsTrue(wktString.Equals("MULTIPOLYGON Z (((90 10 7, 90 90 1, 10 90 7, 10 10 1, 90 10 7)))")); }
public static void TestImportExportShapeMultiPoint() { com.esri.core.geometry.OperatorExportToESRIShape exporterShape = (com.esri.core.geometry.OperatorExportToESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToESRIShape); com.esri.core.geometry.OperatorImportFromESRIShape importerShape = (com.esri.core.geometry.OperatorImportFromESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromESRIShape); com.esri.core.geometry.MultiPoint multipoint = MakeMultiPoint(); // Test Import MultiPoint from MultiPoint System.IO.MemoryStream multipointShapeBuffer = exporterShape.Execute(0, multipoint); com.esri.core.geometry.MultiPoint multipointShapeGeometry = (com.esri.core.geometry.MultiPoint)importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.MultiPoint, multipointShapeBuffer); //com.esri.core.geometry.TestCommonMethods.CompareGeometryContent((com.esri.core.geometry.MultiPoint)multipointShapeGeometry, multipoint); // Test Import Envelope from MultiPoint com.esri.core.geometry.Geometry envelopeShapeGeometry = importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Envelope, multipointShapeBuffer); com.esri.core.geometry.Envelope envelope = (com.esri.core.geometry.Envelope)envelopeShapeGeometry; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope otherenv = new com.esri.core.geometry.Envelope(); envelope.QueryEnvelope(env); multipoint.QueryEnvelope(otherenv); NUnit.Framework.Assert.IsTrue(env.GetXMin() == otherenv.GetXMin()); NUnit.Framework.Assert.IsTrue(env.GetXMax() == otherenv.GetXMax()); NUnit.Framework.Assert.IsTrue(env.GetYMin() == otherenv.GetYMin()); NUnit.Framework.Assert.IsTrue(env.GetYMax() == otherenv.GetYMax()); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D otherinterval; interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); otherinterval = multipoint.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(interval.vmin == otherinterval.vmin); NUnit.Framework.Assert.IsTrue(interval.vmax == otherinterval.vmax); interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0); otherinterval = multipoint.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0); NUnit.Framework.Assert.IsTrue(interval.vmin == otherinterval.vmin); NUnit.Framework.Assert.IsTrue(interval.vmax == otherinterval.vmax); }
public static void TestRandom() { int passcount = 10; int figureSize = 100; int figureSize2 = 100; com.esri.core.geometry.Envelope extent1 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent2 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent3 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent4 = new com.esri.core.geometry.Envelope(); extent1.SetCoords(-10000, 5000, 10000, 25000); // red extent2.SetCoords(-10000, 2000, 10000, 8000); // blue extent3.SetCoords(-10000, -8000, 10000, -2000); // blue extent4.SetCoords(-10000, -25000, 10000, -5000); // red com.esri.core.geometry.RandomCoordinateGenerator generator1 = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), extent1, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator2 = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), extent2, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator3 = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), extent3, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator4 = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), extent4, 0.001); System.Random random = new System.Random(1982); int rand_max = 511; int qCount = 0; int eCount = 0; int bCount = 0; for (int c = 0; c < passcount; c++) { com.esri.core.geometry.Polygon polyRed = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon polyBlue = new com.esri.core.geometry.Polygon(); int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator1.GetRandomCoord(); if (j == 0 || bRandomNew) { polyRed.StartPath(pt); } else { polyRed.LineTo(pt); } } for (int j_1 = 0; j_1 < r; j_1++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator4.GetRandomCoord(); if (j_1 == 0 || bRandomNew) { polyRed.StartPath(pt); } else { polyRed.LineTo(pt); } } r = figureSize2; if (r < 3) { continue; } for (int j_2 = 0; j_2 < r; j_2++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator2.GetRandomCoord(); if (j_2 == 0 || bRandomNew) { polyBlue.StartPath(pt); } else { polyBlue.LineTo(pt); } } for (int j_3 = 0; j_3 < r; j_3++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator3.GetRandomCoord(); if (j_3 == 0 || bRandomNew) { polyBlue.StartPath(pt); } else { polyBlue.LineTo(pt); } } com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); // Quad_tree com.esri.core.geometry.QuadTree quadTree = BuildQuadTree(polyBlue); com.esri.core.geometry.QuadTree.QuadTreeIterator iterator = quadTree.GetIterator(); com.esri.core.geometry.SegmentIteratorImpl _segIterRed = ((com.esri.core.geometry.MultiPathImpl)polyRed._getImpl()).QuerySegmentIterator(); while (_segIterRed.NextPath()) { while (_segIterRed.HasNextSegment()) { com.esri.core.geometry.Segment segmentRed = _segIterRed.NextSegment(); segmentRed.QueryEnvelope2D(env); iterator.ResetIterator(env, 0.001); while (iterator.Next() != -1) { qCount++; } } } // Envelope_2D_intersector System.Collections.Generic.List<com.esri.core.geometry.Envelope2D> envelopes_red = new System.Collections.Generic.List<com.esri.core.geometry.Envelope2D>(); System.Collections.Generic.List<com.esri.core.geometry.Envelope2D> envelopes_blue = new System.Collections.Generic.List<com.esri.core.geometry.Envelope2D>(); com.esri.core.geometry.SegmentIterator segIterRed = polyRed.QuerySegmentIterator(); while (segIterRed.NextPath()) { while (segIterRed.HasNextSegment()) { com.esri.core.geometry.Segment segment = segIterRed.NextSegment(); env = new com.esri.core.geometry.Envelope2D(); segment.QueryEnvelope2D(env); envelopes_red.Add(env); } } com.esri.core.geometry.SegmentIterator segIterBlue = polyBlue.QuerySegmentIterator(); while (segIterBlue.NextPath()) { while (segIterBlue.HasNextSegment()) { com.esri.core.geometry.Segment segment = segIterBlue.NextSegment(); env = new com.esri.core.geometry.Envelope2D(); segment.QueryEnvelope2D(env); envelopes_blue.Add(env); } } com.esri.core.geometry.Envelope2DIntersectorImpl intersector = new com.esri.core.geometry.Envelope2DIntersectorImpl(); intersector.SetTolerance(0.001); intersector.StartRedConstruction(); for (int i = 0; i < envelopes_red.Count; i++) { intersector.AddRedEnvelope(i, envelopes_red[i]); } intersector.EndRedConstruction(); intersector.StartBlueConstruction(); for (int i_1 = 0; i_1 < envelopes_blue.Count; i_1++) { intersector.AddBlueEnvelope(i_1, envelopes_blue[i_1]); } intersector.EndBlueConstruction(); while (intersector.Next()) { eCount++; } NUnit.Framework.Assert.IsTrue(qCount == eCount); } }
public static void TestImportExportShapeEnvelope() { com.esri.core.geometry.OperatorExportToESRIShape exporterShape = (com.esri.core.geometry.OperatorExportToESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToESRIShape); com.esri.core.geometry.OperatorImportFromESRIShape importerShape = (com.esri.core.geometry.OperatorImportFromESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromESRIShape); // Test Export Envelope to Polygon com.esri.core.geometry.Envelope envelope = MakeEnvelope(); System.IO.MemoryStream polygonShapeBuffer = exporterShape.Execute(0, envelope); com.esri.core.geometry.Polygon polygon = (com.esri.core.geometry.Polygon)importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Polygon, polygonShapeBuffer); int pointCount = polygon.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 4); com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); envelope.QueryEnvelope(env); // interval = envelope.queryInterval(VertexDescription.Semantics.Z, 0); com.esri.core.geometry.Point point3d; point3d = polygon.GetPoint(0); NUnit.Framework.Assert.IsTrue(point3d.GetX() == env.GetXMin() && point3d.GetY() == env.GetYMin()); // && point3d.z == // interval.vmin); point3d = polygon.GetPoint(1); NUnit.Framework.Assert.IsTrue(point3d.GetX() == env.GetXMin() && point3d.GetY() == env.GetYMax()); // && point3d.z == // interval.vmax); point3d = polygon.GetPoint(2); NUnit.Framework.Assert.IsTrue(point3d.GetX() == env.GetXMax() && point3d.GetY() == env.GetYMax()); // && point3d.z == // interval.vmin); point3d = polygon.GetPoint(3); NUnit.Framework.Assert.IsTrue(point3d.GetX() == env.GetXMax() && point3d.GetY() == env.GetYMin()); // && point3d.z == // interval.vmax); com.esri.core.geometry.Envelope1D interval; interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0); double m = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0); NUnit.Framework.Assert.IsTrue(m == interval.vmin); m = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(m == interval.vmax); m = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0); NUnit.Framework.Assert.IsTrue(m == interval.vmin); m = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0); NUnit.Framework.Assert.IsTrue(m == interval.vmax); interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0); double id = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 0); NUnit.Framework.Assert.IsTrue(id == interval.vmin); id = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 1, 0); NUnit.Framework.Assert.IsTrue(id == interval.vmax); id = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 2, 0); NUnit.Framework.Assert.IsTrue(id == interval.vmin); id = polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.ID, 3, 0); NUnit.Framework.Assert.IsTrue(id == interval.vmax); }
public virtual void TestCloneStuffEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(11, 12, 15, 24); com.esri.core.geometry.Envelope eCopy = (com.esri.core.geometry.Envelope)env.Copy(); NUnit.Framework.Assert.IsTrue(eCopy.Equals(env)); NUnit.Framework.Assert.IsTrue(eCopy.GetXMin() == 11); NUnit.Framework.Assert.IsTrue(eCopy.GetYMin() == 12); NUnit.Framework.Assert.IsTrue(eCopy.GetXMax() == 15); NUnit.Framework.Assert.IsTrue(eCopy.GetYMax() == 24); }
public static void TestImportExportShapePoint() { com.esri.core.geometry.OperatorExportToESRIShape exporterShape = (com.esri.core.geometry.OperatorExportToESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ExportToESRIShape); com.esri.core.geometry.OperatorImportFromESRIShape importerShape = (com.esri.core.geometry.OperatorImportFromESRIShape)com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.ImportFromESRIShape); // Point com.esri.core.geometry.Point point = MakePoint(); // Test Import Point from Point System.IO.MemoryStream pointShapeBuffer = exporterShape.Execute(0, point); com.esri.core.geometry.Point pointShapeGeometry = (com.esri.core.geometry.Point)importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Point, pointShapeBuffer); double x1 = point.GetX(); double x2 = pointShapeGeometry.GetX(); NUnit.Framework.Assert.IsTrue(x1 == x2); double y1 = point.GetY(); double y2 = pointShapeGeometry.GetY(); NUnit.Framework.Assert.IsTrue(y1 == y2); double z1 = point.GetZ(); double z2 = pointShapeGeometry.GetZ(); NUnit.Framework.Assert.IsTrue(z1 == z2); double m1 = point.GetM(); double m2 = pointShapeGeometry.GetM(); NUnit.Framework.Assert.IsTrue(m1 == m2); int id1 = point.GetID(); int id2 = pointShapeGeometry.GetID(); NUnit.Framework.Assert.IsTrue(id1 == id2); // Test Import Multipoint from Point com.esri.core.geometry.MultiPoint multipointShapeGeometry = (com.esri.core.geometry.MultiPoint)importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.MultiPoint, pointShapeBuffer); com.esri.core.geometry.Point point2d = multipointShapeGeometry.GetPoint(0); NUnit.Framework.Assert.IsTrue(x1 == point2d.GetX() && y1 == point2d.GetY()); int pointCount = multipointShapeGeometry.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); z2 = multipointShapeGeometry.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0); NUnit.Framework.Assert.IsTrue(z1 == z2); m2 = multipointShapeGeometry.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0); NUnit.Framework.Assert.IsTrue(m1 == m2); id2 = multipointShapeGeometry.GetAttributeAsInt(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 0); NUnit.Framework.Assert.IsTrue(id1 == id2); // Test Import Envelope from Point com.esri.core.geometry.Geometry envelopeShapeGeometry = importerShape.Execute(0, com.esri.core.geometry.Geometry.Type.Envelope, pointShapeBuffer); com.esri.core.geometry.Envelope envelope = (com.esri.core.geometry.Envelope)envelopeShapeGeometry; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope otherenv = new com.esri.core.geometry.Envelope(); envelope.QueryEnvelope(env); point.QueryEnvelope(otherenv); NUnit.Framework.Assert.IsTrue(env.GetXMin() == otherenv.GetXMin()); NUnit.Framework.Assert.IsTrue(env.GetXMax() == otherenv.GetXMax()); NUnit.Framework.Assert.IsTrue(env.GetYMin() == otherenv.GetYMin()); NUnit.Framework.Assert.IsTrue(env.GetYMax() == otherenv.GetYMax()); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D otherinterval; interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); otherinterval = point.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(interval.vmin == otherinterval.vmin); NUnit.Framework.Assert.IsTrue(interval.vmax == otherinterval.vmax); interval = envelope.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0); otherinterval = point.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0); NUnit.Framework.Assert.IsTrue(interval.vmin == otherinterval.vmin); NUnit.Framework.Assert.IsTrue(interval.vmax == otherinterval.vmax); }
public virtual void TestTouchOnEnvelopes() { // case1, not touched // Envelope env = new Envelope(new Point(-117,20), 12, 12); // Envelope env2 = new Envelope(-100,20,-80,30); // case2 touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(new com.esri.core.geometry.Point(-117, 20), 12, 12); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(-117, 26, -80, 30); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.Touches(env, env2, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public static void testRandom() { int passcount = 10; int figureSize = 100; int figureSize2 = 100; com.esri.core.geometry.Envelope extent1 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent2 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent3 = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Envelope extent4 = new com.esri.core.geometry.Envelope(); extent1.setCoords(-10000, 5000, 10000, 25000); // red extent2.setCoords(-10000, 2000, 10000, 8000); // blue extent3.setCoords(-10000, -8000, 10000, -2000); // blue extent4.setCoords(-10000, -25000, 10000, -5000); // red com.esri.core.geometry.RandomCoordinateGenerator generator1 = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), extent1, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator2 = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), extent2, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator3 = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), extent3, 0.001); com.esri.core.geometry.RandomCoordinateGenerator generator4 = new com.esri.core.geometry.RandomCoordinateGenerator (System.Math.max(figureSize, 10000), extent4, 0.001); java.util.Random random = new java.util.Random(1982); int rand_max = 511; int qCount = 0; int eCount = 0; int bCount = 0; for (int c = 0; c < passcount; c++) { com.esri.core.geometry.Polygon polyRed = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon polyBlue = new com.esri.core.geometry.Polygon(); int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator1.GetRandomCoord(); if (j == 0 || bRandomNew) { polyRed.startPath(pt); } else { polyRed.lineTo(pt); } } for (int j_1 = 0; j_1 < r; j_1++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator4.GetRandomCoord(); if (j_1 == 0 || bRandomNew) { polyRed.startPath(pt); } else { polyRed.lineTo(pt); } } r = figureSize2; if (r < 3) { continue; } for (int j_2 = 0; j_2 < r; j_2++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator2.GetRandomCoord(); if (j_2 == 0 || bRandomNew) { polyBlue.startPath(pt); } else { polyBlue.lineTo(pt); } } for (int j_3 = 0; j_3 < r; j_3++) { int rand = random.nextInt(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator3.GetRandomCoord(); if (j_3 == 0 || bRandomNew) { polyBlue.startPath(pt); } else { polyBlue.lineTo(pt); } } com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); // Quad_tree com.esri.core.geometry.QuadTree quadTree = buildQuadTree(polyBlue); com.esri.core.geometry.QuadTree.QuadTreeIterator iterator = quadTree.getIterator( ); com.esri.core.geometry.SegmentIteratorImpl _segIterRed = ((com.esri.core.geometry.MultiPathImpl )polyRed._getImpl()).querySegmentIterator(); while (_segIterRed.nextPath()) { while (_segIterRed.hasNextSegment()) { com.esri.core.geometry.Segment segmentRed = _segIterRed.nextSegment(); segmentRed.queryEnvelope2D(env); iterator.resetIterator(env, 0.001); while (iterator.next() != -1) { qCount++; } } } // Envelope_2D_intersector System.Collections.Generic.List <com.esri.core.geometry.Envelope2D> envelopes_red = new System.Collections.Generic.List <com.esri.core.geometry.Envelope2D>(); System.Collections.Generic.List <com.esri.core.geometry.Envelope2D> envelopes_blue = new System.Collections.Generic.List <com.esri.core.geometry.Envelope2D>(); com.esri.core.geometry.SegmentIterator segIterRed = polyRed.querySegmentIterator( ); while (segIterRed.nextPath()) { while (segIterRed.hasNextSegment()) { com.esri.core.geometry.Segment segment = segIterRed.nextSegment(); env = new com.esri.core.geometry.Envelope2D(); segment.queryEnvelope2D(env); envelopes_red.add(env); } } com.esri.core.geometry.SegmentIterator segIterBlue = polyBlue.querySegmentIterator (); while (segIterBlue.nextPath()) { while (segIterBlue.hasNextSegment()) { com.esri.core.geometry.Segment segment = segIterBlue.nextSegment(); env = new com.esri.core.geometry.Envelope2D(); segment.queryEnvelope2D(env); envelopes_blue.add(env); } } com.esri.core.geometry.Envelope2DIntersectorImpl intersector = new com.esri.core.geometry.Envelope2DIntersectorImpl (); intersector.setTolerance(0.001); intersector.startRedConstruction(); for (int i = 0; i < envelopes_red.Count; i++) { intersector.addRedEnvelope(i, envelopes_red[i]); } intersector.endRedConstruction(); intersector.startBlueConstruction(); for (int i_1 = 0; i_1 < envelopes_blue.Count; i_1++) { intersector.addBlueEnvelope(i_1, envelopes_blue[i_1]); } intersector.endBlueConstruction(); while (intersector.next()) { eCount++; } NUnit.Framework.Assert.IsTrue(qCount == eCount); } }
public virtual void TestTouchesOnPointAndEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Point p = new com.esri.core.geometry.Point(-130, 10); // Envelope env = new Envelope(p, 12, 12);//not touched com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(-130, 10, -110, 20); // touched bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.Touches(p, env, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public virtual void TestReplaceNaNs() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(); pt.SetXY(1, 2); pt.SetZ(double.NaN); pt.QueryEnvelope(env); pt.ReplaceNaNs(com.esri.core.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(pt.Equals(new com.esri.core.geometry.Point(1, 2, 5))); NUnit.Framework.Assert.IsTrue(env.HasZ()); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).IsEmpty()); env.ReplaceNaNs(com.esri.core.geometry.VertexDescription.Semantics.Z, 5); NUnit.Framework.Assert.IsTrue(env.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0).Equals(new com.esri.core.geometry.Envelope1D(5, 5))); }
public virtual void TestMultipoint() { com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(855277, 3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.MultiPoint multiPoint = new com.esri.core.geometry.MultiPoint(); multiPoint.Add(855277 + 10, 3892059 + 10); multiPoint.Add(855277, 3892059); multiPoint.Add(855277 + 100, 3892059 + 100); multiPoint.Add(855277 + 100, 3892059 + 101); multiPoint.Add(855277 + 101, 3892059 + 100); multiPoint.Add(855277 + 101, 3892059 + 101); com.esri.core.geometry.OperatorIntersection operatorIntersection = (com.esri.core.geometry.OperatorIntersection)projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersection); com.esri.core.geometry.MultiPoint mpResult = (com.esri.core.geometry.MultiPoint)operatorIntersection.Execute(poly1, multiPoint, inputSR, null); NUnit.Framework.Assert.IsTrue(mpResult.GetPointCount() == 3); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(0).GetX() == 855277 + 10 && mpResult.GetPoint(0).GetY() == 3892059 + 10); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(1).GetX() == 855277 && mpResult.GetPoint(1).GetY() == 3892059); NUnit.Framework.Assert.IsTrue(mpResult.GetPoint(2).GetX() == 855277 + 100 && mpResult.GetPoint(2).GetY() == 3892059 + 100); // Test intersection of Polygon with Envelope (calls Clip) com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(10, 10); poly.LineTo(20, 0); env1.SetXMin(0); env1.SetXMax(20); env1.SetYMin(5); env1.SetYMax(15); com.esri.core.geometry.Envelope envelope1 = env1; com.esri.core.geometry.Polygon clippedPoly = (com.esri.core.geometry.Polygon)operatorIntersection.Execute(poly, envelope1, inputSR, null); double area = clippedPoly.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Geometry res = GeometryEngine.difference(poly, envelope1, inputSR); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(855277 + 1, 3892059 + 1, 855277 + 30, 3892059 + 20); env2.SetXMin(5); env2.SetXMax(10); env2.SetYMin(0); env2.SetYMax(20); com.esri.core.geometry.Envelope envelope2 = env2; com.esri.core.geometry.Envelope clippedEnvelope = (com.esri.core.geometry.Envelope)operatorIntersection.Execute(envelope1, envelope2, inputSR, null); area = clippedEnvelope.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 50) < 0.00001); }
public virtual void TestCreation() { { com.esri.core.geometry.OperatorFactoryLocal projEnv = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.SpatialReference inputSR = com.esri.core.geometry.SpatialReference.Create(3857); com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env1 = new com.esri.core.geometry.Envelope2D(); env1.SetCoords(855277, 3892059, 855277 + 100, 3892059 + 100); poly1.AddEnvelope(env1, false); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env2 = new com.esri.core.geometry.Envelope2D(); env2.SetCoords(855277, 3892059, 855277 + 300, 3892059 + 200); poly2.AddEnvelope(env2, false); { com.esri.core.geometry.OperatorEquals operatorEquals = (com.esri.core.geometry.OperatorEquals)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Equals)); bool result = operatorEquals.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); com.esri.core.geometry.Polygon poly11 = new com.esri.core.geometry.Polygon(); poly1.CopyTo(poly11); result = operatorEquals.Execute(poly1, poly11, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorCrosses operatorCrosses = (com.esri.core.geometry.OperatorCrosses)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Crosses)); bool result = operatorCrosses.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); } { com.esri.core.geometry.OperatorWithin operatorWithin = (com.esri.core.geometry.OperatorWithin)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Within)); bool result = operatorWithin.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); bool result = operatorDisjoint.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); poly2.QueryEnvelope2D(env2D); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env2D); bool result = operatorDisjoint.Execute(envelope, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(envelope, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorDisjoint operatorDisjoint = (com.esri.core.geometry.OperatorDisjoint)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.OperatorIntersects operatorIntersects = (com.esri.core.geometry.OperatorIntersects)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); env2D.SetCoords(855277, 3892059, 855277 + 100, 3892059 + 100); poly.AddEnvelope(env2D, false); env2D.SetCoords(855277 + 10, 3892059 + 10, 855277 + 90, 3892059 + 90); poly.AddEnvelope(env2D, true); env2D.SetCoords(855277 + 20, 3892059 + 20, 855277 + 200, 3892059 + 80); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env2D); bool result = operatorDisjoint.Execute(envelope, poly, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); { result = operatorIntersects.Execute(envelope, poly, inputSR, null); NUnit.Framework.Assert.IsTrue(result); } } { com.esri.core.geometry.OperatorTouches operatorTouches = (com.esri.core.geometry.OperatorTouches)(projEnv.GetOperator(com.esri.core.geometry.Operator.Type.Touches)); bool result = operatorTouches.Execute(poly1, poly2, inputSR, null); NUnit.Framework.Assert.IsTrue(!result); } } }
public static void testDifferenceAndSymmetricDifference() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorDifference differenceOp = (com.esri.core.geometry.OperatorDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.Difference); com.esri.core.geometry.SpatialReference spatialRef = com.esri.core.geometry.SpatialReference .create(102113); com.esri.core.geometry.Polygon polygon1 = makePolygon1(); com.esri.core.geometry.Polygon polygon2 = makePolygon2(); com.esri.core.geometry.Polyline polyline1 = makePolyline1(); com.esri.core.geometry.MultiPoint multipoint1 = makeMultiPoint1(); com.esri.core.geometry.MultiPoint multipoint2 = makeMultiPoint2(); com.esri.core.geometry.MultiPoint multipoint3 = makeMultiPoint3(); com.esri.core.geometry.Point point1 = makePoint1(); com.esri.core.geometry.Point point2 = makePoint2(); com.esri.core.geometry.Envelope envelope1 = makeEnvelope1(); com.esri.core.geometry.Envelope envelope2 = makeEnvelope2(); com.esri.core.geometry.Envelope envelope3 = makeEnvelope3(); com.esri.core.geometry.Polygon outputPolygon = (com.esri.core.geometry.Polygon)differenceOp .execute(polygon1, polygon2, spatialRef, null); double area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); { com.esri.core.geometry.Point point_1 = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Point point_2 = new com.esri.core.geometry.Point(-130, 10); com.esri.core.geometry.Geometry baseGeom = new com.esri.core.geometry.Point(point_1 .getX(), point_1.getY()); com.esri.core.geometry.Geometry comparisonGeom = new com.esri.core.geometry.Point (point_2.getX(), point2.getY()); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Geometry geom = differenceOp.execute(baseGeom, comparisonGeom , sr, null); } com.esri.core.geometry.OperatorSymmetricDifference symDifferenceOp = (com.esri.core.geometry.OperatorSymmetricDifference )engine.getOperator(com.esri.core.geometry.Operator.Type.SymmetricDifference); outputPolygon = (com.esri.core.geometry.Polygon)symDifferenceOp.execute(polygon1, polygon2, spatialRef, null); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 150) <= 0.001); com.esri.core.geometry.Polyline outputPolyline = (com.esri.core.geometry.Polyline )differenceOp.execute(polyline1, polygon1, spatialRef, null); double length = outputPolyline.calculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(length * length - 50) < 0.001); com.esri.core.geometry.MultiPoint outputMultiPoint = (com.esri.core.geometry.MultiPoint )differenceOp.execute(multipoint1, polygon1, spatialRef, null); int pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1 , point1, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(symDifferenceOp.execute(multipoint1 , point2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 4); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , point1, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , point2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon1, envelope1 , spatialRef, null)); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(polygon2, envelope2 , spatialRef, null)); area = outputPolygon.calculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(area - 75) <= 0.001); outputPolyline = (com.esri.core.geometry.Polyline)(differenceOp.execute(polyline1 , envelope2, spatialRef, null)); length = outputPolyline.calculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.abs(length * length - 50) <= 0.001); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint1 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 1); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint2 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 6); outputMultiPoint = (com.esri.core.geometry.MultiPoint)(differenceOp.execute(multipoint3 , envelope2, spatialRef, null)); pointCount = outputMultiPoint.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 0); com.esri.core.geometry.Point outputPoint = (com.esri.core.geometry.Point)(differenceOp .execute(point1, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(!outputPoint.isEmpty()); outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point2, envelope2 , spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint.isEmpty()); outputPolygon = (com.esri.core.geometry.Polygon)(differenceOp.execute(envelope3, envelope2, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty()); outputPolygon = (com.esri.core.geometry.Polygon)(symDifferenceOp.execute(envelope3 , envelope3, spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPolygon != null && outputPolygon.isEmpty()); outputPoint = (com.esri.core.geometry.Point)(differenceOp.execute(point1, polygon1 , spatialRef, null)); NUnit.Framework.Assert.IsTrue(outputPoint != null); }
public virtual void TestDisjointRelationFalse() { { com.esri.core.geometry.OperatorDisjoint op = (com.esri.core.geometry.OperatorDisjoint)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(50, 50, 150, 150); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(25, 25, 175, 175); bool result = op.Execute(env1, env2, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(!result); } { com.esri.core.geometry.OperatorIntersects op = (com.esri.core.geometry.OperatorIntersects)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Intersects)); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(50, 50, 150, 150); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(25, 25, 175, 175); bool result = op.Execute(env1, env2, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorContains op = (com.esri.core.geometry.OperatorContains)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Contains)); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(100, 175, 200, 225); com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(200, 175); polyline.LineTo(200, 225); polyline.LineTo(125, 200); bool result = op.Execute(env1, polyline, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorTouches op = (com.esri.core.geometry.OperatorTouches)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Touches)); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(100, 200, 400, 400); com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(300, 60); polyline.LineTo(300, 200); polyline.LineTo(400, 50); bool result = op.Execute(env1, polyline, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorTouches op = (com.esri.core.geometry.OperatorTouches)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Touches)); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(50, 50, 150, 150); com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(100, 20); polyline.LineTo(100, 50); polyline.LineTo(150, 10); bool result = op.Execute(polyline, env1, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(result); } { com.esri.core.geometry.OperatorDisjoint op = (com.esri.core.geometry.OperatorDisjoint)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); polyline.StartPath(-5, 4); polyline.LineTo(5, -6); bool result = op.Execute(polyline, polygon, com.esri.core.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(result); } }
public virtual void testBufferEnvelope() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Envelope inputGeom = new com.esri.core.geometry.Envelope(1 , 0, 200, 400); com.esri.core.geometry.OperatorBuffer buffer = (com.esri.core.geometry.OperatorBuffer )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .Buffer); com.esri.core.geometry.OperatorSimplify simplify = (com.esri.core.geometry.OperatorSimplify )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .Simplify); com.esri.core.geometry.Geometry result = buffer.execute(inputGeom, sr, 40.0, null ); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); com.esri.core.geometry.Polygon poly = (com.esri.core.geometry.Polygon)(result); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); result.queryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - (80 + 199)) < 0.001 && System.Math.abs(env2D.getHeight() - (80 + 400)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 201.0 / 2) < 0.001 && System.Math.abs(env2D.getCenterY() - 400 / 2.0) < 0.001); 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); com.esri.core.geometry.NonSimpleResult nsr = new com.esri.core.geometry.NonSimpleResult (); NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, true, nsr, null )); { result = buffer.execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); NUnit.Framework.Assert.IsTrue(result.isEmpty()); } { result = buffer.execute(inputGeom, sr, -200.0, null); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); NUnit.Framework.Assert.IsTrue(result.isEmpty()); } { result = buffer.execute(inputGeom, sr, -199 / 2.0, null); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); NUnit.Framework.Assert.IsTrue(result.isEmpty()); } { result = buffer.execute(inputGeom, sr, -50.0, null); poly = (com.esri.core.geometry.Polygon)(result); result.queryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - (199 - 100)) < 0.001 && System.Math.abs(env2D.getHeight() - (400 - 100)) < 0.001); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 201.0 / 2) < 0.001 && System.Math.abs(env2D.getCenterY() - 400 / 2.0) < 0.001); pathCount = poly.getPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); pointCount = poly.getPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 4.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.isSimpleAsFeature(result, sr, null)); } }
public static void TestCreation() { { // simple create com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); NUnit.Framework.Assert.IsTrue(mpoint.GetType() == Geometry.Type.MultiPoint); // assertFalse(mpoint.getClass() == Polyline.class); NUnit.Framework.Assert.IsTrue(mpoint != null); NUnit.Framework.Assert.IsTrue(mpoint.GetType() == com.esri.core.geometry.Geometry.Type.MultiPoint); NUnit.Framework.Assert.IsTrue(mpoint.IsEmpty()); NUnit.Framework.Assert.IsTrue(mpoint.GetPointCount() == 0); mpoint = null; NUnit.Framework.Assert.IsFalse(mpoint != null); } { // play with default attributes com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); SimpleTest(mpoint); } { // simple create 2D com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.MultiPoint mpoint1 = new com.esri.core.geometry.MultiPoint(); NUnit.Framework.Assert.IsTrue(mpoint1 != null); mpoint.SetEmpty(); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.Add(pt); com.esri.core.geometry.Point pt3 = mpoint.GetPoint(0); NUnit.Framework.Assert.IsTrue(pt3.GetX() == 0 && pt3.GetY() == 0); // assertFalse(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // pt3.setZ(115.0); mpoint.SetPoint(0, pt3); pt3 = mpoint.GetPoint(0); NUnit.Framework.Assert.IsTrue(pt3.GetX() == 0 && pt3.GetY() == 0); } { /* && pt3.getZ() == 115 */ // assertTrue(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // CompareGeometryContent(mpoint, &pt, 1); // move 3d com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.Add(pt); com.esri.core.geometry.Point pt3 = mpoint.GetPoint(0); NUnit.Framework.Assert.IsTrue(pt3.GetX() == 0 && pt3.GetY() == 0); } { /* && pt3.getZ() == 0 */ // test QueryInterval com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(-1.0); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 0.0); // pt2.setZ(1.0); mpoint.Add(pt1); mpoint.Add(pt2); // Envelope1D e = // mpoint->QueryInterval(enum_value2(VertexDescription, Semantics, // Z), 0); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); mpoint.QueryEnvelope(e); } { // assertTrue(e.get == -1.0 && e.vmax == 1.0); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // for (int i = 0; i < sz; i++) // geom.add(openString[i]); // CompareGeometryContent(geom, openString, sz); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // Point point = GCNEW Point; // for (int i = 0; i < sz; i++) // { // point.setXY(openString[i]); // geom.add(point); // } // CompareGeometryContent(geom, openString, sz); // Test AddPoints com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // geom.addPoints(openString, sz, 0, -1); // CompareGeometryContent((MultiVertexGeometry)geom, openString, // sz); // Test InsertPoint(Point2D) com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point pt0 = new com.esri.core.geometry.Point(0.0, 0.0); // pt0.setZ(-1.0); // pt0.setID(7); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(1.0); // pt1.setID(11); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 1.0); // pt2.setZ(1.0); // pt2.setID(13); mpoint.Add(pt0); mpoint.Add(pt1); mpoint.Add(pt2); com.esri.core.geometry.Point pt3 = new com.esri.core.geometry.Point(-11.0, -13.0); mpoint.Add(pt3); mpoint.InsertPoint(1, pt3); NUnit.Framework.Assert.IsTrue(mpoint.GetPointCount() == 5); com.esri.core.geometry.Point pt; pt = mpoint.GetPoint(0); NUnit.Framework.Assert.IsTrue(pt.GetX() == pt0.GetX() && pt.GetY() == pt0.GetY()); /* * && * pt. * getZ * () == * pt0 * .getZ * () */ pt = mpoint.GetPoint(1); NUnit.Framework.Assert.IsTrue(pt.GetX() == pt3.GetX() && pt.GetY() == pt3.GetY()); pt = mpoint.GetPoint(2); NUnit.Framework.Assert.IsTrue(pt.GetX() == pt1.GetX() && pt.GetY() == pt1.GetY()); /* * && * pt. * getZ * () == * pt1 * .getZ * () */ pt = mpoint.GetPoint(3); NUnit.Framework.Assert.IsTrue(pt.GetX() == pt2.GetX() && pt.GetY() == pt2.GetY()); /* * && * pt. * getZ * () == * pt2 * .getZ * () */ com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); point.SetXY(17.0, 19.0); // point.setID(12); // point.setM(5); mpoint.InsertPoint(2, point); mpoint.Add(point); NUnit.Framework.Assert.IsTrue(mpoint.GetPointCount() == 7); } // double m; // int id; // pt = mpoint.getXYZ(2); // assertTrue(pt.x == 17.0 && pt.y == 19.0 && pt.z == defaultZ); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 2, 0); // assertTrue(m == 5); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 2, 0); // assertTrue(id == 23); // // pt = mpoint.getXYZ(3); // assertTrue(pt.x == pt1.x && pt.y == pt1.y && pt.z == pt1.z); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 3, 0); // assertTrue(NumberUtils::IsNaN(m)); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 3, 0); // assertTrue(id == 11); com.esri.core.geometry.MultiPoint mpoint_1 = new com.esri.core.geometry.MultiPoint(); com.esri.core.geometry.Point pt0_1 = new com.esri.core.geometry.Point(0.0, 0.0, -1.0); com.esri.core.geometry.Point pt1_1 = new com.esri.core.geometry.Point(0.0, 0.0, 1.0); com.esri.core.geometry.Point pt2_1 = new com.esri.core.geometry.Point(0.0, 1.0, 1.0); mpoint_1.Add(pt0_1); mpoint_1.Add(pt1_1); mpoint_1.Add(pt2_1); mpoint_1.RemovePoint(1); com.esri.core.geometry.Point pt_1; pt_1 = mpoint_1.GetPoint(0); NUnit.Framework.Assert.IsTrue(pt_1.GetX() == pt0_1.GetX() && pt_1.GetY() == pt0_1.GetY()); pt_1 = mpoint_1.GetPoint(1); NUnit.Framework.Assert.IsTrue(pt_1.GetX() == pt2_1.GetX() && pt_1.GetY() == pt2_1.GetY()); NUnit.Framework.Assert.IsTrue(mpoint_1.GetPointCount() == 2); }
public virtual void TestIsSimpleBasicsEnvelope() { // Envelope is simple, when it's width and height are not degenerate com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); bool result = simplifyOp.IsSimpleAsFeature(env, sr4326, false, null, null); // Empty is simple NUnit.Framework.Assert.IsTrue(result); env.SetCoords(0, 0, 10, 10); result = simplifyOp.IsSimpleAsFeature(env, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(result); // sliver but still simple env.SetCoords(0, 0, 0 + sr4326.GetTolerance() * 2, 10); result = simplifyOp.IsSimpleAsFeature(env, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(result); // sliver and not simple env.SetCoords(0, 0, 0 + sr4326.GetTolerance() * 0.5, 10); result = simplifyOp.IsSimpleAsFeature(env, sr4326, false, null, null); NUnit.Framework.Assert.IsTrue(!result); }
public static void TestIntervalTreeRandomConstruction() { int pointcount = 0; int passcount = 1000; int figureSize = 50; com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.SetCoords(-10000, -10000, 10000, 10000); com.esri.core.geometry.RandomCoordinateGenerator generator = new com.esri.core.geometry.RandomCoordinateGenerator(System.Math.Max(figureSize, 10000), env, 0.001); System.Random random = new System.Random(2013); int rand_max = 98765; System.Collections.Generic.List<com.esri.core.geometry.Envelope1D> intervals = new System.Collections.Generic.List<com.esri.core.geometry.Envelope1D>(); com.esri.core.geometry.AttributeStreamOfInt8 intervalsFound = new com.esri.core.geometry.AttributeStreamOfInt8(0); for (int i = 0; i < passcount; i++) { int r = figureSize; if (r < 3) { continue; } com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.Next(rand_max); bool bRandomNew = (r > 10) && ((1.0 * rand) / rand_max > 0.95); pt = generator.GetRandomCoord(); if (j == 0 || bRandomNew) { poly.StartPath(pt); } else { poly.LineTo(pt); } } { intervals.Clear(); com.esri.core.geometry.SegmentIterator seg_iter = poly.QuerySegmentIterator(); com.esri.core.geometry.Envelope1D interval; com.esri.core.geometry.Envelope1D range = poly.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.POSITION, 0); range.vmin -= 0.01; range.vmax += 0.01; while (seg_iter.NextPath()) { while (seg_iter.HasNextSegment()) { com.esri.core.geometry.Segment segment = seg_iter.NextSegment(); interval = segment.QueryInterval(com.esri.core.geometry.VertexDescription.Semantics.POSITION, 0); intervals.Add(interval); } } intervalsFound.Resize(intervals.Count, 0); // Just test construction for assertions com.esri.core.geometry.IntervalTreeImpl intervalTree = new com.esri.core.geometry.IntervalTreeImpl(true); Construct(intervalTree, intervals); for (int j_1 = 0; j_1 < intervals.Count; j_1++) { intervalTree.Insert(j_1); } com.esri.core.geometry.IntervalTreeImpl.IntervalTreeIteratorImpl iterator = intervalTree.GetIterator(range, 0.0); int count = 0; int handle; while ((handle = iterator.Next()) != -1) { count++; intervalsFound.Write(handle, unchecked((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count); for (int j_2 = 0; j_2 < intervalsFound.Size(); j_2++) { interval = intervals[j_2]; NUnit.Framework.Assert.IsTrue(intervalsFound.Read(j_2) == 1); } for (int j_3 = 0; j_3 < intervals.Count >> 1; j_3++) { intervalTree.Remove(j_3); } iterator.ResetIterator(range, 0.0); count = 0; while ((handle = iterator.Next()) != -1) { count++; intervalsFound.Write(handle, unchecked((byte)1)); } NUnit.Framework.Assert.IsTrue(count == intervals.Count - (intervals.Count >> 1)); for (int j_4 = (intervals.Count >> 1); j_4 < intervals.Count; j_4++) { intervalTree.Remove(j_4); } } } }
public static com.esri.core.geometry.Envelope MakeEnvelope3() { com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.SetCoords(5, 5, 6, 6); com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(env); return envelope; }
public virtual void testEnvelope() { com.esri.core.geometry.Envelope env = new com.esri.core.geometry.Envelope(); env.setCoords(100, 200, 250, 300); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0).isEmpty()); env.setInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 1, 2); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0).vmax == 2); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmax == 0); env.setInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 3, 4); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmax == 4); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID)); env.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID); NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .ID)); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmin == 0); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmax == 0); env.setInterval(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 5, 6); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmax == 4); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0).vmin == 1); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0).vmax == 2); env.dropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); NUnit.Framework.Assert.IsFalse(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmax == 4); com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(); env.copyTo(env1); NUnit.Framework.Assert.IsFalse(env1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); NUnit.Framework.Assert.IsTrue(env1.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmin == 5); NUnit.Framework.Assert.IsTrue(env1.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .ID, 0).vmax == 6); NUnit.Framework.Assert.IsTrue(env1.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmin == 3); NUnit.Framework.Assert.IsTrue(env1.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0).vmax == 4); }
/// <exception cref="org.codehaus.jackson.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool testEnvelope() { bool bAnswer = true; com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); envelope.setCoords(-109.55, 25.76, -86.39, 49.94); { org.codehaus.jackson.JsonParser envelopeWGS84Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine .geometryToJson(spatialReferenceWGS84, envelope)); com.esri.core.geometry.MapGeometry envelopeWGS84MP = com.esri.core.geometry.GeometryEngine .jsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelope.isEmpty() == envelopeWGS84MP.getGeometry() .isEmpty()); NUnit.Framework.Assert.IsTrue(envelope.getXMax() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getXMax()); NUnit.Framework.Assert.IsTrue(envelope.getYMax() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getYMax()); NUnit.Framework.Assert.IsTrue(envelope.getXMin() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getXMin()); NUnit.Framework.Assert.IsTrue(envelope.getYMin() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getYMin()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.getID() == envelopeWGS84MP.getSpatialReference ().getID()); if (!checkResultSpatialRef(envelopeWGS84MP, 4326, 0)) { bAnswer = false; } } { // export com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); e.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); e.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); string s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1 , e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":null,\"ymin\":null,\"xmax\":null,\"ymax\":null,\"zmin\":null,\"zmax\":null,\"mmin\":null,\"mmax\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); e.setCoords(0, 1, 2, 3); com.esri.core.geometry.Envelope1D z = new com.esri.core.geometry.Envelope1D(); com.esri.core.geometry.Envelope1D m = new com.esri.core.geometry.Envelope1D(); z.setCoords(5, 7); m.setCoords(11, 13); e.setInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, z); e.setInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, m); s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1 , e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":0,\"ymin\":1,\"xmax\":2,\"ymax\":3,\"zmin\":5,\"zmax\":7,\"mmin\":11,\"mmax\":13,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); } { // import string s = "{\"xmin\":0.0,\"ymin\":1.0,\"xmax\":2.0,\"ymax\":3.0,\"zmin\":5.0,\"zmax\":7.0,\"mmin\":11.0,\"mmax\":13.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; org.codehaus.jackson.JsonParser parser = factory.createJsonParser(s); com.esri.core.geometry.MapGeometry map_env = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Envelope env = (com.esri.core.geometry.Envelope)map_env.getGeometry (); com.esri.core.geometry.Envelope1D z = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0); com.esri.core.geometry.Envelope1D m = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0); NUnit.Framework.Assert.IsTrue(z.vmin == 5.0); NUnit.Framework.Assert.IsTrue(z.vmax == 7.0); NUnit.Framework.Assert.IsTrue(m.vmin == 11.0); NUnit.Framework.Assert.IsTrue(m.vmax == 13.0); } { string s = "{ \"zmin\" : 33, \"xmin\" : -109.55, \"zmax\" : 53, \"ymin\" : 25.76, \"xmax\" : -86.39, \"ymax\" : 49.94, \"mmax\" : 13}"; org.codehaus.jackson.JsonParser parser = factory.createJsonParser(s); com.esri.core.geometry.MapGeometry map_env = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Envelope env = (com.esri.core.geometry.Envelope)map_env.getGeometry (); com.esri.core.geometry.Envelope2D e = new com.esri.core.geometry.Envelope2D(); env.queryEnvelope2D(e); NUnit.Framework.Assert.IsTrue(e.xmin == -109.55 && e.ymin == 25.76 && e.xmax == - 86.39 && e.ymax == 49.94); com.esri.core.geometry.Envelope1D e1D; NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); e1D = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(e1D.vmin == 33 && e1D.vmax == 53); NUnit.Framework.Assert.IsTrue(!env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); } return(bAnswer); }
public static void testCreation() { { // simple create com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(Sharpen.Runtime.getClassForObject(mpoint) == Sharpen.Runtime.getClassForType (typeof(com.esri.core.geometry.MultiPoint))); // assertFalse(mpoint.getClass() == Polyline.class); NUnit.Framework.Assert.IsTrue(mpoint != null); NUnit.Framework.Assert.IsTrue(mpoint.getType() == com.esri.core.geometry.Geometry.Type .MultiPoint); NUnit.Framework.Assert.IsTrue(mpoint.isEmpty()); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 0); mpoint = null; NUnit.Framework.Assert.IsFalse(mpoint != null); } { // play with default attributes com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); simpleTest(mpoint); } { // simple create 2D com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.MultiPoint mpoint1 = new com.esri.core.geometry.MultiPoint (); NUnit.Framework.Assert.IsTrue(mpoint1 != null); mpoint.setEmpty(); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.add(pt); com.esri.core.geometry.Point pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); // assertFalse(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // pt3.setZ(115.0); mpoint.setPoint(0, pt3); pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); } { /* && pt3.getZ() == 115 */ // assertTrue(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // CompareGeometryContent(mpoint, &pt, 1); // move 3d com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.add(pt); com.esri.core.geometry.Point pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); } { /* && pt3.getZ() == 0 */ // test QueryInterval com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(-1.0); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 0.0); // pt2.setZ(1.0); mpoint.add(pt1); mpoint.add(pt2); // Envelope1D e = // mpoint->QueryInterval(enum_value2(VertexDescription, Semantics, // Z), 0); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); mpoint.queryEnvelope(e); } { // assertTrue(e.get == -1.0 && e.vmax == 1.0); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // for (int i = 0; i < sz; i++) // geom.add(openString[i]); // CompareGeometryContent(geom, openString, sz); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // Point point = GCNEW Point; // for (int i = 0; i < sz; i++) // { // point.setXY(openString[i]); // geom.add(point); // } // CompareGeometryContent(geom, openString, sz); // Test AddPoints com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // geom.addPoints(openString, sz, 0, -1); // CompareGeometryContent((MultiVertexGeometry)geom, openString, // sz); // Test InsertPoint(Point2D) com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); com.esri.core.geometry.Point pt0 = new com.esri.core.geometry.Point(0.0, 0.0); // pt0.setZ(-1.0); // pt0.setID(7); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(1.0); // pt1.setID(11); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 1.0); // pt2.setZ(1.0); // pt2.setID(13); mpoint.add(pt0); mpoint.add(pt1); mpoint.add(pt2); com.esri.core.geometry.Point pt3 = new com.esri.core.geometry.Point(-11.0, -13.0); mpoint.add(pt3); mpoint.insertPoint(1, pt3); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 5); com.esri.core.geometry.Point pt; pt = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt.getX() == pt0.getX() && pt.getY() == pt0.getY()); /* * && * pt. * getZ * () == * pt0 * .getZ * () */ pt = mpoint.getPoint(1); NUnit.Framework.Assert.IsTrue(pt.getX() == pt3.getX() && pt.getY() == pt3.getY()); pt = mpoint.getPoint(2); NUnit.Framework.Assert.IsTrue(pt.getX() == pt1.getX() && pt.getY() == pt1.getY()); /* * && * pt. * getZ * () == * pt1 * .getZ * () */ pt = mpoint.getPoint(3); NUnit.Framework.Assert.IsTrue(pt.getX() == pt2.getX() && pt.getY() == pt2.getY()); /* * && * pt. * getZ * () == * pt2 * .getZ * () */ com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); point.setXY(17.0, 19.0); // point.setID(12); // point.setM(5); mpoint.insertPoint(2, point); mpoint.add(point); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 7); } // double m; // int id; // pt = mpoint.getXYZ(2); // assertTrue(pt.x == 17.0 && pt.y == 19.0 && pt.z == defaultZ); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 2, 0); // assertTrue(m == 5); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 2, 0); // assertTrue(id == 23); // // pt = mpoint.getXYZ(3); // assertTrue(pt.x == pt1.x && pt.y == pt1.y && pt.z == pt1.z); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 3, 0); // assertTrue(NumberUtils::IsNaN(m)); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 3, 0); // assertTrue(id == 11); com.esri.core.geometry.MultiPoint mpoint_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point pt0_1 = new com.esri.core.geometry.Point(0.0, 0.0, - 1.0); com.esri.core.geometry.Point pt1_1 = new com.esri.core.geometry.Point(0.0, 0.0, 1.0 ); com.esri.core.geometry.Point pt2_1 = new com.esri.core.geometry.Point(0.0, 1.0, 1.0 ); mpoint_1.add(pt0_1); mpoint_1.add(pt1_1); mpoint_1.add(pt2_1); mpoint_1.removePoint(1); com.esri.core.geometry.Point pt_1; pt_1 = mpoint_1.getPoint(0); NUnit.Framework.Assert.IsTrue(pt_1.getX() == pt0_1.getX() && pt_1.getY() == pt0_1 .getY()); pt_1 = mpoint_1.getPoint(1); NUnit.Framework.Assert.IsTrue(pt_1.getX() == pt2_1.getX() && pt_1.getY() == pt2_1 .getY()); NUnit.Framework.Assert.IsTrue(mpoint_1.getPointCount() == 2); }