Search in sources :

Example 86 with Geometry

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();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) QName(javax.xml.namespace.QName) TreeSet(java.util.TreeSet) AttributeDescriptorComparator(org.codice.ddf.spatial.ogc.wfs.catalog.common.AttributeDescriptorComparator) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor)

Example 87 with Geometry

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Serializable(java.io.Serializable) XmlNode(org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 88 with Geometry

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MultiGeometryType(net.opengis.gml.v_3_2_1.MultiGeometryType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 89 with Geometry

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");
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)

Example 90 with Geometry

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);
    }
}
Also used : JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)125 WKTReader (com.vividsolutions.jts.io.WKTReader)35 Test (org.junit.Test)31 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 Point (com.vividsolutions.jts.geom.Point)21 ParseException (com.vividsolutions.jts.io.ParseException)19 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)14 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)14 Envelope (com.vividsolutions.jts.geom.Envelope)13 WKTWriter (com.vividsolutions.jts.io.WKTWriter)13 ArrayList (java.util.ArrayList)13 LineString (com.vividsolutions.jts.geom.LineString)10 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)9 Metacard (ddf.catalog.data.Metacard)9 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Optional (com.google.common.base.Optional)6 IOException (java.io.IOException)6 RevFeature (org.locationtech.geogig.api.RevFeature)6 JtsGeometry (org.locationtech.spatial4j.shape.jts.JtsGeometry)6 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)5