コード例 #1
0
  /**
   * Tests whether this PreparedPolygon intersects a given geometry.
   *
   * @param geom the test geometry
   * @return true if the test geometry intersects
   */
  public boolean intersects(Geometry geom) {
    /**
     * Do point-in-poly tests first, since they are cheaper and may result in a quick positive
     * result.
     *
     * <p>If a point of any test components lie in target, result is true
     */
    boolean isInPrepGeomArea = isAnyTestComponentInTarget(geom);
    if (isInPrepGeomArea) return true;

    /** If any segments intersect, result is true */
    List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom);
    // only request intersection finder if there are segments (ie NOT for point inputs)
    if (lineSegStr.size() > 0) {
      boolean segsIntersect = prepPoly.getIntersectionFinder().intersects(lineSegStr);
      if (segsIntersect) return true;
    }

    /**
     * If the test has dimension = 2 as well, it is necessary to test for proper inclusion of the
     * target. Since no segments intersect, it is sufficient to test representative points.
     */
    if (geom.getDimension() == 2) {
      // TODO: generalize this to handle GeometryCollections
      boolean isPrepGeomInArea =
          isAnyTargetComponentInAreaTest(geom, prepPoly.getRepresentativePoints());
      if (isPrepGeomInArea) return true;
    }

    return false;
  }
コード例 #2
0
  private void findAndClassifyIntersections(Geometry geom) {
    List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom);

    LineIntersector li = new RobustLineIntersector();
    SegmentIntersectionDetector intDetector = new SegmentIntersectionDetector(li);
    intDetector.setFindAllIntersectionTypes(true);
    prepPoly.getIntersectionFinder().intersects(lineSegStr, intDetector);

    hasSegmentIntersection = intDetector.hasIntersection();
    hasProperIntersection = intDetector.hasProperIntersection();
    hasNonProperIntersection = intDetector.hasNonProperIntersection();
  }
コード例 #3
0
  /**
   * Tests whether this geometry intersects a given geometry.
   *
   * @param geom the test geometry
   * @return true if the test geometry intersects
   */
  public boolean intersects(Geometry geom) {
    /** If any segments intersect, obviously intersects = true */
    List lineSegStr = SegmentStringUtil.extractSegmentStrings(geom);
    boolean segsIntersect = prepLine.getIntersectionFinder().intersects(lineSegStr);
    // MD - performance testing
    //		boolean segsIntersect = false;
    if (segsIntersect) return true;

    /** For L/L case we are done */
    if (geom.getDimension() == 1) return false;

    /** For L/A case, need to check for proper inclusion of the target in the test */
    if (geom.getDimension() == 2 && prepLine.isAnyTargetComponentInTest(geom)) return true;

    /** For L/P case, need to check if any points lie on line(s) */
    if (geom.getDimension() == 0) return isAnyTestPointInTarget(geom);

    //		return prepLine.getGeometry().intersects(geom);
    return false;
  }