public virtual void testMultiPointAndMultiPoint2() { com.esri.core.geometry.MultiPoint basePl = new com.esri.core.geometry.MultiPoint( ); basePl.add(new com.esri.core.geometry.Point(-116, 20)); basePl.add(new com.esri.core.geometry.Point(-118, 21)); com.esri.core.geometry.MultiPoint compPl = new com.esri.core.geometry.MultiPoint( ); compPl.add(new com.esri.core.geometry.Point(-116, 20)); compPl.add(new com.esri.core.geometry.Point(-118, 21)); int noException = 1; // no exception com.esri.core.geometry.Geometry intersectGeom = null; try { intersectGeom = com.esri.core.geometry.GeometryEngine.intersect(basePl, compPl, com.esri.core.geometry.SpatialReference .create(4326)); } catch (System.Exception) { noException = 0; } NUnit.Framework.Assert.AreEqual(noException, 1); NUnit.Framework.Assert.IsNotNull(intersectGeom); NUnit.Framework.Assert.IsTrue(intersectGeom.getType() == com.esri.core.geometry.Geometry.Type .MultiPoint); com.esri.core.geometry.MultiPoint ip = (com.esri.core.geometry.MultiPoint)intersectGeom; NUnit.Framework.Assert.AreEqual(-116, 0.1E7, ip.getPoint(0).getX()); NUnit.Framework.Assert.AreEqual(20, 0.1E7, ip.getPoint(0).getY()); NUnit.Framework.Assert.AreEqual(-118, 0.1E7, ip.getPoint(0).getX()); NUnit.Framework.Assert.AreEqual(21, 0.1E7, ip.getPoint(0).getY()); }
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 virtual void testSerializeMultiPoint() { try { java.io.ByteArrayOutputStream streamOut = new java.io.ByteArrayOutputStream(); java.io.ObjectOutputStream oo = new java.io.ObjectOutputStream(streamOut); com.esri.core.geometry.MultiPoint pt = new com.esri.core.geometry.MultiPoint(); pt.add(10, 30); pt.add(120, 40); 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.MultiPoint ptRes = (com.esri.core.geometry.MultiPoint)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.Equals(pt)); } catch (System.Exception) { fail("MultiPoint serialization failure"); } // try // { // FileOutputStream streamOut = new FileOutputStream(m_thisDirectory + // "savedMultiPoint.txt"); // ObjectOutputStream oo = new ObjectOutputStream(streamOut); // MultiPoint pt = new MultiPoint(); // pt.add(10, 30); // pt.add(120, 40); // oo.writeObject(pt); // } // catch(Exception ex) // { // fail("MultiPoint serialization failure"); // } try { java.io.InputStream s = Sharpen.Runtime.getClassForType(typeof(com.esri.core.geometry.TestSerialization )).getResourceAsStream("savedMultiPoint.txt"); java.io.ObjectInputStream ii = new java.io.ObjectInputStream(s); com.esri.core.geometry.MultiPoint ptRes = (com.esri.core.geometry.MultiPoint)ii.readObject (); NUnit.Framework.Assert.IsTrue(ptRes.getPoint(1).getY() == 40); } catch (System.Exception) { fail("MultiPoint serialization failure"); } }
public static void testCopy() { com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); com.esri.core.geometry.Point pt0 = new com.esri.core.geometry.Point(0.0, 0.0, -1.0 ); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0, 1.0 ); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 1.0, 1.0 ); mpoint.add(pt0); mpoint.add(pt1); mpoint.add(pt2); mpoint.removePoint(1); com.esri.core.geometry.MultiPoint mpCopy = (com.esri.core.geometry.MultiPoint)mpoint .copy(); NUnit.Framework.Assert.IsTrue(mpCopy.Equals(mpoint)); com.esri.core.geometry.Point pt; pt = mpCopy.getPoint(0); NUnit.Framework.Assert.IsTrue(pt.getX() == pt0.getX() && pt.getY() == pt0.getY()); pt = mpCopy.getPoint(1); NUnit.Framework.Assert.IsTrue(pt.getX() == pt2.getX() && pt.getY() == pt2.getY()); NUnit.Framework.Assert.IsTrue(mpCopy.getPointCount() == 2); }
/// <exception cref="org.codehaus.jackson.JsonParseException"/> /// <exception cref="System.IO.IOException"/> internal virtual bool testMultiPoint() { bool bAnswer = true; com.esri.core.geometry.MultiPoint multiPoint1 = new com.esri.core.geometry.MultiPoint (); multiPoint1.add(-97.06138, 32.837); multiPoint1.add(-97.06133, 32.836); multiPoint1.add(-97.06124, 32.834); multiPoint1.add(-97.06127, 32.832); { string s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWGS84 , multiPoint1); org.codehaus.jackson.JsonParser mPointWgs84Parser = factory.createJsonParser(s); com.esri.core.geometry.MapGeometry mPointWgs84MP = com.esri.core.geometry.GeometryEngine .jsonToGeometry(mPointWgs84Parser); NUnit.Framework.Assert.IsTrue(multiPoint1.getPointCount() == ((com.esri.core.geometry.MultiPoint )mPointWgs84MP.getGeometry()).getPointCount()); NUnit.Framework.Assert.IsTrue(multiPoint1.getPoint(0).getX() == ((com.esri.core.geometry.MultiPoint )mPointWgs84MP.getGeometry()).getPoint(0).getX()); NUnit.Framework.Assert.IsTrue(multiPoint1.getPoint(0).getY() == ((com.esri.core.geometry.MultiPoint )mPointWgs84MP.getGeometry()).getPoint(0).getY()); int lastIndex = multiPoint1.getPointCount() - 1; NUnit.Framework.Assert.IsTrue(multiPoint1.getPoint(lastIndex).getX() == ((com.esri.core.geometry.MultiPoint )mPointWgs84MP.getGeometry()).getPoint(lastIndex).getX()); NUnit.Framework.Assert.IsTrue(multiPoint1.getPoint(lastIndex).getY() == ((com.esri.core.geometry.MultiPoint )mPointWgs84MP.getGeometry()).getPoint(lastIndex).getY()); NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.getID() == mPointWgs84MP.getSpatialReference ().getID()); if (!checkResultSpatialRef(mPointWgs84MP, 4326, 0)) { bAnswer = false; } } { com.esri.core.geometry.MultiPoint p = new com.esri.core.geometry.MultiPoint(); p.addAttribute(com.esri.core.geometry.VertexDescription.Semantics.Z); 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("{\"hasZ\":true,\"hasM\":true,\"points\":[],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); p.add(10.0, 20.0, 30.0); p.add(20.0, 40.0, 60.0); s = com.esri.core.geometry.GeometryEngine.geometryToJson(spatialReferenceWebMerc1 , p); NUnit.Framework.Assert.IsTrue(s.Equals("{\"hasZ\":true,\"hasM\":true,\"points\":[[10,20,30,null],[20,40,60,null]],\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}" )); } { string points = "{\"hasM\" : false, \"hasZ\" : true, \"uncle remus\" : null, \"points\" : [ [0,0,1], [0.0,10.0,1], [10.0,10.0,1], [10.0,0.0,1, 6666] ],\"spatialReference\" : {\"wkid\" : 4326}}"; com.esri.core.geometry.MapGeometry mp = com.esri.core.geometry.GeometryEngine.jsonToGeometry (factory.createJsonParser(points)); com.esri.core.geometry.MultiPoint multipoint = (com.esri.core.geometry.MultiPoint )mp.getGeometry(); NUnit.Framework.Assert.IsTrue(multipoint.getPointCount() == 4); com.esri.core.geometry.Point2D point2d; point2d = multipoint.getXY(0); NUnit.Framework.Assert.IsTrue(point2d.x == 0.0 && point2d.y == 0.0); point2d = multipoint.getXY(1); NUnit.Framework.Assert.IsTrue(point2d.x == 0.0 && point2d.y == 10.0); point2d = multipoint.getXY(2); NUnit.Framework.Assert.IsTrue(point2d.x == 10.0 && point2d.y == 10.0); point2d = multipoint.getXY(3); NUnit.Framework.Assert.IsTrue(point2d.x == 10.0 && point2d.y == 0.0); NUnit.Framework.Assert.IsTrue(multipoint.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .Z)); NUnit.Framework.Assert.IsTrue(!multipoint.hasAttribute(com.esri.core.geometry.VertexDescription.Semantics .M)); double z = multipoint.getAttributeAsDbl(com.esri.core.geometry.VertexDescription.Semantics .Z, 0, 0); NUnit.Framework.Assert.IsTrue(z == 1); com.esri.core.geometry.SpatialReference spatial_reference = mp.getSpatialReference (); NUnit.Framework.Assert.IsTrue(spatial_reference.getID() == 4326); } return(bAnswer); }
public static void testCreation() { { // simple create com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(Sharpen.Runtime.getClassForObject(mpoint) == Sharpen.Runtime.getClassForType (typeof(com.esri.core.geometry.MultiPoint))); // assertFalse(mpoint.getClass() == Polyline.class); NUnit.Framework.Assert.IsTrue(mpoint != null); NUnit.Framework.Assert.IsTrue(mpoint.getType() == com.esri.core.geometry.Geometry.Type .MultiPoint); NUnit.Framework.Assert.IsTrue(mpoint.isEmpty()); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 0); mpoint = null; NUnit.Framework.Assert.IsFalse(mpoint != null); } { // play with default attributes com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); simpleTest(mpoint); } { // simple create 2D com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.MultiPoint mpoint1 = new com.esri.core.geometry.MultiPoint (); NUnit.Framework.Assert.IsTrue(mpoint1 != null); mpoint.setEmpty(); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.add(pt); com.esri.core.geometry.Point pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); // assertFalse(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // pt3.setZ(115.0); mpoint.setPoint(0, pt3); pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); } { /* && pt3.getZ() == 115 */ // assertTrue(mpoint->HasAttribute(VertexDescription::Semantics::Z)); // CompareGeometryContent(mpoint, &pt, 1); // move 3d com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); NUnit.Framework.Assert.IsTrue(mpoint != null); com.esri.core.geometry.Point pt = new com.esri.core.geometry.Point(0, 0); mpoint.add(pt); com.esri.core.geometry.Point pt3 = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt3.getX() == 0 && pt3.getY() == 0); } { /* && pt3.getZ() == 0 */ // test QueryInterval com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(-1.0); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 0.0); // pt2.setZ(1.0); mpoint.add(pt1); mpoint.add(pt2); // Envelope1D e = // mpoint->QueryInterval(enum_value2(VertexDescription, Semantics, // Z), 0); com.esri.core.geometry.Envelope e = new com.esri.core.geometry.Envelope(); mpoint.queryEnvelope(e); } { // assertTrue(e.get == -1.0 && e.vmax == 1.0); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // for (int i = 0; i < sz; i++) // geom.add(openString[i]); // CompareGeometryContent(geom, openString, sz); com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // Point point = GCNEW Point; // for (int i = 0; i < sz; i++) // { // point.setXY(openString[i]); // geom.add(point); // } // CompareGeometryContent(geom, openString, sz); // Test AddPoints com.esri.core.geometry.MultiPoint geom = new com.esri.core.geometry.MultiPoint(); } { // int sz = sizeof(openString) / sizeof(openString[0]); // geom.addPoints(openString, sz, 0, -1); // CompareGeometryContent((MultiVertexGeometry)geom, openString, // sz); // Test InsertPoint(Point2D) com.esri.core.geometry.MultiPoint mpoint = new com.esri.core.geometry.MultiPoint( ); com.esri.core.geometry.Point pt0 = new com.esri.core.geometry.Point(0.0, 0.0); // pt0.setZ(-1.0); // pt0.setID(7); com.esri.core.geometry.Point pt1 = new com.esri.core.geometry.Point(0.0, 0.0); // pt1.setZ(1.0); // pt1.setID(11); com.esri.core.geometry.Point pt2 = new com.esri.core.geometry.Point(0.0, 1.0); // pt2.setZ(1.0); // pt2.setID(13); mpoint.add(pt0); mpoint.add(pt1); mpoint.add(pt2); com.esri.core.geometry.Point pt3 = new com.esri.core.geometry.Point(-11.0, -13.0); mpoint.add(pt3); mpoint.insertPoint(1, pt3); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 5); com.esri.core.geometry.Point pt; pt = mpoint.getPoint(0); NUnit.Framework.Assert.IsTrue(pt.getX() == pt0.getX() && pt.getY() == pt0.getY()); /* * && * pt. * getZ * () == * pt0 * .getZ * () */ pt = mpoint.getPoint(1); NUnit.Framework.Assert.IsTrue(pt.getX() == pt3.getX() && pt.getY() == pt3.getY()); pt = mpoint.getPoint(2); NUnit.Framework.Assert.IsTrue(pt.getX() == pt1.getX() && pt.getY() == pt1.getY()); /* * && * pt. * getZ * () == * pt1 * .getZ * () */ pt = mpoint.getPoint(3); NUnit.Framework.Assert.IsTrue(pt.getX() == pt2.getX() && pt.getY() == pt2.getY()); /* * && * pt. * getZ * () == * pt2 * .getZ * () */ com.esri.core.geometry.Point point = new com.esri.core.geometry.Point(); point.setXY(17.0, 19.0); // point.setID(12); // point.setM(5); mpoint.insertPoint(2, point); mpoint.add(point); NUnit.Framework.Assert.IsTrue(mpoint.getPointCount() == 7); } // double m; // int id; // pt = mpoint.getXYZ(2); // assertTrue(pt.x == 17.0 && pt.y == 19.0 && pt.z == defaultZ); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 2, 0); // assertTrue(m == 5); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 2, 0); // assertTrue(id == 23); // // pt = mpoint.getXYZ(3); // assertTrue(pt.x == pt1.x && pt.y == pt1.y && pt.z == pt1.z); // m = mpoint.getAttributeAsDbl(enum_value2(VertexDescription, // Semantics, M), 3, 0); // assertTrue(NumberUtils::IsNaN(m)); // id = mpoint.getAttributeAsInt(enum_value2(VertexDescription, // Semantics, ID), 3, 0); // assertTrue(id == 11); com.esri.core.geometry.MultiPoint mpoint_1 = new com.esri.core.geometry.MultiPoint (); com.esri.core.geometry.Point pt0_1 = new com.esri.core.geometry.Point(0.0, 0.0, - 1.0); com.esri.core.geometry.Point pt1_1 = new com.esri.core.geometry.Point(0.0, 0.0, 1.0 ); com.esri.core.geometry.Point pt2_1 = new com.esri.core.geometry.Point(0.0, 1.0, 1.0 ); mpoint_1.add(pt0_1); mpoint_1.add(pt1_1); mpoint_1.add(pt2_1); mpoint_1.removePoint(1); com.esri.core.geometry.Point pt_1; pt_1 = mpoint_1.getPoint(0); NUnit.Framework.Assert.IsTrue(pt_1.getX() == pt0_1.getX() && pt_1.getY() == pt0_1 .getY()); pt_1 = mpoint_1.getPoint(1); NUnit.Framework.Assert.IsTrue(pt_1.getX() == pt2_1.getX() && pt_1.getY() == pt2_1 .getY()); NUnit.Framework.Assert.IsTrue(mpoint_1.getPointCount() == 2); }