/// <summary> /// /// </summary> /// <param name="geom"></param> protected override void Visit(Geometry geom) { if (!(geom is Polygon)) { return; } var elementEnv = geom.EnvelopeInternal; if (!_rectEnv.Intersects(elementEnv)) { return; } // test each corner of rectangle for inclusion var rectPt = _rectSeq.CreateCoordinate(); for (int i = 0; i < 4; i++) { _rectSeq.GetCoordinate(i, rectPt); if (!elementEnv.Contains(rectPt)) { continue; } // check rect point in poly (rect is known not to touch polygon at this point) if (SimplePointInAreaLocator.ContainsPointInPolygon(rectPt, (Polygon)geom)) { ContainsPoint = true; return; } } }
/// <summary> /// Determines the <see cref="Geometries.Location"/> of a point in a ring. /// </summary> /// <param name="p">The point to test</param> /// <param name="ring">A coordinate sequence forming a ring</param> /// <returns>The location of the point in the ring</returns> public static Location LocatePointInRing(Coordinate p, CoordinateSequence ring) { var counter = new RayCrossingCounter(p); var p1 = ring.CreateCoordinate(); var p2 = ring.CreateCoordinate(); int count = ring.Count; for (int i = 1; i < count; i++) { ring.GetCoordinate(i, p1); ring.GetCoordinate(i - 1, p2); counter.CountSegment(p1, p2); if (counter.IsOnSegment) { return(counter.Location); } } return(counter.Location); }
/// <summary> /// Tests whether a point lies on the line defined by a list of /// coordinates. /// </summary> /// <param name="p">The point to test</param> /// <param name="line">The line coordinates</param> /// <returns> /// <c>true</c> if the point is a vertex of the line or lies in the interior /// of a line segment in the line /// </returns> public static bool IsOnLine(Coordinate p, CoordinateSequence line) { var lineIntersector = new RobustLineIntersector(); var p0 = line.CreateCoordinate(); var p1 = p0.Copy(); int n = line.Count; for (int i = 1; i < n; i++) { line.GetCoordinate(i - 1, p0); line.GetCoordinate(i, p1); lineIntersector.ComputeIntersection(p, p0, p1); if (lineIntersector.HasIntersection) { return(true); } } return(false); }
/// <summary> /// Tests for equality using all supported accessors, /// to provides test coverage for them. /// </summary> /// <param name="seq"></param> /// <param name="coords"></param> /// <returns></returns> protected bool IsEqual(CoordinateSequence seq, Coordinate[] coords) { if (seq.Count != coords.Length) { return(false); } // carefully get coordinate of the same type as the sequence var p = seq.CreateCoordinate(); for (int i = 0; i < seq.Count; i++) { if (!coords[i].Equals(seq.GetCoordinate(i))) { return(false); } // Ordinate named getters if (!coords[i].X.Equals(seq.GetX(i))) { return(false); } if (!coords[i].Y.Equals(seq.GetY(i))) { return(false); } if (seq.HasZ) { if (!coords[i].Z.Equals(seq.GetZ(i))) { return(false); } } if (seq.HasM) { if (!coords[i].M.Equals(seq.GetM(i))) { return(false); } } // Ordinate indexed getters if (!coords[i].X.Equals(seq.GetOrdinate(i, 0))) { return(false); } if (!coords[i].Y.Equals(seq.GetOrdinate(i, 1))) { return(false); } if (seq.Dimension > 2) { if (!coords[i][2].Equals(seq.GetOrdinate(i, 2))) { return(false); } } if (seq.Dimension > 3) { if (!coords[i][3].Equals(seq.GetOrdinate(i, 3))) { return(false); } } // Coordinate getter seq.GetCoordinate(i, p); if (!coords[i].X.Equals(p.X)) { return(false); } if (!coords[i].Y.Equals(p.Y)) { return(false); } if (seq.HasZ) { if (!coords[i].Z.Equals(p.Z)) { return(false); } } if (seq.HasM) { if (!coords[i].M.Equals(p.M)) { return(false); } } } return(true); }