use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.
the class AbstractJTSAggregate method computeJTSPeer.
/**
* {@inheritDoc }
*/
@Override
protected org.locationtech.jts.geom.Geometry computeJTSPeer() {
final List<org.locationtech.jts.geom.Geometry> childParts = new ArrayList<org.locationtech.jts.geom.Geometry>();
for (Geometry prim : elements) {
if (prim instanceof JTSGeometry) {
final JTSGeometry jtsGeom = (JTSGeometry) prim;
final org.locationtech.jts.geom.Geometry geom = jtsGeom.getJTSGeometry();
if (geom != null) {
childParts.add(geom);
}
} else {
throw new IllegalStateException("Only JTSGeometries are allowed in the JTSAggregate class.");
}
}
org.locationtech.jts.geom.Geometry result = null;
// we want a multi geometry event if there is only one geometry
if (childParts.size() == 1) {
org.locationtech.jts.geom.Geometry geom = childParts.get(0);
if (geom instanceof LineString) {
result = JTSUtils.GEOMETRY_FACTORY.createMultiLineString(new LineString[] { (LineString) geom });
}
if (geom instanceof Polygon) {
result = JTSUtils.GEOMETRY_FACTORY.createMultiPolygon(new Polygon[] { (Polygon) geom });
}
if (geom instanceof Point) {
result = JTSUtils.GEOMETRY_FACTORY.createMultiPoint(new Point[] { (Point) geom });
}
}
if (result == null) {
result = JTSUtils.GEOMETRY_FACTORY.buildGeometry(childParts);
}
CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
if (crs != null) {
final int srid = SRIDGenerator.toSRID(crs, Version.V1);
result.setSRID(srid);
}
return result;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.
the class JTSComplex method computeJTSPeer.
/**
* Creates the JTS peer.
*/
@Override
protected final org.locationtech.jts.geom.Geometry computeJTSPeer() {
ArrayList subParts = new ArrayList();
Iterator elemIt = elements.iterator();
while (elemIt.hasNext()) {
JTSGeometry prim = (JTSGeometry) elemIt.next();
subParts.add(prim.getJTSGeometry());
}
// class it can.
return JTSUtils.GEOMETRY_FACTORY.buildGeometry(subParts);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.
the class JTSPolygon method computeJTSPeer.
/**
* {@inheritDoc }
*/
@Override
public org.locationtech.jts.geom.Geometry computeJTSPeer() {
final SurfaceBoundary boundary = getBoundary();
final Ring exterior = boundary.getExterior();
final List interiors = boundary.getInteriors();
if (exterior != null) {
final org.locationtech.jts.geom.Geometry g = ((JTSGeometry) exterior).getJTSGeometry();
final int numHoles = (interiors != null) ? interiors.size() : 0;
final org.locationtech.jts.geom.LinearRing jtsExterior = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g.getCoordinates());
final org.locationtech.jts.geom.LinearRing[] jtsInterior = new org.locationtech.jts.geom.LinearRing[numHoles];
for (int i = 0; i < numHoles; i++) {
final org.locationtech.jts.geom.Geometry g2 = ((JTSGeometry) interiors.get(i)).getJTSGeometry();
jtsInterior[i] = JTSUtils.GEOMETRY_FACTORY.createLinearRing(g2.getCoordinates());
}
final org.locationtech.jts.geom.Polygon result = JTSUtils.GEOMETRY_FACTORY.createPolygon(jtsExterior, jtsInterior);
final CoordinateReferenceSystem crs = getCoordinateReferenceSystem();
if (crs != null) {
final int srid = SRIDGenerator.toSRID(crs, Version.V1);
result.setSRID(srid);
}
return result;
}
return null;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.
the class JTSPolyhedralSurface method computeJTSPeer.
/**
* {@inheritDoc }
*/
@Override
protected org.locationtech.jts.geom.Geometry computeJTSPeer() {
if (patches.size() > 1) {
// throw new UnsupportedOperationException("This implementation does not support surfaces with multiple patches.");
final org.locationtech.jts.geom.Polygon[] polygons = new org.locationtech.jts.geom.Polygon[patches.size()];
for (int i = 0; i < patches.size(); i++) {
final JTSGeometry jtsGeometry = (JTSGeometry) patches.get(i);
polygons[i] = (org.locationtech.jts.geom.Polygon) jtsGeometry.getJTSGeometry();
}
return JTSUtils.GEOMETRY_FACTORY.createMultiPolygon(polygons);
}
return ((JTSGeometry) patches.get(0)).getJTSGeometry();
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.JTSGeometry in project geotoolkit by Geomatys.
the class GeometryMapping method readValue.
@Override
public void readValue(XMLStreamReader reader, GenericName propName, Feature feature) throws XMLStreamException {
final String localName = reader.getLocalName();
if (decorated) {
// check if we are dealing with a link href
String link = reader.getAttributeValue(GMLConvention.XLINK_NAMESPACE, "href");
if (link != null) {
toTagEnd(reader, localName);
Attribute attribute = (Attribute) feature.getProperty(propName.toString());
AttributeType<String> charType = (AttributeType) attribute.getType().characteristics().get(GMLConvention.XLINK_HREF.tip().toString());
Attribute<String> charValue = charType.newInstance();
charValue.setValue(link);
attribute.characteristics().put(GMLConvention.XLINK_HREF.tip().toString(), charValue);
return;
}
}
boolean skipCurrent = decorated;
int event;
Object value;
// backward compatible with incorrect old writings
final String propertyName = propertyType.getName().tip().toString();
if (propertyName.equals(localName)) {
skipCurrent = true;
}
// special case for SurfacePropertyType which may contain a simple polygon
boolean forceMultiPolygon = propertyName.equalsIgnoreCase("multipolygon");
if (skipCurrent) {
event = reader.next();
} else {
event = reader.getEventType();
}
while (event != START_ELEMENT) {
if (event == END_ELEMENT) {
return;
}
event = reader.next();
}
try {
Unmarshaller unmarshaller = pool.acquireUnmarshaller();
final Geometry jtsGeom;
final Object geometry = ((JAXBElement) unmarshaller.unmarshal(reader)).getValue();
if (geometry instanceof JTSGeometry) {
final JTSGeometry isoGeom = (JTSGeometry) geometry;
if (isoGeom instanceof JTSMultiCurve) {
((JTSMultiCurve) isoGeom).applyCRSonChild();
}
jtsGeom = isoGeom.getJTSGeometry();
} else if (geometry instanceof PolygonType) {
final PolygonType polygon = ((PolygonType) geometry);
jtsGeom = polygon.getJTSPolygon().getJTSGeometry();
if (polygon.getCoordinateReferenceSystem() != null) {
JTS.setCRS(jtsGeom, polygon.getCoordinateReferenceSystem());
}
} else if (geometry instanceof LineStringPosListType) {
final JTSLineString line = ((LineStringPosListType) geometry).getJTSLineString();
jtsGeom = line.getJTSGeometry();
if (line.getCoordinateReferenceSystem() != null) {
JTS.setCRS(jtsGeom, line.getCoordinateReferenceSystem());
}
} else if (geometry instanceof AbstractGeometry) {
try {
jtsGeom = GeometrytoJTS.toJTS((AbstractGeometry) geometry, longitudeFirst, forceMultiPolygon);
} catch (FactoryException ex) {
throw new XMLStreamException("Factory Exception while transforming GML object to JTS", ex);
}
} else {
throw new IllegalArgumentException("unexpected geometry type:" + geometry);
}
value = jtsGeom;
value = JTSMapping.convertType(jtsGeom, ((AttributeType) propertyType).getValueClass());
pool.recycle(unmarshaller);
} catch (JAXBException ex) {
String msg = ex.getMessage();
if (msg == null && ex.getLinkedException() != null) {
msg = ex.getLinkedException().getMessage();
}
throw new IllegalArgumentException("JAXB exception while reading the feature geometry: " + msg, ex);
}
JAXPStreamFeatureReader.setValue(feature, propertyType, propName, null, value);
}
Aggregations