Search in sources :

Example 36 with DirectPositionType

use of org.geotoolkit.gml.xml.v311.DirectPositionType in project ddf by codice.

the class SlotWebConverter method getPointMapFromPointType.

private static Map<String, Object> getPointMapFromPointType(PointType point) {
    Map<String, Object> pointMap = new HashMap<>();
    if (point.isSetSrsDimension()) {
        pointMap.put(SRS_DIMENSION, point.getSrsDimension().intValue());
    }
    if (point.isSetSrsName()) {
        pointMap.put(SRS_NAME, point.getSrsName());
    }
    if (point.isSetPos()) {
        DirectPositionType directPosition = point.getPos();
        List<String> pointValues = new ArrayList<>();
        pointValues.addAll(directPosition.getValue().stream().map(String::valueOf).collect(Collectors.toList()));
        String position = String.join(" ", pointValues);
        if (StringUtils.isNotBlank(position)) {
            pointMap.put(POSITION, position);
        }
    }
    return pointMap;
}
Also used : DirectPositionType(net.opengis.gml.v_3_1_1.DirectPositionType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 37 with DirectPositionType

use of org.geotoolkit.gml.xml.v311.DirectPositionType in project ddf by codice.

the class SlotTypeConverter method getEnvelope.

private Optional<EnvelopeType> getEnvelope(Map<String, Object> envelopeMap) {
    Optional<EnvelopeType> optionalEnvelope = Optional.empty();
    if (MapUtils.isEmpty(envelopeMap)) {
        return optionalEnvelope;
    }
    optionalEnvelope = Optional.of(GML_FACTORY.createEnvelopeType());
    String valueToPopulate = MapUtils.getString(envelopeMap, SRS_NAME);
    if (StringUtils.isNotBlank(valueToPopulate)) {
        optionalEnvelope.get().setSrsName(valueToPopulate);
    }
    String upperCorner = MapUtils.getString(envelopeMap, UPPER_CORNER);
    String lowerCorner = MapUtils.getString(envelopeMap, LOWER_CORNER);
    if (StringUtils.isNotBlank(upperCorner)) {
        List<Double> values = Arrays.stream(StringUtils.split(upperCorner)).map(e -> new Double(e)).collect(Collectors.toList());
        DirectPositionType directPosition = GML_FACTORY.createDirectPositionType();
        directPosition.setValue(values);
        optionalEnvelope.get().setUpperCorner(directPosition);
    }
    if (StringUtils.isNotBlank(lowerCorner)) {
        List<Double> values = Arrays.stream(StringUtils.split(lowerCorner)).map(e -> new Double(e)).collect(Collectors.toList());
        DirectPositionType directPosition = GML_FACTORY.createDirectPositionType();
        directPosition.setValue(values);
        optionalEnvelope.get().setLowerCorner(directPosition);
    }
    return optionalEnvelope;
}
Also used : DirectPositionType(net.opengis.gml.v_3_1_1.DirectPositionType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) MapToSchemaElement(org.codice.ddf.registry.schemabindings.helper.MapToSchemaElement) WebMapHelper(org.codice.ddf.registry.schemabindings.helper.WebMapHelper) AnyValueType(net.opengis.cat.wrs.v_1_0_2.AnyValueType) POINT_KEY(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.POINT_KEY) LOWER_CORNER(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.LOWER_CORNER) EnvelopeType(net.opengis.gml.v_3_1_1.EnvelopeType) GML_FACTORY(org.codice.ddf.registry.schemabindings.EbrimConstants.GML_FACTORY) NAME(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.NAME) RIM_FACTORY(org.codice.ddf.registry.schemabindings.EbrimConstants.RIM_FACTORY) ENVELOPE_KEY(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.ENVELOPE_KEY) POSITION(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.POSITION) SRS_DIMENSION(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.SRS_DIMENSION) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) BigInteger(java.math.BigInteger) WRS_FACTORY(org.codice.ddf.registry.schemabindings.EbrimConstants.WRS_FACTORY) SRS_NAME(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.SRS_NAME) UPPER_CORNER(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.UPPER_CORNER) ValueListType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ValueListType) MapUtils(org.apache.commons.collections.MapUtils) Collectors(java.util.stream.Collectors) List(java.util.List) SLOT_TYPE(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.SLOT_TYPE) SlotType1(oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1) VALUE(org.codice.ddf.registry.schemabindings.converter.web.SlotWebConverter.VALUE) PointType(net.opengis.gml.v_3_1_1.PointType) Optional(java.util.Optional) EnvelopeType(net.opengis.gml.v_3_1_1.EnvelopeType) DirectPositionType(net.opengis.gml.v_3_1_1.DirectPositionType)

