use of org.geotoolkit.internal.jaxb.LineStringPosListType 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