Search in sources :

Example 21 with LinearRingType

use of org.geotoolkit.kml.xml.v220.LinearRingType in project tiamat by entur.

the class PolygonConverterTest method convertFrom.

@Test
public void convertFrom() throws Exception {
    List<Double> values = new ArrayList<>();
    values.add(9.8468);
    values.add(59.2649);
    values.add(9.8456);
    values.add(59.2654);
    values.add(9.8457);
    values.add(59.2655);
    values.add(values.get(0));
    values.add(values.get(1));
    DirectPositionListType positionList = new DirectPositionListType().withValue(values);
    LinearRingType linearRing = new LinearRingType().withPosList(positionList);
    PolygonType polygonType = new PolygonType().withId("KVE-07").withExterior(new AbstractRingPropertyType().withAbstractRing(openGisObjectFactory.createLinearRing(linearRing)));
    Polygon polygon = polygonConverter.convertFrom(polygonType, new TypeBuilder<Polygon>() {
    }.build(), new MappingContext(new HashMap<>()));
    assertThat(polygon).isExactlyInstanceOf(Polygon.class).isNotNull();
    assertThat(polygon.getExteriorRing().getCoordinates()).hasSize(values.size() / 2);
    assertCoordinatesMatch(polygon.getExteriorRing(), values, "Exterior ring");
}
Also used : MappingContext(ma.glasnost.orika.MappingContext) TypeBuilder(ma.glasnost.orika.metadata.TypeBuilder) HashMap(java.util.HashMap) LinearRingType(net.opengis.gml._3.LinearRingType) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) ArrayList(java.util.ArrayList) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) PolygonType(net.opengis.gml._3.PolygonType) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 22 with LinearRingType

use of org.geotoolkit.kml.xml.v220.LinearRingType in project geotoolkit by Geomatys.

the class KMLStore method convert.

private static Geometry convert(Object geomType) throws DataStoreException {
    if (geomType instanceof JAXBElement)
        geomType = ((JAXBElement) geomType).getValue();
    Geometry geom = null;
    if (geomType instanceof ModelType) {
        final ModelType modelType = (ModelType) geomType;
        final LocationType location = modelType.getLocation();
        geom = GF.createPoint(new Coordinate(location.getLongitude(), location.getLatitude()));
    } else if (geomType instanceof PointType) {
        final PointType pointType = (PointType) geomType;
        final List<String> coordinates = pointType.getCoordinates();
        geom = GF.createPoint(toCoordinates(coordinates, 1, false));
    } else if (geomType instanceof PolygonType) {
        final PolygonType polygonType = (PolygonType) geomType;
        final CoordinateSequence outter = toCoordinates(polygonType.getOuterBoundaryIs().getLinearRing().getCoordinates(), 3, true);
        final List<BoundaryType> inners = polygonType.getInnerBoundaryIs();
        final LinearRing[] holes = new LinearRing[inners.size()];
        for (int i = 0; i < holes.length; i++) {
            holes[i] = GF.createLinearRing(toCoordinates(inners.get(i).getLinearRing().getCoordinates(), 3, true));
        }
        geom = GF.createPolygon(GF.createLinearRing(outter), holes);
    } else if (geomType instanceof LinearRingType) {
        final LinearRingType linearRingType = (LinearRingType) geomType;
        geom = GF.createLineString(toCoordinates(linearRingType.getCoordinates(), 3, true));
    } else if (geomType instanceof MultiGeometryType) {
        final MultiGeometryType multigeometryType = (MultiGeometryType) geomType;
        final List<JAXBElement<? extends AbstractGeometryType>> children = multigeometryType.getAbstractGeometryGroup();
        final Geometry[] childs = new Geometry[children.size()];
        for (int i = 0; i < childs.length; i++) {
            childs[i] = convert(children.get(i));
        }
        geom = GF.createGeometryCollection(childs);
    } else if (geomType instanceof LineStringType) {
        final LineStringType lineStringType = (LineStringType) geomType;
        geom = GF.createLineString(toCoordinates(lineStringType.getCoordinates(), 2, false));
    }
    if (geom != null) {
        JTS.setCRS(geom, CRS);
    }
    return geom;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.locationtech.jts.geom.impl.PackedCoordinateSequence) AbstractGeometryType(org.geotoolkit.kml.xml.v220.AbstractGeometryType) LinearRingType(org.geotoolkit.kml.xml.v220.LinearRingType) MultiGeometryType(org.geotoolkit.kml.xml.v220.MultiGeometryType) PolygonType(org.geotoolkit.kml.xml.v220.PolygonType) JAXBElement(javax.xml.bind.JAXBElement) LineStringType(org.geotoolkit.kml.xml.v220.LineStringType) Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) ModelType(org.geotoolkit.kml.xml.v220.ModelType) PointType(org.geotoolkit.kml.xml.v220.PointType) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) LinearRing(org.locationtech.jts.geom.LinearRing) LocationType(org.geotoolkit.kml.xml.v220.LocationType) BoundaryType(org.geotoolkit.kml.xml.v220.BoundaryType)

Aggregations

Test (org.junit.Test)13 LinearRingType (net.opengis.gml.v_3_1_1.LinearRingType)9 ArrayList (java.util.ArrayList)7 MultiPolygonType (net.opengis.gml.v_3_1_1.MultiPolygonType)7 BinarySpatialOpType (net.opengis.filter.v_1_1_0.BinarySpatialOpType)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 PolygonType (net.opengis.gml.v_3_1_1.PolygonType)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Polygon (org.locationtech.jts.geom.Polygon)5 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)3 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)3 LinearRingType (net.opengis.gml._3.LinearRingType)3 PolygonType (net.opengis.gml._3.PolygonType)3 LinearRingMemberType (ogc.schema.opengis.gml.v_2_1_2.LinearRingMemberType)3 LinearRingType (ogc.schema.opengis.gml.v_2_1_2.LinearRingType)3 MultiPolygonType (ogc.schema.opengis.gml.v_2_1_2.MultiPolygonType)3 PolygonType (ogc.schema.opengis.gml.v_2_1_2.PolygonType)3 Geometry (org.locationtech.jts.geom.Geometry)3 LinearRing (org.locationtech.jts.geom.LinearRing)3 HashMap (java.util.HashMap)2