Search in sources :

Example 1 with ModelType

use of org.geotoolkit.kml.xml.v220.ModelType 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

ArrayList (java.util.ArrayList)1 List (java.util.List)1 JAXBElement (javax.xml.bind.JAXBElement)1 AbstractGeometryType (org.geotoolkit.kml.xml.v220.AbstractGeometryType)1 BoundaryType (org.geotoolkit.kml.xml.v220.BoundaryType)1 LineStringType (org.geotoolkit.kml.xml.v220.LineStringType)1 LinearRingType (org.geotoolkit.kml.xml.v220.LinearRingType)1 LocationType (org.geotoolkit.kml.xml.v220.LocationType)1 ModelType (org.geotoolkit.kml.xml.v220.ModelType)1 MultiGeometryType (org.geotoolkit.kml.xml.v220.MultiGeometryType)1 PointType (org.geotoolkit.kml.xml.v220.PointType)1 PolygonType (org.geotoolkit.kml.xml.v220.PolygonType)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)1 Geometry (org.locationtech.jts.geom.Geometry)1 LinearRing (org.locationtech.jts.geom.LinearRing)1 PackedCoordinateSequence (org.locationtech.jts.geom.impl.PackedCoordinateSequence)1 NodeList (org.w3c.dom.NodeList)1