public static void testDifferenceOnPolyline() { // # * * # // # * @ // # @ * // # * // // /////////////////////////////// // // The polyline drawn in *s represents basePl // The polyline drawn in #s represents compPl // The @ represents their intersection points, so that // the difference polyline will be basePl with two new vertices @ added. com.esri.core.geometry.Polyline basePl = new com.esri.core.geometry.Polyline(); basePl.startPath(new com.esri.core.geometry.Point(-117, 20)); basePl.lineTo(new com.esri.core.geometry.Point(-130, 10)); basePl.lineTo(new com.esri.core.geometry.Point(-120, 50)); com.esri.core.geometry.Polyline compPl = new com.esri.core.geometry.Polyline(); compPl.startPath(new com.esri.core.geometry.Point(-116, 20)); compPl.lineTo(new com.esri.core.geometry.Point(-131, 10)); compPl.lineTo(new com.esri.core.geometry.Point(-121, 50)); com.esri.core.geometry.Geometry diffGeom = com.esri.core.geometry.GeometryEngine. difference(basePl, compPl, com.esri.core.geometry.SpatialReference.create(4326)); NUnit.Framework.Assert.IsTrue(diffGeom is com.esri.core.geometry.Polyline); com.esri.core.geometry.Polyline diffPolyline = (com.esri.core.geometry.Polyline)diffGeom; int pointCountDiffPolyline = diffPolyline.getPointCount(); // first line in comp_pl is 3y = 2x + 292 NUnit.Framework.Assert.AreEqual(3 * 20, 2 * (-116) + 292); NUnit.Framework.Assert.AreEqual(3 * 10, 2 * (-131) + 292); // new points should also lie on this line NUnit.Framework.Assert.IsTrue(3.0 * diffPolyline.getCoordinates2D()[1].y - 2.0 * diffPolyline.getCoordinates2D()[1].x - 292.0 == 0.0); NUnit.Framework.Assert.IsTrue(3.0 * diffPolyline.getCoordinates2D()[3].y - 2.0 * diffPolyline.getCoordinates2D()[3].x - 292.0 == 0.0); for (int i = 0; i < 3; i++) { NUnit.Framework.Assert.IsTrue(basePl.getCoordinates2D()[i].x == diffPolyline.getCoordinates2D ()[2 * i].x); NUnit.Framework.Assert.IsTrue(basePl.getCoordinates2D()[i].y == diffPolyline.getCoordinates2D ()[2 * i].y); } NUnit.Framework.Assert.AreEqual(5, pointCountDiffPolyline); }
public static void test2() { com.esri.core.geometry.OperatorFactoryLocal engine = com.esri.core.geometry.OperatorFactoryLocal .getInstance(); com.esri.core.geometry.OperatorGeneralize op = (com.esri.core.geometry.OperatorGeneralize )engine.getOperator(com.esri.core.geometry.Operator.Type.Generalize); com.esri.core.geometry.Polyline polyline = new com.esri.core.geometry.Polyline(); polyline.startPath(0, 0); polyline.lineTo(1, 1); polyline.lineTo(2, 0); polyline.lineTo(3, 2); polyline.lineTo(4, 1); polyline.lineTo(5, 0); polyline.lineTo(5, 10); polyline.lineTo(0, 10); com.esri.core.geometry.Geometry geom = op.execute(polyline, 2, true, null); com.esri.core.geometry.Polyline p = (com.esri.core.geometry.Polyline)geom; com.esri.core.geometry.Point2D[] points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 4); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 5 && points[1].y == 0); NUnit.Framework.Assert.IsTrue(points[2].x == 5 && points[2].y == 10); NUnit.Framework.Assert.IsTrue(points[3].x == 0 && points[3].y == 10); com.esri.core.geometry.Geometry geom1 = op.execute(geom, 5, false, null); p = (com.esri.core.geometry.Polyline)geom1; points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 2); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 0 && points[1].y == 10); geom1 = op.execute(geom, 5, true, null); p = (com.esri.core.geometry.Polyline)geom1; points = p.getCoordinates2D(); NUnit.Framework.Assert.IsTrue(points.Length == 2); NUnit.Framework.Assert.IsTrue(points[0].x == 0 && points[0].y == 0); NUnit.Framework.Assert.IsTrue(points[1].x == 0 && points[1].y == 10); }