Search in sources :

Example 21 with LineString

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

the class CurveHelper method combineCurve.

/**
 * Combine the given {@link LineString}s to a single {@link LineString} if
 * possible.
 *
 * @param lineStrings the line strings
 * @param fact a geometry factory
 * @return the combined {@link LineString} or <code>null</code> if the
 *         geometry did not meet the requirements of the strict mode
 */
@Nullable
public static LineString combineCurve(List<? extends LineString> lineStrings, GeometryFactory fact) {
    return combineCurve(lineStrings, true, geoms -> {
        List<Coordinate> coordinates = new ArrayList<>();
        boolean skipFirst = false;
        for (LineString geom : geoms) {
            int index = 0;
            if (!skipFirst) {
                skipFirst = true;
            } else {
                index = 1;
            }
            for (int i = index; i < geom.getNumPoints(); i++) {
                coordinates.add(geom.getCoordinateN(i));
            }
        }
        return fact.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
    });
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) ArrayList(java.util.ArrayList) Nullable(javax.annotation.Nullable)

Example 22 with LineString

use of org.locationtech.jts.geom.LineString in project sldeditor by robward-scisys.

the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.

/**
 * Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
 * symbolizer type and the legend dimensions.
 *
 * @param symbolizer the Symbolizer for whose type a sample shape will be created
 * @param legendWidth the requested width, in output units, of the legend graphic
 * @param legendHeight the requested height, in output units, of the legend graphic
 * @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
 *     is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
 * @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
 */
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
    LiteShape2 sampleShape;
    final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
    final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
    if (symbolizer instanceof LineSymbolizer) {
        Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
        LineString geom = geomFac.createLineString(coords);
        try {
            this.sampleLine = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleLine = null;
        }
        sampleShape = this.sampleLine;
    } else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
        final float w = legendWidth - (2 * hpad) - 1;
        final float h = legendHeight - (2 * vpad) - 1;
        Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
        LinearRing shell = geomFac.createLinearRing(coords);
        Polygon geom = geomFac.createPolygon(shell, null);
        try {
            this.sampleRect = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleRect = null;
        }
        sampleShape = this.sampleRect;
    } else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
        Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
        try {
            this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
        } catch (Exception e) {
            this.samplePoint = null;
        }
        sampleShape = this.samplePoint;
    } else {
        throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
    }
    return sampleShape;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) LiteShape2(org.geotools.geometry.jts.LiteShape2) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

Example 23 with LineString

use of org.locationtech.jts.geom.LineString in project ddf by codice.

the class Wfs20JTStoGML321Converter method convertToPolygonType.

public static PolygonType convertToPolygonType(Polygon polygon, String srsName) {
    PolygonType polygonType = GML320_OBJECT_FACTORY.createPolygonType();
    // exterior
    LineString lineString = polygon.getExteriorRing();
    LinearRing linearRing = lineString.getFactory().createLinearRing(lineString.getCoordinateSequence());
    RingType ringType = convertToRingType(linearRing, srsName);
    JAXBElement<RingType> ringTypeJAXBElement = GML320_OBJECT_FACTORY.createRing(ringType);
    AbstractRingPropertyType abstractRingPropertyType = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
    abstractRingPropertyType.setAbstractRing(ringTypeJAXBElement);
    polygonType.setExterior(abstractRingPropertyType);
    // interiors
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LineString interiorRingN = polygon.getInteriorRingN(i);
        LinearRing linearRing1 = interiorRingN.getFactory().createLinearRing(interiorRingN.getCoordinateSequence());
        RingType ringType1 = convertToRingType(linearRing1, srsName);
        JAXBElement<RingType> ringTypeJAXBElement1 = GML320_OBJECT_FACTORY.createRing(ringType1);
        AbstractRingPropertyType abstractRingPropertyType1 = GML320_OBJECT_FACTORY.createAbstractRingPropertyType();
        abstractRingPropertyType1.setAbstractRing(ringTypeJAXBElement1);
        polygonType.getInterior().add(abstractRingPropertyType1);
    }
    polygonType.setSrsName(srsName);
    return polygonType;
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) AbstractRingPropertyType(net.opengis.gml.v_3_2_1.AbstractRingPropertyType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) RingType(net.opengis.gml.v_3_2_1.RingType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 24 with LineString

use of org.locationtech.jts.geom.LineString in project ddf by codice.

the class Wfs20JTStoGML321Converter method createGeometryPropertyType.

private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
    final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
    if (geometry instanceof Point) {
        PointType pointType = convertToPointType((Point) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
    } else if (geometry instanceof LineString) {
        LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
    } else if (geometry instanceof Polygon) {
        PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
    } else if (geometry instanceof MultiPoint) {
        MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
    } else if (geometry instanceof MultiLineString) {
        MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
    } else if (geometry instanceof MultiPolygon) {
        MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
    } else if (geometry instanceof GeometryCollection) {
        MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
    } else {
        throw new IllegalArgumentException();
    }
    return geometryPropertyType;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiCurveType(net.opengis.gml.v_3_2_1.MultiCurveType) MultiGeometryType(net.opengis.gml.v_3_2_1.MultiGeometryType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

Example 25 with LineString

use of org.locationtech.jts.geom.LineString in project ddf by codice.

the class WfsFilterDelegate method createGeometryOperand.

private JAXBElement<?> createGeometryOperand(String wkt) {
    String convertedWkt = convertWktToLatLonOrdering(wkt);
    Geometry wktGeometry = null;
    try {
        wktGeometry = getGeometryFromWkt(convertedWkt);
    } catch (ParseException e) {
        throw new UnsupportedOperationException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
    }
    if (wktGeometry instanceof Polygon) {
        GeometryOperand polygonOperand = new GeometryOperand();
        polygonOperand.setName(Wfs20Constants.POLYGON);
        if (isGeometryOperandSupported(polygonOperand)) {
            return createPolygon(wktGeometry);
        }
        GeometryOperand envelopeOperand = new GeometryOperand();
        envelopeOperand.setName(Wfs20Constants.ENVELOPE);
        if (isGeometryOperandSupported(envelopeOperand)) {
            return createEnvelope(wktGeometry);
        }
    } else if (wktGeometry instanceof Point) {
        GeometryOperand pointOperand = new GeometryOperand();
        pointOperand.setName(Wfs20Constants.POINT);
        if (isGeometryOperandSupported(pointOperand)) {
            return createPoint(wktGeometry);
        }
    } else if (wktGeometry instanceof LineString) {
        GeometryOperand lineStringOperand = new GeometryOperand();
        lineStringOperand.setName(Wfs20Constants.LINESTRING);
        if (isGeometryOperandSupported(lineStringOperand)) {
            return createLineString(wktGeometry);
        }
    }
    throw new UnsupportedOperationException(MessageFormat.format(NOT_SUPPORTED_MSG, "Geometry Operand from WKT", convertedWkt));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryOperand(net.opengis.filter.v_2_0_0.GeometryOperandsType.GeometryOperand) LineString(org.locationtech.jts.geom.LineString) LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException) Point(org.locationtech.jts.geom.Point) Polygon(org.locationtech.jts.geom.Polygon)

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