/** * Returns a completed multi type. * * @param geometryFactory The factory this method should use to create the multi type. * @return Appropriate multi geometry type. */ public Geometry create(GeometryFactory geometryFactory) { if (internalType.equals("Point")) { Point[] pointArray = geometryFactory.toPointArray(geometries); MultiPoint multiPoint = geometryFactory.createMultiPoint(pointArray); multiPoint.setUserData(getSRS()); multiPoint.setSRID(getSRID()); LOGGER.fine("created " + multiPoint); return multiPoint; } else if (internalType.equals("LineString")) { LineString[] lineStringArray = geometryFactory.toLineStringArray(geometries); MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStringArray); multiLineString.setUserData(getSRS()); multiLineString.setSRID(getSRID()); LOGGER.fine("created " + multiLineString); return multiLineString; } else if (internalType.equals("Polygon")) { Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries); MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray); multiPolygon.setUserData(getSRS()); multiPolygon.setSRID(getSRID()); LOGGER.fine("created " + multiPolygon); return multiPolygon; } else { return null; } }
private Geometry polygonize(Geometry geometry) { List lines = LineStringExtracter.getLines(geometry); Polygonizer polygonizer = new Polygonizer(); polygonizer.add(lines); Collection polys = polygonizer.getPolygons(); Polygon[] polyArray = GeometryFactory.toPolygonArray(polys); return geometry.getFactory().createGeometryCollection(polyArray); }