Search in sources :

Example 6 with GeometryNotSupportedException

use of eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException in project hale by halestudio.

the class PolygonHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@SuppressWarnings("unchecked")
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    LinearRing[] holes = null;
    Polygon polygon = null;
    CRSDefinition crs = null;
    // for use with GML 2
    // to parse outer linear rings
    Collection<Object> values = PropertyResolver.getValues(instance, "outerBoundaryIs.LinearRing", false);
    if (values != null && !values.isEmpty()) {
        Iterator<Object> iterator = values.iterator();
        List<LinearRing> outerRing = new ArrayList<>(1);
        while (iterator.hasNext()) {
            Object value = iterator.next();
            if (value instanceof Instance) {
                // outerRing must be a
                // GeometryProperty<LinearRing> instance
                GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                outerRing.add(ring.getGeometry());
                crs = checkCommonCrs(crs, ring.getCRSDefinition());
            }
        }
        // to parse inner linear rings
        values = PropertyResolver.getValues(instance, "innerBoundaryIs.LinearRing", false);
        if (values != null && !values.isEmpty()) {
            iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
    }
    // to parse inner linear rings
    if (polygon == null) {
        values = PropertyResolver.getValues(instance, "interior.LinearRing", false);
        Collection<Object> ringValues = PropertyResolver.getValues(instance, "interior.Ring", false);
        values = combineCollections(values, ringValues);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<LinearRing> innerRings = new ArrayList<LinearRing>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // innerRings have to be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    innerRings.add(ring.getGeometry());
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            holes = innerRings.toArray(new LinearRing[innerRings.size()]);
        }
        // to parse outer linear rings
        values = PropertyResolver.getValues(instance, "exterior.LinearRing", false);
        ringValues = PropertyResolver.getValues(instance, "exterior.Ring", false);
        values = combineCollections(values, ringValues);
        List<LinearRing> outerRing = new ArrayList<>(1);
        if (values != null && !values.isEmpty()) {
            LinearRing outer = null;
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    // outerRing must be a
                    // GeometryProperty<LinearRing> instance
                    GeometryProperty<LinearRing> ring = (GeometryProperty<LinearRing>) ((Instance) value).getValue();
                    outer = ring.getGeometry();
                    crs = checkCommonCrs(crs, ring.getCRSDefinition());
                }
            }
            outerRing.add(outer);
            polygon = getGeometryFactory().createPolygon(outerRing.get(0), holes);
        }
    }
    if (polygon != null) {
        if (crs == null) {
            crs = GMLGeometryUtil.findCRS(instance);
        }
        return new DefaultGeometryProperty<Polygon>(crs, polygon);
    }
    throw new GeometryNotSupportedException();
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 7 with GeometryNotSupportedException

use of eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException in project hale by halestudio.

the class ArcHandler method createGeometry.

@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    // read arc to LineString
    @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 must be defined by three points");
    }
    Arc arc = new ArcByPointsImpl(coords[0], coords[1], coords[2]);
    // get interpolation algorithm
    InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
    LineString interpolatedArc = interpol.interpolateArc(arc);
    if (interpolatedArc == null) {
        log.error("Arc could be not interpolated to Linestring");
        return null;
    }
    return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedArc);
}
Also used : 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(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)

Example 8 with GeometryNotSupportedException

use of eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException 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 += 3) {
        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(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArcStringImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)

Example 9 with GeometryNotSupportedException

use of eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException 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(com.vividsolutions.jts.geom.Point) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ParseException(java.text.ParseException)

Example 10 with GeometryNotSupportedException

use of eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException in project hale by halestudio.

the class EnvelopeHandler method createGeometry.

/**
 * @see GeometryHandler#createGeometry(Instance, int, IOProvider)
 */
@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    MultiPoint envelope = null;
    List<Point> points = new ArrayList<Point>();
    Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
    if (values != null && !values.isEmpty()) {
        Iterator<Object> iterator = values.iterator();
        while (iterator.hasNext()) {
            Object value = iterator.next();
            if (value instanceof Instance) {
                try {
                    Coordinate[] cs = GMLGeometryUtil.parseCoordinates((Instance) value);
                    if (cs != null && cs.length > 0) {
                        points.add(getGeometryFactory().createPoint(cs[0]));
                    }
                } catch (ParseException e) {
                    throw new GeometryNotSupportedException("Could not parse coordinates", e);
                }
            }
        }
    }
    if (points.isEmpty()) {
        values = PropertyResolver.getValues(instance, "pos", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
                    if (c != null) {
                        points.add(getGeometryFactory().createPoint(c));
                    }
                }
            }
        }
    }
    if (points.isEmpty()) {
        values = PropertyResolver.getValues(instance, "coord", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
                    if (c != null) {
                        points.add(getGeometryFactory().createPoint(c));
                    }
                }
            }
        }
    }
    if (!points.isEmpty()) {
        Coordinate[] coordinates = new Coordinate[] { points.get(0).getCoordinate(), points.get(1).getCoordinate() };
        coordinates = InterpolationHelper.moveCoordinates(reader, coordinates);
        envelope = getGeometryFactory().createMultiPoint(coordinates);
    }
    if (envelope != null) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        return new DefaultGeometryProperty<MultiPoint>(crsDef, envelope);
    }
    throw new GeometryNotSupportedException();
}
Also used : MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) Coordinate(com.vividsolutions.jts.geom.Coordinate) ParseException(java.text.ParseException)

Aggregations

GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)12 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)11 Coordinate (com.vividsolutions.jts.geom.Coordinate)8 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)8 LineString (com.vividsolutions.jts.geom.LineString)7 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)6 ArrayList (java.util.ArrayList)6 Point (com.vividsolutions.jts.geom.Point)5 InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)5 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)5 ParseException (java.text.ParseException)5 LinearRing (com.vividsolutions.jts.geom.LinearRing)3 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)3 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)3 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)3 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 Geometries (eu.esdihumboldt.hale.io.gml.geometry.Geometries)1 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)1