Search in sources :

Example 76 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class ArcStringHandler method createGeometry.

@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    @SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> lineStringGeomProperty = (DefaultGeometryProperty<LineString>) super.createGeometry(instance, srsDimension, reader);
    // create Arc
    Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
    if (coords.length < 3) {
        throw new GeometryNotSupportedException("Arc string must be defined by at least three points");
    }
    List<Arc> arcs = new ArrayList<>();
    for (int i = 0; i < coords.length - 2; i += 2) {
        Arc arc = new ArcByPointsImpl(coords[i], coords[i + 1], coords[i + 2]);
        arcs.add(arc);
    }
    ArcString arcString = new ArcStringImpl(arcs);
    // get interpolation algorithm
    InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
    LineString interpolatedArcString = interpol.interpolateArcString(arcString);
    if (interpolatedArcString == null) {
        log.error("ArcString could be not interpolated to Linestring");
        return null;
    }
    return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedArcString);
}
Also used : GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ArcStringImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)

Example 77 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class CircleByCenterPointHandler method createGeometry.

@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    PointHandler handler = new PointHandler();
    // XXX support for different types of line strings in one instance (we
    // support only one type per instance!)
    Coordinate[] controlCoord = null;
    double radius = 0;
    // to parse coordinates of a line string
    // for use with GML 2, 3, 3.1, 3.2
    Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value instanceof Instance) {
            try {
                controlCoord = GMLGeometryUtil.parseCoordinates((Instance) value);
            } catch (ParseException e) {
                throw new GeometryNotSupportedException("Could not parse coordinates", e);
            }
        }
    }
    // for use with GML 3, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pos", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
                    if (c != null) {
                        cs.add(c);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML 3.1, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "posList", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            Object value = iterator.next();
            if (value instanceof Instance) {
                controlCoord = GMLGeometryUtil.parsePosList((Instance) value, srsDimension);
            }
        }
    }
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pointRep.Point", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    try {
                        @SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
                        cs.add(point.getGeometry().getCoordinate());
                    } catch (GeometryNotSupportedException e) {
                        throw new GeometryNotSupportedException("Could not parse Point Representation", e);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML 3.1
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pointProperty.Point", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    try {
                        @SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
                        cs.add(point.getGeometry().getCoordinate());
                    } catch (GeometryNotSupportedException e) {
                        throw new GeometryNotSupportedException("Could not parse Point Property", e);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML2, 3, 3.1, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "coord", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
                    if (c != null) {
                        cs.add(c);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    values = PropertyResolver.getValues(instance, "radius", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value instanceof Instance) {
            // ##TODO :: need to check with real time data
            radius = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
        }
    }
    if (controlCoord != null && controlCoord.length != 0 && radius != 0) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        // create Arc representing a circle
        Arc arc = new ArcByCenterPointImpl(controlCoord[0], radius, Angle.fromDegrees(0), Angle.fromDegrees(0), true);
        // get interpolation algorithm
        InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
        LineString interpolatedCircle = interpol.interpolateArc(arc);
        if (interpolatedCircle == null) {
            log.error("Circle could be not interpolated to Linestring");
            return null;
        }
        return new DefaultGeometryProperty<LineString>(crsDef, interpolatedCircle);
    }
    throw new GeometryNotSupportedException();
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) Point(org.locationtech.jts.geom.Point) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) ParseException(java.text.ParseException)

Example 78 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class MultiCurveWriter method write.

/**
 * @see GeometryWriter#write(XMLStreamWriter, Geometry, TypeDefinition,
 *      QName, String, DecimalFormat)
 */
@Override
public void write(XMLStreamWriter writer, MultiLineString geometry, TypeDefinition elementType, QName elementName, String gmlNs, DecimalFormat decimalFormatter) throws XMLStreamException {
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
        if (i > 0) {
            writer.writeStartElement(elementName.getNamespaceURI(), elementName.getLocalPart());
        }
        Descent descent = descend(// $NON-NLS-1$
        writer, // $NON-NLS-1$
        Pattern.parse("*/LineString"), elementType, elementName, gmlNs, false);
        LineString line = (LineString) geometry.getGeometryN(i);
        writeCoordinates(writer, line.getCoordinates(), descent.getPath().getLastType(), gmlNs, decimalFormatter);
        descent.close();
        if (i < geometry.getNumGeometries() - 1) {
            writer.writeEndElement();
        }
    }
}
Also used : LineString(org.locationtech.jts.geom.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) Descent(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.Descent)

Example 79 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class MultiLineStringWriter method write.

/**
 * @see GeometryWriter#write(XMLStreamWriter, Geometry, TypeDefinition,
 *      QName, String, DecimalFormat)
 */
@Override
public void write(XMLStreamWriter writer, MultiLineString geometry, TypeDefinition elementType, QName elementName, String gmlNs, DecimalFormat decimalFormatter) throws XMLStreamException {
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
        if (i > 0) {
            writer.writeStartElement(elementName.getNamespaceURI(), elementName.getLocalPart());
        }
        Descent descent = descend(// $NON-NLS-1$
        writer, // $NON-NLS-1$
        Pattern.parse("*/LineString"), elementType, elementName, gmlNs, false);
        LineString line = (LineString) geometry.getGeometryN(i);
        writeCoordinates(writer, line.getCoordinates(), descent.getPath().getLastType(), gmlNs, decimalFormatter);
        descent.close();
        if (i < geometry.getNumGeometries() - 1) {
            writer.writeEndElement();
        }
    }
}
Also used : LineString(org.locationtech.jts.geom.LineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) Descent(eu.esdihumboldt.hale.io.gml.writer.internal.geometry.Descent)

Example 80 with LineString

use of org.locationtech.jts.geom.LineString in project hale by halestudio.

the class PolygonWriter method write.

/**
 * @see GeometryWriter#write(XMLStreamWriter, Geometry, TypeDefinition,
 *      QName, String, DecimalFormat)
 */
@Override
public void write(XMLStreamWriter writer, Polygon polygon, TypeDefinition elementType, QName elementName, String gmlNs, DecimalFormat decimalFormatter) throws XMLStreamException {
    // write exterior ring
    LineString exterior = polygon.getExteriorRing();
    descendAndWriteCoordinates(// $NON-NLS-1$
    writer, // $NON-NLS-1$
    Pattern.parse("*/exterior/LinearRing"), exterior.getCoordinates(), elementType, elementName, gmlNs, false, decimalFormatter);
    // write interior rings
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LineString interior = polygon.getInteriorRingN(i);
        descendAndWriteCoordinates(// $NON-NLS-1$
        writer, // $NON-NLS-1$
        Pattern.parse("*/interior/LinearRing"), interior.getCoordinates(), elementType, elementName, gmlNs, false, decimalFormatter);
    }
}
Also used : LineString(org.locationtech.jts.geom.LineString)

Aggregations

LineString (org.locationtech.jts.geom.LineString)120 MultiLineString (org.locationtech.jts.geom.MultiLineString)48 Coordinate (org.locationtech.jts.geom.Coordinate)38 Geometry (org.locationtech.jts.geom.Geometry)35 Point (org.locationtech.jts.geom.Point)32 Test (org.junit.Test)24 Polygon (org.locationtech.jts.geom.Polygon)21 MultiPoint (org.locationtech.jts.geom.MultiPoint)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)14 WKTReader (org.locationtech.jts.io.WKTReader)13 ArrayList (java.util.ArrayList)12 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)12 HashMap (java.util.HashMap)10 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)9 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)9 ParseException (org.locationtech.jts.io.ParseException)9 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)8 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)7 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6