public virtual void testMP2onCR175871() { com.esri.core.geometry.Polygon pg = new com.esri.core.geometry.Polygon(); pg.startPath(-50, 10); pg.lineTo(-50, 12); pg.lineTo(-45, 12); pg.lineTo(-45, 10); com.esri.core.geometry.Polygon pg1 = new com.esri.core.geometry.Polygon(); pg1.startPath(-45, 10); pg1.lineTo(-40, 10); pg1.lineTo(-40, 8); pg.add(pg1, false); try { string jSonStr = com.esri.core.geometry.GeometryEngine.geometryToJson(4326, pg); org.codehaus.jackson.JsonFactory jf = new org.codehaus.jackson.JsonFactory(); org.codehaus.jackson.JsonParser jp = jf.createJsonParser(jSonStr); jp.nextToken(); com.esri.core.geometry.MapGeometry mg = com.esri.core.geometry.GeometryEngine.jsonToGeometry (jp); com.esri.core.geometry.Geometry gm = mg.getGeometry(); NUnit.Framework.Assert.AreEqual(com.esri.core.geometry.Geometry.Type.Polygon, gm. getType()); com.esri.core.geometry.Polygon pgNew = (com.esri.core.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(pg.getPoint(0).getX(), 0.000000001, pgNew.getPoint (0).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getX(), 0.000000001, pgNew.getPoint (1).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getX(), 0.000000001, pgNew.getPoint (2).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getX(), 0.000000001, pgNew.getPoint (3).getX()); NUnit.Framework.Assert.AreEqual(pg.getPoint(0).getY(), 0.000000001, pgNew.getPoint (0).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(1).getY(), 0.000000001, pgNew.getPoint (1).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(2).getY(), 0.000000001, pgNew.getPoint (2).getY()); NUnit.Framework.Assert.AreEqual(pg.getPoint(3).getY(), 0.000000001, pgNew.getPoint (3).getY()); } catch (System.Exception ex) { string err = ex.Message; System.Console.Out.Write(err); throw; } }
public static void testContainsFailureCR186456() { string str = "{\"rings\":[[[406944.399999999,287461.450000001],[406947.750000011,287462.299999997],[406946.44999999,287467.450000001],[406943.050000005,287466.550000005],[406927.799999992,287456.849999994],[406926.949999996,287456.599999995],[406924.800000005,287455.999999998],[406924.300000007,287455.849999999],[406924.200000008,287456.099999997],[406923.450000011,287458.449999987],[406922.999999987,287459.800000008],[406922.29999999,287462.099999998],[406921.949999991,287463.449999992],[406921.449999993,287465.050000011],[406920.749999996,287466.700000004],[406919.800000001,287468.599999996],[406919.050000004,287469.99999999],[406917.800000009,287471.800000008],[406916.04999999,287473.550000001],[406915.449999993,287473.999999999],[406913.700000001,287475.449999993],[406913.300000002,287475.899999991],[406912.050000008,287477.250000011],[406913.450000002,287478.150000007],[406915.199999994,287478.650000005],[406915.999999991,287478.800000005],[406918.300000007,287479.200000003],[406920.649999997,287479.450000002],[406923.100000013,287479.550000001],[406925.750000001,287479.450000002],[406928.39999999,287479.150000003],[406929.80000001,287478.950000004],[406932.449999998,287478.350000006],[406935.099999987,287477.60000001],[406938.699999998,287476.349999989],[406939.649999994,287473.949999999],[406939.799999993,287473.949999999],[406941.249999987,287473.75],[406942.700000007,287473.250000002],[406943.100000005,287473.100000003],[406943.950000001,287472.750000004],[406944.799999998,287472.300000006],[406944.999999997,287472.200000007],[406946.099999992,287471.200000011],[406946.299999991,287470.950000012],[406948.00000001,287468.599999996],[406948.10000001,287468.399999997],[406950.100000001,287465.050000011],[406951.949999993,287461.450000001],[406952.049999993,287461.300000001],[406952.69999999,287459.900000007],[406953.249999987,287458.549999987],[406953.349999987,287458.299999988],[406953.650000012,287457.299999992],[406953.900000011,287456.349999996],[406954.00000001,287455.300000001],[406954.00000001,287454.750000003],[406953.850000011,287453.750000008],[406953.550000012,287452.900000011],[406953.299999987,287452.299999988],[406954.500000008,287450.299999996],[406954.00000001,287449.000000002],[406953.399999987,287447.950000006],[406953.199999988,287447.550000008],[406952.69999999,287446.850000011],[406952.149999992,287446.099999988],[406951.499999995,287445.499999991],[406951.149999996,287445.249999992],[406950.449999999,287444.849999994],[406949.600000003,287444.599999995],[406949.350000004,287444.549999995],[406948.250000009,287444.499999995],[406947.149999987,287444.699999994],[406946.849999989,287444.749999994],[406945.899999993,287444.949999993],[406944.999999997,287445.349999991],[406944.499999999,287445.64999999],[406943.650000003,287446.349999987],[406942.900000006,287447.10000001],[406942.500000008,287447.800000007],[406942.00000001,287448.700000003],[406941.600000011,287449.599999999],[406941.350000013,287450.849999994],[406941.350000013,287451.84999999],[406941.450000012,287452.850000012],[406941.750000011,287453.850000007],[406941.800000011,287454.000000007],[406942.150000009,287454.850000003],[406942.650000007,287455.6],[406943.150000005,287456.299999997],[406944.499999999,287457.299999992],[406944.899999997,287457.599999991],[406945.299999995,287457.949999989],[406944.399999999,287461.450000001],[406941.750000011,287461.999999998],[406944.399999999,287461.450000001]],[[406944.399999999,287461.450000001],[406947.750000011,287462.299999997],[406946.44999999,287467.450000001],[406943.050000005,287466.550000005],[406927.799999992,287456.849999994],[406944.399999999,287461.450000001]]]}"; org.codehaus.jackson.JsonFactory jsonFactory = new org.codehaus.jackson.JsonFactory (); org.codehaus.jackson.JsonParser jsonParser = jsonFactory.createJsonParser(str); com.esri.core.geometry.MapGeometry mg = com.esri.core.geometry.GeometryEngine.jsonToGeometry (jsonParser); bool res = com.esri.core.geometry.GeometryEngine.contains(mg.getGeometry(), mg.getGeometry (), null); NUnit.Framework.Assert.IsTrue(res); }
public static com.esri.core.geometry.MapGeometry fromJson(string jsonString) { org.codehaus.jackson.JsonFactory factory = new org.codehaus.jackson.JsonFactory(); try { org.codehaus.jackson.JsonParser jsonParser = factory.createJsonParser(jsonString); jsonParser.nextToken(); com.esri.core.geometry.OperatorImportFromJson importer = (com.esri.core.geometry.OperatorImportFromJson )com.esri.core.geometry.OperatorFactoryLocal.getInstance().getOperator(com.esri.core.geometry.Operator.Type .ImportFromJson); return(importer.execute(com.esri.core.geometry.Geometry.Type.Unknown, jsonParser)); } catch (System.Exception) { } return(null); }
public virtual void testMultiPolygon() { org.codehaus.jackson.JsonFactory jsonFactory = new org.codehaus.jackson.JsonFactory (); string geoJsonPolygon = "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[-100.0,-100.0],[-100.0,100.0],[100.0,100.0],[100.0,-100.0],[-100.0,-100.0]],[[-90.0,-90.0],[90.0,90.0],[-90.0,90.0],[90.0,-90.0],[-90.0,-90.0]]],[[[-10.0,-10.0],[-10.0,10.0],[10.0,10.0],[10.0,-10.0],[-10.0,-10.0]]]]}"; string esriJsonPolygon = "{\"rings\": [[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[-90, -90], [90, 90], [-90, 90], [90, -90], [-90, -90]], [[-10, -10], [-10, 10], [10, 10], [10, -10], [-10, -10]]]}"; org.codehaus.jackson.JsonParser parser = jsonFactory.createJsonParser(esriJsonPolygon ); com.esri.core.geometry.MapGeometry parsedPoly = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); //MapGeometry parsedPoly = GeometryEngine.geometryFromGeoJson(jsonPolygon, 0, Geometry.Type.Polygon); com.esri.core.geometry.Polygon poly = (com.esri.core.geometry.Polygon)parsedPoly. getGeometry(); com.esri.core.geometry.OperatorExportToGeoJson exporter = (com.esri.core.geometry.OperatorExportToGeoJson )factory.getOperator(com.esri.core.geometry.Operator.Type.ExportToGeoJson); //String result = exporter.execute(parsedPoly.getGeometry()); string result = exporter.execute(poly); NUnit.Framework.Assert.AreEqual(geoJsonPolygon, result); }
public static void testDistanceWithNullSpatialReference() { // There was a bug that distance op did not work with null Spatial // Reference. string str1 = "{\"paths\":[[[-117.138791850991,34.017492675023],[-117.138762336971,34.0174925550462]]]}"; string str2 = "{\"paths\":[[[-117.138867827972,34.0174854109623],[-117.138850197027,34.0174929160126],[-117.138791850991,34.017492675023]]]}"; org.codehaus.jackson.JsonFactory jsonFactory = new org.codehaus.jackson.JsonFactory (); org.codehaus.jackson.JsonParser jsonParser1 = jsonFactory.createJsonParser(str1); org.codehaus.jackson.JsonParser jsonParser2 = jsonFactory.createJsonParser(str2); com.esri.core.geometry.MapGeometry geom1 = com.esri.core.geometry.GeometryEngine. jsonToGeometry(jsonParser1); com.esri.core.geometry.MapGeometry geom2 = com.esri.core.geometry.GeometryEngine. jsonToGeometry(jsonParser2); double distance = com.esri.core.geometry.GeometryEngine.distance(geom1.getGeometry (), geom2.getGeometry(), null); NUnit.Framework.Assert.IsTrue(distance == 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()); }
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) { } }