private Polygon Poly1() { _coords1 = new Coordinates(); Coordinate coord = new Coordinate(5, 1); _coords1.Add(coord); coord = new Coordinate(6, 2); _coords1.Add(coord); coord = new Coordinate(7, 3); _coords1.Add(coord); coord = new Coordinate(6, 4); _coords1.Add(coord); coord = new Coordinate(5, 5); _coords1.Add(coord); coord = new Coordinate(4, 4); _coords1.Add(coord); coord = new Coordinate(3, 3); _coords1.Add(coord); coord = new Coordinate(4, 2); _coords1.Add(coord); coord = new Coordinate(5, 1); _coords1.Add(coord); _gf = new GeometryFactory(_precMod, _sRID); _exterior1 = _gf.CreateLinearRing(_coords1); Polygon polygon = _gf.CreatePolygon(_exterior1); return polygon; }
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> /// Creates a new instance of Coordinates adding each coordinate in coords to this instance. /// </summary> /// <param name="coords">The set of coordinates to be used to create this set.</param> public Coordinates(Coordinates coords) : base() { foreach(Coordinate coord in coords) { Add(coord, true); } }
public void TestPointLine1() { // 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 coordPoint1 = new Coordinate(5.0,5.0); Coordinates coordinates = new Coordinates(); coordinates.Add(coordLine1); coordinates.Add(coordLine2); Point point1 = _factory.CreatePoint(coordPoint1); LineString linestring = _factory.CreateLineString(coordinates); Assertion.AssertEquals("intersects",true,point1.Intersects(linestring)); Assertion.AssertEquals("disjoint",false,point1.Disjoint(linestring)); Assertion.AssertEquals("contains",false,point1.Contains(linestring)); Assertion.AssertEquals("within",false,point1.Within(linestring)); // always returns false when a point is involves Assertion.AssertEquals("crosses",false,point1.Crosses(linestring)); Assertion.AssertEquals("touches",true,point1.Touches(linestring)); // always returns false when a point is involved Assertion.AssertEquals("overlaps",false,point1.Overlaps(linestring)); }
public void TestPointLine2() { // 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 coordPoint1 = new Coordinate(6.0,6.0); Coordinates coordinates = new Coordinates(); coordinates.Add(coordLine1); coordinates.Add(coordLine2); Point point1 = _factory.CreatePoint(coordPoint1); LineString linestring = _factory.CreateLineString(coordinates); Assertion.AssertEquals("intersects",true,point1.Intersects(linestring)); Assertion.AssertEquals("intersects",true,linestring.Intersects(point1)); Assertion.AssertEquals("disjoint",false,point1.Disjoint(linestring)); Assertion.AssertEquals("contains",false,point1.Contains(linestring)); Assertion.AssertEquals("OppositeContains", true, linestring.Contains( point1 )); Assertion.AssertEquals("within",true,point1.Within(linestring)); // point1 is within linestring and linestring contains point. // always returns false when a point is involves Assertion.AssertEquals("crosses",false,point1.Crosses(linestring)); Assertion.AssertEquals("touches",false,point1.Touches(linestring)); // false because point is in the interior of linestring and not the boundary. The boundary is the endpoints. // always returns false when a point is involved Assertion.AssertEquals("overlaps",false,point1.Overlaps(linestring)); }
private MultiPolygon CreateMP1() { Polygon[] polygons = new Polygon[2]; LineString[] rings = new LineString[2]; Coordinates coords = new Coordinates(); Coordinate coord = new Coordinate(5, 1); coords.Add(coord); coord = new Coordinate(6, 2); coords.Add(coord); coord = new Coordinate(7, 3); coords.Add(coord); coord = new Coordinate(6, 4); coords.Add(coord); coord = new Coordinate(5, 5); coords.Add(coord); coord = new Coordinate(4, 4); coords.Add(coord); coord = new Coordinate(3, 3); coords.Add(coord); coord = new Coordinate(4, 2); coords.Add(coord); coord = new Coordinate(5, 1); coords.Add(coord); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LinearRing exterior1 = gf.CreateLinearRing(coords); polygons[0] = gf.CreatePolygon(exterior1); rings[0] = exterior1 as LineString; coords = new Coordinates(); coord = new Coordinate(5, 1); coords.Add(coord); coord = new Coordinate(6, 2); coords.Add(coord); coord = new Coordinate(7, 3); coords.Add(coord); coord = new Coordinate(6, 4); coords.Add(coord); coord = new Coordinate(5, 5); coords.Add(coord); coord = new Coordinate(4, 4); coords.Add(coord); coord = new Coordinate(3, 3); coords.Add(coord); coord = new Coordinate(4, 2); coords.Add(coord); coord = new Coordinate(5, 1); coords.Add(coord); LinearRing exterior2 = gf.CreateLinearRing(coords); polygons[1] = gf.CreatePolygon(exterior2); rings[1] = exterior2; _mls1 = gf.CreateMultiLineString(rings); return gf.CreateMultiPolygon(polygons); }
public void test_Constructor() { Coordinates coords = new Coordinates(); Assertion.AssertEquals("Constructor-1: ", 0, coords.Count); coords = Coords1(); Assertion.AssertEquals("Constructor-2: ", 10, coords.Count); }
public void TestMultiPoint1() { Coordinates coordinates = new Coordinates(); coordinates.Add( new Coordinate(1,2) ); coordinates.Add( new Coordinate(1.2,2.3) ); MultiPoint multipoint = _factory.CreateMultiPoint( coordinates ); string wkt = _writer.WriteFormatted(multipoint); Assertion.AssertEquals("multi point","MULTIPOINT (1 2, 1.2 2.3)",wkt); }
public void TestLineString1() { Coordinates coordinates = new Coordinates(); coordinates.Add( new Coordinate(1,2) ); coordinates.Add( new Coordinate(1.2,2.3) ); LineString linestring = _factory.CreateLineString( coordinates ); string wkt = _writer.WriteFormatted(linestring); Assertion.AssertEquals("multi point","LINESTRING (1 2, 1.2 2.3)",wkt); }
/// <summary> /// Returns the unique Coordinates. /// </summary> /// <returns>Return the Coordinates collected by this CoordinateArrayFilter.</returns> public Coordinates GetCoordinates() { // copy costruct a new list of coordinates. Coordinates coordinates = new Coordinates(); foreach(object obj in _treeSet) { coordinates.Add(obj); } return coordinates; }
/// <summary> /// Return a list of the monotone chains /// for the given list of coordinates. /// </summary> /// <param name="pts"></param> /// <returns></returns> public static ArrayList GetChains(Coordinates pts) { ArrayList mcList = new ArrayList(); int[] startIndex = GetChainStartIndices( pts ); for ( int i = 0; i < startIndex.Length - 1; i++ ) { MonotoneChain mc = new MonotoneChain( pts, startIndex[i], startIndex[i + 1] ); mcList.Add( mc ); } // for ( int i = 0; i < startIndex.Length - 1; i++ ) return mcList; } // public static ArrayList GetChains(Coordinates pts)
/// <summary> /// Method to create a Simple LinearRing for testing purposes /// </summary> /// <returns>A LinearRing</returns> private LinearRing Simple() { Coordinates coords = new Coordinates(); Coordinate coord ;//Coordinate(0, 0); coord = new Coordinate(10, 13); coords.Add(coord); coord = new Coordinate(11, 13); coords.Add(coord); coord = new Coordinate(12, 13); coords.Add(coord); coord = new Coordinate(13, 14); coords.Add(coord); coord = new Coordinate(14, 15); coords.Add(coord); coord = new Coordinate(15, 16); coords.Add(coord); coord = new Coordinate(15, 17); coords.Add(coord); coord = new Coordinate(15, 18); coords.Add(coord); coord = new Coordinate(14, 19); coords.Add(coord); coord = new Coordinate(13, 20); coords.Add(coord); coord = new Coordinate(12, 21); coords.Add(coord); coord = new Coordinate(11, 21); coords.Add(coord); coord = new Coordinate(10, 21); coords.Add(coord); coord = new Coordinate(9, 20); coords.Add(coord); coord = new Coordinate(8, 19); coords.Add(coord); coord = new Coordinate(7, 18); coords.Add(coord); coord = new Coordinate(7, 17); coords.Add(coord); coord = new Coordinate(7, 16); coords.Add(coord); coord = new Coordinate(8, 15); coords.Add(coord); coord = new Coordinate(9, 14); coords.Add(coord); coord = new Coordinate(10, 13); coords.Add(coord); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LinearRing lr = gf.CreateLinearRing(coords); return lr; }
public bool HasRepeatedPoint(Coordinates coord) { for (int i = 1; i < coord.Count; i++) { if (coord[i - 1].Equals(coord[i]) ) { _repeatedCoord = coord[i]; return true; } } return false; }
/// <summary> /// Initializes a new instance LinearRing with the given points. /// </summary> /// <param name="points"> /// Points forming a closed and simple linestring, or null or an empty array /// to create the empty geometry. This array must not contain null elements. /// Consecutive points may not be equal. /// </param> /// <param name="precisionModel"> /// The specification of the grid of allowable points for this LinearRing. /// </param> /// <param name="SRID"> /// The ID of the Spatial Reference System used by this LinearRing. /// </param> internal LinearRing(Coordinates points, PrecisionModel precisionModel, int SRID) : base(points,precisionModel,SRID) { if (!IsEmpty() && !base.IsClosed()) { // uses base.IsClosed() since this.IsClosed() always returns true. throw new ArgumentException("Points must form a closed linestring."); } if ((points != null) && (points.Count >= 1 && points.Count <= 3)) { throw new ArgumentException("Points must contain 0 or >3 elements."); } }
/// <summary> /// Constructs a LineString with the given points. /// </summary> /// <param name="points"> /// The points of the linestring, or null to create the empty geometry. This array must not contain null /// elements. Consecutive points may not be equal. /// </param> /// <param name="precisionModel">The specification of the grid of allowable points for this LineString.</param> /// <param name="SRID"> The ID of the Spatial Reference System used by this LineString.</param> internal LineString(Coordinates points, PrecisionModel precisionModel, int SRID) : base( precisionModel, SRID) { if (points == null) { points = new Coordinates(); } if (HasNullElements(points)) { throw new ArgumentNullException("point array must not contain null elements"); } if (points.Count == 1) { throw new ArgumentException("point array must contain 0 or >1 elements"); } this._points = points; }
} // public static ArrayList GetChains(Coordinates pts) /// <summary> /// Return an array containing lists of start/end indexes of the monotone chains /// for the given list of coordinates. /// The last entry in the array points to the end point of the point array, /// for use as a sentinel. /// </summary> /// <param name="pts"></param> /// <returns></returns> public static int[] GetChainStartIndices( Coordinates pts ) { // find the startpoint (and endpoints) of all monotone chains in this edge int start = 0; ArrayList startIndexList = new ArrayList(); startIndexList.Add( start ); do { int last = FindChainEnd( pts, start ); startIndexList.Add( last ); start = last; } while ( start < pts.Count - 1); // copy list to an array of ints, for efficiency int[] startIndex = ( int[] )startIndexList.ToArray( Type.GetType( "System.Int32" ) ); return startIndex; } // public static int[] GetChainStartIndices( Coordinates pts )
/// <summary> /// Return the index of the last point in the monotone chain /// </summary> /// <param name="pts"></param> /// <param name="start"></param> /// <returns></returns> private static int FindChainEnd(Coordinates pts, int start) { // determine quadrant for chain int chainQuad = Quadrant.QuadrantLocation( pts[start], pts[start + 1] ); int last = start + 1; while (last < pts.Count ) { // compute quadrant for next possible segment in chain int quad = Quadrant.QuadrantLocation( pts[last - 1], pts[last] ); if (quad != chainQuad) { break; } last++; } return last - 1; }
/// <summary> /// Tests whether a point lies inside a simple polygon (ring). The ring may be oriented in either /// direction. If the point lies on the ring boundary the result of this method is unspecified. /// </summary> /// <param name="p">Point to test.</param> /// <param name="ring">Simple polygon ring to test if point lies inside.</param> /// <returns>Returns true if the point lies in the interior of the ring.</returns> public override bool IsPointInRing(Coordinate p, Coordinates ring) { int i, i1; // point index; i1 = i-1 mod n double xInt; // x intersection of e with ray int crossings = 0; // number of edge/ray crossings double x1,y1,x2,y2; int nPts = ring.Count; // For each line edge l = (i-1, i), see if it crosses ray from test point in positive x direction. for (i = 1; i < nPts; i++ ) { i1 = i - 1; Coordinate p1 = ring[i]; Coordinate p2 = ring[i1]; x1 = p1.X - p.X; y1 = p1.Y - p.Y; x2 = p2.X - p.X; y2 = p2.Y - p.Y; if( ( ( y1 > 0 ) && ( y2 <= 0 ) ) || ( ( y2 > 0 ) && ( y1 <= 0 ) ) ) { // e straddles x axis, so compute intersection. xInt = ( x1 * y2 - x2 * y1 ) / (y2 - y1); //xsave = xInt; // crosses ray if strictly positive intersection. if ( 0.0 < xInt ) { crossings++; } } } // p is inside if an odd number of crossings. if( (crossings % 2) == 1 ) { return true; } else { return false; } } // public override bool IsPointInPolygon(Coordinate p, Coordinates ring)
/// <summary> /// Applies the projection to the coordinates. /// </summary> /// <param name="geometry">The geometry object to apply the filter to.</param> public void Filter(Geometry geometry) { /*if (geometry is Polygon) { Polygon polygon = (Polygon)geometry; Filter(polygon.Shell); foreach(LinearRing linearring in polygon.Holes) { Filter(linearring); } }*/ if (geometry is LinearRing || geometry is LineString || geometry is Point) { int sourceSRID = int.Parse(_coordinateTransform.SourceCS.AuthorityCode); int targetSRID = int.Parse(_coordinateTransform.TargetCS.AuthorityCode); MapProjection projection = (MapProjection)_coordinateTransform.MathTransform; Coordinates projectedCoordinates = new Coordinates(); double x=0.0; double y=0.0; Coordinate coordinate; for(int i=0; i < geometry.GetCoordinates().Count; i++) { coordinate = geometry.GetCoordinates()[i]; if (geometry.GetSRID() == sourceSRID) { projection.MetersToDegrees(coordinate.X, coordinate.Y, out x, out y); } else if (geometry.GetSRID() == targetSRID) { projection.DegreesToMeters(coordinate.X, coordinate.Y, out x, out y); } coordinate.X = x; coordinate.Y = y; } } /*else { throw new NotSupportedException(geometry.GetType().Name); }*/ }
/// <summary> /// Find a point from the list of testCoords /// that is NOT a node in the edge for the list of searchCoords /// </summary> /// <param name="testCoords"></param> /// <param name="searchRing"></param> /// <param name="graph"></param> /// <returns>return the point found, or null if none found</returns> public static Coordinate FindPtNotNode( Coordinates testCoords, LinearRing searchRing, GeometryGraph graph) { // find edge corresponding to searchRing. Edge searchEdge = graph.FindEdge(searchRing ); // find a point in the testCoords which is not a node of the searchRing EdgeIntersectionList eiList = searchEdge.EdgeIntersectionList; // somewhat inefficient - is there a better way? (Use a node map, for instance?) for (int i = 0 ; i < testCoords.Count; i++) { Coordinate pt = testCoords[i]; if (! eiList.IsIntersection(pt)) { return pt; } } return null; }
public Coordinates Filter(Coordinates inputPts) { _newPts.Clear(); int i = 0; while (i < inputPts.Count) { AddPoint((Coordinate)inputPts[i]); int loopSize = CheckForLoop(inputPts, i); // skip loop if one was found i++; if (loopSize > 0) { //Assert.isTrue(inputPts[i - 1].equals(inputPts[i - 1 + loopSize]), "non-loop found in LoopFilter"); if (!(inputPts[i - 1].Equals(inputPts[i - 1 + loopSize]))) { throw new InvalidOperationException("non-loop found in LoopFilter"); } i += loopSize; } } //return (Coordinate[]) newPts.toArray(arrayTypeCoordinate); return _newPts; }
/// <summary> /// Method to create a Simple NonClosed Linestring for testing purposes /// </summary> /// <returns>A lineString</returns> private LineString SimpleOpen() { _coords = new Coordinates(); Coordinate coord = new Coordinate(0.0,0.0); for(int i = 1; i < 12; i++) { coord = new Coordinate((double)i, (double)i); _coords.Add(coord); } coord = new Coordinate(11, 12); _coords.Add(coord); coord = new Coordinate(10, 13); _coords.Add(coord); coord = new Coordinate(9, 14); _coords.Add(coord); coord = new Coordinate(8, 15); _coords.Add(coord); coord = new Coordinate(9, 16); _coords.Add(coord); coord = new Coordinate(10, 17); _coords.Add(coord); coord = new Coordinate(11, 18); _coords.Add(coord); coord = new Coordinate(12, 19); _coords.Add(coord); coord = new Coordinate(11, 20); _coords.Add(coord); coord = new Coordinate(10, 21); _coords.Add(coord); coord = new Coordinate(9, 22); _coords.Add(coord); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LineString ls = gf.CreateLineString(_coords); return ls; }
private MultiLineString nonSimpleMLS() { Coordinates coords = new Coordinates(); Coordinate coord = new Coordinate(); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LineString lineString = gf.CreateLineString(coords); LineString[] ls = new LineString[1]; coord = new Coordinate(2, 2); coords.Add(coord); coord = new Coordinate(3, 3); coords.Add(coord); coord = new Coordinate(4, 4); coords.Add(coord); coord = new Coordinate(5, 5); coords.Add(coord); coord = new Coordinate(6, 6); coords.Add(coord); coord = new Coordinate(7, 7); coords.Add(coord); coord = new Coordinate(8, 8); coords.Add(coord); coord = new Coordinate(9, 7); coords.Add(coord); coord = new Coordinate(10, 6); coords.Add(coord); coord = new Coordinate(10, 5); coords.Add(coord); coord = new Coordinate(9, 4); coords.Add(coord); coord = new Coordinate(8, 3); coords.Add(coord); coord = new Coordinate(7, 4); coords.Add(coord); coord = new Coordinate(7, 5); coords.Add(coord); coord = new Coordinate(6, 6); coords.Add(coord); coord = new Coordinate(5, 7); coords.Add(coord); coord = new Coordinate(4, 8); coords.Add(coord); coord = new Coordinate(3, 9); coords.Add(coord); ls[0] = gf.CreateLineString(coords); MultiLineString multiLS = gf.CreateMultiLineString(ls); return multiLS; }
private MultiLineString CreateMLS1() { Coordinates coords = new Coordinates(); Coordinate coord = new Coordinate(); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LineString lineString = gf.CreateLineString(coords); LineString[] ls = new LineString[10]; int c = 0; for(int i = 10; i > 0; i--) { for(int j = i; j < i+10; j++) { coord = new Coordinate(); coord.X = (double)j; coord.Y = (double)j+5; coords.Add(coord); } lineString = gf.CreateLineString(coords); ls[c] = lineString; c++; } MultiLineString multiLS = gf.CreateMultiLineString(ls); return multiLS; }
private MultiLineString closedMLS() { Coordinates coords = new Coordinates(); Coordinate coord = new Coordinate(); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LineString lineString = gf.CreateLineString(coords); LineString[] ls = new LineString[2]; coord = new Coordinate(10, 13); coords.Add(coord); coord = new Coordinate(11, 13); coords.Add(coord); coord = new Coordinate(12, 13); coords.Add(coord); coord = new Coordinate(13, 14); coords.Add(coord); coord = new Coordinate(14, 15); coords.Add(coord); coord = new Coordinate(15, 16); coords.Add(coord); coord = new Coordinate(15, 17); coords.Add(coord); coord = new Coordinate(15, 18); coords.Add(coord); coord = new Coordinate(14, 19); coords.Add(coord); coord = new Coordinate(13, 20); coords.Add(coord); coord = new Coordinate(12, 21); coords.Add(coord); coord = new Coordinate(11, 21); coords.Add(coord); coord = new Coordinate(10, 21); coords.Add(coord); coord = new Coordinate(9, 20); coords.Add(coord); coord = new Coordinate(8, 19); coords.Add(coord); coord = new Coordinate(7, 18); coords.Add(coord); coord = new Coordinate(7, 17); coords.Add(coord); coord = new Coordinate(7, 16); coords.Add(coord); coord = new Coordinate(8, 15); coords.Add(coord); coord = new Coordinate(9, 14); coords.Add(coord); coord = new Coordinate(10, 13); coords.Add(coord); ls[0] = gf.CreateLineString(coords); coords = new Coordinates(); coord = new Coordinate(5, 1); coords.Add(coord); coord = new Coordinate(6, 2); coords.Add(coord); coord = new Coordinate(7, 3); coords.Add(coord); coord = new Coordinate(6, 4); coords.Add(coord); coord = new Coordinate(5, 5); coords.Add(coord); coord = new Coordinate(4, 4); coords.Add(coord); coord = new Coordinate(3, 3); coords.Add(coord); coord = new Coordinate(4, 2); coords.Add(coord); coord = new Coordinate(5, 1); coords.Add(coord); ls[1] = gf.CreateLineString(coords); MultiLineString multiLS = gf.CreateMultiLineString(ls); return multiLS; }
public void test_Geometry() { LineString[] linestrings = new LineString[2]; Coordinates coords1 = new Coordinates(); Coordinate coord = new Coordinate(5,3); coords1.Add(coord); coord = new Coordinate(4,5); coords1.Add(coord); coord = new Coordinate(3,4); coords1.Add(coord); GeometryFactory gf = new GeometryFactory(_precMod, _sRID); LineString ls = gf.CreateLineString(coords1); linestrings[0] = ls; Coordinates coords2 = new Coordinates(); coord = new Coordinate(2,7); coords2.Add(coord); coord = new Coordinate(9,2); coords2.Add(coord); coord = new Coordinate(7,9); coords2.Add(coord); ls = gf.CreateLineString(coords2); linestrings[1] = ls; MultiLineString mls = gf.CreateMultiLineString(linestrings); Assertion.AssertEquals("Geometry-1: ", "LineString:(5, 3, NaN),(4, 5, NaN),(3, 4, NaN)", mls.GetGeometryN(0).ToString()); Assertion.AssertEquals("Geometry-2: ", "LineString:(2, 7, NaN),(9, 2, NaN),(7, 9, NaN)", mls.GetGeometryN(1).ToString()); }
/// <summary> /// Initializes a new instance of the SimplePointInRing class. /// </summary> public SimplePointInRing(LinearRing ring) { _pts = ring.GetCoordinates(); }
} // public static int OrientationIndex(Coordinate p1, Coordinate p2, Coordinate q) /// <summary> /// Tests whether a ring is oriented counter-clockwise. /// </summary> /// <param name="ring">Ring to test.</param> /// <returns>Return true if ring is oriented counter-clockwise.</returns> public override bool IsCCW(Coordinates ring) { Coordinate hip; Coordinate p; Coordinate prev; Coordinate next; int hii; int i; int nPts = ring.Count; // check that this is a valid ring - if not, simply return a dummy value. if ( nPts < 4 ) return false; // algorithm to check if a Ring is stored in CCW order // find highest point hip = ring[0]; hii = 0; for (i = 1; i < nPts; i++) { p = ring[i]; if (p.Y > hip.Y) { hip = p; hii = i; } } // find points on either side of highest int iPrev = hii - 1; if (iPrev < 0) { iPrev = nPts - 2; } int iNext = hii + 1; if (iNext >= nPts) { iNext = 1; } prev = ring[iPrev]; next = ring[iNext]; int disc = ComputeOrientation(prev, hip, next); // // If disc is exactly 0, lines are collinear. There are two possible cases: // (1) the lines lie along the x axis in opposite directions // (2) the line lie on top of one another // (2) should never happen, so we're going to ignore it! // (Might want to assert this) // (1) is handled by checking if next is left of prev ==> CCW // if (disc == 0) { // poly is CCW if prev x is right of next x return (prev.X > next.X); } else { // if area is positive, points are ordered CCW return (disc > 0); } } // public override bool IsCCW(Coordinates ring)
} // public override int ComputeOrientation(Coordinate p1, Coordinate p2, Coordinate q) /// <summary> /// Tests to see if point p is in the envelope of ring. /// </summary> /// <param name="p">Point to test.</param> /// <param name="ring">Geometry from which to create envelope.</param> /// <returns>Returns true if point is in envelope of ring.</returns> private bool IsInEnvelope(Coordinate p, Coordinates ring) { Envelope envelope = new Envelope(); for (int i = 0; i < ring.Count; i++) { envelope.ExpandToInclude( ring[i] ); } return envelope.Contains( p ); } // private bool IsInEnvelope(Coordinate p, Coordinates ring)
} // public override bool IsPointInPolygon(Coordinate p, Coordinates ring) /// <summary> /// Tests whether a point lies on a linestring. /// </summary> /// <param name="p">Point to test.</param> /// <param name="pt">LineString to test.</param> /// <returns>Returns true if the point is a vertex of the line or lies in the interior of a line /// segment in the linestring.</returns> public override bool IsOnLine(Coordinate p, Coordinates pt) { for (int i = 1; i < pt.Count; i++) { Coordinate p0 = pt[i - 1]; Coordinate p1 = pt[i]; _lineIntersector.ComputeIntersection(p, p0, p1); if ( _lineIntersector.HasIntersection() ) { return true; } } return false; } // public override bool IsOnLine(Coordinate p, Coordinates pt)