Beispiel #1
0
 public virtual void TestPolygon()
 {
     com.epl.geometry.Polygon mp = new com.epl.geometry.Polygon();
     mp.StartPath(new com.epl.geometry.Point(100, 200));
     mp.LineTo(new com.epl.geometry.Point(101, 201));
     mp.LineTo(new com.epl.geometry.Point(102, 202));
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0)));
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 1);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 2);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 0);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0, 11);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0, 21);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0, 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     mp.AddAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
     NUnit.Framework.Assert.IsTrue(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == 0);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0, -11);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0, -21);
     mp.SetAttribute(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0, -31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 1);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 2);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 3);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     mp.DropAttribute(com.epl.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsFalse(mp.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     com.epl.geometry.Polygon mp1 = new com.epl.geometry.Polygon();
     mp.CopyTo(mp1);
     NUnit.Framework.Assert.IsFalse(mp1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 11);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 21);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 31);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == -11);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == -21);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == -31);
     mp1.DropAllAttributes();
     mp1.MergeVertexDescription(mp.GetDescription());
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.Z, 2, 0) == 0);
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0)));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0)));
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 0, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 1, 0) == 0);
     NUnit.Framework.Assert.IsTrue(mp1.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.ID, 2, 0) == 0);
 }
        /// <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);
        }