Reputation: 575
The following code does not give me the result I expected. I expect to have all the points as the nodes of the polygon and the polygon contains all the points. How to use the API correctly? Also if I set thresold less than 1, the program got into some kind infinite loop.
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);
}
}
}
Results:
false
true
false
true
false
(0.0, 2.0, NaN)
(2.0, 2.0, NaN)
Upvotes: 0
Views: 392
Reputation: 51
it works fine for me. I used ConcaveHull-0.2 and geospark-1.1.3 libs. Here is my result after running your piece of code:
com.vividsolutions.jts.geom.GeometryFactory@1e81f4dc true true true true true (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)
In addition, it worked with threshold < 1.0
Upvotes: 0