Search in sources :

Example 1 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project OpenTripPlanner by opentripplanner.

the class ServiceLinkMapperTest method createServiceLink.

private ServiceLink createServiceLink(String id, double distance, Double[] coordinates) {
    DirectPositionListType directPositionListType = new DirectPositionListType().withValue(coordinates);
    LinkSequenceProjection linkSequenceProjection = new LinkSequenceProjection().withLineString(new LineStringType().withPosList(directPositionListType));
    JAXBElement<LinkSequenceProjection_VersionStructure> linkSequenceProjection_versionStructure = MappingSupport.createJaxbElement(linkSequenceProjection);
    Projections_RelStructure projections_relStructure = new Projections_RelStructure().withProjectionRefOrProjection(linkSequenceProjection_versionStructure);
    return new ServiceLink().withId(id).withDistance(new BigDecimal(distance)).withProjections(projections_relStructure);
}
Also used : LinkSequenceProjection(org.rutebanken.netex.model.LinkSequenceProjection) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) Projections_RelStructure(org.rutebanken.netex.model.Projections_RelStructure) LinkSequenceProjection_VersionStructure(org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure) ServiceLink(org.rutebanken.netex.model.ServiceLink) LineStringType(net.opengis.gml._3.LineStringType) BigDecimal(java.math.BigDecimal)

Example 2 with DirectPositionListType

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

the class GmlEncoderv321 method createLineStringFromJtsGeometry.

/**
 * Creates a XML LineString from a SOS LineString.
 *
 * @param jtsLineString
 *            SOS LineString
 * @param xbLst
 *            XML LinetSring
 */
private void createLineStringFromJtsGeometry(LineString jtsLineString, LineStringType xbLst) {
    String srsName = getSrsName(jtsLineString);
    xbLst.setSrsName(srsName);
    DirectPositionListType xbPosList = xbLst.addNewPosList();
    xbPosList.setSrsName(srsName);
    xbPosList.setStringValue(JTSHelper.getCoordinatesString(jtsLineString));
}
Also used : DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 3 with DirectPositionListType

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

the class GmlEncoderv321 method createPolygonFromJtsGeometry.

/**
 * Creates a XML Polygon from a SOS Polygon.
 *
 * @param jtsPolygon
 *            SOS Polygon
 * @param xbPolType
 *            XML Polygon
 */
private void createPolygonFromJtsGeometry(Polygon jtsPolygon, PolygonType xbPolType) {
    List<?> jtsPolygons = PolygonExtracter.getPolygons(jtsPolygon);
    String srsName = getSrsName(jtsPolygon);
    for (int i = 0; i < jtsPolygons.size(); i++) {
        Polygon pol = (Polygon) jtsPolygons.get(i);
        AbstractRingPropertyType xbArpt = xbPolType.addNewExterior();
        AbstractRingType xbArt = xbArpt.addNewAbstractRing();
        LinearRingType xbLrt = LinearRingType.Factory.newInstance();
        // Exterior ring
        // LineString ring = pol.getExteriorRing();
        Coordinate[] ring = JTSHelper.getExteriorRingCoordinatesFromPolygon(pol);
        DirectPositionListType xbPosList = xbLrt.addNewPosList();
        xbPosList.setSrsName(srsName);
        xbPosList.setStringValue(JTSHelper.getCoordinatesString(ring));
        xbArt.set(xbLrt);
        // Rename element name for output
        XmlCursor cursor = xbArpt.newCursor();
        if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
            cursor.setName(GmlConstants.QN_LINEAR_RING_32);
        }
        cursor.dispose();
        // Interior ring
        int numberOfInteriorRings = pol.getNumInteriorRing();
        for (int ringNumber = 0; ringNumber < numberOfInteriorRings; ringNumber++) {
            xbArpt = xbPolType.addNewInterior();
            xbArt = xbArpt.addNewAbstractRing();
            xbLrt = LinearRingType.Factory.newInstance();
            xbPosList = xbLrt.addNewPosList();
            xbPosList.setSrsName(srsName);
            xbPosList.setStringValue(JTSHelper.getCoordinatesString(pol.getInteriorRingN(ringNumber)));
            xbArt.set(xbLrt);
            // Rename element name for output
            cursor = xbArpt.newCursor();
            if (cursor.toChild(GmlConstants.QN_ABSTRACT_RING_32)) {
                cursor.setName(GmlConstants.QN_LINEAR_RING_32);
            }
            cursor.dispose();
        }
    }
}
Also used : AbstractRingType(net.opengis.gml.x32.AbstractRingType) Coordinate(org.locationtech.jts.geom.Coordinate) AbstractRingPropertyType(net.opengis.gml.x32.AbstractRingPropertyType) LinearRingType(net.opengis.gml.x32.LinearRingType) DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 4 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlPolygonToJTSTest3D.

@Test
public void gmlPolygonToJTSTest3D() throws Exception {
    GeometryFactory fact = GF;
    final Coordinate[] coordinates = new Coordinate[5];
    coordinates[0] = new Coordinate(0, 0, 1);
    coordinates[1] = new Coordinate(0, 1, 1);
    coordinates[2] = new Coordinate(1, 1, 1);
    coordinates[3] = new Coordinate(1, 0, 1);
    coordinates[4] = new Coordinate(0, 0, 1);
    LinearRing linear = GF.createLinearRing(coordinates);
    Polygon expected = new Polygon(linear, null, fact);
    expected.setSRID(2154);
    LinearRingType exterior = new LinearRingType();
    List<Double> coords = new ArrayList<>();
    coords.add(0.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(1.0);
    coords.add(0.0);
    coords.add(0.0);
    coords.add(1.0);
    exterior.setPosList(new DirectPositionListType(coords));
    exterior.setSrsDimension(3);
    PolygonType gml = new PolygonType(exterior, null);
    final Geometry result = GeometrytoJTS.toJTS((org.geotoolkit.gml.xml.Polygon) gml);
    Assert.assertEquals(expected, result);
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRingType(org.geotoolkit.gml.xml.v321.LinearRingType) ArrayList(java.util.ArrayList) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) PolygonType(org.geotoolkit.gml.xml.v321.PolygonType) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 5 with DirectPositionListType

use of org.geotoolkit.gml.xml.v311.DirectPositionListType in project geotoolkit by Geomatys.

the class GeometrytoJTSTest method gmlGeodesicStringToJTSTest2D.

@Test
public void gmlGeodesicStringToJTSTest2D() throws Exception {
    final DirectPositionListType posLst = new DirectPositionListType(Arrays.asList(10.0, 20.0, 30.0, 40.0, 50.0, 60.0));
    final GeodesicStringType s = new GeodesicStringType();
    s.setPosList(posLst);
    final CurveSegmentArrayPropertyType segments = new CurveSegmentArrayPropertyType();
    segments.setAbstractCurveSegment(s);
    final CurveType curve = new CurveType();
    curve.setSegments(segments);
    final LineString expected = GF.createLineString(new Coordinate[] { new Coordinate(10, 20), new Coordinate(30, 40), new Coordinate(50, 60) });
    final Geometry result = GeometrytoJTS.toJTS(curve);
    Assert.assertEquals(expected, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CurveSegmentArrayPropertyType(org.geotoolkit.gml.xml.v321.CurveSegmentArrayPropertyType) CurveType(org.geotoolkit.gml.xml.v321.CurveType) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) GeodesicStringType(org.geotoolkit.gml.xml.v321.GeodesicStringType) Test(org.junit.Test)

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