以下代码没有给出我预期的结果。我期望将所有点作为多边形的节点,并且多边形包含所有点。如何正确使用API?此外,如果我将thresold设置为小于1,程序会进入某种无限循环。
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.util.Set;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.opensphere.geometry.algorithm.ConcaveHull;
public class ConcaveHullTrial {
public static void main(String args[]) {
ConcaveHull cch = null;
com.vividsolutions.jts.geom.Point point[] = new Point[5];
Set<GeometryFactory> testing = JTSFactoryFinder.getGeometryFactories();
for (GeometryFactory f : testing) {
System.out.println(f);
}
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
point[0] = gf.createPoint(new Coordinate(0.0, 0.0));
point[1] = gf.createPoint(new Coordinate(0.0, 2.0));
point[2] = gf.createPoint(new Coordinate(2.0, 0.0));
point[3] = gf.createPoint(new Coordinate(2.0, 2.0));
point[4] = gf.createPoint(new Coordinate(1.8, 1.5));
GeometryCollection gc = new GeometryCollection(point, gf);
double threshold = 4;
cch = new ConcaveHull(gc, threshold);
Geometry hull = cch.getConcaveHull();
for (int i = 0; i < 5; i++) {
System.out.println(hull.covers(point[i]));
}
for (Coordinate c: hull.getCoordinates()) {
System.out.println(c);
}
}
}
结果:
false
true
false
true
false
(0.0, 2.0, NaN)
(2.0, 2.0, NaN)
答案 0 :(得分:0)
对我来说很好。我使用了ConcaveHull-0.2和geospark-1.1.3库。这是运行您的代码后的结果:
com.vividsolutions.jts.geom.GeometryFactory@1e81f4dc 真正 真正 真正 真正 真正 (0.0,0.0,NaN) (2.0,0.0,NaN) (2.0、2.0,NaN) (0.0、2.0,NaN) (0.0,0.0,NaN)
此外,它的阈值<1.0也可以使用