public static void compareGeometryContent(com.esri.core.geometry.MultiPoint geom1 , com.esri.core.geometry.MultiPoint geom2) { // Geometry types NUnit.Framework.Assert.IsTrue(geom1.getType().value() == geom2.getType().value()); // Envelopes com.esri.core.geometry.Envelope env1 = new com.esri.core.geometry.Envelope(); geom1.queryEnvelope(env1); com.esri.core.geometry.Envelope env2 = new com.esri.core.geometry.Envelope(); geom2.queryEnvelope(env2); NUnit.Framework.Assert.IsTrue(env1.getXMin() == env2.getXMin() && env1.getXMax() == env2.getXMax() && env1.getYMin() == env2.getYMin() && env1.getYMax() == env2. getYMax()); // Point count int pointCount1 = geom1.getPointCount(); int pointCount2 = geom2.getPointCount(); NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2); com.esri.core.geometry.Point point1; com.esri.core.geometry.Point point2; for (int i = 0; i < pointCount1; i++) { point1 = geom1.getPoint(i); point2 = geom2.getPoint(i); double x1 = point1.getX(); double x2 = point2.getX(); NUnit.Framework.Assert.IsTrue(x1 == x2); double y1 = point1.getY(); double y2 = point2.getY(); NUnit.Framework.Assert.IsTrue(y1 == y2); } }
public static void testClipIssue258243() { com.esri.core.geometry.Polygon poly1 = new com.esri.core.geometry.Polygon(); poly1.startPath(21.476191371901479, 41.267022001907215); poly1.lineTo(59.669186665158051, 36.62700518555863); poly1.lineTo(20.498578117352313, 30.363180148246094); poly1.lineTo(18.342565836615044, 46.303295352085627); poly1.lineTo(17.869569458621626, 23.886816966894159); poly1.lineTo(19.835465558090434, 20); poly1.lineTo(18.83911285048551, 43.515995498114791); poly1.lineTo(20.864485260298004, 20.235921201027757); poly1.lineTo(18.976127544787012, 20); poly1.lineTo(34.290201277718218, 61.801369014954794); poly1.lineTo(20.734727419368866, 20); poly1.lineTo(18.545865698148113, 20); poly1.lineTo(19.730260558565515, 20); poly1.lineTo(19.924806216827005, 23.780315893949187); poly1.lineTo(21.675168105421452, 36.699924873001258); poly1.lineTo(22.500527828912158, 43.703424859922983); poly1.lineTo(42.009527116514818, 36.995486982256089); poly1.lineTo(24.469729873835782, 58.365871758247039); poly1.lineTo(24.573736036545878, 36.268390409195824); poly1.lineTo(22.726502169802746, 20); poly1.lineTo(23.925834885228145, 20); poly1.lineTo(25.495346880936729, 20); poly1.lineTo(23.320941499288317, 20); poly1.lineTo(24.05655665646276, 28.659578774758632); poly1.lineTo(23.205940789341135, 38.491506888710504); poly1.lineTo(21.472847203385509, 53.057228182018044); poly1.lineTo(25.04257681654104, 20); poly1.lineTo(25.880572351149542, 25.16102863979474); poly1.lineTo(26.756283333879658, 20); poly1.lineTo(21.476191371901479, 41.267022001907215); com.esri.core.geometry.Envelope2D env = new com.esri.core.geometry.Envelope2D(); env.setCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793 ); try { com.esri.core.geometry.Geometry output_geom = com.esri.core.geometry.OperatorClip .local().execute(poly1, env, com.esri.core.geometry.SpatialReference.create(4326 ), null); com.esri.core.geometry.Envelope envPoly = new com.esri.core.geometry.Envelope(); poly1.queryEnvelope(envPoly); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(env); e.intersect(envPoly); com.esri.core.geometry.Envelope clippedEnv = new com.esri.core.geometry.Envelope( ); output_geom.queryEnvelope(clippedEnv); NUnit.Framework.Assert.IsTrue(System.Math.abs(clippedEnv.getXMin() - e.getXMin()) < 1e-10 && System.Math.abs(clippedEnv.getYMin() - e.getYMin()) < 1e-10 && System.Math .abs(clippedEnv.getXMax() - e.getXMax()) < 1e-10 && System.Math.abs(clippedEnv.getYMax () - e.getYMax()) < 1e-10); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue(false); } }
public virtual void testSerializeEnvelope() { try { java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream oo = new java.io.ObjectOutputStream(streamOut); com.esri.core.geometry.Envelope pt = new com.esri.core.geometry.Envelope(10, 10, 400, 300); oo.writeObject(pt); java.io.ByteArrayInputStream streamIn = new java.io.ByteArrayInputStream(streamOut .toByteArray()); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(streamIn); com.esri.core.geometry.Envelope ptRes = (com.esri.core.geometry.Envelope)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt)); } catch (System.Exception) { fail("Envelope serialization failure"); } // try // { // FileOutputStream streamOut = new FileOutputStream(m_thisDirectory + // "savedEnvelope.txt"); // ObjectOutputStream oo = new ObjectOutputStream(streamOut); // Envelope pt = new Envelope(10, 10, 400, 300); // oo.writeObject(pt); // } // catch(Exception ex) // { // fail("Envelope serialization failure"); // } try { java.io.InputStream s = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization )).getResourceAsStream("savedEnvelope.txt"); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(s); com.esri.core.geometry.Envelope ptRes = (com.esri.core.geometry.Envelope)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.getXMax() == 400); } catch (System.Exception) { fail("Envelope serialization failure"); } }
/// <exception cref="org.codehaus.jackson.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool testEnvelope() { bool bAnswer = true; com.esri.core.geometry.Envelope envelope = new com.esri.core.geometry.Envelope(); envelope.setCoords(-109.55, 25.76, -86.39, 49.94); { org.codehaus.jackson.JsonParser envelopeWGS84Parser = factory.createJsonParser(com.esri.core.geometry.GeometryEngine .geometryToJson(spatialReferenceWGS84, envelope)); com.esri.core.geometry.MapGeometry envelopeWGS84MP = com.esri.core.geometry.GeometryEngine .jsonToGeometry(envelopeWGS84Parser); NUnit.Framework.Assert.IsTrue(envelope.isEmpty() == envelopeWGS84MP.getGeometry() .isEmpty()); NUnit.Framework.Assert.IsTrue(envelope.getXMax() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getXMax()); NUnit.Framework.Assert.IsTrue(envelope.getYMax() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getYMax()); NUnit.Framework.Assert.IsTrue(envelope.getXMin() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getXMin()); NUnit.Framework.Assert.IsTrue(envelope.getYMin() == ((com.esri.core.geometry.Envelope )envelopeWGS84MP.getGeometry()).getYMin()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.getID() == envelopeWGS84MP.getSpatialReference ().getID()); if (!checkResultSpatialRef(envelopeWGS84MP, 4326, 0)) { bAnswer = false; } } { // export com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); e.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); e.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.M); string s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1 , e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":null,\"ymin\":null,\"xmax\":null,\"ymax\":null,\"zmin\":null,\"zmax\":null,\"mmin\":null,\"mmax\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); e.setCoords(0, 1, 2, 3); com.esri.core.geometry.Envelope1D z = new com.esri.core.geometry.Envelope1D(); com.esri.core.geometry.Envelope1D m = new com.esri.core.geometry.Envelope1D(); z.setCoords(5, 7); m.setCoords(11, 13); e.setInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0, z); e.setInterval(com.esri.core.geometry.VertexDescription.Semantics.M, 0, m); s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1 , e); NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":0,\"ymin\":1,\"xmax\":2,\"ymax\":3,\"zmin\":5,\"zmax\":7,\"mmin\":11,\"mmax\":13,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); } { // import string s = "{\"xmin\":0.0,\"ymin\":1.0,\"xmax\":2.0,\"ymax\":3.0,\"zmin\":5.0,\"zmax\":7.0,\"mmin\":11.0,\"mmax\":13.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"; org.codehaus.jackson.JsonParser parser = factory.createJsonParser(s); com.esri.core.geometry.MapGeometry map_env = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Envelope env = (com.esri.core.geometry.Envelope)map_env.getGeometry (); com.esri.core.geometry.Envelope1D z = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .Z, 0); com.esri.core.geometry.Envelope1D m = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics .M, 0); NUnit.Framework.Assert.IsTrue(z.vmin == 5.0); NUnit.Framework.Assert.IsTrue(z.vmax == 7.0); NUnit.Framework.Assert.IsTrue(m.vmin == 11.0); NUnit.Framework.Assert.IsTrue(m.vmax == 13.0); } { string s = "{ \"zmin\" : 33, \"xmin\" : -109.55, \"zmax\" : 53, \"ymin\" : 25.76, \"xmax\" : -86.39, \"ymax\" : 49.94, \"mmax\" : 13}"; org.codehaus.jackson.JsonParser parser = factory.createJsonParser(s); com.esri.core.geometry.MapGeometry map_env = com.esri.core.geometry.GeometryEngine .jsonToGeometry(parser); com.esri.core.geometry.Envelope env = (com.esri.core.geometry.Envelope)map_env.getGeometry (); com.esri.core.geometry.Envelope2D e = new com.esri.core.geometry.Envelope2D(); env.queryEnvelope2D(e); NUnit.Framework.Assert.IsTrue(e.xmin == -109.55 && e.ymin == 25.76 && e.xmax == - 86.39 && e.ymax == 49.94); com.esri.core.geometry.Envelope1D e1D; NUnit.Framework.Assert.IsTrue(env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); e1D = env.queryInterval(com.esri.core.geometry.VertexDescription.Semantics.Z, 0); NUnit.Framework.Assert.IsTrue(e1D.vmin == 33 && e1D.vmax == 53); NUnit.Framework.Assert.IsTrue(!env.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); } return(bAnswer); }