Search in sources :

Example 11 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project ddf by codice.

the class CswJTSToGML311LinearRingConverter method doCreateGeometryType.

/**
 * @see {@code JTSToGML311LinearRingConverter#doCreateGeometryType}
 */
@Override
protected LinearRingType doCreateGeometryType(LinearRing linearRing) {
    final LinearRingType resultLinearRing;
    if (usePosList) {
        resultLinearRing = getObjectFactory().createLinearRingType();
        List<Double> posDoubleList = new ArrayList<Double>();
        for (Coordinate coordinate : linearRing.getCoordinates()) {
            posDoubleList.add(coordinate.x);
            posDoubleList.add(coordinate.y);
        }
        DirectPositionListType directPosListType = new DirectPositionListType();
        directPosListType.setValue(posDoubleList);
        resultLinearRing.setPosList(directPosListType);
    } else {
        resultLinearRing = super.doCreateGeometryType(linearRing);
    }
    return resultLinearRing;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRingType(net.opengis.gml.v_3_1_1.LinearRingType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml.v_3_1_1.DirectPositionListType)

Example 12 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType 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 13 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType 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)

Example 14 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project arctic-sea by 52North.

the class AbstractRectifiedGridCoverageTypeEncoder method encodeDomainSet.

private XmlObject encodeDomainSet(RectifiedGridCoverage rectifiedGridCoverage) {
    List<ComparableValue<?, ?>> domainSet = rectifiedGridCoverage.getDomainSet();
    if (!checkForRange(domainSet)) {
        SimpleMultiPointDocument smpd = SimpleMultiPointDocument.Factory.newInstance();
        SimpleMultiPointType smpt = smpd.addNewSimpleMultiPoint();
        smpt.setId("smp_" + rectifiedGridCoverage.getGmlId());
        DirectPositionListType dplt = smpt.addNewPosList();
        List<String> uoms = getUoms(domainSet);
        if (!uoms.isEmpty()) {
            dplt.setUomLabels(Lists.newArrayList(uoms));
        }
        dplt.setListValue(getList(rectifiedGridCoverage.getDomainSet()));
        return smpd;
    } else {
        LineStringDocument lsd = LineStringDocument.Factory.newInstance();
        LineStringType lst = lsd.addNewLineString();
        lst.setId("ls_" + rectifiedGridCoverage.getGmlId());
        lst.setUomLabels(getUoms(domainSet));
        for (ComparableValue<?, ?> quantityValued : domainSet) {
            Object value = quantityValued.getValue();
            if (value instanceof Double) {
                lst.addNewPos().setListValue(Lists.newArrayList((Double) value));
            } else if (value instanceof RangeValue) {
                lst.addNewPos().setListValue(((RangeValue) value).getRangeAsList());
            }
        }
        return lsd;
    }
}
Also used : SimpleMultiPointType(net.opengis.gml.x33.ce.SimpleMultiPointType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) LineStringType(net.opengis.gml.x32.LineStringType) ComparableValue(org.n52.shetland.ogc.om.values.ComparableValue) RangeValue(org.n52.shetland.ogc.swe.RangeValue) SimpleMultiPointDocument(net.opengis.gml.x33.ce.SimpleMultiPointDocument) LineStringDocument(net.opengis.gml.x32.LineStringDocument) XmlObject(org.apache.xmlbeans.XmlObject)

Example 15 with DirectPositionListType

use of net.opengis.gml._3.DirectPositionListType in project geotoolkit by Geomatys.

the class GmlXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws JAXBException
 */
@Test
public void marshallingTest() throws Exception {
    DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
    DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
    EnvelopeType env = new EnvelopeType("bound-1", lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
    StringWriter sw = new StringWriter();
    marshaller.marshal(FACTORY.createEnvelope(env), sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    String expResult = "<gml:Envelope xmlns:gml=\"" + GML + '"' + " srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\">" + '\n' + "  <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + "  <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
    Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
    TimePeriodType tp = new TimePeriodType(d1);
    marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
    TimePositionType tpos = new TimePositionType("2002-08-15");
    tp = new TimePeriodType(tpos);
    marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
    // System.out.println(sw.toString());
    LineStringSegmentType ls = new LineStringSegmentType();
    DirectPositionListType posList = new DirectPositionListType();
    posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
    ls.setPosList(posList);
    sw = new StringWriter();
    marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<gml:LineStringSegment xmlns:gml=\"" + GML + "\">\n" + "  <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
    ls = new LineStringSegmentType();
    DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
    DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
    ls.getPos().add(pos1);
    ls.getPos().add(pos2);
    sw = new StringWriter();
    marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<gml:LineStringSegment xmlns:gml=\"" + GML + "\">\n" + "  <gml:pos>1.1 1.2</gml:pos>" + '\n' + "  <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
    assertXmlEquals(expResult, result, "xmlns:*");
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v311.EnvelopeType) LineStringSegmentType(org.geotoolkit.gml.xml.v311.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) StringWriter(java.io.StringWriter) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) DirectPositionListType(org.geotoolkit.gml.xml.v311.DirectPositionListType) Duration(javax.xml.datatype.Duration) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Aggregations

Test (org.junit.Test)8 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)7 ArrayList (java.util.ArrayList)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)5 DirectPositionListType (org.geotoolkit.gml.xml.v321.DirectPositionListType)5 Polygon (org.locationtech.jts.geom.Polygon)5 LineStringType (net.opengis.gml._3.LineStringType)4 LineString (org.locationtech.jts.geom.LineString)4 TypeBuilder (ma.glasnost.orika.metadata.TypeBuilder)3 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)3 LinearRingType (net.opengis.gml._3.LinearRingType)3 PolygonType (net.opengis.gml._3.PolygonType)3 Geometry (org.locationtech.jts.geom.Geometry)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 JAXBElement (javax.xml.bind.JAXBElement)2 Duration (javax.xml.datatype.Duration)2