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 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 static void TestQuadTreeWithDuplicates() { int pass_count = 10; int figure_size = 400; int figure_size2 = 100; com.epl.geometry.Envelope extent1 = new com.epl.geometry.Envelope(); extent1.SetCoords(-100000, -100000, 100000, 100000); com.epl.geometry.RandomCoordinateGenerator generator1 = new com.epl.geometry.RandomCoordinateGenerator(System.Math.Max(figure_size, 10000), extent1, 0.001); System.Random random = new System.Random(2013); int rand_max = 32; com.epl.geometry.Polygon poly_red = new com.epl.geometry.Polygon(); com.epl.geometry.Polygon poly_blue = new com.epl.geometry.Polygon(); int r = figure_size; for (int c = 0; c < pass_count; c++) { com.epl.geometry.Point pt; for (int j = 0; j < r; j++) { int rand = random.Next(rand_max); bool b_random_new = r > 10 && ((1.0 * rand) / rand_max > 0.95); pt = generator1.GetRandomCoord(); if (j == 0 || b_random_new) { poly_blue.StartPath(pt); } else { poly_blue.LineTo(pt); } } com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); com.epl.geometry.QuadTree quad_tree_blue = BuildQuadTree_((com.epl.geometry.MultiPathImpl)poly_blue._getImpl(), false); com.epl.geometry.QuadTree quad_tree_blue_duplicates = BuildQuadTree_((com.epl.geometry.MultiPathImpl)poly_blue._getImpl(), true); com.epl.geometry.Envelope2D e1 = quad_tree_blue.GetDataExtent(); com.epl.geometry.Envelope2D e2 = quad_tree_blue_duplicates.GetDataExtent(); NUnit.Framework.Assert.IsTrue(e1.Equals(e2)); NUnit.Framework.Assert.IsTrue(quad_tree_blue.GetElementCount() == poly_blue.GetSegmentCount()); com.epl.geometry.SegmentIterator seg_iter_blue = poly_blue.QuerySegmentIterator(); poly_red.SetEmpty(); r = figure_size2; if (r < 3) { continue; } for (int j_1 = 0; j_1 < r; j_1++) { int rand = random.Next(rand_max); bool b_random_new = r > 10 && ((1.0 * rand) / rand_max > 0.95); pt = generator1.GetRandomCoord(); if (j_1 == 0 || b_random_new) { poly_red.StartPath(pt); } else { poly_red.LineTo(pt); } } com.epl.geometry.QuadTree.QuadTreeIterator iterator = quad_tree_blue.GetIterator(); com.epl.geometry.SegmentIteratorImpl seg_iter_red = ((com.epl.geometry.MultiPathImpl)poly_red._getImpl()).QuerySegmentIterator(); System.Collections.Generic.Dictionary <int, bool> map1 = new System.Collections.Generic.Dictionary <int, bool>(0); int count = 0; int intersections_per_query = 0; while (seg_iter_red.NextPath()) { while (seg_iter_red.HasNextSegment()) { com.epl.geometry.Segment segment_red = seg_iter_red.NextSegment(); segment_red.QueryEnvelope2D(env); iterator.ResetIterator(env, 0.0); int count_upper = 0; int element_handle; while ((element_handle = iterator.Next()) != -1) { count_upper++; int index = quad_tree_blue.GetElement(element_handle); bool iter = map1.ContainsKey(index); if (!iter) { count++; map1[index] = true; } intersections_per_query++; } int intersection_count = quad_tree_blue.GetIntersectionCount(env, 0.0, -1); NUnit.Framework.Assert.IsTrue(intersection_count == count_upper); } } seg_iter_red.ResetToFirstPath(); System.Collections.Generic.Dictionary <int, bool> map2 = new System.Collections.Generic.Dictionary <int, bool>(0); com.epl.geometry.QuadTree.QuadTreeIterator iterator_duplicates = quad_tree_blue_duplicates.GetIterator(); int count_duplicates = 0; int intersections_per_query_duplicates = 0; while (seg_iter_red.NextPath()) { while (seg_iter_red.HasNextSegment()) { com.epl.geometry.Segment segment_red = seg_iter_red.NextSegment(); segment_red.QueryEnvelope2D(env); iterator_duplicates.ResetIterator(env, 0.0); int count_lower = 0; System.Collections.Generic.Dictionary <int, bool> map_per_query = new System.Collections.Generic.Dictionary <int, bool>(0); int count_upper = 0; int element_handle; while ((element_handle = iterator_duplicates.Next()) != -1) { count_upper++; int index = quad_tree_blue_duplicates.GetElement(element_handle); bool iter = map2.ContainsKey(index); if (!iter) { count_duplicates++; map2[index] = true; } bool iter_lower = map_per_query.ContainsKey(index); if (!iter_lower) { count_lower++; intersections_per_query_duplicates++; map_per_query[index] = true; } int q = quad_tree_blue_duplicates.GetQuad(element_handle); NUnit.Framework.Assert.IsTrue(quad_tree_blue_duplicates.GetSubTreeElementCount(q) >= quad_tree_blue_duplicates.GetContainedSubTreeElementCount(q)); } int intersection_count = quad_tree_blue_duplicates.GetIntersectionCount(env, 0.0, -1); bool b_has_data = quad_tree_blue_duplicates.HasData(env, 0.0); NUnit.Framework.Assert.IsTrue(b_has_data || intersection_count == 0); NUnit.Framework.Assert.IsTrue(count_lower <= intersection_count && intersection_count <= count_upper); NUnit.Framework.Assert.IsTrue(count_upper <= 4 * count_lower); } } NUnit.Framework.Assert.IsTrue(count == count_duplicates); NUnit.Framework.Assert.IsTrue(intersections_per_query == intersections_per_query_duplicates); } }
/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool TestPolygon() { bool bAnswer = true; 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.CreateParser(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()); if (!CheckResultSpatialRef(mPolygonWGS84MP, 4326, 0)) { bAnswer = false; } } { com.epl.geometry.Polygon p = new com.epl.geometry.Polygon(); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z); p.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); p.StartPath(0, 0); p.LineTo(0, 1); p.LineTo(4, 4); p.StartPath(2, 2); p.LineTo(3, 3); p.LineTo(7, 8); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 3); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 7); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 5); p.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 5, 0, 5); s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"rings\":[[[0,0,3,null],[0,1,0,7],[4,4,0,5],[0,0,3,null]],[[2,2,0,null],[3,3,0,null],[7,8,0,5],[2,2,0,null]]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}")); } { // Test Import Polygon from Polygon string rings = "{\"hasZ\": true, \"rings\" : [ [ [0,0, 5], [0.0, 10.0, 5], [10.0,10.0, 5, 66666], [10.0,0.0, 5] ], [ [12, 12] ], [ [13 , 17], [13 , 17] ], [ [1.0, 1.0, 5, 66666], [9.0,1.0, 5], [9.0,9.0, 5], [1.0,9.0, 5], [1.0, 1.0, 5] ] ] }"; com.epl.geometry.MapGeometry mapGeometry = com.epl.geometry.GeometryEngine.JsonToGeometry(factory.CreateParser(rings)); com.epl.geometry.Polygon p = (com.epl.geometry.Polygon)mapGeometry.GetGeometry(); double area = p.CalculateArea2D(); double length = p.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(p.GetPathCount() == 4); int count = p.GetPointCount(); NUnit.Framework.Assert.IsTrue(count == 15); NUnit.Framework.Assert.IsTrue(p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z)); NUnit.Framework.Assert.IsTrue(!p.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M)); } return(bAnswer); }