use of org.locationtech.jts.geom.GeometryCollection in project series-rest-api by 52North.
the class GeoJSONTest method testGeometryCollectionWithZCoordinate.
@Test
public void testGeometryCollectionWithZCoordinate() throws GeoJSONException, IOException {
GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomGeometryCollection(CRSUtils.EPSG_WGS84), randomGeometryCollection(2000) });
geometry.apply(new RandomZCoordinateFilter());
geometry.geometryChanged();
readWriteTest(geometry);
}
use of org.locationtech.jts.geom.GeometryCollection 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 org.locationtech.jts.geom.GeometryCollection in project ddf by codice.
the class CswMarshallHelper method writeBoundingBox.
static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
List<Geometry> geometries = new LinkedList<>();
for (AttributeDescriptor ad : attrDescs) {
if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
Attribute attr = metacard.getAttribute(ad.getName());
if (attr != null) {
if (ad.isMultiValued()) {
for (Serializable value : attr.getValues()) {
geometries.add(XmlNode.readGeometry((String) value));
}
} else {
geometries.add(XmlNode.readGeometry((String) attr.getValue()));
}
}
}
}
Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
Envelope bounds = allGeometry.getEnvelopeInternal();
if (!bounds.isNull()) {
String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
writer.startNode(bbox);
writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
writer.startNode(lower);
writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
writer.endNode();
writer.startNode(upper);
writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
writer.endNode();
writer.endNode();
}
}
use of org.locationtech.jts.geom.GeometryCollection in project ddf by codice.
the class KmlToJtsMultiGeometryConverterTest method testConvertMultiGeometry.
@Test
public void testConvertMultiGeometry() {
GeometryCollection geometryCollection = KmlToJtsMultiGeometryConverter.from(testKmlMultiGeometry);
assertJtsGeometryCollection(geometryCollection);
}
use of org.locationtech.jts.geom.GeometryCollection in project hale by halestudio.
the class GenericGeometryHandler method createGeometry.
/**
* Create a geometry value from a given instance.
*
* @param instance the instance
* @param childGeometries the child geometries found in the instance
* @param defaultCrs the definition of the default CRS for this instance
* @param reader the IO provider
* @return the geometry value derived from the instance, the return type
* should match the {@link Binding} created in
* {@link #getTypeConstraints(TypeDefinition)}.
* @throws GeometryNotSupportedException if the type definition doesn't
* represent a geometry type supported by the handler
*/
@SuppressWarnings("unused")
protected Collection<GeometryProperty<?>> createGeometry(Instance instance, List<GeometryProperty<?>> childGeometries, CRSDefinition defaultCrs, IOProvider reader) throws GeometryNotSupportedException {
List<Geometry> geomList = new ArrayList<Geometry>();
Class<? extends Geometry> commonGeomType = null;
CRSWrapper commonCrs = null;
boolean allowCombine = true;
// TODO partition based on CRS?
for (GeometryProperty<?> geomProp : childGeometries) {
if (geomProp.getGeometry() instanceof GeometryCollection) {
GeometryCollection geomCollection = (GeometryCollection) geomProp.getGeometry();
for (int i = 0; i < geomCollection.getNumGeometries(); i++) {
// find the common geometry class
Class<? extends Geometry> geometryType = geomCollection.getGeometryN(i).getClass();
if (commonGeomType == null) {
commonGeomType = geometryType;
} else if (!commonGeomType.equals(geometryType)) {
// TODO determine common type in inheritance?
commonGeomType = Geometry.class;
}
geomList.add(geomCollection.getGeometryN(i));
}
} else {
// find the common geometry class
Class<? extends Geometry> geometryType = geomProp.getGeometry().getClass();
if (commonGeomType == null) {
commonGeomType = geometryType;
} else if (!commonGeomType.equals(geometryType)) {
// find common super class
commonGeomType = findClosestCommonSuperclass(commonGeomType, geometryType);
}
geomList.add(geomProp.getGeometry());
}
// check common CRS
CRSWrapper crs = new CRSWrapper(geomProp.getCRSDefinition());
if (commonCrs == null) {
commonCrs = crs;
} else if (!commonCrs.equals(crs)) {
allowCombine = false;
}
}
if (allowCombine && commonGeomType != null) {
if (!(commonGeomType.equals(Polygon.class) || commonGeomType.equals(Point.class) || commonGeomType.equals(LineString.class))) {
// check if it is a subclass of a supported type
if (LineString.class.isAssignableFrom(commonGeomType)) {
// for instance for InterpolatedLineString
commonGeomType = LineString.class;
}
if (Point.class.isAssignableFrom(commonGeomType)) {
commonGeomType = Point.class;
}
if (Polygon.class.isAssignableFrom(commonGeomType)) {
commonGeomType = Polygon.class;
}
}
Geometry geom = null;
if (commonGeomType.equals(Polygon.class)) {
// create a MultiPolygon
Polygon[] polygons = new Polygon[geomList.size()];
for (int i = 0; i < geomList.size(); i++) {
polygons[i] = (Polygon) geomList.get(i);
}
geom = combine(polygons, reader);
} else if (commonGeomType.equals(LineString.class)) {
// create a MultiLineString
LineString[] lines = new LineString[geomList.size()];
for (int i = 0; i < geomList.size(); i++) {
lines[i] = (LineString) geomList.get(i);
}
geom = combine(lines, reader);
} else if (commonGeomType.equals(Point.class)) {
// create a MultiPoint
Point[] points = new Point[geomList.size()];
for (int i = 0; i < geomList.size(); i++) {
points[i] = (Point) geomList.get(i);
}
geom = combine(points, reader);
}
if (geom != null) {
// returned combined property
CRSDefinition crs = (commonCrs != null && commonCrs.getCrsDef() != null) ? (commonCrs.getCrsDef()) : (defaultCrs);
return Collections.<GeometryProperty<?>>singleton(new DefaultGeometryProperty<Geometry>(crs, geom));
}
}
// fall-back: return a collection of geometry properties
if (childGeometries.isEmpty()) {
return null;
}
return childGeometries;
}
Aggregations