public static void Test2() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorGeneralize op = (com.epl.geometry.OperatorGeneralize)engine.GetOperator(com.epl.geometry.Operator.Type.Generalize); com.epl.geometry.Polyline polyline = new com.epl.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.epl.geometry.Geometry geom = op.Execute(polyline, 2, true, null); com.epl.geometry.Polyline p = (com.epl.geometry.Polyline)geom; com.epl.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.epl.geometry.Geometry geom1 = op.Execute(geom, 5, false, null); p = (com.epl.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.epl.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); }
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.epl.geometry.Polyline basePl = new com.epl.geometry.Polyline(); basePl.StartPath(new com.epl.geometry.Point(-117, 20)); basePl.LineTo(new com.epl.geometry.Point(-130, 10)); basePl.LineTo(new com.epl.geometry.Point(-120, 50)); com.epl.geometry.Polyline compPl = new com.epl.geometry.Polyline(); compPl.StartPath(new com.epl.geometry.Point(-116, 20)); compPl.LineTo(new com.epl.geometry.Point(-131, 10)); compPl.LineTo(new com.epl.geometry.Point(-121, 50)); com.epl.geometry.Geometry diffGeom = com.epl.geometry.GeometryEngine.Difference(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326)); NUnit.Framework.Assert.IsTrue(diffGeom is com.epl.geometry.Polyline); com.epl.geometry.Polyline diffPolyline = (com.epl.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); }