use of ddf.geo.formatter.CompositeGeometry in project ddf by codice.
the class AtomTransformer method getGeoRssPositions.
private List<Position> getGeoRssPositions(Metacard metacard) {
List<Position> georssPositions = new ArrayList<Position>();
for (AttributeDescriptor ad : metacard.getMetacardType().getAttributeDescriptors()) {
if (ad != null && ad.getType() != null && BasicTypes.GEO_TYPE.getAttributeFormat().equals(ad.getType().getAttributeFormat())) {
Attribute geoAttribute = metacard.getAttribute(ad.getName());
if (geoAttribute == null) {
continue;
}
for (Serializable geo : geoAttribute.getValues()) {
if (geo != null) {
try {
Geometry geometry = new WKTReader(GEOMETRY_FACTORY).read(geo.toString());
CompositeGeometry formatter = CompositeGeometry.getCompositeGeometry(geometry);
if (null != formatter) {
georssPositions.addAll(formatter.toGeoRssPositions());
} else {
LOGGER.debug("When cycling through geometries, could not get composite geometry [{}]", geo);
}
} catch (ParseException e) {
LOGGER.info("When cycling through geometries, could not parse [{}]", geo, e);
}
}
}
}
}
return georssPositions;
}
use of ddf.geo.formatter.CompositeGeometry in project ddf by codice.
the class GeoJsonInputTransformer method transform.
@Override
public Metacard transform(InputStream input, String id) throws IOException, CatalogTransformerException {
validateInput(input);
Map<String, Object> rootObject = getRootObject(input);
validateTypeValue(rootObject);
Map<String, Object> properties = getProperties(rootObject);
final String propertyTypeName = (String) properties.get(METACARD_TYPE_PROPERTY_KEY);
MetacardImpl metacard = getMetacard(propertyTypeName, properties);
MetacardType metacardType = metacard.getMetacardType();
LOGGER.debug("Metacard type name: {}", metacardType.getName());
// retrieve geometry
CompositeGeometry geoJsonGeometry = getCompositeGeometry(rootObject);
if (geoJsonGeometry != null && StringUtils.isNotEmpty(geoJsonGeometry.toWkt())) {
metacard.setLocation(geoJsonGeometry.toWkt());
}
Map<String, AttributeDescriptor> attributeDescriptorMap = metacardType.getAttributeDescriptors().stream().collect(toMap(AttributeDescriptor::getName, Function.identity()));
properties.entrySet().forEach(entry -> addAttributeToMetacard(metacard, attributeDescriptorMap, entry));
if (isNotEmpty(metacard.getSourceId())) {
properties.put(SOURCE_ID_PROPERTY, metacard.getSourceId());
}
if (id != null) {
metacard.setId(id);
}
return metacard;
}
use of ddf.geo.formatter.CompositeGeometry in project ddf by codice.
the class GeoJsonMetacardTransformer method convertValue.
private static Object convertValue(Serializable value, AttributeType.AttributeFormat format) throws CatalogTransformerException {
if (value == null) {
return null;
}
switch(format) {
case BOOLEAN:
return value;
case DATE:
SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_8601_DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormat.format((Date) value);
case BINARY:
byte[] bytes = (byte[]) value;
String base64 = DatatypeConverter.printBase64Binary(bytes);
return base64;
case DOUBLE:
case LONG:
case FLOAT:
case INTEGER:
case SHORT:
case STRING:
case XML:
return value.toString();
case GEOMETRY:
WKTReader reader = new WKTReader();
try {
Geometry geometry = reader.read(value.toString());
CompositeGeometry geoJsonGeometry = CompositeGeometry.getCompositeGeometry(geometry);
if (geoJsonGeometry == null) {
throw new CatalogTransformerException("Could not perform transform: unsupported geometry [" + value + "]");
}
return geoJsonGeometry.toJsonMap();
} catch (ParseException e) {
throw new CatalogTransformerException("Could not perform transform: could not parse geometry [" + value + "]", e);
}
case OBJECT:
default:
return null;
}
}
use of ddf.geo.formatter.CompositeGeometry in project ddf by codice.
the class GeoJsonInputTransformer method getCompositeGeometry.
private CompositeGeometry getCompositeGeometry(Map<String, Object> rootObject) {
Map<String, Object> geometryJson = (Map<String, Object>) rootObject.get(CompositeGeometry.GEOMETRY_KEY);
CompositeGeometry geoJsonGeometry = null;
if (geometryJson != null) {
if (geometryJson.get(CompositeGeometry.TYPE_KEY) != null && (geometryJson.get(CompositeGeometry.COORDINATES_KEY) != null || geometryJson.get(CompositeGeometry.GEOMETRIES_KEY) != null)) {
String geometryTypeJson = geometryJson.get(CompositeGeometry.TYPE_KEY).toString();
geoJsonGeometry = CompositeGeometry.getCompositeGeometry(geometryTypeJson, geometryJson);
} else {
LOGGER.debug("Could not find geometry type.");
}
}
return geoJsonGeometry;
}
Aggregations