Search in sources :

Example 1 with Clip

use of org.openstreetmap.atlas.geography.clipping.Clip in project atlas-checks by osmlab.

the class IntersectingBuildingsCheck method findIntersectionType.

/**
 * Find {@link IntersectionType} for given {@link Polygon}s. There are some edge cases where
 * there are minor boundary intersections. So we do additional area check to filter off the
 * false positives.
 *
 * @param polygon
 *            {@link Polygon} to check for intersection
 * @param otherPolygon
 *            Another {@link Polygon} to check against for intersection
 * @param areaSizeToCheck
 *            Area size to decide if intersection area is big enough for overlap
 * @return {@link IntersectionType} between given {@link Polygon}s
 */
private IntersectionType findIntersectionType(final Polygon polygon, final Polygon otherPolygon) {
    Clip clip = null;
    try {
        clip = polygon.clip(otherPolygon, ClipType.AND);
    } catch (final TopologyException e) {
        logger.warn(String.format("Skipping intersection check. Error clipping [%s] and [%s].", polygon, otherPolygon), e);
    }
    // Skip if nothing is returned
    if (clip == null) {
        return IntersectionType.NONE;
    }
    // Sum intersection area
    long intersectionArea = 0;
    for (final PolyLine polyline : clip.getClip()) {
        if (polyline != null && polyline instanceof Polygon) {
            final Polygon clippedPolygon = (Polygon) polyline;
            intersectionArea += clippedPolygon.surface().asDm7Squared();
        }
    }
    // Avoid division by zero
    if (intersectionArea == 0) {
        return IntersectionType.NONE;
    }
    // Pick the smaller building's area as baseline
    final long baselineArea = Math.min(polygon.surface().asDm7Squared(), otherPolygon.surface().asDm7Squared());
    final double proportion = (double) intersectionArea / baselineArea;
    if (proportion >= this.overlapLowerLimit) {
        return IntersectionType.OVERLAP;
    } else if (proportion >= this.intersectionLowerLimit) {
        return IntersectionType.INTERSECT;
    }
    return IntersectionType.NONE;
}
Also used : Clip(org.openstreetmap.atlas.geography.clipping.Clip) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Polygon(org.openstreetmap.atlas.geography.Polygon) TopologyException(com.vividsolutions.jts.geom.TopologyException)

Aggregations

TopologyException (com.vividsolutions.jts.geom.TopologyException)1 PolyLine (org.openstreetmap.atlas.geography.PolyLine)1 Polygon (org.openstreetmap.atlas.geography.Polygon)1 Clip (org.openstreetmap.atlas.geography.clipping.Clip)1