Ejemplo n.º 1
0
        public virtual void testWKB2()
        {
            // JSON -> GEOM -> WKB
            // String strPolygon1 =
            // "{\"xmin\":-1.16605115291E7,\"ymin\":4925189.941699997,\"xmax\":-1.16567772126E7,\"ymax\":4928658.771399997,\"spatialReference\":{\"wkid\":102100}}";
            string strPolygon1 = "{\"rings\" : [ [ [-1.16605115291E7,4925189.941699997], [-1.16567772126E7,4925189.941699997], [-1.16567772126E7,4928658.771399997], [-1.16605115291E7,4928658.771399997], [-1.16605115291E7,4925189.941699997] ] ], \"spatialReference\" : {\"wkid\" : 102100}}";

            org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory();
            org.codehaus.jackson.JsonParser  parser  = factory.createJsonParser(strPolygon1);
            parser.nextToken();
            com.esri.core.geometry.MapGeometry mapGeom = com.esri.core.geometry.GeometryEngine
                                                         .jsonToGeometry(parser);
            com.esri.core.geometry.Geometry geom = mapGeom.getGeometry();
            // simplifying geom
            com.esri.core.geometry.OperatorSimplify operatorSimplify = (com.esri.core.geometry.OperatorSimplify
                                                                        )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                               .Simplify);
            com.esri.core.geometry.SpatialReference sr = com.esri.core.geometry.SpatialReference
                                                         .create(102100);
            geom = operatorSimplify.execute(geom, sr, true, null);
            com.esri.core.geometry.OperatorExportToWkb operatorExport = (com.esri.core.geometry.OperatorExportToWkb
                                                                         )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                                .ExportToWkb);
            java.nio.ByteBuffer byteBuffer = operatorExport.execute(0, geom, null);
            byte[] wkb = ((byte[])byteBuffer.array());
            // // checking WKB correctness
            // WKBReader jtsReader = new WKBReader();
            // com.vividsolutions.jts.geom.Geometry jtsGeom = jtsReader.read(wkb);
            // System.out.println("jtsGeom = " + jtsGeom);
            // WKB -> GEOM -> JSON
            com.esri.core.geometry.OperatorImportFromWkb operatorImport = (com.esri.core.geometry.OperatorImportFromWkb
                                                                           )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                                  .ImportFromWkb);
            geom = operatorImport.execute(0, com.esri.core.geometry.Geometry.Type.Polygon, java.nio.ByteBuffer
                                          .wrap(wkb), null);
            NUnit.Framework.Assert.IsTrue(!geom.isEmpty());
        }
