public static void Run() { //ExStart: DetermineIfGeometriesCrossEachOther var geometry1 = new LineString(); geometry1.AddPoint(0, 0); geometry1.AddPoint(2, 2); var geometry2 = new LineString(); geometry2.AddPoint(1, 1); geometry2.AddPoint(3, 3); Console.WriteLine(geometry1.Crosses(geometry2)); // False var geometry3 = new LineString(); geometry3.AddPoint(0, 2); geometry3.AddPoint(2, 0); Console.WriteLine(geometry1.Crosses(geometry3)); // True //ExEnd: DetermineIfGeometriesCrossEachOther }
public void TestLineLine1() { // test when the point being tested in a node on the line Coordinate coordLine1 = new Coordinate(5.0, 5.0); Coordinate coordLine2 = new Coordinate(10.0, 10.0); Coordinate coordLine3 = new Coordinate(5.0, 10.0); Coordinate coordLine4 = new Coordinate(10.0, 5.0); Coordinates coordinates1 = new Coordinates(); coordinates1.Add(coordLine1); coordinates1.Add(coordLine2); Coordinates coordinates2 = new Coordinates(); coordinates2.Add(coordLine3); coordinates2.Add(coordLine4); LineString linestring1 = _factory.CreateLineString(coordinates1); LineString linestring2 = _factory.CreateLineString(coordinates2); Geometry pt = linestring1.Intersection(linestring2); Assertion.AssertEquals("intersects", true, linestring1.Intersects(linestring2)); Assertion.AssertEquals("disjoint", false, linestring1.Disjoint(linestring2)); Assertion.AssertEquals("contains", false, linestring1.Contains(linestring2)); Assertion.AssertEquals("within", false, linestring1.Within(linestring2)); Assertion.AssertEquals("crosses", true, linestring1.Crosses(linestring2)); Assertion.AssertEquals("touches", false, linestring1.Touches(linestring2)); // always returns false when a point is involved Assertion.AssertEquals("overlaps", false, linestring1.Overlaps(linestring2)); }
/// <summary> /// /// </summary> public void Start() { var pointInLine = Factory.CreatePoint(new Coordinate(20, 10)); var pointOutLine = Factory.CreatePoint(new Coordinate(20, 31)); var aLine = Factory.CreateLineString(new Coordinate[] { new Coordinate(23, 32.2), new Coordinate(922, 11) }); var anotherLine = Factory.CreateLineString(new Coordinate[] { new Coordinate(0, 1), new Coordinate(30, 30) }); try { Write(line.Area); Write(line.Boundary); Write(line.BoundaryDimension); Write(line.Centroid); Write(line.Coordinate); Write(line.Coordinates); Write(line.CoordinateSequence); Write(line.Dimension); Write(line.EndPoint); Write(line.Envelope); Write(line.EnvelopeInternal); Write(line.InteriorPoint); Write(line.IsClosed); Write(line.IsEmpty); Write(line.IsRing); Write(line.IsSimple); Write(line.IsValid); Write(line.Length); Write(line.NumPoints); Write(line.StartPoint); if (line.UserData != null) { Write(line.UserData); } else { Write("UserData null"); } Write(line.Buffer(10)); Write(line.Buffer(10, new BufferParameters { EndCapStyle = EndCapStyle.Flat })); Write(line.Buffer(10, new BufferParameters { EndCapStyle = EndCapStyle.Square })); Write(line.Buffer(10, 20)); Write(line.Buffer(10, new BufferParameters(20) { EndCapStyle = EndCapStyle.Flat })); Write(line.Buffer(10, new BufferParameters(20) { EndCapStyle = EndCapStyle.Square })); Write(line.Contains(pointInLine)); Write(line.Contains(pointOutLine)); Write(line.Crosses(pointInLine)); Write(line.Crosses(pointOutLine)); Write(line.Difference(pointInLine)); Write(line.Difference(pointOutLine)); Write(line.Disjoint(pointInLine)); Write(line.Disjoint(pointOutLine)); Write(line.Distance(pointInLine)); Write(line.Distance(pointOutLine)); Write(line.EqualsTopologically(line.Copy() as LineString)); Write(line.EqualsExact(line.Copy() as LineString)); Write(line.ConvexHull()); Write(line.Intersection(pointInLine)); Write(line.Intersection(pointOutLine)); Write(line.Intersection(aLine)); Write(line.Intersects(pointInLine)); Write(line.Intersects(pointOutLine)); Write(line.Intersects(aLine)); Write(line.IsWithinDistance(pointOutLine, 2)); Write(line.IsWithinDistance(pointOutLine, 222)); Write(line.Overlaps(pointInLine)); Write(line.Overlaps(pointOutLine)); Write(line.Overlaps(aLine)); Write(line.Overlaps(anotherLine)); Write(line.Relate(pointInLine)); Write(line.Relate(pointOutLine)); Write(line.Relate(aLine)); Write(line.Relate(anotherLine)); Write(line.SymmetricDifference(pointInLine)); Write(line.SymmetricDifference(pointOutLine)); Write(line.SymmetricDifference(aLine)); Write(line.SymmetricDifference(anotherLine)); Write(line.ToString()); Write(line.AsText()); Write(line.Touches(pointInLine)); Write(line.Touches(pointOutLine)); Write(line.Touches(aLine)); Write(line.Touches(anotherLine)); Write(line.Union(pointInLine)); Write(line.Union(pointOutLine)); Write(line.Union(aLine)); Write(line.Union(anotherLine)); Write(line.Within(pointInLine)); Write(line.Within(pointOutLine)); Write(line.Within(aLine)); Write(line.Within(anotherLine)); string linestring = "LINESTRING (1.2 3.4, 5.6 7.8, 9.1 10.12)"; string anotherlinestringg = "LINESTRING (12345 3654321, 685 7777.945677, 782 111.1)"; var geom1 = Reader.Read(linestring); Write(geom1.AsText()); var geom2 = Reader.Read(anotherlinestringg); Write(geom2.AsText()); byte[] bytes = line.AsBinary(); var test1 = new WKBReader().Read(bytes); Write(test1.ToString()); bytes = new GDBWriter().Write(line); test1 = new GDBReader().Read(bytes); Write(test1.ToString()); } catch (Exception ex) { throw ex; } }