Search in sources :

Example 1 with AbstractGeometryType

use of net.opengis.gml.v_3_1_1.AbstractGeometryType in project ddf by codice.

the class CswQueryFactoryTest method createPolygon.

private JAXBElement<AbstractGeometryType> createPolygon() {
    PolygonType localPolygon = new PolygonType();
    LinearRingType ring = new LinearRingType();
    for (Coordinate coordinate : polygon.getCoordinates()) {
        CoordType coord = new CoordType();
        coord.setX(BigDecimal.valueOf(coordinate.x));
        coord.setY(BigDecimal.valueOf(coordinate.y));
        if (!Double.isNaN(coordinate.z)) {
            coord.setZ(BigDecimal.valueOf(coordinate.z));
        }
        ring.getCoord().add(coord);
    }
    AbstractRingPropertyType abstractRing = new AbstractRingPropertyType();
    abstractRing.setRing(gmlObjectFactory.createLinearRing(ring));
    localPolygon.setExterior(gmlObjectFactory.createExterior(abstractRing));
    JAXBElement<AbstractGeometryType> agt = new JAXBElement<>(new QName("http://www.opengis.net/gml", "Polygon"), AbstractGeometryType.class, null, localPolygon);
    return agt;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) LinearRingType(net.opengis.gml.v_3_1_1.LinearRingType) AbstractRingPropertyType(net.opengis.gml.v_3_1_1.AbstractRingPropertyType) QName(javax.xml.namespace.QName) PolygonType(net.opengis.gml.v_3_1_1.PolygonType) JAXBElement(javax.xml.bind.JAXBElement) CoordType(net.opengis.gml.v_3_1_1.CoordType)

Example 2 with AbstractGeometryType

use of net.opengis.gml.v_3_1_1.AbstractGeometryType in project ddf by codice.

the class CswFilterFactory method createDistanceBufferType.

@SuppressWarnings("unchecked")
private DistanceBufferType createDistanceBufferType(PropertyNameType propertyName, JAXBElement<? extends AbstractGeometryType> geometry, DistanceType distance) {
    DistanceBufferType distanceBuffer = new DistanceBufferType();
    distanceBuffer.setDistance(distance);
    distanceBuffer.setGeometry((JAXBElement<AbstractGeometryType>) geometry);
    distanceBuffer.setPropertyName(propertyName);
    return distanceBuffer;
}
Also used : AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) DistanceBufferType(net.opengis.filter.v_1_1_0.DistanceBufferType)

Example 3 with AbstractGeometryType

use of net.opengis.gml.v_3_1_1.AbstractGeometryType in project ddf by codice.

the class RegistryPackageConverter method setSlotGeoAttribute.

private static void setSlotGeoAttribute(SlotType1 slot, String metacardAttributeName, MetacardImpl metacard) throws RegistryConversionException {
    if (slot.isSetValueList()) {
        net.opengis.cat.wrs.v_1_0_2.ValueListType valueList = (net.opengis.cat.wrs.v_1_0_2.ValueListType) slot.getValueList().getValue();
        List<AnyValueType> anyValues = valueList.getAnyValue();
        for (AnyValueType anyValue : anyValues) {
            if (anyValue.isSetContent()) {
                for (Object content : anyValue.getContent()) {
                    if (content instanceof JAXBElement) {
                        JAXBElement jaxbElement = (JAXBElement) content;
                        AbstractGeometryType geometry = (AbstractGeometryType) jaxbElement.getValue();
                        String convertedGeometry = getWKTFromGeometry(geometry, jaxbElement);
                        if (StringUtils.isNotBlank(convertedGeometry)) {
                            metacard.setAttribute(metacardAttributeName, convertedGeometry);
                        }
                    }
                }
            }
        }
    }
}
Also used : AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) JAXBElement(javax.xml.bind.JAXBElement) AnyValueType(net.opengis.cat.wrs.v_1_0_2.AnyValueType)

Example 4 with AbstractGeometryType

use of net.opengis.gml.v_3_1_1.AbstractGeometryType in project ddf by codice.

the class GeometryAdapter method marshalFrom.

public static GeometryElement marshalFrom(Attribute attribute) throws CatalogTransformerException {
    GeometryElement element = new GeometryElement();
    element.setName(attribute.getName());
    if (attribute.getValue() != null) {
        for (Serializable value : attribute.getValues()) {
            if (!(value instanceof String)) {
                continue;
            }
            String wkt = (String) value;
            WKTReader wktReader = new WKTReader(geometryFactory);
            Geometry jtsGeometry = null;
            try {
                jtsGeometry = wktReader.read(wkt);
            } catch (ParseException e) {
                throw new CatalogTransformerException("Could not transform Metacard to XML.  Invalid WKT.", e);
            }
            JTSToGML311GeometryConverter converter = new JTSToGML311GeometryConverter();
            @SuppressWarnings("unchecked") JAXBElement<AbstractGeometryType> gmlElement = (JAXBElement<AbstractGeometryType>) converter.createElement(jtsGeometry);
            GeometryElement.Value geoValue = new GeometryElement.Value();
            geoValue.setGeometry(gmlElement);
            ((GeometryElement) element).getValue().add(geoValue);
        }
    }
    return element;
}
Also used : Serializable(java.io.Serializable) JTSToGML311GeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) JAXBElement(javax.xml.bind.JAXBElement) WKTReader(com.vividsolutions.jts.io.WKTReader) Geometry(com.vividsolutions.jts.geom.Geometry) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value) GeometryElement(ddf.catalog.transformer.xml.binding.GeometryElement) ParseException(com.vividsolutions.jts.io.ParseException)

Example 5 with AbstractGeometryType

use of net.opengis.gml.v_3_1_1.AbstractGeometryType in project ddf by codice.

the class Gml3ToWktImpl method convert.

@SuppressWarnings("unchecked")
public String convert(InputStream xml) throws ValidationExceptionImpl {
    AbstractGeometryType geometry = null;
    try {
        JAXBElement<AbstractGeometryType> jaxbElement = parser.unmarshal(configurator, JAXBElement.class, xml);
        geometry = jaxbElement.getValue();
        GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
        Geometry jtsGeo = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
        WKTWriter wktWriter = new WKTWriter();
        return wktWriter.write(jtsGeo);
    } catch (ParserException e) {
        LOGGER.debug("Cannot parse gml", e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot parse gml"), new ArrayList<String>());
    } catch (ConversionFailedException e) {
        LOGGER.debug("Cannot convert gml311 geo object {} to jts", geometry, e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot convert geo object"), new ArrayList<String>());
    }
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) WKTWriter(com.vividsolutions.jts.io.WKTWriter) ParserException(org.codice.ddf.parser.ParserException) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) ArrayList(java.util.ArrayList)

Aggregations

AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)7 Geometry (com.vividsolutions.jts.geom.Geometry)4 JAXBElement (javax.xml.bind.JAXBElement)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)2 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)2 BinarySpatialOpType (net.opengis.filter.v_1_1_0.BinarySpatialOpType)2 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)2 GML311ToJTSGeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 GeometryElement (ddf.catalog.transformer.xml.binding.GeometryElement)1 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 AnyValueType (net.opengis.cat.wrs.v_1_0_2.AnyValueType)1 DistanceBufferType (net.opengis.filter.v_1_1_0.DistanceBufferType)1