Ejemplo n.º 2
0
 public virtual void testWKB()
 {
     try
     {
         // JSON -> GEOM -> WKB
         string strPolygon1 = "{\"xmin\":-1.1663479012889031E7,\"ymin\":4919777.494405342,\"xmax\":-1.1658587043078788E7,\"ymax\":4924669.464215587,\"spatialReference\":{\"wkid\":102100}}";
         // String strPolygon1 =
         // "{\"rings\":[[[-119.152450421001,38.4118009590513],[-119.318825070203,38.5271086243914],[-119.575687062955,38.7029101298904],[-119.889341639399,38.9222515603984],[-119.995254694357,38.9941061536377],[-119.995150114198,39.0634913594691],[-119.994541258334,39.1061318056708],[-119.995527335641,39.1587132866355],[-119.995304181493,39.3115454332125],[-119.996011479298,39.4435009764511],[-119.996165311172,39.7206108077274],[-119.996324660047,41.1775662656441],[-119.993459369715,41.9892049531992],[-119.351692186077,41.9888529749781],[-119.3109421304,41.9891353872811],[-118.185316829038,41.9966370981387],[-117.018864363596,41.9947941808341],[-116.992313337997,41.9947945094663],[-115.947544658193,41.9945994628997],[-115.024862911148,41.996506455953],[-114.269471632824,41.9959242345073],[-114.039072662345,41.9953908974688],[-114.038151248682,40.9976868405942],[-114.038108189376,40.1110466529553],[-114.039844684228,39.9087788600023],[-114.040105338584,39.5386849268845],[-114.044267501155,38.6789958815881],[-114.045090206153,38.5710950539539],[-114.047272999176,38.1376524399918],[-114.047260595159,37.5984784866001],[-114.043939384154,36.9965379371421],[-114.043716435713,36.8418489458647],[-114.037392074194,36.2160228969702],[-114.045105557286,36.1939778840226],[-114.107775185788,36.1210907070504],[-114.12902308363,36.041730493896],[-114.206768869568,36.0172554164834],[-114.233472615347,36.0183310595897],[-114.307587598189,36.0622330993643],[-114.303857056018,36.0871084040611],[-114.316095374696,36.1114380366653],[-114.344233941709,36.1374802520568],[-114.380803116644,36.1509912717765],[-114.443945697733,36.1210532841897],[-114.466613475422,36.1247112590539],[-114.530573568745,36.1550902046725],[-114.598935242024,36.1383354528834],[-114.621610747198,36.1419666834504],[-114.712761724737,36.1051810523675],[-114.728150311069,36.0859627711604],[-114.728966012834,36.0587530361083],[-114.717673567756,36.0367580437018],[-114.736212493583,35.9876483502758],[-114.699275906446,35.9116119537412],[-114.661600122152,35.8804735854242],[-114.662462095522,35.8709599070091],[-114.689867343369,35.8474424944766],[-114.682739704595,35.7647034175617],[-114.688820027649,35.7325957399896],[-114.665091345861,35.6930994107107],[-114.668486064922,35.6563989882404],[-114.654065925137,35.6465840800053],[-114.6398667219,35.6113485698329],[-114.653134321223,35.5848331056108],[-114.649792053474,35.5466373866597],[-114.672215155693,35.5157541647721],[-114.645396168451,35.4507608261463],[-114.589584275424,35.3583787306827],[-114.587889840369,35.30476812919],[-114.559583045727,35.2201828714608],[-114.561039964054,35.1743461616313],[-114.572255261053,35.1400677445931],[-114.582616239058,35.1325604694085],[-114.626440825485,35.1339067529872],[-114.6359090842,35.1186557767895],[-114.595631971944,35.0760579746697],[-114.633779872695,35.0418633504303],[-114.621068606189,34.9989144286133],[-115.626197382816,35.7956983148418],[-115.88576934392,36.0012259572723],[-117.160423771838,36.9595941441767],[-117.838686423167,37.457298239715],[-118.417419755966,37.8866767486211],[-119.152450421001,38.4118009590513]]], \"spatialReference\":{\"wkid\":4326}}";
         org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory();
         org.codehaus.jackson.JsonParser  parser  = factory.createJsonParser(strPolygon1);
         parser.nextToken();
         com.esri.core.geometry.MapGeometry mapGeom = com.esri.core.geometry.GeometryEngine
                                                      .jsonToGeometry(parser);
         com.esri.core.geometry.Geometry            geom           = mapGeom.getGeometry();
         com.esri.core.geometry.OperatorExportToWkb operatorExport = (com.esri.core.geometry.OperatorExportToWkb
                                                                      )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                             .ExportToWkb);
         java.nio.ByteBuffer byteBuffer = operatorExport.execute(0, geom, null);
         byte[] wkb = ((byte[])byteBuffer.array());
         // WKB -> GEOM -> JSON
         com.esri.core.geometry.OperatorImportFromWkb operatorImport = (com.esri.core.geometry.OperatorImportFromWkb
                                                                        )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type
                                                                                                                                               .ImportFromWkb);
         geom = operatorImport.execute(0, com.esri.core.geometry.Geometry.Type.Polygon, java.nio.ByteBuffer
                                       .wrap(wkb), null);
         // geom = operatorImport.execute(0, Geometry.Type.Polygon,
         // byteBuffer);
         string outputPolygon1 = com.esri.core.geometry.GeometryEngine.geometryToJson(-1,
                                                                                      geom);
     }
     catch (org.codehaus.jackson.JsonParseException)
     {
     }
     catch (System.IO.IOException)
     {
     }
 }