Skip to content

Commit

Permalink
ConcaveHull for Points (#823)
Browse files Browse the repository at this point in the history
* ConcaveHull for Points, with Length, Length Factor and Area Ratio target criteria

Signed-off-by: Martin Davis <[email protected]>
  • Loading branch information
dr-jts authored Jan 4, 2022
1 parent e1fc931 commit d33f083
Show file tree
Hide file tree
Showing 8 changed files with 1,066 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.locationtech.jts.algorithm.MinimumDiameter;
import org.locationtech.jts.algorithm.construct.LargestEmptyCircle;
import org.locationtech.jts.algorithm.construct.MaximumInscribedCircle;
import org.locationtech.jts.algorithm.hull.ConcaveHull;
import org.locationtech.jts.densify.Densifier;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
Expand Down Expand Up @@ -130,4 +131,58 @@ public static Geometry circleByRadiusLine(Geometry radiusLine,
return radiusLine.getFactory().createPolygon(circlePts);
}

public static Geometry concaveHullByLen(Geometry geom,
@Metadata(title="Length")
double maxLen) {
return ConcaveHull.concaveHullByLength(geom, maxLen);
}

public static Geometry concaveHullWithHolesByLen(Geometry geom,
@Metadata(title="Length")
double maxLen) {
return ConcaveHull.concaveHullByLength(geom, maxLen, true);
}

public static Geometry concaveHullByLenFactor(Geometry geom,
@Metadata(title="Length factor")
double maxLen) {
return ConcaveHull.concaveHullByLengthFactor(geom, maxLen);
}

public static Geometry concaveHullWithHolesByLenFactor(Geometry geom,
@Metadata(title="Length factor")
double maxLen) {
return ConcaveHull.concaveHullByLengthFactor(geom, maxLen, true);
}

public static Geometry concaveHullByArea(Geometry geom,
@Metadata(title="Area ratio")
double minAreaPct) {
return ConcaveHull.concaveHullByArea(geom, minAreaPct);
}

public static double concaveHullLenGuess(Geometry geom) {
return ConcaveHull.uniformGridEdgeLength(geom);
}

/**
* A concaveness measure defined in terms of the perimeter length
* relative to the convex hull perimeter.
* <pre>
* C = ( P(geom) - P(CH) ) / P(CH)
* </pre>
* Concaveness values are >= 0.
* A convex polygon has C = 0.
* A higher concaveness indicates a more concave polygon.
* <p>
* Originally defined by Park & Oh, 2012.
*
* @param geom a polygonal geometry
* @return the concaveness measure of the geometry
*/
public static double concaveness(Geometry geom) {
double convexLen = geom.convexHull().getLength();
return (geom.getLength() - convexLen) / convexLen;
}

}
Loading

0 comments on commit d33f083

Please sign in to comment.