use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class CswRecordMapperFilterVisitor method convertGeometryExpressionToEpsg4326.
private static void convertGeometryExpressionToEpsg4326(Expression expression) {
if (expression instanceof LiteralExpressionImpl) {
LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) expression;
Object valueObj = literalExpression.getValue();
if (valueObj instanceof Geometry) {
Geometry geometry = (Geometry) valueObj;
Object userDataObj = geometry.getUserData();
if (userDataObj instanceof CoordinateReferenceSystem) {
CoordinateReferenceSystem sourceCRS = (CoordinateReferenceSystem) userDataObj;
Geometry convertedGeometry = null;
try {
convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(geometry, sourceCRS);
literalExpression.setValue(convertedGeometry);
} catch (GeoFormatException e) {
LOGGER.trace("Unable to convert geometry to EPSG:4326 format", e);
}
}
}
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class RegistryPackageConverter method getWKTFromGeometry.
private static String getWKTFromGeometry(AbstractGeometryType geometry, JAXBElement jaxbElement) throws RegistryConversionException {
String convertedGeometry = null;
if (geometry != null) {
try {
GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
Geometry jtsGeometry = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
if (jtsGeometry != null) {
WKTWriter writer = new WKTWriter();
convertedGeometry = writer.write(jtsGeometry);
}
} catch (ConversionFailedException e) {
String message = "Error converting geometry. Caught an exception.";
throw new RegistryConversionException(message, e);
}
}
return convertedGeometry;
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class Gml3ToWktImpl method convert.
@SuppressWarnings("unchecked")
public String convert(InputStream xml) throws ValidationExceptionImpl {
AbstractGeometryType geometry = null;
try {
JAXBElement<AbstractGeometryType> jaxbElement = parser.unmarshal(configurator, JAXBElement.class, xml);
geometry = jaxbElement.getValue();
GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
Geometry jtsGeo = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
WKTWriter wktWriter = new WKTWriter();
return wktWriter.write(jtsGeo);
} catch (ParserException e) {
LOGGER.debug("Cannot parse gml", e);
throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot parse gml"), new ArrayList<String>());
} catch (ConversionFailedException e) {
LOGGER.debug("Cannot convert gml311 geo object {} to jts", geometry, e);
throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot convert geo object"), new ArrayList<String>());
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GmlHandler method endElement.
/**
* Takes in a sax event from {@link org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate}, and if it is a gml:Point or a sub-element of a gml:Point, it will
* * hand the event off to the GML handler for further parsing.
* If it is a gml:Point, the point is stored as a WKT in the attributes list
*
* @param namespaceURI the namespaceURI that is passed in by {@link org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate}
* @param localName the localName that is passed in by {@link org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate}
* @param qName the qName that is passed in by {@link org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerDelegate}
*/
@Override
public void endElement(String namespaceURI, String localName, String qName) {
if (readingGml) {
try {
gml3Element.toElement(namespaceURI, localName);
} catch (XMLStreamException e) {
LOGGER.debug("Error writing to element in SaxEventToXmlConverter()", e);
}
if (!readingGml3) {
try {
gh.endElement(namespaceURI, localName, qName);
} catch (SAXException e) {
LOGGER.debug("GML threw a SAX exception", e);
}
}
state.pop();
if (state.size() == 0) {
readingGml = false;
if (!readingGml3) {
Geometry geo = gh.getGeometry();
attributes.add(new AttributeImpl(Metacard.GEOGRAPHY, wktWriter.write(geo)));
} else {
try {
attributes.add(new AttributeImpl(Metacard.GEOGRAPHY, gml3Converter.convert(gml3Element.toString())));
} catch (ValidationException e) {
this.attributes.add(new AttributeImpl(Validation.VALIDATION_ERRORS, "geospatial-handler"));
}
}
readingGml3 = false;
gml3Element.reset();
}
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class XmlNode method readGeometry.
public static Geometry readGeometry(String value) {
WKTReader wktReader = new WKTReader();
Geometry geo = null;
try {
geo = wktReader.read(value);
} catch (ParseException e) {
LOGGER.debug("Failed to parse geometry information.", e);
}
return geo;
}
Aggregations