use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GenericFeatureConverterWfs20 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 "id" attribute if we have an ID
if (metacard.getAttribute(Metacard.ID).getValue() != null) {
String id = (String) metacard.getAttribute(Metacard.ID).getValue();
writer.addAttribute(ID, id);
}
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 AbstractFeatureConverterWfs20 method getValueForMetacardAttribute.
protected Serializable getValueForMetacardAttribute(AttributeFormat attributeFormat, HierarchicalStreamReader reader) {
Serializable ser = null;
switch(attributeFormat) {
case BOOLEAN:
ser = Boolean.valueOf(reader.getValue());
break;
case DOUBLE:
ser = Double.valueOf(reader.getValue());
break;
case FLOAT:
ser = Float.valueOf(reader.getValue());
break;
case INTEGER:
ser = Integer.valueOf(reader.getValue());
break;
case LONG:
ser = Long.valueOf(reader.getValue());
break;
case SHORT:
ser = Short.valueOf(reader.getValue());
break;
case XML:
case STRING:
ser = reader.getValue();
break;
case GEOMETRY:
XmlNode node = new XmlNode(reader);
String geometryXml = node.toString();
Geometry geo = null;
geo = (Geometry) readGml(geometryXml);
LOGGER.debug("coordinateOrder = {}", coordinateOrder);
if (GeospatialUtil.LAT_LON_ORDER.equals(coordinateOrder)) {
swapCoordinates(geo);
}
if (geo != null) {
WKTWriter wktWriter = new WKTWriter();
ser = wktWriter.write(geo);
LOGGER.debug("wkt = {}", ser);
}
break;
case BINARY:
try {
ser = reader.getValue().getBytes(UTF8_ENCODING);
} catch (UnsupportedEncodingException e) {
LOGGER.debug("Error encoding the binary value into the metacard.", e);
}
break;
case DATE:
ser = parseDateFromXml(reader);
break;
default:
break;
}
return ser;
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class Wfs20JTStoGML321Converter method convertToMultiGeometryType.
public static MultiGeometryType convertToMultiGeometryType(GeometryCollection multiGeometry, String srsName) {
final MultiGeometryType multiGeometryType = GML320_OBJECT_FACTORY.createMultiGeometryType();
for (int index = 0; index < multiGeometry.getNumGeometries(); index++) {
final Geometry geometry = multiGeometry.getGeometryN(index);
multiGeometryType.getGeometryMember().add(createGeometryPropertyType(geometry, srsName));
}
return multiGeometryType;
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class FeatureCollectionConverterWfs20 method marshal.
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
if (value != null) {
Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) value;
String schemaLoc = generateSchemaLocationFromMetacards(wfc.getMembers(), prefixToUriMapping);
for (Entry<String, String> entry : prefixToUriMapping.entrySet()) {
writer.addAttribute(XMLConstants.XMLNS_ATTRIBUTE + ":" + entry.getKey(), entry.getValue());
}
writer.addAttribute(Wfs20Constants.ATTRIBUTE_SCHEMA_LOCATION, schemaLoc);
Geometry allGeometry = getBounds(wfc.getMembers());
if (!allGeometry.isEmpty()) {
XmlNode.writeEnvelope(Wfs20Constants.GML_PREFIX + ":" + "boundedBy", context, writer, allGeometry.getEnvelopeInternal());
}
for (Metacard mc : wfc.getMembers()) {
writer.startNode(Wfs20Constants.GML_PREFIX + ":" + FEATURE_MEMBER);
context.convertAnother(mc);
writer.endNode();
}
} else {
LOGGER.debug("Incoming value was null");
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class SolrFilterDelegate method nearestNeighbor.
@Override
public SolrQuery nearestNeighbor(String propertyName, String wkt) {
Geometry geo = getGeometry(wkt);
if (geo != null) {
Point pnt;
if (isPoint(geo)) {
pnt = (Point) geo;
} else {
pnt = geo.getCentroid();
}
SolrQuery query = null;
if (null != pnt) {
String nearestNeighborQuery = geoPointToCircleQuery(propertyName, NEAREST_NEIGHBOR_DISTANCE_LIMIT, pnt);
updateDistanceSort(propertyName, pnt);
query = new SolrQuery(nearestNeighborQuery);
}
return query;
} else {
throw new UnsupportedOperationException("Unable to read given WKT: " + wkt);
}
}
Aggregations