/** * Extracts the {@link LineString} elements from a single {@link Geometry} * and adds them to the provided {@link List}. * * @param geom the geometry from which to extract * @param lines the list to add the extracted LineStrings to * @return the list argument */ public static List getLines(Geometry geom, List lines) { if (geom instanceof LineString) { lines.add(geom); } else if (geom instanceof GeometryCollection) { geom.apply(new LineStringExtracter(lines)); } // skip non-LineString elemental geometries return lines; }
List<Geometry> points = new ArrayList<>(); geom.apply(new PolygonExtracter(polys)); geom.apply(new LineStringExtracter(lines)); geom.apply(new PointExtracter(points)); geom = geom.getFactory().buildGeometry(polys);