Search in sources :

Example 1 with CompositeGeometry

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;
}
Also used : CompositeGeometry(ddf.geo.formatter.CompositeGeometry) Geometry(org.locationtech.jts.geom.Geometry) Serializable(java.io.Serializable) Position(org.apache.abdera.ext.geo.Position) Attribute(ddf.catalog.data.Attribute) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 2 with CompositeGeometry

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;
}
Also used : CompositeGeometry(ddf.geo.formatter.CompositeGeometry) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType)

Example 3 with CompositeGeometry

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;
    }
}
Also used : CompositeGeometry(ddf.geo.formatter.CompositeGeometry) Geometry(org.locationtech.jts.geom.Geometry) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) MimeTypeParseException(javax.activation.MimeTypeParseException) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with CompositeGeometry

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;
}
Also used : CompositeGeometry(ddf.geo.formatter.CompositeGeometry) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

CompositeGeometry (ddf.geo.formatter.CompositeGeometry)4 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 Geometry (org.locationtech.jts.geom.Geometry)2 ParseException (org.locationtech.jts.io.ParseException)2 WKTReader (org.locationtech.jts.io.WKTReader)2 Attribute (ddf.catalog.data.Attribute)1 MetacardType (ddf.catalog.data.MetacardType)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 Serializable (java.io.Serializable)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Position (org.apache.abdera.ext.geo.Position)1