Java Code Examples for com.vividsolutions.jts.algorithm.CGAlgorithms#isPointInRing()

The following examples show how to use com.vividsolutions.jts.algorithm.CGAlgorithms#isPointInRing() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EdgeRing.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method will cause the ring to be computed.
 * It will also check any holes, if they have been assigned.
 */
public boolean containsPoint(Coordinate p)
{
  LinearRing shell = getLinearRing();
  Envelope env = shell.getEnvelopeInternal();
  if (! env.contains(p)) return false;
  if (! CGAlgorithms.isPointInRing(p, shell.getCoordinates()) ) return false;

  for (Iterator i = holes.iterator(); i.hasNext(); ) {
    EdgeRing hole = (EdgeRing) i.next();
    if (hole.containsPoint(p) )
      return false;
  }
  return true;
}
 
Example 2
Source File: PolygonHandler.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ArrayList assignHolesToShells(ArrayList shells, ArrayList holes)
{
  // now we have a list of all shells and all holes
  ArrayList holesForShells = new ArrayList(shells.size());
  for (int i = 0; i < shells.size(); i++) {
    holesForShells.add(new ArrayList());
  }

  // find homes
  for (int i = 0; i < holes.size(); i++) {
    LinearRing testHole = (LinearRing) holes.get(i);
    LinearRing minShell = null;
    Envelope minEnv = null;
    Envelope testHoleEnv = testHole.getEnvelopeInternal();
    Coordinate testHolePt = testHole.getCoordinateN(0);
    LinearRing tryShell;
    int nShells = shells.size();
    for (int j = 0; j < nShells; j++) {
      tryShell = (LinearRing) shells.get(j);
      Envelope tryShellEnv = tryShell.getEnvelopeInternal();
      if (! tryShellEnv.contains(testHoleEnv)) continue;
      
      boolean isContained = false;
      Coordinate[] coordList = tryShell.getCoordinates();

      if (nShells <= 1 
          || CGAlgorithms.isPointInRing(testHolePt, coordList) 
          || pointInList(testHolePt, coordList))
        isContained = true;
      
      // check if new containing ring is smaller than the current minimum ring
      if (minShell != null)
        minEnv = minShell.getEnvelopeInternal();
      if (isContained) {
        if (minShell == null || minEnv.contains(tryShellEnv)) {
          minShell = tryShell;
        }
      }
    }

    if (minShell == null) {
      System.err.println("Found polygon with a hole not inside a shell");
    }
    else {
      // ((ArrayList)holesForShells.get(shells.indexOf(minShell))).add(testRing);
      ((ArrayList) holesForShells.get(findIndex(shells, minShell)))
          .add(testHole);
    }
  }
  return holesForShells;
}
 
Example 3
Source File: QuadEdgeTriangle.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean contains(Coordinate pt) {
	Coordinate[] ring = getCoordinates();
	return CGAlgorithms.isPointInRing(pt, ring);
}
 
Example 4
Source File: QuadEdgeTriangle.java    From jts with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Tests whether the point pt is contained in the triangle defined by 3
 * {@link QuadEdge}es.
 * 
 * @param tri
 *          an array containing at least 3 QuadEdges
 * @param pt
 *          the point to test
 * @return true if the point is contained in the triangle
 */
public static boolean contains(QuadEdge[] tri, Coordinate pt) {
	Coordinate[] ring = new Coordinate[] { tri[0].orig().getCoordinate(),
			tri[1].orig().getCoordinate(), tri[2].orig().getCoordinate(),
			tri[0].orig().getCoordinate() };
	return CGAlgorithms.isPointInRing(pt, ring);
}
 
Example 5
Source File: SimplePointInAreaLocator.java    From jts with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Determines whether a point lies in a LinearRing,
 * using the ring envelope to short-circuit if possible.
 * 
 * @param p the point to test
 * @param ring a linear ring
 * @return true if the point lies inside the ring
 */
private static boolean isPointInRing(Coordinate p, LinearRing ring)
{
	// short-circuit if point is not in ring envelope
	if (! ring.getEnvelopeInternal().intersects(p))
		return false;
	return CGAlgorithms.isPointInRing(p, ring.getCoordinates());
}
 
Example 6
Source File: QuadEdgeTriangle.java    From jts with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Tests whether the point pt is contained in the triangle defined by 3
 * {@link Vertex}es.
 * 
 * @param tri
 *          an array containing at least 3 Vertexes
 * @param pt
 *          the point to test
 * @return true if the point is contained in the triangle
 */
public static boolean contains(Vertex[] tri, Coordinate pt) {
	Coordinate[] ring = new Coordinate[] { tri[0].getCoordinate(),
			tri[1].getCoordinate(), tri[2].getCoordinate(), tri[0].getCoordinate() };
	return CGAlgorithms.isPointInRing(pt, ring);
}