/** * Determines whether a point lies in the interior, on the boundary, or in the * exterior of a ring. The ring may be oriented in either direction. * <p> * This method does <i>not</i> first check the point against the envelope of * the ring. * * @param p * point to check for ring inclusion * @param ring * an array of coordinates representing the ring (which must have * first point identical to last point) * @return the {@link Location} of p relative to the ring */ public static int locateInRing(Coordinate p, Coordinate[] ring) { return RayCrossingCounter.locatePointInRing(p, ring); }
/** * Determines the {@link Location} of a point in a ring. * This method is an exemplar of how to use this class. * * @param p the point to test * @param ring an array of Coordinates forming a ring * @return the location of the point in the ring */ public static int locatePointInRing(Coordinate p, Coordinate[] ring) { RayCrossingCounter counter = new RayCrossingCounter(p); for (int i = 1; i < ring.length; i++) { Coordinate p1 = ring[i]; Coordinate p2 = ring[i-1]; counter.countSegment(p1, p2); if (counter.isOnSegment()) return counter.getLocation(); } return counter.getLocation(); }
/** * Determines the {@link Location} of a point in an areal {@link Geometry}. * * @param p the point to test * @return the location of the point in the geometry */ public int locate(Coordinate p) { RayCrossingCounter rcc = new RayCrossingCounter(p); SegmentVisitor visitor = new SegmentVisitor(rcc); index.query(p.y, p.y, visitor); /* // MD - slightly slower alternative List segs = index.query(p.y, p.y); countSegs(rcc, segs); */ return rcc.getLocation(); }
public void visitItem(Object item) { LineSegment seg = (LineSegment) item; counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1)); } }
public boolean isDone() { return rcc.isOnSegment(); }
/** * Tests whether the point lies in or on * the ring, polygon * or multipolygon from which the processed segments were provided. * <p> * This method only determines the correct location * if <b>all</b> relevant segments must have been processed. * * @return true if the point lies in or on the supplied polygon */ public boolean isPointInPolygon() { return getLocation() != Location.EXTERIOR; } }
public int locate(Coordinate p) { RayCrossingCounter rcc = new RayCrossingCounter(p); RayCrossingSegmentFilter filter = new RayCrossingSegmentFilter(rcc); geom.apply(filter); return rcc.getLocation(); }
public void select(LineSegment ls) { rcc.countSegment(ls.getCoordinate(0), ls.getCoordinate(1)); } }
private void countSegs(RayCrossingCounter rcc, Envelope rayEnv, List monoChains, MCSegmentCounter mcSegCounter) { for (Iterator i = monoChains.iterator(); i.hasNext(); ) { MonotoneChain mc = (MonotoneChain) i.next(); mc.select(rayEnv, mcSegCounter); // short-circuit if possible if (rcc.isOnSegment()) return; } }
/** * Determines the {@link Location} of a point in a ring. * * @param p * the point to test * @param ring * a coordinate sequence forming a ring * @return the location of the point in the ring */ public static int locatePointInRing(Coordinate p, CoordinateSequence ring) { RayCrossingCounter counter = new RayCrossingCounter(p); Coordinate p1 = new Coordinate(); Coordinate p2 = new Coordinate(); for (int i = 1; i < ring.size(); i++) { ring.getCoordinate(i, p1); ring.getCoordinate(i - 1, p2); counter.countSegment(p1, p2); if (counter.isOnSegment()) return counter.getLocation(); } return counter.getLocation(); }
/** * Determines whether a point lies in the interior, on the boundary, or in the * exterior of a ring. The ring may be oriented in either direction. * <p> * This method does <i>not</i> first check the point against the envelope of * the ring. * * @param p * point to check for ring inclusion * @param ring * an array of coordinates representing the ring (which must have * first point identical to last point) * @return the {@link Location} of p relative to the ring */ public static int locatePointInRing(Coordinate p, Coordinate[] ring) { return RayCrossingCounter.locatePointInRing(p, ring); }
/** * Determines the {@link Location} of a point in an areal {@link Geometry}. * * @param p the point to test * @return the location of the point in the geometry */ public int locate(Coordinate p) { RayCrossingCounter rcc = new RayCrossingCounter(p); MCSegmentCounter mcSegCounter = new MCSegmentCounter(rcc); Envelope rayEnv = new Envelope(p.x, maxXExtent, p.y, p.y); List mcs = index.query(rayEnv); countSegs(rcc, rayEnv, mcs, mcSegCounter); return rcc.getLocation(); }
public void filter(CoordinateSequence seq, int i) { if (i == 0) return; seq.getCoordinate(i - 1, p0); seq.getCoordinate(i, p1); rcc.countSegment(p0, p1); }
private int locate(Coordinate pt, LineString ring) { CoordinateSequence seq = ring.getCoordinateSequence(); CoordinateSequence seqProj = project(seq, facingPlane); Coordinate ptProj = project(pt, facingPlane); return RayCrossingCounter.locatePointInRing(ptProj, seqProj); }
public boolean intersects(Coordinate pt, LineString ring) { CoordinateSequence seq = ring.getCoordinateSequence(); CoordinateSequence seqProj = project(seq, facingPlane); Coordinate ptProj = project(pt, facingPlane); return Location.EXTERIOR != RayCrossingCounter.locatePointInRing(ptProj, seqProj); }
protected void runPtInRing(int expectedLoc, Coordinate pt, String wkt) throws Exception { Geometry geom = reader.read(wkt); assertEquals(expectedLoc, RayCrossingCounter.locatePointInRing(pt, geom.getCoordinates())); }
Polygon polygon = (Polygon) object; Coordinate p = polygon.getInteriorPoint().getCoordinate(); int location = RayCrossingCounter.locatePointInRing(p, ring.getCoordinateSequence()); if (location == Location.INTERIOR) { geoms.add(polygon);