Example 38 with DirectPositionType

use of org.geotoolkit.gml.xml.v311.DirectPositionType in project arctic-sea by 52North.

the class GmlDecoderv321 method parsePointType.

private Geometry parsePointType(PointType xbPointType) throws DecodingException {
    String geomWKT = null;
    int srid = -1;
    if (xbPointType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbPointType.getSrsName());
    }
    if (xbPointType.getPos() != null) {
        DirectPositionType xbPos = xbPointType.getPos();
        if (srid == -1 && xbPos.getSrsName() != null) {
            srid = CRSHelper.parseSrsName(xbPos.getSrsName());
        }
        String directPosition = getString4Pos(xbPos);
        geomWKT = "POINT(" + directPosition + ")";
    } else if (xbPointType.getCoordinates() != null) {
        CoordinatesType xbCoords = xbPointType.getCoordinates();
        String directPosition = getString4Coordinates(xbCoords);
        geomWKT = "POINT" + directPosition;
    } else {
        throw new DecodingException("For geometry type 'gml:Point' only element " + "'gml:pos' and 'gml:coordinates' are allowed " + "in the feature of interest parameter!");
    }
    srid = setDefaultForUnsetSrid(srid);
    try {
        return JTSHelper.createGeometryFromWKT(geomWKT, srid);
    } catch (ParseException ex) {
        throw new DecodingException(ex);
    }
}
Also used : DirectPositionType(net.opengis.gml.x32.DirectPositionType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException) CoordinatesType(net.opengis.gml.x32.CoordinatesType)

Example 39 with DirectPositionType

use of org.geotoolkit.gml.xml.v311.DirectPositionType in project arctic-sea by 52North.

the class GmlDecoderv321 method parseLineStringType.

private Geometry parseLineStringType(LineStringType xbLineStringType) throws DecodingException {
    int srid = -1;
    if (xbLineStringType.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbLineStringType.getSrsName());
    }
    DirectPositionType[] xbPositions = xbLineStringType.getPosArray();
    String geomWKT;
    if (xbPositions != null && xbPositions.length > 0) {
        if (srid == -1 && xbPositions[0].getSrsName() != null && !(xbPositions[0].getSrsName().isEmpty())) {
            srid = CRSHelper.parseSrsName(xbPositions[0].getSrsName());
        }
        geomWKT = "LINESTRING" + getString4PosArray(xbLineStringType.getPosArray(), false) + "";
    } else if (xbLineStringType.getPosList() != null) {
        StringBuilder builder = new StringBuilder();
        builder.append("LINESTRING(");
        DirectPositionListType posList = xbLineStringType.getPosList();
        int dim;
        if (posList.getSrsDimension() == null) {
            dim = 2;
        } else {
            dim = posList.getSrsDimension().intValue();
        }
        if (posList.getListValue().size() % dim != 0) {
            throw new DecodingException("posList does not contain a multiple of %d coordinates", dim);
        }
        @SuppressWarnings("unchecked") Iterator<Double> iterator = posList.getListValue().iterator();
        if (iterator.hasNext()) {
            builder.append(iterator.next());
            for (int i = 1; i < dim; ++i) {
                builder.append(' ').append(iterator.next());
            }
            while (iterator.hasNext()) {
                builder.append(", ");
                builder.append(iterator.next());
                for (int i = 1; i < dim; ++i) {
                    builder.append(' ').append(iterator.next());
                }
            }
        }
        builder.append(")");
        geomWKT = builder.toString();
    } else {
        geomWKT = null;
    }
    srid = setDefaultForUnsetSrid(srid);
    if (geomWKT != null) {
        try {
            return JTSHelper.createGeometryFromWKT(geomWKT, srid);
        } catch (ParseException ex) {
            throw new DecodingException(ex);
        }
    } else {
        return JTSHelper.getGeometryFactoryForSRID(srid).createGeometryCollection(null);
    }
}
Also used : DirectPositionType(net.opengis.gml.x32.DirectPositionType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) Iterator(java.util.Iterator) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DateTimeParseException(org.n52.shetland.util.DateTimeParseException) ParseException(org.locationtech.jts.io.ParseException)

