Esempio n. 1
0
 public virtual void testPoint()
 {
     com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point();
     pt.setXY(100, 200);
     NUnit.Framework.Assert.IsFalse(pt.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                    .M));
     pt.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsTrue(pt.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                   .M));
     NUnit.Framework.Assert.IsTrue(double.IsNaN(pt.getM()));
     pt.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.M, 0, 13);
     NUnit.Framework.Assert.IsTrue(pt.getM() == 13);
     pt.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z);
     NUnit.Framework.Assert.IsTrue(pt.getZ() == 0);
     NUnit.Framework.Assert.IsTrue(pt.getM() == 13);
     pt.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, 11);
     NUnit.Framework.Assert.IsTrue(pt.getZ() == 11);
     NUnit.Framework.Assert.IsTrue(pt.getM() == 13);
     pt.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID);
     NUnit.Framework.Assert.IsTrue(pt.getID() == 0);
     NUnit.Framework.Assert.IsTrue(pt.getZ() == 11);
     NUnit.Framework.Assert.IsTrue(pt.getM() == 13);
     pt.setAttribute(com.esri.core.geometry.VertexDescription.Semantics.ID, 0, 1);
     NUnit.Framework.Assert.IsTrue(pt.getID() == 1);
     NUnit.Framework.Assert.IsTrue(pt.getZ() == 11);
     NUnit.Framework.Assert.IsTrue(pt.getM() == 13);
     pt.dropAttribute(com.esri.core.geometry.VertexDescription.Semantics.M);
     NUnit.Framework.Assert.IsTrue(pt.getID() == 1);
     NUnit.Framework.Assert.IsTrue(pt.getZ() == 11);
     NUnit.Framework.Assert.IsFalse(pt.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                    .M));
     com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point();
     NUnit.Framework.Assert.IsFalse(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                     .M));
     NUnit.Framework.Assert.IsFalse(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                     .Z));
     NUnit.Framework.Assert.IsFalse(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                     .ID));
     pt1.mergeVertexDescription(pt.getDescription());
     NUnit.Framework.Assert.IsFalse(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                     .M));
     NUnit.Framework.Assert.IsTrue(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                    .Z));
     NUnit.Framework.Assert.IsTrue(pt1.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics
                                                    .ID));
 }
        /// <exception cref="org.codehaus.jackson.JsonParseException"/>
        /// <exception cref="System.IO.IOException"/>
        internal virtual bool testPoint()
        {
            bool bAnswer = true;

            com.esri.core.geometry.Point point1 = new com.esri.core.geometry.Point(10.0, 20.0
                                                                                   );
            com.esri.core.geometry.Point pointEmpty = new com.esri.core.geometry.Point();
            {
                org.codehaus.jackson.JsonParser pointWebMerc1Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine
                                                                                               .geometryToJson(spatialReferenceWebMerc1, point1));
                com.esri.core.geometry.MapGeometry pointWebMerc1MP = com.esri.core.geometry.GeometryEngine
                                                                     .jsonToGeometry(pointWebMerc1Parser);
                NUnit.Framework.Assert.IsTrue(point1.getX() == ((com.esri.core.geometry.Point)pointWebMerc1MP
                                                                .getGeometry()).getX());
                NUnit.Framework.Assert.IsTrue(point1.getY() == ((com.esri.core.geometry.Point)pointWebMerc1MP
                                                                .getGeometry()).getY());
                NUnit.Framework.Assert.IsTrue(spatialReferenceWebMerc1.getID() == pointWebMerc1MP
                                              .getSpatialReference().getID() || pointWebMerc1MP.getSpatialReference().getID()
                                              == 3857);
                if (!checkResultSpatialRef(pointWebMerc1MP, 102100, 3857))
                {
                    bAnswer = false;
                }
                pointWebMerc1Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine
                                                               .geometryToJson(null, point1));
                pointWebMerc1MP = com.esri.core.geometry.GeometryEngine.jsonToGeometry(pointWebMerc1Parser
                                                                                       );
                NUnit.Framework.Assert.IsTrue(null == pointWebMerc1MP.getSpatialReference());
                if (pointWebMerc1MP.getSpatialReference() != null)
                {
                    if (!checkResultSpatialRef(pointWebMerc1MP, 102100, 3857))
                    {
                        bAnswer = false;
                    }
                }
                string pointEmptyString = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1
                                                                                               , pointEmpty);
                pointWebMerc1Parser = factory.createJsonParser(pointEmptyString);
            }
            org.codehaus.jackson.JsonParser pointWebMerc2Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine
                                                                                           .geometryToJson(spatialReferenceWebMerc2, point1));
            com.esri.core.geometry.MapGeometry pointWebMerc2MP = com.esri.core.geometry.GeometryEngine
                                                                 .jsonToGeometry(pointWebMerc2Parser);
            NUnit.Framework.Assert.IsTrue(point1.getX() == ((com.esri.core.geometry.Point)pointWebMerc2MP
                                                            .getGeometry()).getX());
            NUnit.Framework.Assert.IsTrue(point1.getY() == ((com.esri.core.geometry.Point)pointWebMerc2MP
                                                            .getGeometry()).getY());
            NUnit.Framework.Assert.IsTrue(spatialReferenceWebMerc2.getLatestID() == pointWebMerc2MP
                                          .getSpatialReference().getLatestID());
            if (!checkResultSpatialRef(pointWebMerc2MP, spatialReferenceWebMerc2.getLatestID(
                                           ), 0))
            {
                bAnswer = false;
            }
            {
                org.codehaus.jackson.JsonParser pointWgs84Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine
                                                                                            .geometryToJson(spatialReferenceWGS84, point1));
                com.esri.core.geometry.MapGeometry pointWgs84MP = com.esri.core.geometry.GeometryEngine
                                                                  .jsonToGeometry(pointWgs84Parser);
                NUnit.Framework.Assert.IsTrue(point1.getX() == ((com.esri.core.geometry.Point)pointWgs84MP
                                                                .getGeometry()).getX());
                NUnit.Framework.Assert.IsTrue(point1.getY() == ((com.esri.core.geometry.Point)pointWgs84MP
                                                                .getGeometry()).getY());
                NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.getID() == pointWgs84MP.getSpatialReference
                                                  ().getID());
                if (!checkResultSpatialRef(pointWgs84MP, 4326, 0))
                {
                    bAnswer = false;
                }
            }
            {
                com.esri.core.geometry.Point p = new com.esri.core.geometry.Point();
                string s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1
                                                                                , p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":null,\"y\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"
                                                       ));
                p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z);
                p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M);
                s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1
                                                                         , p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":null,\"y\":null,\"z\":null,\"m\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"
                                                       ));
            }
            {
                com.esri.core.geometry.Point p = new com.esri.core.geometry.Point(10.0, 20.0, 30.0
                                                                                  );
                p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M);
                string s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1
                                                                                , p);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"x\":10,\"y\":20,\"z\":30,\"m\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"
                                                       ));
            }
            {
                // import
                string s = "{\"x\":0.0,\"y\":1.0,\"z\":5.0,\"m\":11.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}";
                org.codehaus.jackson.JsonParser    parser = factory.createJsonParser(s);
                com.esri.core.geometry.MapGeometry map_pt = com.esri.core.geometry.GeometryEngine
                                                            .jsonToGeometry(parser);
                com.esri.core.geometry.Point pt = (com.esri.core.geometry.Point)map_pt.getGeometry
                                                      ();
                NUnit.Framework.Assert.IsTrue(pt.getX() == 0.0);
                NUnit.Framework.Assert.IsTrue(pt.getY() == 1.0);
                NUnit.Framework.Assert.IsTrue(pt.getZ() == 5.0);
                NUnit.Framework.Assert.IsTrue(pt.getM() == 11.0);
            }
            {
                string s = "{\"x\" : 5.0, \"y\" : null, \"spatialReference\" : {\"wkid\" : 4326}} ";
                org.codehaus.jackson.JsonParser    parser = factory.createJsonParser(s);
                com.esri.core.geometry.MapGeometry map_pt = com.esri.core.geometry.GeometryEngine
                                                            .jsonToGeometry(parser);
                com.esri.core.geometry.Point pt = (com.esri.core.geometry.Point)map_pt.getGeometry
                                                      ();
                NUnit.Framework.Assert.IsTrue(pt.isEmpty());
                com.esri.core.geometry.SpatialReference spatial_reference = map_pt.getSpatialReference
                                                                                ();
                NUnit.Framework.Assert.IsTrue(spatial_reference.getID() == 4326);
            }
            return(bAnswer);
        }