use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GenericFeatureConverter method marshal.
/**
* This method will convert a {@link Metacard} instance into xml that will validate against the
* GML 2.1.2 AbstractFeatureType.
*
* @param value the {@link Metacard} to convert
* @param writer the stream writer responsible for writing this xml doc
* @param context a reference back to the Xstream marshalling context. Allows you to call
* "convertAnother" which will lookup other registered converters.
*/
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
Metacard metacard = (Metacard) value;
// TODO when we have a reference to the MCT we can get the namespace too
QName qname = WfsQnameBuilder.buildQName(metacard.getMetacardType().getName(), metacard.getContentTypeName());
writer.startNode(qname.getPrefix() + ":" + qname.getLocalPart());
// Add the "fid" attribute if we have an ID
String fid = (String) metacard.getAttribute(Metacard.ID).getValue();
if (fid != null) {
writer.addAttribute(FID, fid);
}
if (null != metacard.getLocation()) {
Geometry geo = XmlNode.readGeometry(metacard.getLocation());
if (geo != null && !geo.isEmpty()) {
XmlNode.writeEnvelope(WfsConstants.GML_PREFIX + ":" + "boundedBy", context, writer, geo.getEnvelopeInternal());
}
}
Set<AttributeDescriptor> descriptors = new TreeSet<AttributeDescriptor>(new AttributeDescriptorComparator());
descriptors.addAll(metacard.getMetacardType().getAttributeDescriptors());
for (AttributeDescriptor attributeDescriptor : descriptors) {
Attribute attribute = metacard.getAttribute(attributeDescriptor.getName());
if (attribute != null) {
writeAttributeToXml(attribute, qname, attributeDescriptor.getType().getAttributeFormat(), context, writer);
}
}
writer.endNode();
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeometryAdapter method unmarshalFrom.
public static Attribute unmarshalFrom(GeometryElement element) throws ConversionFailedException {
AttributeImpl attribute = null;
GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
WKTWriter wktWriter = new WKTWriter();
for (Value xmlValue : element.getValue()) {
JAXBElement<AbstractGeometryType> xmlGeometry = xmlValue.getGeometry();
Geometry geometry = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
String wkt = wktWriter.write(geometry);
if (attribute == null) {
attribute = new AttributeImpl(element.getName(), wkt);
} else {
attribute.addValue(wkt);
}
}
return attribute;
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326UTM.
@Test
public void testTransformEpsg4326UTM() throws FactoryException, TransformException, GeoFormatException {
double lon = 33.45;
double lat = 25.22;
double easting = 545328.48;
double northing = 2789384.24;
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate utmCoordinate = new Coordinate(easting, northing);
Point utmPoint = geometryFactory.createPoint(utmCoordinate);
Envelope envelope = JTS.toEnvelope(utmPoint);
Geometry utmGeometry = JTS.toGeometry(envelope);
Geometry lonLatGeom = GeospatialUtil.transformToEPSG4326LonLatFormat(utmGeometry, sourceCRS);
assertThat(lonLatGeom.getCoordinates()[0].x, closeTo(lon, .00001));
assertThat(lonLatGeom.getCoordinates()[0].y, closeTo(lat, .00001));
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326LonLatNullSrs.
@Test
public void testTransformEpsg4326LonLatNullSrs() throws GeoFormatException {
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate(25.22, 33.45);
Point point = gf.createPoint(coord);
Geometry geom = GeospatialUtil.transformToEPSG4326LonLatFormat(point, (String) null);
assertThat(geom, is(point));
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GeoUtilTest method testTransformEpsg4326LonLatBadSrs.
@Test(expected = GeoFormatException.class)
public void testTransformEpsg4326LonLatBadSrs() throws GeoFormatException {
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate(25.22, 33.45);
Point point = gf.createPoint(coord);
Geometry geom = GeospatialUtil.transformToEPSG4326LonLatFormat(point, "ESPG:Bad");
}
Aggregations