Example 40 with DirectPositionType

use of org.geotoolkit.gml.xml.v311.DirectPositionType in project arctic-sea by 52North.

the class GmlDecoderv321 method getCoordString4LinearRing.

/**
 * method parses the passed linearRing(generated thru XmlBEans) and returns a string containing the coordinate
 * values of the passed ring
 *
 * @param xbLinearRing linearRing(generated thru XmlBEans)
 *
 * @return Returns a string containing the coordinate values of the passed ring
 *
 * @throws DecodingException * if parsing the linear Ring failed
 */
private String getCoordString4LinearRing(LinearRingType xbLinearRing) throws DecodingException {
    String result = "";
    DirectPositionListType xbPosList = xbLinearRing.getPosList();
    CoordinatesType xbCoordinates = xbLinearRing.getCoordinates();
    DirectPositionType[] xbPosArray = xbLinearRing.getPosArray();
    if (xbPosList != null && !(xbPosList.getStringValue().isEmpty())) {
        result = getString4PosList(xbPosList);
    } else if (xbCoordinates != null && !(xbCoordinates.getStringValue().isEmpty())) {
        result = getString4Coordinates(xbCoordinates);
    } else if (xbPosArray != null && xbPosArray.length > 0) {
        result = getString4PosArray(xbPosArray, true);
    } else {
        throw new DecodingException("The Polygon must contain the following elements " + "<gml:exterior><gml:LinearRing><gml:posList>, " + "<gml:exterior><gml:LinearRing><gml:coordinates> " + "or <gml:exterior><gml:LinearRing><gml:pos>{<gml:pos>}!");
    }
    return result;
}
Also used : DirectPositionType(net.opengis.gml.x32.DirectPositionType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) CoordinatesType(net.opengis.gml.x32.CoordinatesType)

Aggregations

DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)24 ArrayList (java.util.ArrayList)14 PointType (org.geotoolkit.gml.xml.v311.PointType)14 Test (org.junit.Test)11 StringWriter (java.io.StringWriter)10 DirectPositionType (net.opengis.gml.v_3_1_1.DirectPositionType)10 DirectPositionType (org.geotoolkit.gml.xml.v321.DirectPositionType)10 EnvelopeType (org.geotoolkit.gml.xml.v311.EnvelopeType)9 StringReader (java.io.StringReader)8 JAXBElement (javax.xml.bind.JAXBElement)8 EnvelopeType (net.opengis.gml.v_3_1_1.EnvelopeType)7 Geometry (org.locationtech.jts.geom.Geometry)7 Coordinate (org.locationtech.jts.geom.Coordinate)6 BBOXType (net.opengis.filter.v_1_1_0.BBOXType)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 DirectPositionType (net.opengis.gml.x32.DirectPositionType)4 FeaturePropertyType (org.geotoolkit.gml.xml.v311.FeaturePropertyType)4 SamplingPointType (org.geotoolkit.sampling.xml.v100.SamplingPointType)4 FilterType (net.opengis.filter.v_1_1_0.FilterType)3 DirectPositionType (net.opengis.gml.v_3_2_1.DirectPositionType)3