/** * Extracts the {@link Point} elements from a single {@link Geometry} * and returns them in a {@link List}. * * @param geom the geometry from which to extract */ public static List getPoints(Geometry geom) { if (geom instanceof Point) { return Collections.singletonList(geom); } return getPoints(geom, new ArrayList()); }
private Geometry onlyPoints(Geometry result) { if ((result instanceof Point) || (result instanceof MultiPoint)) { return result; } List pts = org.locationtech.jts.geom.util.PointExtracter.getPoints(result); if (pts.size() == 0) { return null; } if (pts.size() == 1) { return (Point) pts.get(0); } return new MultiPoint( (Point[]) pts.toArray(new Point[pts.size()]), result.getFactory()); } }