public static void TestDistanceBetweenHugeGeometries() { /* const */ int N = 1000; // Should be even /* const */ double theoreticalDistance = 0.77; com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); com.epl.geometry.Polygon poly2 = new com.epl.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.epl.geometry.GeometryEngine.Distance(poly, poly2, null); NUnit.Framework.Assert.IsTrue(System.Math.Abs(distance - theoreticalDistance) < 1.0e-10); }
public static void TestPointInPolygonBugCR181840() { com.epl.geometry.PolygonUtils.PiPResult res; { // pointInPolygonBugCR181840 - point in polygon bug com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); // outer ring1 polygon.StartPath(0, 0); polygon.LineTo(10, 10); polygon.LineTo(20, 0); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(15, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(2, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(5, 5), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside); } { // CR181840 - point in polygon bug com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); // outer ring1 polygon.StartPath(10, 10); polygon.LineTo(20, 0); polygon.LineTo(0, 0); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(15, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(2, 10), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPOutside); res = com.epl.geometry.PolygonUtils.IsPointInPolygon2D(polygon, com.epl.geometry.Point2D.Construct(5, 5), 0); NUnit.Framework.Assert.IsTrue(res == com.epl.geometry.PolygonUtils.PiPResult.PiPInside); } }
public virtual void TestEqualsOnPolygons() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polygon baseMp = new com.epl.geometry.Polygon(); com.epl.geometry.Polygon compMp = new com.epl.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.epl.geometry.GeometryEngine.Equals(baseMp, compMp, sr); } catch (System.ArgumentException) { isEqual = false; } NUnit.Framework.Assert.IsTrue(isEqual); }
public virtual void TestGeometryToJSONOldID() { // CR com.epl.geometry.Polygon geom = new com.epl.geometry.Polygon(); geom.StartPath(new com.epl.geometry.Point(-113, 34)); geom.LineTo(new com.epl.geometry.Point(-105, 34)); geom.LineTo(new com.epl.geometry.Point(-108, 40)); string outputPolygon = com.epl.geometry.GeometryEngine.GeometryToJson(com.epl.geometry.SpatialReference.Create(3857), geom); // Test // WKID // == // -1 string correctPolygon = "{\"rings\":[[[-113,34],[-105,34],[-108,40],[-113,34]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; NUnit.Framework.Assert.IsTrue(outputPolygon.Equals(correctPolygon)); com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jp = jf.CreateJsonParser(outputPolygon); jp.NextToken(); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp); int srId = mg.GetSpatialReference().GetID(); int srOldId = mg.GetSpatialReference().GetOldID(); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 3857); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetLatestID() == 3857); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetOldID() == 102100); }
public virtual void TestIntersectBetweenPolylineAndPolygon() { com.epl.geometry.Polyline basePl = new com.epl.geometry.Polyline(); basePl.StartPath(new com.epl.geometry.Point(-117, 20)); basePl.LineTo(new com.epl.geometry.Point(-117, 10)); basePl.LineTo(new com.epl.geometry.Point(-130, 10)); basePl.LineTo(new com.epl.geometry.Point(-130, 20)); basePl.LineTo(new com.epl.geometry.Point(-117, 20)); com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon(); compPl.StartPath(-116, 20); compPl.LineTo(-131, 10); compPl.LineTo(-121, 50); com.epl.geometry.Geometry intersectGeom = null; int noException = 1; // no exception try { intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.IsNotNull(intersectGeom); }
public virtual void TestPointAndPolygon3() { com.epl.geometry.Point basePl = new com.epl.geometry.Point(-121, 20); com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon(); compPl.StartPath(new com.epl.geometry.Point(-116, 20)); compPl.LineTo(new com.epl.geometry.Point(-131, 10)); compPl.LineTo(new com.epl.geometry.Point(-121, 50)); int noException = 1; // no exception com.epl.geometry.Geometry intersectGeom = null; try { intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.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.epl.geometry.Geometry.Type.Point); com.epl.geometry.Point ip = (com.epl.geometry.Point)intersectGeom; NUnit.Framework.Assert.AreEqual(ip.GetX(), -121, 0.1E7); NUnit.Framework.Assert.AreEqual(ip.GetY(), 20, 0.1E7); }
public virtual void TestPolygon() { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(-97.06138, 32.837); polygon.LineTo(-97.06133, 32.836); polygon.LineTo(-97.06124, 32.834); polygon.LineTo(-97.06127, 32.832); polygon.StartPath(-97.06326, 32.759); polygon.LineTo(-97.06298, 32.755); { com.fasterxml.jackson.core.JsonParser polygonPathsWgs84Parser = factory.CreateJsonParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, polygon)); com.epl.geometry.MapGeometry mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(polygon.GetPointCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPointCount()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(0).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(0).GetY()); NUnit.Framework.Assert.IsTrue(polygon.GetPathCount() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPathCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount() + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount()); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(0) == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(0)); NUnit.Framework.Assert.IsTrue(polygon.GetSegmentCount(1) + 1 == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetSegmentCount(1)); int lastIndex = polygon.GetPointCount() - 1; NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetX() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetX()); NUnit.Framework.Assert.IsTrue(polygon.GetPoint(lastIndex).GetY() == ((com.epl.geometry.Polygon)mPolygonWGS84MP.GetGeometry()).GetPoint(lastIndex).GetY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); com.epl.geometry.Polygon emptyPolygon = new com.epl.geometry.Polygon(); string emptyPolygonString = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, emptyPolygon); polygonPathsWgs84Parser = factory.CreateJsonParser(emptyPolygonString); mPolygonWGS84MP = com.epl.geometry.GeometryEngine.JsonToGeometry(polygonPathsWgs84Parser); NUnit.Framework.Assert.IsTrue(mPolygonWGS84MP.GetGeometry().IsEmpty()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == mPolygonWGS84MP.GetSpatialReference().GetID()); } }
public virtual void TestGeometryCollection() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); System.Text.StringBuilder geometrySb = new System.Text.StringBuilder(); geometrySb.Append("{\"type\" : \"GeometryCollection\", \"geometries\" : ["); com.epl.geometry.ogc.OGCPoint point = new com.epl.geometry.ogc.OGCPoint(new com.epl.geometry.Point(1.0, 1.0), sr); NUnit.Framework.Assert.AreEqual("{\"x\":1,\"y\":1,\"spatialReference\":{\"wkid\":4326}}", point.AsJson()); NUnit.Framework.Assert.AreEqual("{\"type\":\"Point\",\"coordinates\":[1,1],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", point.AsGeoJson()); geometrySb.Append(point.AsGeoJson()).Append(", "); com.epl.geometry.ogc.OGCLineString line = new com.epl.geometry.ogc.OGCLineString(new com.epl.geometry.Polyline(new com.epl.geometry.Point(1.0, 1.0), new com.epl.geometry.Point(2.0, 2.0)), 0, sr); NUnit.Framework.Assert.AreEqual("{\"paths\":[[[1,1],[2,2]]],\"spatialReference\":{\"wkid\":4326}}", line.AsJson()); NUnit.Framework.Assert.AreEqual("{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", line.AsGeoJson()); geometrySb.Append(line.AsGeoJson()).Append(", "); com.epl.geometry.Polygon p = new com.epl.geometry.Polygon(); p.StartPath(1.0, 1.0); p.LineTo(2.0, 2.0); p.LineTo(3.0, 1.0); p.LineTo(2.0, 0.0); com.epl.geometry.ogc.OGCPolygon polygon = new com.epl.geometry.ogc.OGCPolygon(p, sr); NUnit.Framework.Assert.AreEqual("{\"rings\":[[[1,1],[2,2],[3,1],[2,0],[1,1]]],\"spatialReference\":{\"wkid\":4326}}", polygon.AsJson()); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}", polygon.AsGeoJson()); geometrySb.Append(polygon.AsGeoJson()).Append("]}"); System.Collections.Generic.IList <com.epl.geometry.ogc.OGCGeometry> geoms = new System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry>(3); geoms.Add(point); geoms.Add(line); geoms.Add(polygon); com.epl.geometry.ogc.OGCConcreteGeometryCollection collection = new com.epl.geometry.ogc.OGCConcreteGeometryCollection(geoms, sr); string s2 = collection.AsGeoJson(); NUnit.Framework.Assert.AreEqual("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1,1]},{\"type\":\"LineString\",\"coordinates\":[[1,1],[2,2]]},{\"type\":\"Polygon\",\"coordinates\":[[[1,1],[2,0],[3,1],[2,2],[1,1]]]}],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}}}" , collection.AsGeoJson()); }
public virtual void TestTouchOnPolygons() { com.epl.geometry.Polygon pg = new com.epl.geometry.Polygon(); pg.StartPath(new com.epl.geometry.Point(-130, 10)); pg.LineTo(-131, 15); pg.LineTo(-140, 20); com.epl.geometry.Polygon pg2 = new com.epl.geometry.Polygon(); pg2.StartPath(new com.epl.geometry.Point(-130, 10)); pg2.LineTo(-131, 15); pg2.LineTo(-120, 20); com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); bool isTouched; bool isTouched2; try { isTouched = com.epl.geometry.GeometryEngine.Touches(pg, pg2, sr); isTouched2 = com.epl.geometry.GeometryEngine.Touches(pg2, pg, sr); } catch (System.ArgumentException) { isTouched = false; isTouched2 = false; } NUnit.Framework.Assert.AreEqual(isTouched && isTouched2, true); }
public virtual void TestTouchesOnPolylineAndPolygon() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polygon basePl = new com.epl.geometry.Polygon(); basePl.StartPath(new com.epl.geometry.Point(-117, 20)); basePl.LineTo(new com.epl.geometry.Point(-100, 20)); basePl.LineTo(new com.epl.geometry.Point(-100, 10)); basePl.LineTo(new com.epl.geometry.Point(-117, 10)); com.epl.geometry.Polyline compPl = new com.epl.geometry.Polyline(); compPl.StartPath(new com.epl.geometry.Point(-117, 20)); compPl.LineTo(new com.epl.geometry.Point(-108, 25)); compPl.LineTo(new com.epl.geometry.Point(-100, 20)); compPl.LineTo(new com.epl.geometry.Point(-100, 30)); bool isTouched; try { isTouched = com.epl.geometry.GeometryEngine.Touches(basePl, compPl, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
internal static com.epl.geometry.Polygon MakePolygon() { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(10, 10); poly.LineTo(20, 0); return(poly); }
public static com.epl.geometry.Polygon MakePolygon2() { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(5, 5); poly.LineTo(5, 15); poly.LineTo(15, 15); poly.LineTo(15, 5); return(poly); }
public static com.epl.geometry.Polygon MakePolygon8() { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 30); poly.LineTo(30, 30); poly.LineTo(30, 0); return(poly); }
internal virtual com.epl.geometry.Polygon MakePolygon2() { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 10); poly.LineTo(10, 10); poly.LineTo(10, 0); return(poly); }
public virtual void TestPolygonGeometryEngine() { com.epl.geometry.Polygon p = new com.epl.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.epl.geometry.GeometryEngine.GeometryToGeoJson(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]]}", result); }
public virtual void TestOGCPolygon() { com.epl.geometry.Polygon p = new com.epl.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.epl.geometry.ogc.OGCPolygon ogcPolygon = new com.epl.geometry.ogc.OGCPolygon(p, null); string result = ogcPolygon.AsGeoJson(); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]],\"crs\":null}", result); }
public virtual void TestPolygon() { com.epl.geometry.Polygon p = new com.epl.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.epl.geometry.OperatorExportToGeoJson exporter = (com.epl.geometry.OperatorExportToGeoJson)factory.GetOperator(com.epl.geometry.Operator.Type.ExportToGeoJson); string result = exporter.Execute(p); NUnit.Framework.Assert.AreEqual("{\"type\":\"Polygon\",\"coordinates\":[[[100,0],[100,1],[101,1],[101,0],[100,0]]]}", result); }
public static void TestArcObjectsFailureCR196492() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 600, 600), false); polygon.StartPath(30, 300); polygon.LineTo(20, 310); polygon.LineTo(10, 300); com.epl.geometry.SpatialReference gcsWGS84 = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Envelope2D envelopeCR = new com.epl.geometry.Envelope2D(10, 10, 500, 500); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelopeCR, gcsWGS84, null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetPointCount() == 7); }
public static void TestProximity2D_3() { com.epl.geometry.OperatorFactoryLocal factory = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorProximity2D proximity = (com.epl.geometry.OperatorProximity2D)factory.GetOperator(com.epl.geometry.Operator.Type.Proximity2D); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.StartPath(new com.epl.geometry.Point(-120, 22)); polygon.LineTo(new com.epl.geometry.Point(-120, 10)); polygon.LineTo(new com.epl.geometry.Point(-110, 10)); polygon.LineTo(new com.epl.geometry.Point(-110, 22)); com.epl.geometry.Point point = new com.epl.geometry.Point(); point.SetXY(-110, 20); com.epl.geometry.Proximity2DResult result = proximity.GetNearestCoordinate(polygon, point, false); com.epl.geometry.Point point2 = new com.epl.geometry.Point(); point2.SetXY(-120, 12); com.epl.geometry.Proximity2DResult[] results = proximity.GetNearestVertices(polygon, point2, 10, 12); }
public static void Test1() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorGeneralize op = (com.epl.geometry.OperatorGeneralize)engine.GetOperator(com.epl.geometry.Operator.Type.Generalize); com.epl.geometry.Polygon poly = new com.epl.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.epl.geometry.Geometry geom = op.Execute(poly, 2, true, null); com.epl.geometry.Polygon p = (com.epl.geometry.Polygon)geom; com.epl.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.epl.geometry.Geometry geom1 = op.Execute(geom, 5, false, null); p = (com.epl.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.epl.geometry.Polygon)geom1; points = p.GetCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 0); }
public static void TestDistanceBetweenTriangles() { double distance; com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); com.epl.geometry.Polygon poly2 = new com.epl.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.epl.geometry.GeometryEngine.Distance(poly, poly2, null); NUnit.Framework.Assert.IsTrue(0.0 < distance && distance < xSeparation + ySeparation); }
public static void TestClipAttributes() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(30, 30); polygon.LineTo(60, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(10, 0, 50, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 100); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996); // 20.0 NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 20); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 40); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 80); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 100); } { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(0, 40); polygon.LineTo(20, 40); polygon.LineTo(20, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 180); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(0, 10, 20, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 15); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 30); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 150); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 165); } }
public virtual void TestMP2onCR175871() { com.epl.geometry.Polygon pg = new com.epl.geometry.Polygon(); pg.StartPath(-50, 10); pg.LineTo(-50, 12); pg.LineTo(-45, 12); pg.LineTo(-45, 10); com.epl.geometry.Polygon pg1 = new com.epl.geometry.Polygon(); pg1.StartPath(-45, 10); pg1.LineTo(-40, 10); pg1.LineTo(-40, 8); pg.Add(pg1, false); com.epl.geometry.SpatialReference spatialReference = com.epl.geometry.SpatialReference.Create(4326); try { string jSonStr = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReference, pg); com.fasterxml.jackson.core.JsonFactory jf = new com.fasterxml.jackson.core.JsonFactory(); com.fasterxml.jackson.core.JsonParser jp = jf.CreateJsonParser(jSonStr); jp.NextToken(); com.epl.geometry.MapGeometry mg = com.epl.geometry.GeometryEngine.JsonToGeometry(jp); com.epl.geometry.Geometry gm = mg.GetGeometry(); NUnit.Framework.Assert.AreEqual(com.epl.geometry.Geometry.Type.Polygon, gm.GetType()); NUnit.Framework.Assert.IsTrue(mg.GetSpatialReference().GetID() == 4326); com.epl.geometry.Polygon pgNew = (com.epl.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(pgNew.GetPoint(0).GetX(), pg.GetPoint(0).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetX(), pg.GetPoint(1).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetX(), pg.GetPoint(2).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetX(), pg.GetPoint(3).GetX(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(0).GetY(), pg.GetPoint(0).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(1).GetY(), pg.GetPoint(1).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(2).GetY(), pg.GetPoint(2).GetY(), 0.000000001); NUnit.Framework.Assert.AreEqual(pgNew.GetPoint(3).GetY(), pg.GetPoint(3).GetY(), 0.000000001); } catch (System.Exception ex) { string err = ex.Message; System.Console.Out.Write(err); throw; } }
public virtual void TestIntersection() { com.epl.geometry.OperatorIntersects op = (com.epl.geometry.OperatorIntersects)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Intersects); com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); // outer ring1 polygon.StartPath(0, 0); polygon.LineTo(10, 10); polygon.LineTo(20, 0); com.epl.geometry.Point point1 = new com.epl.geometry.Point(15, 10); com.epl.geometry.Point point2 = new com.epl.geometry.Point(2, 10); com.epl.geometry.Point point3 = new com.epl.geometry.Point(5, 5); bool res = op.Execute(polygon, point1, null, null); NUnit.Framework.Assert.IsTrue(!res); res = op.Execute(polygon, point2, null, null); NUnit.Framework.Assert.IsTrue(!res); res = op.Execute(polygon, point3, null, null); NUnit.Framework.Assert.IsTrue(res); }
public virtual void TestTouchesBetweenPolylineAndPolygon() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polyline pl = new com.epl.geometry.Polyline(); pl.StartPath(2, 4); pl.LineTo(1, 10); pl.LineTo(6, 12); com.epl.geometry.Polygon compPg = new com.epl.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.epl.geometry.GeometryEngine.Touches(pl, compPg, sr); NUnit.Framework.Assert.AreEqual(isTouched, true); }
public virtual void TestGeometryToJSON() { com.epl.geometry.Polygon geom = new com.epl.geometry.Polygon(); geom.StartPath(new com.epl.geometry.Point(-113, 34)); geom.LineTo(new com.epl.geometry.Point(-105, 34)); geom.LineTo(new com.epl.geometry.Point(-108, 40)); string outputPolygon1 = com.epl.geometry.GeometryEngine.GeometryToJson(-1, geom); // Test // WKID // == -1 // System.out.println("Geom JSON STRING is" + outputPolygon1); string correctPolygon1 = "{\"rings\":[[[-113,34],[-105,34],[-108,40],[-113,34]]]}"; NUnit.Framework.Assert.AreEqual(correctPolygon1, outputPolygon1); string outputPolygon2 = com.epl.geometry.GeometryEngine.GeometryToJson(4326, geom); // System.out.println("Geom JSON STRING is" + outputPolygon2); string correctPolygon2 = "{\"rings\":[[[-113,34],[-105,34],[-108,40],[-113,34]]],\"spatialReference\":{\"wkid\":4326}}"; NUnit.Framework.Assert.AreEqual(correctPolygon2, outputPolygon2); }
public static void Test5() { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.StartPath(0, 0); poly.LineTo(0, 1); poly.LineTo(1, 1); poly.LineTo(1, 0); poly.StartPath(2, 0); poly.LineTo(2, 1); poly.LineTo(3, 1); poly.LineTo(3, 0); poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 1); poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 3); poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 6, 0, 1); poly.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 4); poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 0, 3, 1); poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 0, 1, 3); poly.InterpolateAttributes(com.epl.geometry.VertexDescription.Semantics.M, 1, 2, 1); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 2); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 1); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 2); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 3); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 3); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 4); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 6, 0) == 1); NUnit.Framework.Assert.IsTrue(poly.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 7, 0) == 2); }
public virtual void TestPointAndPolygon2() { com.epl.geometry.Point basePl = new com.epl.geometry.Point(-115, 20); com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon(); compPl.StartPath(new com.epl.geometry.Point(-116, 20)); compPl.LineTo(new com.epl.geometry.Point(-131, 10)); compPl.LineTo(new com.epl.geometry.Point(-121, 50)); int noException = 1; // no exception com.epl.geometry.Geometry intersectGeom = null; try { intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.AreEqual(noException, 1); NUnit.Framework.Assert.IsTrue(intersectGeom.IsEmpty()); }
public virtual void TestTouchesOnPolygonAndEnvelope() { com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(4326); com.epl.geometry.Polygon basePl = new com.epl.geometry.Polygon(); basePl.StartPath(new com.epl.geometry.Point(-117, 20)); basePl.LineTo(new com.epl.geometry.Point(-100, 20)); basePl.LineTo(new com.epl.geometry.Point(-100, 10)); basePl.LineTo(new com.epl.geometry.Point(-117, 10)); // Envelope env = new Envelope(new Point(-117,20), 12, 12);//not touched com.epl.geometry.Envelope env = new com.epl.geometry.Envelope(-100, 20, -80, 30); // touched bool isTouched; try { isTouched = com.epl.geometry.GeometryEngine.Touches(basePl, env, sr); } catch (System.ArgumentException) { isTouched = false; } NUnit.Framework.Assert.AreEqual(isTouched, true); }
/// <summary>Gets the current bounding geometry.</summary> /// <remarks> /// Gets the current bounding geometry. /// Returns a Geometry. /// </remarks> internal virtual com.epl.geometry.Geometry GetBoundingGeometry() { // Extracts the convex hull from the tree. Reading the tree in order from first to last is the resulting convex hull. com.epl.geometry.Point point = new com.epl.geometry.Point(); int first = m_tree_hull.GetFirst(-1); com.epl.geometry.Polygon hull = new com.epl.geometry.Polygon(m_shape.GetVertexDescription()); m_shape.QueryPoint(m_tree_hull.GetElement(first), point); hull.StartPath(point); for (int i = m_tree_hull.GetNext(first); i != -1; i = m_tree_hull.GetNext(i)) { m_shape.QueryPoint(m_tree_hull.GetElement(i), point); hull.LineTo(point); } return(hull); }