use of com.vividsolutions.jts.geom.MultiPolygon in project series-rest-api by 52North.
the class GeoJSONEncoder method encode.
protected ObjectNode encode(MultiPolygon geometry, int parentSrid) {
ObjectNode json = jsonFactory.objectNode();
ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POLYGON).putArray(JSONConstants.COORDINATES);
for (int i = 0; i < geometry.getNumGeometries(); ++i) {
list.add(encodeCoordinates((Polygon) geometry.getGeometryN(i)));
}
encodeCRS(json, geometry, parentSrid);
return json;
}
use of com.vividsolutions.jts.geom.MultiPolygon in project series-rest-api by 52North.
the class GeoJSONTest method randomMultiPolygon.
private MultiPolygon randomMultiPolygon(int srid) {
MultiPolygon geometry = geometryFactory.createMultiPolygon(new Polygon[] { randomPolygon(srid), randomPolygon(srid), randomPolygon(srid) });
geometry.setSRID(srid);
return geometry;
}
use of com.vividsolutions.jts.geom.MultiPolygon in project spatial-portal by AtlasOfLivingAustralia.
the class ShapefileUtils method saveShapefile.
public static void saveShapefile(File shpfile, String wktString, String name) {
try {
final SimpleFeatureType type = createFeatureType();
List<SimpleFeature> features = new ArrayList<SimpleFeature>();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(type);
WKTReader wkt = new WKTReader();
Geometry geom = wkt.read(wktString);
if (geom instanceof GeometryCollection) {
GeometryCollection gc = (GeometryCollection) geom;
for (int i = 0; i < gc.getNumGeometries(); i++) {
Geometry g = gc.getGeometryN(i);
if (g instanceof Polygon) {
g = new GeometryBuilder().multiPolygon((Polygon) g);
}
featureBuilder.add(g);
SimpleFeature feature = featureBuilder.buildFeature(null);
feature.setAttribute("name", name);
features.add(feature);
}
} else {
Geometry g = geom;
if (g instanceof Polygon) {
g = new GeometryBuilder().multiPolygon((Polygon) g);
}
featureBuilder.add(g);
SimpleFeature feature = featureBuilder.buildFeature(null);
features.add(feature);
}
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", shpfile.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
newDataStore.createSchema(type);
newDataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
Transaction transaction = new DefaultTransaction("create");
String typeName = newDataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = newDataStore.getFeatureSource(typeName);
if (featureSource instanceof SimpleFeatureStore) {
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
DefaultFeatureCollection collection = new DefaultFeatureCollection();
collection.addAll(features);
featureStore.setTransaction(transaction);
try {
featureStore.addFeatures(collection);
transaction.commit();
} catch (Exception problem) {
LOGGER.error("error pricessing shape file: " + shpfile.getAbsolutePath(), problem);
transaction.rollback();
} finally {
transaction.close();
}
}
LOGGER.debug("Active Area shapefile written to: " + shpfile.getAbsolutePath());
} catch (Exception e) {
LOGGER.error("Unable to save shapefile: " + shpfile.getAbsolutePath(), e);
}
}
use of com.vividsolutions.jts.geom.MultiPolygon in project ddf by codice.
the class Wfs20JTStoGML321Converter method createGeometryPropertyType.
private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
if (geometry instanceof Point) {
PointType pointType = convertToPointType((Point) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
} else if (geometry instanceof LineString) {
LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
} else if (geometry instanceof Polygon) {
PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
} else if (geometry instanceof MultiPoint) {
MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
} else if (geometry instanceof MultiLineString) {
MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
} else if (geometry instanceof MultiPolygon) {
MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
} else if (geometry instanceof GeometryCollection) {
MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
} else {
throw new IllegalArgumentException();
}
return geometryPropertyType;
}
use of com.vividsolutions.jts.geom.MultiPolygon in project ddf by codice.
the class WfsFilterDelegate method createGeometryOperand.
private JAXBElement<? extends AbstractGeometryType> createGeometryOperand(String wkt) {
String convertedWkt = wkt;
Geometry wktGeometry = null;
try {
wktGeometry = getGeometryFromWkt(convertedWkt);
} catch (ParseException e) {
throw new IllegalArgumentException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
}
if (wktGeometry instanceof Polygon) {
if (isGeometryOperandSupported(Wfs10Constants.POLYGON)) {
return createPolygon(convertedWkt);
} else {
throw new IllegalArgumentException("The Polygon operand is not supported.");
}
} else if (wktGeometry instanceof Point) {
if (isGeometryOperandSupported(Wfs10Constants.POINT)) {
return createPoint(convertedWkt);
} else {
throw new IllegalArgumentException("The Point operand is not supported.");
}
} else if (wktGeometry instanceof LineString) {
if (isGeometryOperandSupported(Wfs10Constants.LINESTRING)) {
return createLineString(wktGeometry);
} else {
throw new IllegalArgumentException("The LineString operand is not supported.");
}
} else if (wktGeometry instanceof MultiPoint) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_POINT)) {
return createMultiPoint(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiPoint operand is not supported.");
}
} else if (wktGeometry instanceof MultiLineString) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_LINESTRING)) {
return createMultiLineString(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiLineString operand is not supported.");
}
} else if (wktGeometry instanceof MultiPolygon) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_POLYGON)) {
return createMultiPolygon(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiPolygon operand is not supported.");
}
} else if (wktGeometry instanceof GeometryCollection) {
if (isGeometryOperandSupported(Wfs10Constants.GEOMETRY_COLLECTION)) {
return createGeometryCollection(wktGeometry);
} else {
throw new IllegalArgumentException("The GeometryCollection operand is not supported.");
}
}
throw new IllegalArgumentException("Unable to create Geometry from WKT String");
}
Aggregations