public static void Test1() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.OperatorGeneralize op = (com.esri.core.geometry.OperatorGeneralize)engine.GetOperator(com.esri.core.geometry.Operator.Type.Generalize); com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(1, 1); poly.LineTo(2, 0); poly.LineTo(3, 2); poly.LineTo(4, 1); poly.LineTo(5, 0); poly.LineTo(5, 10); poly.LineTo(0, 10); com.esri.core.geometry.Geometry geom = op.Execute(poly, 2, true, null); com.esri.core.geometry.Polygon p = (com.esri.core.geometry.Polygon)geom; com.esri.core.geometry.Point2D[] points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 4); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 0); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); NUnit.Framework.Assert.IsTrue(points[3].x == 0 && points[3].y == 10); com.esri.core.geometry.Geometry geom1 = op.Execute(geom, 5, false, null); p = (com.esri.core.geometry.Polygon)geom1; points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 3); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 10); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); geom1 = op.Execute(geom, 5, true, null); p = (com.esri.core.geometry.Polygon)geom1; points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 0); }
public static void test1() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorGeneralize op = (com.esri.core.geometry.OperatorGeneralize )engine.getOperator(com.esri.core.geometry.Operator.Type.Generalize); com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(0, 0); poly.lineTo(1, 1); poly.lineTo(2, 0); poly.lineTo(3, 2); poly.lineTo(4, 1); poly.lineTo(5, 0); poly.lineTo(5, 10); poly.lineTo(0, 10); com.esri.core.geometry.Geometry geom = op.execute(poly, 2, true, null); com.esri.core.geometry.Polygon p = (com.esri.core.geometry.Polygon)geom; com.esri.core.geometry.Point2D[] points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 4); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 0); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); NUnit.Framework.Assert.IsTrue(points[3].x == 0 && points[3].y == 10); com.esri.core.geometry.Geometry geom1 = op.execute(geom, 5, false, null); p = (com.esri.core.geometry.Polygon)geom1; points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 3); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 10); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); geom1 = op.execute(geom, 5, true, null); p = (com.esri.core.geometry.Polygon)geom1; points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 0); }
public static void testEngine(com.esri.core.geometry.SpatialReference spatialReference ) { com.esri.core.geometry.Polygon polygon8 = makePolygon8(); com.esri.core.geometry.Polyline cutter8 = makePolygonCutter8(); com.esri.core.geometry.Geometry[] cuts = com.esri.core.geometry.GeometryEngine.cut (polygon8, cutter8, spatialReference); com.esri.core.geometry.Polygon cut; int pathCount; int pointCount; double area; cut = (com.esri.core.geometry.Polygon)cuts[0]; pathCount = cut.getPathCount(); pointCount = cut.getPointCount(); area = cut.calculateArea2D(); NUnit.Framework.Assert.IsTrue(pathCount == 1); NUnit.Framework.Assert.IsTrue(pointCount == 4); NUnit.Framework.Assert.IsTrue(area == 100); cut = (com.esri.core.geometry.Polygon)cuts[1]; pathCount = cut.getPathCount(); pointCount = cut.getPointCount(); area = cut.calculateArea2D(); NUnit.Framework.Assert.IsTrue(pathCount == 2); NUnit.Framework.Assert.IsTrue(pointCount == 8); NUnit.Framework.Assert.IsTrue(area == 800); }
public virtual void testIntersectBetweenPolylineAndPolygon() { com.esri.core.geometry.Polyline basePl = new com.esri.core.geometry.Polyline(); basePl.startPath(new com.esri.core.geometry.Point(-117, 20)); basePl.lineTo(new com.esri.core.geometry.Point(-117, 10)); basePl.lineTo(new com.esri.core.geometry.Point(-130, 10)); basePl.lineTo(new com.esri.core.geometry.Point(-130, 20)); basePl.lineTo(new com.esri.core.geometry.Point(-117, 20)); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.startPath(-116, 20); compPl.lineTo(-131, 10); compPl.lineTo(-121, 50); com.esri.core.geometry.Geometry intersectGeom = null; int noException = 1; // no exception try { intersectGeom = com.esri.core.geometry.GeometryEngine.intersect(basePl, compPl, com.esri.core.geometry.SpatialReference .create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.IsNotNull(intersectGeom); }
public static void testPolygon9(com.esri.core.geometry.SpatialReference spatialReference ) { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorCut opCut = (com.esri.core.geometry.OperatorCut)engine .getOperator(com.esri.core.geometry.Operator.Type.Cut); com.esri.core.geometry.Polygon cut; int path_count; int point_count; double area; com.esri.core.geometry.Polygon polygon9 = makePolygon9(); com.esri.core.geometry.Polyline cutter9 = makePolygonCutter9(); com.esri.core.geometry.GeometryCursor cursor = opCut.execute(false, polygon9, cutter9 , spatialReference, null); cut = (com.esri.core.geometry.Polygon)cursor.next(); path_count = cut.getPathCount(); point_count = cut.getPointCount(); area = cut.calculateArea2D(); NUnit.Framework.Assert.IsTrue(path_count == 3); NUnit.Framework.Assert.IsTrue(point_count == 12); NUnit.Framework.Assert.IsTrue(area == 150); cut = (com.esri.core.geometry.Polygon)cursor.next(); path_count = cut.getPathCount(); point_count = cut.getPointCount(); area = cut.calculateArea2D(); NUnit.Framework.Assert.IsTrue(path_count == 3); NUnit.Framework.Assert.IsTrue(point_count == 12); NUnit.Framework.Assert.IsTrue(area == 150); cut = (com.esri.core.geometry.Polygon)cursor.next(); NUnit.Framework.Assert.IsTrue(cut == null); }
public static void test1() { com.esri.core.geometry.Polyline polyline; polyline = makePolyline(); com.esri.core.geometry.MultiPathImpl polylineImpl = (com.esri.core.geometry.MultiPathImpl )polyline._getImpl(); com.esri.core.geometry.QuadTree quadtree = buildQuadTree_(polylineImpl); com.esri.core.geometry.Line queryline = new com.esri.core.geometry.Line(34, 9, 66 , 46); com.esri.core.geometry.QuadTree.QuadTreeIterator qtIter = quadtree.getIterator(); NUnit.Framework.Assert.IsTrue(qtIter.next() == -1); qtIter.resetIterator(queryline, 0.0); int element_handle = qtIter.next(); while (element_handle > 0) { int index = quadtree.getElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.next(); } com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D (34, 9, 66, 46); com.esri.core.geometry.Polygon queryPolygon = new com.esri.core.geometry.Polygon( ); queryPolygon.addEnvelope(envelope, true); qtIter.resetIterator(queryline, 0.0); element_handle = qtIter.next(); while (element_handle > 0) { int index = quadtree.getElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.next(); } }
public virtual void TestIntersectBetweenPolylineAndPolygon() { com.esri.core.geometry.Polyline basePl = new com.esri.core.geometry.Polyline(); basePl.StartPath(new com.esri.core.geometry.Point(-117, 20)); basePl.LineTo(new com.esri.core.geometry.Point(-117, 10)); basePl.LineTo(new com.esri.core.geometry.Point(-130, 10)); basePl.LineTo(new com.esri.core.geometry.Point(-130, 20)); basePl.LineTo(new com.esri.core.geometry.Point(-117, 20)); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.StartPath(-116, 20); compPl.LineTo(-131, 10); compPl.LineTo(-121, 50); com.esri.core.geometry.Geometry intersectGeom = null; int noException = 1; // no exception try { intersectGeom = com.esri.core.geometry.GeometryEngine.Intersect(basePl, compPl, com.esri.core.geometry.SpatialReference.Create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.IsNotNull(intersectGeom); }
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 testTouchesOnPolylineAndPolygon() { 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)); com.esri.core.geometry.Polyline compPl = new com.esri.core.geometry.Polyline(); compPl.startPath(new com.esri.core.geometry.Point(-117, 20)); compPl.lineTo(new com.esri.core.geometry.Point(-108, 25)); compPl.lineTo(new com.esri.core.geometry.Point(-100, 20)); compPl.lineTo(new com.esri.core.geometry.Point(-100, 30)); bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.touches(basePl, compPl, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
public virtual void OffsetPolygon_(double distance, com.esri.core.geometry.OperatorOffset.JoinType joins) { com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.startPath(0, 0); polygon.lineTo(0, 16); polygon.lineTo(16, 16); polygon.lineTo(16, 11); polygon.lineTo(10, 10); polygon.lineTo(10, 12); polygon.lineTo(3, 12); polygon.lineTo(3, 4); polygon.lineTo(10, 4); polygon.lineTo(10, 6); polygon.lineTo(16, 5); polygon.lineTo(16, 0); com.esri.core.geometry.OperatorOffset offset = (com.esri.core.geometry.OperatorOffset )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .Offset); com.esri.core.geometry.Geometry outputGeom = offset.execute(polygon, null, distance , joins, 2, 0, null); NUnit.Framework.Assert.IsNotNull(outputGeom); if (distance > 2) { NUnit.Framework.Assert.IsTrue(outputGeom.isEmpty()); } }
public virtual void testTouchOnPolygons() { com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon(); pg.startPath(new com.esri.core.geometry.Point(-130, 10)); pg.lineTo(-131, 15); pg.lineTo(-140, 20); com.esri.core.geometry.Polygon pg2 = new com.esri.core.geometry.Polygon(); pg2.startPath(new com.esri.core.geometry.Point(-130, 10)); pg2.lineTo(-131, 15); pg2.lineTo(-120, 20); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); bool isTouched; bool isTouched2; try { isTouched = com.esri.core.geometry.GeometryEngine.touches(pg, pg2, sr); isTouched2 = com.esri.core.geometry.GeometryEngine.touches(pg2, pg, sr); } catch (System.ArgumentException) { isTouched = false; isTouched2 = false; } NUnit.Framework.Assert.AreEqual(isTouched && isTouched2, true); }
public static void Test1() { com.esri.core.geometry.Polyline polyline; polyline = MakePolyline(); com.esri.core.geometry.MultiPathImpl polylineImpl = (com.esri.core.geometry.MultiPathImpl)polyline._getImpl(); com.esri.core.geometry.QuadTree quadtree = BuildQuadTree_(polylineImpl); com.esri.core.geometry.Line queryline = new com.esri.core.geometry.Line(34, 9, 66, 46); com.esri.core.geometry.QuadTree.QuadTreeIterator qtIter = quadtree.GetIterator(); NUnit.Framework.Assert.IsTrue(qtIter.Next() == -1); qtIter.ResetIterator(queryline, 0.0); int element_handle = qtIter.Next(); while (element_handle > 0) { int index = quadtree.GetElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.Next(); } com.esri.core.geometry.Envelope2D envelope = new com.esri.core.geometry.Envelope2D(34, 9, 66, 46); com.esri.core.geometry.Polygon queryPolygon = new com.esri.core.geometry.Polygon(); queryPolygon.AddEnvelope(envelope, true); qtIter.ResetIterator(queryline, 0.0); element_handle = qtIter.Next(); while (element_handle > 0) { int index = quadtree.GetElement(element_handle); NUnit.Framework.Assert.IsTrue(index == 6 || index == 8 || index == 14); element_handle = qtIter.Next(); } }
public virtual void testEqualsOnPolygons() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Polygon baseMp = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon compMp = new com.esri.core.geometry.Polygon(); baseMp.startPath(-116, 40); baseMp.lineTo(-120, 39); baseMp.lineTo(-121, 10); baseMp.lineTo(-130, 12); baseMp.lineTo(-108, 25); compMp.startPath(-116, 40); compMp.lineTo(-120, 39); compMp.lineTo(-121, 10); compMp.lineTo(-130, 12); compMp.lineTo(-108, 25); bool isEqual; try { isEqual = com.esri.core.geometry.GeometryEngine.equals(baseMp, compMp, sr); } catch (System.ArgumentException) { isEqual = false; } NUnit.Framework.Assert.IsTrue(isEqual); }
public virtual void TestEqualsOnPolygons() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Polygon baseMp = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon compMp = new com.esri.core.geometry.Polygon(); baseMp.StartPath(-116, 40); baseMp.LineTo(-120, 39); baseMp.LineTo(-121, 10); baseMp.LineTo(-130, 12); baseMp.LineTo(-108, 25); compMp.StartPath(-116, 40); compMp.LineTo(-120, 39); compMp.LineTo(-121, 10); compMp.LineTo(-130, 12); compMp.LineTo(-108, 25); bool isEqual; try { isEqual = com.esri.core.geometry.GeometryEngine.Equals(baseMp, compMp, sr); } catch (System.ArgumentException) { isEqual = false; } NUnit.Framework.Assert.IsTrue(isEqual); }
public static void TestDistanceBetweenHugeGeometries() { /* const */ int N = 1000; // Should be even /* const */ double theoreticalDistance = 0.77; com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); double theta = 0.0; double thetaPlusPi = System.Math.PI; double dTheta = 2.0 * System.Math.PI / N; double distance; poly.StartPath(System.Math.Cos(theta), System.Math.Sin(theta)); // Add something so that poly2's bounding box is in poly's. Deleting // this should not affect answer. poly.LineTo(1.0, 1.5 + theoreticalDistance); poly.LineTo(3.5 + theoreticalDistance, 1.5 + theoreticalDistance); poly.LineTo(3.5 + theoreticalDistance, 2.0 + theoreticalDistance); poly.LineTo(0.95, 2.0 + theoreticalDistance); // /////////////////////////////////////////////////////////// poly2.StartPath(2.0 + theoreticalDistance + System.Math.Cos(thetaPlusPi), System.Math.Sin(thetaPlusPi)); for (double i = 1; i < N; i++) { theta += dTheta; thetaPlusPi += dTheta; poly.LineTo(System.Math.Cos(theta), System.Math.Sin(theta)); poly2.LineTo(2.0 + theoreticalDistance + System.Math.Cos(thetaPlusPi), System.Math.Sin(thetaPlusPi)); } distance = com.esri.core.geometry.GeometryEngine.Distance(poly, poly2, null); NUnit.Framework.Assert.IsTrue(System.Math.Abs(distance - theoreticalDistance) < 1.0e-10); }
public virtual void TestTouchOnPolygons() { com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon(); pg.StartPath(new com.esri.core.geometry.Point(-130, 10)); pg.LineTo(-131, 15); pg.LineTo(-140, 20); com.esri.core.geometry.Polygon pg2 = new com.esri.core.geometry.Polygon(); pg2.StartPath(new com.esri.core.geometry.Point(-130, 10)); pg2.LineTo(-131, 15); pg2.LineTo(-120, 20); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); bool isTouched; bool isTouched2; try { isTouched = com.esri.core.geometry.GeometryEngine.Touches(pg, pg2, sr); isTouched2 = com.esri.core.geometry.GeometryEngine.Touches(pg2, pg, sr); } catch (System.ArgumentException) { isTouched = false; isTouched2 = false; } NUnit.Framework.Assert.AreEqual(isTouched && isTouched2, true); }
public virtual void testPointAndPolygon3() { com.esri.core.geometry.Point basePl = new com.esri.core.geometry.Point(-121, 20); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.startPath(new com.esri.core.geometry.Point(-116, 20)); compPl.lineTo(new com.esri.core.geometry.Point(-131, 10)); compPl.lineTo(new com.esri.core.geometry.Point(-121, 50)); int noException = 1; // no exception com.esri.core.geometry.Geometry intersectGeom = null; try { intersectGeom = com.esri.core.geometry.GeometryEngine.intersect(basePl, compPl, com.esri.core.geometry.SpatialReference .create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.AreEqual(noException, 1); NUnit.Framework.Assert.IsNotNull(intersectGeom); NUnit.Framework.Assert.IsTrue(intersectGeom.getType() == com.esri.core.geometry.Geometry.Type .Point); com.esri.core.geometry.Point ip = (com.esri.core.geometry.Point)intersectGeom; NUnit.Framework.Assert.AreEqual(-121, 0.1E7, ip.getX()); NUnit.Framework.Assert.AreEqual(20, 0.1E7, ip.getY()); }
public static com.esri.core.geometry.Polygon makePolygon() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(0, 0); poly.lineTo(10, 10); poly.lineTo(20, 0); return(poly); }
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 static com.esri.core.geometry.Polygon makePolygon2() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(5, 5); poly.lineTo(5, 15); poly.lineTo(15, 15); poly.lineTo(15, 5); return(poly); }
internal virtual com.esri.core.geometry.Polygon MakePolygon2() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(0, 0); poly.lineTo(0, 10); poly.lineTo(10, 10); poly.lineTo(10, 0); return poly; }
// done /* * ------------>---------------->--------------- | | | (1) | | | | --->--- * ------->------- | | | | | (5) | | | | | | --<-- | | | | (2) | | | | | | | * | | | | (4) | | | | | | | -->-- | | --<-- | ---<--- | | | | | | * -------<------- | | (3) | -------------<---------------<--------------- * -->-- */ // Bowtie case with vertices at intersection public virtual com.esri.core.geometry.Polygon MakeNonSimplePolygon5() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 0); poly.LineTo(0, 0); poly.LineTo(5, 5); poly.LineTo(10, 10); poly.LineTo(0, 10); poly.LineTo(5, 5); return poly; }
public virtual void testPolygonGeometryEngine() { com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon(); p.startPath(100.0, 0.0); p.lineTo(101.0, 0.0); p.lineTo(101.0, 1.0); p.lineTo(100.0, 1.0); p.closePathWithLine(); string result = com.esri.core.geometry.GeometryEngine.geometryToGeoJson(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}" , result); }
private static com.esri.core.geometry.Polygon makePolygon() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.startPath(0, 0); poly.lineTo(0, 10); poly.lineTo(10, 10); poly.lineTo(10, 0); poly.startPath(3, 3); poly.lineTo(7, 3); poly.lineTo(7, 7); poly.lineTo(3, 7); return(poly); }
public virtual void testMP2onCR175871() { com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon(); pg.startPath(-50, 10); pg.lineTo(-50, 12); pg.lineTo(-45, 12); pg.lineTo(-45, 10); com.esri.core.geometry.Polygon pg1 = new com.esri.core.geometry.Polygon(); pg1.startPath(-45, 10); pg1.lineTo(-40, 10); pg1.lineTo(-40, 8); pg.add(pg1, false); try { string jSonStr = com.esri.core.geometry.GeometryEngine.geometryToJson(4326, pg); org.codehaus.jackson.JsonFactory jf = new org.codehaus.jackson.JsonFactory(); org.codehaus.jackson.JsonParser jp = jf.createJsonParser(jSonStr); jp.nextToken(); com.esri.core.geometry.MapGeometry mg = com.esri.core.geometry.GeometryEngine.jsonToGeometry (jp); com.esri.core.geometry.Geometry gm = mg.getGeometry(); NUnit.Framework.Assert.AreEqual(com.esri.core.geometry.Geometry.Type.Polygon, gm. getType()); com.esri.core.geometry.Polygon pgNew = (com.esri.core.geometry.Polygon)gm; NUnit.Framework.Assert.AreEqual(pgNew.getPathCount(), pg.getPathCount()); NUnit.Framework.Assert.AreEqual(pgNew.getPointCount(), pg.getPointCount()); NUnit.Framework.Assert.AreEqual(pgNew.getSegmentCount(), pg.getSegmentCount()); NUnit.Framework.Assert.AreEqual(pg.getPoint(0).getX(), 0.000000001, pgNew.getPoint (0).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getX(), 0.000000001, pgNew.getPoint (1).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getX(), 0.000000001, pgNew.getPoint (2).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getX(), 0.000000001, pgNew.getPoint (3).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(0).getY(), 0.000000001, pgNew.getPoint (0).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getY(), 0.000000001, pgNew.getPoint (1).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getY(), 0.000000001, pgNew.getPoint (2).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getY(), 0.000000001, pgNew.getPoint (3).getY()); } catch (System.Exception ex) { string err = ex.Message; System.Console.Out.Write(err); throw; } }
public virtual void testEmptyPolygon() { com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.OperatorExportToGeoJson exporter = (com.esri.core.geometry.OperatorExportToGeoJson )factory.getOperator(com.esri.core.geometry.Operator.Type.ExportToGeoJson); string result = exporter.execute(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":null}", result ); com.esri.core.geometry.MapGeometry imported = com.esri.core.geometry.OperatorImportFromGeoJson .local().execute(0, com.esri.core.geometry.Geometry.Type.Unknown, result, null); NUnit.Framework.Assert.IsTrue(imported.getGeometry().isEmpty()); NUnit.Framework.Assert.IsTrue(imported.getGeometry().getType() == com.esri.core.geometry.Geometry.Type .Polygon); }
public virtual void testPolygon() { com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon(); p.startPath(100.0, 0.0); p.lineTo(101.0, 0.0); p.lineTo(101.0, 1.0); p.lineTo(100.0, 1.0); p.closePathWithLine(); com.esri.core.geometry.OperatorExportToGeoJson exporter = (com.esri.core.geometry.OperatorExportToGeoJson )factory.getOperator(com.esri.core.geometry.Operator.Type.ExportToGeoJson); string result = exporter.execute(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]]}" , result); }
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 static void TestDistanceBetweenTriangles() { double distance; com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); poly.StartPath(0.0, 0.0); poly.LineTo(1.0, 2.0); poly.LineTo(0.0, 2.0); double xSeparation = 0.1; double ySeparation = 0.1; poly2.StartPath(xSeparation + 1.0, 2.0 - ySeparation); poly2.LineTo(xSeparation + 2.0, 2.0 - ySeparation); poly2.LineTo(xSeparation + 2.0, 4.0 - ySeparation); distance = com.esri.core.geometry.GeometryEngine.Distance(poly, poly2, null); NUnit.Framework.Assert.IsTrue(0.0 < distance && distance < xSeparation + ySeparation); }
public virtual com.esri.core.geometry.Polygon MakeNonSimplePolygon2() { //MapGeometry mg = OperatorFactoryLocal.loadGeometryFromJSONFileDbg("c:/temp/simplify_polygon_gnomonic.txt"); //Geometry res = OperatorSimplify.local().execute(mg.getGeometry(), mg.getSpatialReference(), true, null); com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 15); poly.LineTo(15, 15); poly.LineTo(15, 0); // This is an interior ring but it is clockwise poly.StartPath(5, 5); poly.LineTo(5, 6); poly.LineTo(6, 6); poly.LineTo(6, 5); return poly; }
public virtual void testBufferPoint() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Point inputGeom = new com.esri.core.geometry.Point(12, 120 ); 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; int pathCount = poly.getPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.getPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.abs(pointCount - 100.0) < 10); com.esri.core.geometry.Envelope2D env2D = new com.esri.core.geometry.Envelope2D(); result.queryEnvelope2D(env2D); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getWidth() - 80) < 0.01 && System.Math .abs(env2D.getHeight() - 80) < 0.01); NUnit.Framework.Assert.IsTrue(System.Math.abs(env2D.getCenterX() - 12) < 0.001 && System.Math.abs(env2D.getCenterY() - 120) < 0.001); com.esri.core.geometry.NonSimpleResult nsr = new com.esri.core.geometry.NonSimpleResult (); bool is_simple = simplify.isSimpleAsFeature(result, sr, true, nsr, null); NUnit.Framework.Assert.IsTrue(is_simple); { result = buffer.execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); NUnit.Framework.Assert.IsTrue(result.isEmpty()); } { result = buffer.execute(inputGeom, sr, -1, null); NUnit.Framework.Assert.IsTrue(result.getType().value() == com.esri.core.geometry.Geometry.GeometryType .Polygon); NUnit.Framework.Assert.IsTrue(result.isEmpty()); } }
public virtual void TestCreation() { // simple create com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); int number = poly.GetStateFlag(); NUnit.Framework.Assert.IsTrue(poly != null); // assertTrue(poly.getClass() == Polygon.class); // assertFalse(poly.getClass() == Envelope.class); NUnit.Framework.Assert.IsTrue(poly.GetType() == com.esri.core.geometry.Geometry.Type.Polygon); NUnit.Framework.Assert.IsTrue(poly.IsEmpty()); NUnit.Framework.Assert.IsTrue(poly.GetPointCount() == 0); NUnit.Framework.Assert.IsTrue(poly.GetPathCount() == 0); number = poly.GetStateFlag(); poly = null; NUnit.Framework.Assert.IsFalse(poly != null); // play with default attributes com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); }
public static void testPointInPolygonBugCR181840() { com.esri.core.geometry.PolygonUtils.PiPResult res; { // pointInPolygonBugCR181840 - point in polygon bug com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); // outer ring1 polygon.startPath(0, 0); polygon.lineTo(10, 10); polygon.lineTo(20, 0); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(15, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPOutside); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(2, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPOutside); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(5, 5), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPInside); } { // CR181840 - point in polygon bug com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); // outer ring1 polygon.startPath(10, 10); polygon.lineTo(20, 0); polygon.lineTo(0, 0); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(15, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPOutside); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(2, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPOutside); res = com.esri.core.geometry.PolygonUtils.isPointInPolygon2D(polygon, com.esri.core.geometry.Point2D .construct(5, 5), 0); NUnit.Framework.Assert.IsTrue(res == com.esri.core.geometry.PolygonUtils.PiPResult .PiPInside); } }
public static void testArcObjectsFailureCR196492() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorClip clipOp = (com.esri.core.geometry.OperatorClip )engine.getOperator(com.esri.core.geometry.Operator.Type.Clip); com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.addEnvelope(new com.esri.core.geometry.Envelope2D(0, 0, 600, 600), false); polygon.startPath(30, 300); polygon.lineTo(20, 310); polygon.lineTo(10, 300); com.esri.core.geometry.SpatialReference gcsWGS84 = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Envelope2D envelopeCR = new com.esri.core.geometry.Envelope2D (10, 10, 500, 500); com.esri.core.geometry.Polygon clippedPolygon = (com.esri.core.geometry.Polygon)clipOp .execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.getPointCount() == 7); }
public virtual void testOGCPolygonWithHole() { com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon(); p.startPath(100.0, 0.0); p.lineTo(100.0, 1.0); p.lineTo(101.0, 1.0); p.lineTo(101.0, 0.0); p.closePathWithLine(); p.startPath(100.2, 0.2); p.lineTo(100.8, 0.2); p.lineTo(100.8, 0.8); p.lineTo(100.2, 0.8); p.closePathWithLine(); com.esri.core.geometry.ogc.OGCPolygon ogcPolygon = new com.esri.core.geometry.ogc.OGCPolygon (p, null); string result = ogcPolygon.asGeoJson(); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[100.0,1.0],[101.0,1.0],[101.0,0.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}" , result); }
public static void testDistanceBetweenTriangles() { double distance; com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polygon poly2 = new com.esri.core.geometry.Polygon(); poly.startPath(0.0, 0.0); poly.lineTo(1.0, 2.0); poly.lineTo(0.0, 2.0); double xSeparation = 0.1; double ySeparation = 0.1; poly2.startPath(xSeparation + 1.0, 2.0 - ySeparation); poly2.lineTo(xSeparation + 2.0, 2.0 - ySeparation); poly2.lineTo(xSeparation + 2.0, 4.0 - ySeparation); distance = com.esri.core.geometry.GeometryEngine.distance(poly, poly2, null); NUnit.Framework.Assert.IsTrue(0.0 < distance && distance < xSeparation + ySeparation ); }
public virtual void testMultiPolygon() { org.codehaus.jackson.JsonFactory jsonFactory = new org.codehaus.jackson.JsonFactory (); string geoJsonPolygon = "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100.0,-100.0],[-100.0,100.0],[100.0,100.0],[100.0,-100.0],[-100.0,-100.0]],[[-90.0,-90.0],[90.0,90.0],[-90.0,90.0],[90.0,-90.0],[-90.0,-90.0]]],[[[-10.0,-10.0],[-10.0,10.0],[10.0,10.0],[10.0,-10.0],[-10.0,-10.0]]]]}"; string esriJsonPolygon = "{\"rings\": [[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[-90, -90], [90, 90], [-90, 90], [90, -90], [-90, -90]], [[-10, -10], [-10, 10], [10, 10], [10, -10], [-10, -10]]]}"; org.codehaus.jackson.JsonParser parser = jsonFactory.createJsonParser(esriJsonPolygon ); com.esri.core.geometry.MapGeometry parsedPoly = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); //MapGeometry parsedPoly = GeometryEngine.geometryFromGeoJson(jsonPolygon, 0, Geometry.Type.Polygon); com.esri.core.geometry.Polygon poly = (com.esri.core.geometry.Polygon)parsedPoly. getGeometry(); com.esri.core.geometry.OperatorExportToGeoJson exporter = (com.esri.core.geometry.OperatorExportToGeoJson )factory.getOperator(com.esri.core.geometry.Operator.Type.ExportToGeoJson); //String result = exporter.execute(parsedPoly.getGeometry()); string result = exporter.execute(poly); NUnit.Framework.Assert.AreEqual(geoJsonPolygon, result); }
public static void testDistanceBetweenVariousGeometries() { com.esri.core.geometry.Polygon polygon = makePolygon(); com.esri.core.geometry.Polyline polyline = makePolyline(); com.esri.core.geometry.MultiPoint multipoint = makeMultiPoint(); com.esri.core.geometry.Point point = makePoint(); // SpatialReference spatialRef = // SpatialReference.create(3857);//PCS_WGS_1984_WEB_MERCATOR_AUXSPHERE double distance; distance = com.esri.core.geometry.GeometryEngine.distance(polygon, polyline, null ); NUnit.Framework.Assert.IsTrue(System.Math.abs(distance - 5.0) < 0.00001); distance = com.esri.core.geometry.GeometryEngine.distance(polygon, multipoint, null ); NUnit.Framework.Assert.IsTrue(System.Math.abs(distance - 5.0) < 0.00001); distance = com.esri.core.geometry.GeometryEngine.distance(polygon, point, null); NUnit.Framework.Assert.IsTrue(System.Math.abs(distance - 5.0) < 0.00001); }
public virtual void testPolygonWithHoleGeometryEngine() { com.esri.core.geometry.Polygon p = new com.esri.core.geometry.Polygon(); p.startPath(100.0, 0.0); //clockwise exterior p.lineTo(100.0, 1.0); p.lineTo(101.0, 1.0); p.lineTo(101.0, 0.0); p.closePathWithLine(); p.startPath(100.2, 0.2); //counterclockwise hole p.lineTo(100.8, 0.2); p.lineTo(100.8, 0.8); p.lineTo(100.2, 0.8); p.closePathWithLine(); string result = com.esri.core.geometry.GeometryEngine.geometryToGeoJson(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100.0,0.0],[100.0,1.0],[101.0,1.0],[101.0,0.0],[100.0,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}" , result); }
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 static void testProximity2D_3() { com.esri.core.geometry.OperatorFactoryLocal factory = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorProximity2D proximity = (com.esri.core.geometry.OperatorProximity2D )factory.getOperator(com.esri.core.geometry.Operator.Type.Proximity2D); com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.startPath(new com.esri.core.geometry.Point(-120, 22)); polygon.lineTo(new com.esri.core.geometry.Point(-120, 10)); polygon.lineTo(new com.esri.core.geometry.Point(-110, 10)); polygon.lineTo(new com.esri.core.geometry.Point(-110, 22)); com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); point.setXY(-110, 20); com.esri.core.geometry.Proximity2DResult result = proximity.getNearestCoordinate( polygon, point, false); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(); point2.setXY(-120, 12); com.esri.core.geometry.Proximity2DResult[] results = proximity.getNearestVertices (polygon, point2, 10, 12); }
public virtual void testTouchesBetweenPolylineAndPolygon() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference .create(4326); com.esri.core.geometry.Polyline pl = new com.esri.core.geometry.Polyline(); pl.startPath(2, 4); pl.lineTo(1, 10); pl.lineTo(6, 12); com.esri.core.geometry.Polygon compPg = new com.esri.core.geometry.Polygon(); compPg.startPath(2, 4); compPg.lineTo(2, 9); compPg.lineTo(9, 9); compPg.lineTo(9, 4); compPg.startPath(2, 9); compPg.lineTo(6, 12); compPg.lineTo(9, 10); bool isTouched = com.esri.core.geometry.GeometryEngine.touches(pl, compPg, sr); NUnit.Framework.Assert.AreEqual(isTouched, true); }
public static void TestEditShape_() { { // std::shared_ptr<Esri_runtimecore::Geometry::Polygon> poly_base_6 // = std::make_shared<Esri_runtimecore::Geometry::Polygon>(); // Single part polygon com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Single part polyline com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Two part poly com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Five part poly. Close one of parts to test if it works. com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(14, 15); poly.LineTo(10, 11); poly.StartPath(100, 10); poly.LineTo(100, 12); poly.LineTo(14, 150); poly.LineTo(10, 101); poly.LineTo(100, 11); poly.StartPath(1100, 101); poly.LineTo(1300, 132); poly.LineTo(144, 150); poly.LineTo(106, 1051); poly.LineTo(1600, 161); poly.StartPath(100, 190); poly.LineTo(1800, 192); poly.LineTo(184, 8150); poly.LineTo(1080, 181); poly.StartPath(1030, 10); poly.LineTo(1300, 132); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.SetClosedPath(editShape.GetNextPath(editShape.GetFirstPath(geom)), true); ((com.esri.core.geometry.MultiPathImpl)poly._getImpl()).ClosePathWithLine(1); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polyline poly = new com.esri.core.geometry.Polyline(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); int vertex = editShape.GetFirstVertex(editShape.GetFirstPath(geom)); vertex = editShape.RemoveVertex(vertex, true); vertex = editShape.GetNextVertex(vertex); editShape.RemoveVertex(vertex, true); com.esri.core.geometry.Polyline poly2 = (com.esri.core.geometry.Polyline)editShape.GetGeometry(geom); poly.SetEmpty(); poly.StartPath(10, 12); poly.LineTo(310, 1301); poly.LineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test erase com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 12); poly.LineTo(314, 3150); poly.LineTo(310, 1301); poly.LineTo(3100, 311); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); int vertex = editShape.GetFirstVertex(editShape.GetFirstPath(geom)); vertex = editShape.RemoveVertex(vertex, true); vertex = editShape.GetNextVertex(vertex); editShape.RemoveVertex(vertex, true); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); poly.SetEmpty(); poly.StartPath(10, 12); poly.LineTo(310, 1301); poly.LineTo(3100, 311); NUnit.Framework.Assert.IsTrue(poly.Equals(poly2)); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(10.001, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.0025); poly.LineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(!poly2.IsEmpty()); } { // Test Filter Close Points com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(10, 10); poly.LineTo(10, 10.001); poly.LineTo(11.0, 10); com.esri.core.geometry.EditShape editShape = new com.esri.core.geometry.EditShape(); int geom = editShape.AddGeometry(poly); editShape.FilterClosePoints(0.002, true, false); com.esri.core.geometry.Polygon poly2 = (com.esri.core.geometry.Polygon)editShape.GetGeometry(geom); NUnit.Framework.Assert.IsTrue(poly2.IsEmpty()); } { // Test attribute splitting 1 com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.StartPath(0, 0); polyline.LineTo(1, 1); polyline.LineTo(2, 2); polyline.LineTo(3, 3); polyline.LineTo(4, 4); polyline.StartPath(5, 5); polyline.LineTo(6, 6); polyline.LineTo(7, 7); polyline.LineTo(8, 8); polyline.LineTo(9, 9); polyline.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 0, 4); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 1, 0, 8); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 2, 0, 12); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 3, 0, 16); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 4, 0, 20); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 5, 0, 22); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 6, 0, 26); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 7, 0, 30); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 8, 0, 34); polyline.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 9, 0, 38); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.AddGeometry(polyline); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32(0); for (int path = shape.GetFirstPath(geometry); path != -1; path = shape.GetNextPath(path)) { for (int vertex = shape.GetFirstVertex(path); vertex != -1; vertex = shape.GetNextVertex(vertex)) { if (vertex != shape.GetLastVertex(path)) { vertex_handles.Add(vertex); } } } double[] t = new double[1]; for (int i = 0; i < vertex_handles.Size(); i++) { int vertex = vertex_handles.Read(i); t[0] = 0.5; shape.SplitSegment(vertex, t, 1); } com.esri.core.geometry.Polyline chopped_polyline = (com.esri.core.geometry.Polyline)shape.GetGeometry(geometry); NUnit.Framework.Assert.IsTrue(chopped_polyline.GetPointCount() == 18); double att_ = 4; for (int i_1 = 0; i_1 < 18; i_1++) { double att = chopped_polyline.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.Z, i_1, 0); NUnit.Framework.Assert.IsTrue(att == att_); att_ += 2; } } { // Test attribute splitting 2 com.esri.core.geometry.Polyline line1 = new com.esri.core.geometry.Polyline(); com.esri.core.geometry.Polyline line2 = new com.esri.core.geometry.Polyline(); line1.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line2.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); line1.StartPath(0, 0); line1.LineTo(10, 10); line2.StartPath(10, 0); line2.LineTo(0, 10); line1.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); line1.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17); line2.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 5); line2.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 15); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int g1 = shape.AddGeometry(line1); int g2 = shape.AddGeometry(line2); com.esri.core.geometry.CrackAndCluster.Execute(shape, 0.001, null, true); com.esri.core.geometry.Polyline chopped_line1 = (com.esri.core.geometry.Polyline)shape.GetGeometry(g1); com.esri.core.geometry.Polyline chopped_line2 = (com.esri.core.geometry.Polyline)shape.GetGeometry(g2); double att1 = chopped_line1.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); double att2 = chopped_line2.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(att1 == 12); NUnit.Framework.Assert.IsTrue(att2 == 10); } { // Test attribute splitting 3 com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.AddAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0, 7); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0, 17); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0, 23); polygon.SetAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0, 43); com.esri.core.geometry.EditShape shape = new com.esri.core.geometry.EditShape(); int geometry = shape.AddGeometry(polygon); com.esri.core.geometry.AttributeStreamOfInt32 vertex_handles = new com.esri.core.geometry.AttributeStreamOfInt32(0); int start_v = shape.GetFirstVertex(shape.GetFirstPath(geometry)); int v = start_v; do { vertex_handles.Add(v); v = shape.GetNextVertex(v); } while (v != start_v); double[] t = new double[1]; for (int i = 0; i < vertex_handles.Size(); i++) { int v1 = vertex_handles.Read(i); t[0] = 0.5; shape.SplitSegment(v1, t, 1); } com.esri.core.geometry.Polygon cut_polygon = (com.esri.core.geometry.Polygon)shape.GetGeometry(geometry); NUnit.Framework.Assert.IsTrue(cut_polygon.GetPointCount() == 8); com.esri.core.geometry.Point2D pt0 = cut_polygon.GetXY(0); double a0 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 0); NUnit.Framework.Assert.IsTrue(a0 == 25); com.esri.core.geometry.Point2D pt1 = cut_polygon.GetXY(1); double a1 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 1, 0); NUnit.Framework.Assert.IsTrue(a1 == 7); com.esri.core.geometry.Point2D pt2 = cut_polygon.GetXY(2); double a2 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 2, 0); NUnit.Framework.Assert.IsTrue(a2 == 12); com.esri.core.geometry.Point2D pt3 = cut_polygon.GetXY(3); double a3 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 3, 0); NUnit.Framework.Assert.IsTrue(a3 == 17); com.esri.core.geometry.Point2D pt4 = cut_polygon.GetXY(4); double a4 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 4, 0); NUnit.Framework.Assert.IsTrue(a4 == 20); com.esri.core.geometry.Point2D pt5 = cut_polygon.GetXY(5); double a5 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 5, 0); NUnit.Framework.Assert.IsTrue(a5 == 23); com.esri.core.geometry.Point2D pt6 = cut_polygon.GetXY(6); double a6 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 6, 0); NUnit.Framework.Assert.IsTrue(a6 == 33); com.esri.core.geometry.Point2D pt7 = cut_polygon.GetXY(7); double a7 = cut_polygon.GetAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics.M, 7, 0); NUnit.Framework.Assert.IsTrue(a7 == 43); } }
public virtual void TestTouchesBetweenMultipartPolygons2() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Polygon pl = new com.esri.core.geometry.Polygon(); pl.StartPath(2, 4); pl.LineTo(1, 9); pl.LineTo(2, 6); pl.StartPath(2, 9); pl.LineTo(6, 14); pl.LineTo(6, 12); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.StartPath(2, 4); compPl.LineTo(2, 9); compPl.LineTo(9, 9); compPl.LineTo(9, 4); compPl.StartPath(2, 9); compPl.LineTo(6, 12); compPl.LineTo(9, 10); bool isTouched = com.esri.core.geometry.GeometryEngine.Touches(pl, compPl, sr); NUnit.Framework.Assert.AreEqual(isTouched, true); }
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 TestTouchesOnPolylineAndPolygon() { 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)); com.esri.core.geometry.Polyline compPl = new com.esri.core.geometry.Polyline(); compPl.StartPath(new com.esri.core.geometry.Point(-117, 20)); compPl.LineTo(new com.esri.core.geometry.Point(-108, 25)); compPl.LineTo(new com.esri.core.geometry.Point(-100, 20)); compPl.LineTo(new com.esri.core.geometry.Point(-100, 30)); bool isTouched; try { isTouched = com.esri.core.geometry.GeometryEngine.Touches(basePl, compPl, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
internal virtual com.esri.core.geometry.Polygon MakePolygon2() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 10); poly.LineTo(10, 10); poly.LineTo(10, 0); return poly; }
public static void TestProximity2D_3() { com.esri.core.geometry.OperatorFactoryLocal factory = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.OperatorProximity2D proximity = (com.esri.core.geometry.OperatorProximity2D)factory.GetOperator(com.esri.core.geometry.Operator.Type.Proximity2D); com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); polygon.StartPath(new com.esri.core.geometry.Point(-120, 22)); polygon.LineTo(new com.esri.core.geometry.Point(-120, 10)); polygon.LineTo(new com.esri.core.geometry.Point(-110, 10)); polygon.LineTo(new com.esri.core.geometry.Point(-110, 22)); com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); point.SetXY(-110, 20); com.esri.core.geometry.Proximity2DResult result = proximity.GetNearestCoordinate(polygon, point, false); com.esri.core.geometry.Point point2 = new com.esri.core.geometry.Point(); point2.SetXY(-120, 12); com.esri.core.geometry.Proximity2DResult[] results = proximity.GetNearestVertices(polygon, point2, 10, 12); }
internal virtual com.esri.core.geometry.Polygon MakePolygon() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(3, -2); poly.LineTo(2, -1); poly.LineTo(3, 0); poly.LineTo(4, 0); poly.StartPath(1.75, 1); poly.LineTo(0.75, 2); poly.LineTo(1.75, 3); poly.LineTo(2.25, 2.5); poly.LineTo(2.75, 2); poly.StartPath(3, 2.5); poly.LineTo(2.5, 3); poly.LineTo(2, 3.5); poly.LineTo(3, 4.5); poly.LineTo(4, 3.5); poly.StartPath(4.75, 1); poly.LineTo(3.75, 2); poly.LineTo(4, 2.25); poly.LineTo(4.75, 3); poly.LineTo(5.75, 2); return poly; }
public virtual void TestPolygonPointRelate() { com.esri.core.geometry.OperatorRelate op = (com.esri.core.geometry.OperatorRelate)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Relate)); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); bool res; string scl; com.esri.core.geometry.Polygon polygon = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(10, 10); polygon.LineTo(10, 0); point.SetXY(0, 0); scl = "FF20FTFFT"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); polygon.SetEmpty(); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); scl = "0FFFFFFF2"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); polygon.SetEmpty(); polygon.StartPath(0, 0); polygon.LineTo(0, 1); polygon.LineTo(0, 0); scl = "0F1FFFFF2"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); point.SetXY(-1, 0); scl = "FF1FFF0F2"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); polygon.SetEmpty(); polygon.StartPath(0, 0); polygon.LineTo(0, 10); polygon.LineTo(0, 0); scl = "FF1FFFTFT"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); polygon.SetEmpty(); polygon.StartPath(0, 0); polygon.LineTo(0, 0); polygon.LineTo(0, 0); scl = "FF0FFF0F2"; res = op.Execute(polygon, point, sr, scl, null); NUnit.Framework.Assert.IsTrue(res); }
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 TestDisjointCrash() { com.esri.core.geometry.Polygon g1 = new com.esri.core.geometry.Polygon(); g1.AddEnvelope(com.esri.core.geometry.Envelope2D.Construct(0, 0, 10, 10), false); com.esri.core.geometry.Polygon g2 = new com.esri.core.geometry.Polygon(); g2.AddEnvelope(com.esri.core.geometry.Envelope2D.Construct(10, 1, 21, 21), false); g1 = (com.esri.core.geometry.Polygon)com.esri.core.geometry.OperatorDensifyByLength.Local().Execute(g1, 0.1, null); com.esri.core.geometry.OperatorDisjoint.Local().AccelerateGeometry(g1, com.esri.core.geometry.SpatialReference.Create(4267), com.esri.core.geometry.Geometry.GeometryAccelerationDegree.enumHot); bool res = com.esri.core.geometry.OperatorDisjoint.Local().Execute(g1, g2, com.esri.core.geometry.SpatialReference.Create(4267), null); NUnit.Framework.Assert.IsTrue(!res); }
public virtual void TestProximity_2D_1() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.OperatorProximity2D proximityOp = (com.esri.core.geometry.OperatorProximity2D)engine.GetOperator(com.esri.core.geometry.Operator.Type.Proximity2D); com.esri.core.geometry.Point inputPoint = new com.esri.core.geometry.Point(3, 2); com.esri.core.geometry.Point point0 = new com.esri.core.geometry.Point(2.75, 2); // Point point1 = new Point(3, 2.5); // Point point2 = new Point(3.75, 2); // Point point3 = new Point(2.25, 2.5); // Point point4 = new Point(4, 2.25); // GetNearestVertices for Polygon (Native and DotNet) com.esri.core.geometry.Polygon polygon = MakePolygon(); com.esri.core.geometry.Proximity2DResult[] resultArray = com.esri.core.geometry.GeometryEngine.GetNearestVertices(polygon, inputPoint, 2.0, 8); NUnit.Framework.Assert.IsTrue(resultArray.Length == 8); double lastdistance; double distance; com.esri.core.geometry.Proximity2DResult result0 = resultArray[0]; lastdistance = result0.GetDistance(); NUnit.Framework.Assert.IsTrue(lastdistance <= 2.0); com.esri.core.geometry.Proximity2DResult result1 = resultArray[1]; distance = result1.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result2 = resultArray[2]; distance = result2.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result3 = resultArray[3]; distance = result3.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result4 = resultArray[4]; distance = result4.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result5 = resultArray[5]; distance = result5.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result6 = resultArray[6]; distance = result6.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); lastdistance = distance; com.esri.core.geometry.Proximity2DResult result7 = resultArray[7]; distance = result7.GetDistance(); NUnit.Framework.Assert.IsTrue(distance <= 2.0 && distance >= lastdistance); // lastdistance = distance; // Point[] coordinates = polygon.get.getCoordinates2D(); // int pointCount = polygon.getPointCount(); // // int hits = 0; // for (int i = 0; i < pointCount; i++) // { // Point ipoint = coordinates[i]; // distance = Point::Distance(ipoint, inputPoint); // // if (distance < lastdistance) // hits++; // } // assertTrue(hits < 8); // GetNearestVertices for Point com.esri.core.geometry.Point point = MakePoint(); resultArray = com.esri.core.geometry.GeometryEngine.GetNearestVertices(point, inputPoint, 1.0, 1); NUnit.Framework.Assert.IsTrue(resultArray.Length == 1); result0 = resultArray[0]; com.esri.core.geometry.Point resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY()); // GetNearestVertex for Polygon result0 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(polygon, inputPoint); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point0.GetX() && resultPoint0.GetY() == point0.GetY()); // GetNearestVertex for Point result0 = com.esri.core.geometry.GeometryEngine.GetNearestVertex(point, inputPoint); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == point.GetX() && resultPoint0.GetY() == point.GetY()); // GetNearestCoordinate for Polygon com.esri.core.geometry.Polygon polygon2 = MakePolygon2(); result0 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(polygon2, inputPoint, true); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == inputPoint.GetX() && resultPoint0.GetY() == inputPoint.GetY()); // GetNearestCoordinate for Polyline com.esri.core.geometry.Polyline polyline = MakePolyline(); result0 = com.esri.core.geometry.GeometryEngine.GetNearestCoordinate(polyline, inputPoint, true); resultPoint0 = result0.GetCoordinate(); NUnit.Framework.Assert.IsTrue(resultPoint0.GetX() == 0.0 && resultPoint0.GetY() == 2.0); com.esri.core.geometry.Polygon pp = new com.esri.core.geometry.Polygon(); pp.StartPath(0, 0); pp.LineTo(0, 10); pp.LineTo(10, 10); pp.LineTo(10, 0); inputPoint.SetXY(15, -5); result0 = proximityOp.GetNearestCoordinate(pp, inputPoint, true, true); bool is_right = result0.IsRightSide(); NUnit.Framework.Assert.IsTrue(!is_right); }
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 virtual void TestPolygonPolylineDisjoint() { com.esri.core.geometry.OperatorDisjoint disjoint = (com.esri.core.geometry.OperatorDisjoint)(com.esri.core.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.esri.core.geometry.Operator.Type.Disjoint)); com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(102100); double tolerance = sr.GetTolerance(com.esri.core.geometry.VertexDescription.Semantics.POSITION); com.esri.core.geometry.Polygon polygon1 = new com.esri.core.geometry.Polygon(); com.esri.core.geometry.Polyline polyline2 = new com.esri.core.geometry.Polyline(); polygon1.StartPath(0, 0); polygon1.LineTo(0, 10); polygon1.LineTo(10, 10); polygon1.LineTo(10, 0); polygon1.StartPath(1, 1); polygon1.LineTo(9, 1); polygon1.LineTo(9, 9); polygon1.LineTo(1, 9); polyline2.StartPath(3, 3); polyline2.LineTo(6, 6); bool res = disjoint.Execute(polyline2, polygon1, sr, null); NUnit.Framework.Assert.IsTrue(res); res = disjoint.Execute(polygon1, polyline2, sr, null); NUnit.Framework.Assert.IsTrue(res); polyline2.StartPath(0, 0); polyline2.LineTo(0, 5); res = disjoint.Execute(polyline2, polygon1, sr, null); NUnit.Framework.Assert.IsTrue(!res); res = disjoint.Execute(polygon1, polyline2, sr, null); NUnit.Framework.Assert.IsTrue(!res); polygon1.SetEmpty(); polyline2.SetEmpty(); polygon1.StartPath(0, 0); polygon1.LineTo(0, 10); polygon1.LineTo(10, 10); polygon1.LineTo(10, 0); polyline2.StartPath(2, 2); polyline2.LineTo(4, 4); com.esri.core.geometry.OperatorFactoryLocal factory = com.esri.core.geometry.OperatorFactoryLocal.GetInstance(); com.esri.core.geometry.OperatorSimplify simplify_op = (com.esri.core.geometry.OperatorSimplify)factory.GetOperator(com.esri.core.geometry.Operator.Type.Simplify); simplify_op.IsSimpleAsFeature(polygon1, sr, null); simplify_op.IsSimpleAsFeature(polyline2, sr, null); res = disjoint.Execute(polyline2, polygon1, sr, null); NUnit.Framework.Assert.IsTrue(!res); res = disjoint.Execute(polygon1, polyline2, sr, null); NUnit.Framework.Assert.IsTrue(!res); }
public static com.esri.core.geometry.Polygon MakePolygon2() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(5, 5); poly.LineTo(5, 15); poly.LineTo(15, 15); poly.LineTo(15, 5); return poly; }
public static com.esri.core.geometry.Polygon MakePolygon1() { com.esri.core.geometry.Polygon poly = new com.esri.core.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 10); poly.LineTo(10, 10); poly.LineTo(10, 0); return poly; }
public virtual void TestPointAndPolygon2() { com.esri.core.geometry.Point basePl = new com.esri.core.geometry.Point(-115, 20); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.StartPath(new com.esri.core.geometry.Point(-116, 20)); compPl.LineTo(new com.esri.core.geometry.Point(-131, 10)); compPl.LineTo(new com.esri.core.geometry.Point(-121, 50)); int noException = 1; // no exception com.esri.core.geometry.Geometry intersectGeom = null; try { intersectGeom = com.esri.core.geometry.GeometryEngine.Intersect(basePl, compPl, com.esri.core.geometry.SpatialReference.Create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.AreEqual(noException, 1); NUnit.Framework.Assert.IsTrue(intersectGeom.IsEmpty()); }
public virtual void TestBufferPolygon() { com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference.Create(4326); com.esri.core.geometry.Polygon inputGeom = new com.esri.core.geometry.Polygon(); 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); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); { com.esri.core.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null); NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.esri.core.geometry.Geometry.GeometryType.Polygon); NUnit.Framework.Assert.IsTrue(result == inputGeom); } { com.esri.core.geometry.Geometry result = buffer.Execute(inputGeom, sr, 10, 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() - 20 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 20 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 104.0) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.esri.core.geometry.SpatialReference.Create(4326); inputGeom = new com.esri.core.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); com.esri.core.geometry.Geometry result = buffer.Execute(inputGeom, sr, -10, 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() - 15.85) < 0.1 && System.Math.Abs(env2D.GetHeight() - 15.85) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 32.07) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 17.93) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 1); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 3); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } { sr = com.esri.core.geometry.SpatialReference.Create(4326); inputGeom = new com.esri.core.geometry.Polygon(); inputGeom.StartPath(0, 0); inputGeom.LineTo(0, 50); inputGeom.LineTo(50, 50); inputGeom.LineTo(50, 0); inputGeom.StartPath(10, 10); inputGeom.LineTo(40, 10); inputGeom.LineTo(40, 40); inputGeom.LineTo(10, 40); com.esri.core.geometry.Geometry result = buffer.Execute(inputGeom, sr, -2, 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() + 4 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() + 4 - 50) < 0.1); NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1); int pathCount = poly.GetPathCount(); NUnit.Framework.Assert.IsTrue(pathCount == 2); int pointCount = poly.GetPointCount(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 108) < 10); NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null)); } }
public virtual void TestPointAndPolygon3() { com.esri.core.geometry.Point basePl = new com.esri.core.geometry.Point(-121, 20); com.esri.core.geometry.Polygon compPl = new com.esri.core.geometry.Polygon(); compPl.StartPath(new com.esri.core.geometry.Point(-116, 20)); compPl.LineTo(new com.esri.core.geometry.Point(-131, 10)); compPl.LineTo(new com.esri.core.geometry.Point(-121, 50)); int noException = 1; // no exception com.esri.core.geometry.Geometry intersectGeom = null; try { intersectGeom = com.esri.core.geometry.GeometryEngine.Intersect(basePl, compPl, com.esri.core.geometry.SpatialReference.Create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.AreEqual(noException, 1); NUnit.Framework.Assert.IsNotNull(intersectGeom); NUnit.Framework.Assert.IsTrue(intersectGeom.GetType() == com.esri.core.geometry.Geometry.Type.Point); com.esri.core.geometry.Point ip = (com.esri.core.geometry.Point)intersectGeom; NUnit.Framework.Assert.AreEqual(ip.GetX(), -121, 0.1E7); NUnit.Framework.Assert.AreEqual(ip.GetY(), 20, 0.1E7); }