Search in sources :

Example 31 with Polygon

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

the class OpenSearchParserImplTest method populateMultipleSearchesSpatial.

@Test
public void populateMultipleSearchesSpatial() throws ParseException {
    double lat = 43.25;
    double lon = -123.45;
    double radius = 10000;
    final PointRadius pointRadius = new PointRadius(lon, lat, radius);
    final Polygon polygon = GEOMETRY_FACTORY.createPolygon(GEOMETRY_FACTORY.createLinearRing(new Coordinate[] { new Coordinate(1, 1), new Coordinate(5, 1), new Coordinate(5, 5), new Coordinate(1, 5), new Coordinate(1, 1) }), null);
    final Geometry geometry = new WKTReader().read(WKT_GEOMETRY);
    final BoundingBox boundingBox = new BoundingBox(170, 50, -150, 60);
    openSearchParser.populateSpatial(webClient, geometry, boundingBox, polygon, pointRadius, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,geometry,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    assertQueryParameterPopulated(OpenSearchConstants.GEOMETRY, WKT_GEOMETRY);
    assertQueryParameterPopulated(OpenSearchConstants.POLYGON, "1.0,1.0,1.0,5.0,5.0,5.0,5.0,1.0,1.0,1.0");
    assertQueryParameterPopulated(OpenSearchConstants.BBOX, "170.0,50.0,-150.0,60.0");
    assertQueryParameterPopulated(OpenSearchConstants.LAT, String.valueOf(lat));
    assertQueryParameterPopulated(OpenSearchConstants.LON, String.valueOf(lon));
    assertQueryParameterPopulated(OpenSearchConstants.RADIUS, String.valueOf(radius));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate) Polygon(org.locationtech.jts.geom.Polygon) WKTReader(org.locationtech.jts.io.WKTReader) Test(org.junit.Test)

Example 32 with Polygon

use of org.locationtech.jts.geom.Polygon 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 33 with Polygon

use of org.locationtech.jts.geom.Polygon 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)

Example 34 with Polygon

use of org.locationtech.jts.geom.Polygon in project arctic-sea by 52North.

the class GeoJSONDecoder method decodeMultiPolygon.

protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
    JsonNode coordinates = requireCoordinates(node);
    Polygon[] polygons = new Polygon[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
    }
    return fac.createMultiPolygon(polygons);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 35 with Polygon

use of org.locationtech.jts.geom.Polygon in project presto by prestodb.

the class JtsGeometrySerde method readPolygon.

private static Geometry readPolygon(SliceInput input, boolean multitype) {
    skipEsriType(input);
    skipEnvelope(input);
    int partCount = input.readInt();
    if (partCount == 0) {
        if (multitype) {
            return GEOMETRY_FACTORY.createMultiPolygon();
        }
        return GEOMETRY_FACTORY.createPolygon();
    }
    int pointCount = input.readInt();
    int[] startIndexes = new int[partCount];
    for (int i = 0; i < partCount; i++) {
        startIndexes[i] = input.readInt();
    }
    int[] partLengths = new int[partCount];
    if (partCount > 1) {
        partLengths[0] = startIndexes[1];
        for (int i = 1; i < partCount - 1; i++) {
            partLengths[i] = startIndexes[i + 1] - startIndexes[i];
        }
    }
    partLengths[partCount - 1] = pointCount - startIndexes[partCount - 1];
    LinearRing shell = null;
    List<LinearRing> holes = new ArrayList<>();
    List<Polygon> polygons = new ArrayList<>();
    try {
        for (int i = 0; i < partCount; i++) {
            Coordinate[] coordinates = readCoordinates(input, partLengths[i]);
            if (isClockwise(coordinates)) {
                // next polygon has started
                if (shell != null) {
                    polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
                    holes.clear();
                }
                shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
            } else {
                holes.add(GEOMETRY_FACTORY.createLinearRing(coordinates));
            }
        }
        polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
    } catch (IllegalArgumentException e) {
        throw new TopologyException("Error constructing Polygon: " + e.getMessage());
    }
    if (multitype) {
        return GEOMETRY_FACTORY.createMultiPolygon(polygons.toArray(new Polygon[0]));
    }
    return getOnlyElement(polygons);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) TopologyException(org.locationtech.jts.geom.TopologyException)

Aggregations

Polygon (org.locationtech.jts.geom.Polygon)56 LineString (org.locationtech.jts.geom.LineString)23 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)22 Point (org.locationtech.jts.geom.Point)22 Geometry (org.locationtech.jts.geom.Geometry)20 Coordinate (org.locationtech.jts.geom.Coordinate)16 MultiPoint (org.locationtech.jts.geom.MultiPoint)15 Test (org.junit.Test)13 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)11 LinearRing (org.locationtech.jts.geom.LinearRing)10 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 MultiLineString (org.locationtech.jts.geom.MultiLineString)8 ArrayList (java.util.ArrayList)7 Test (org.junit.jupiter.api.Test)6 DimensionInfo (org.apache.jena.geosparql.implementation.DimensionInfo)5 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)5 WKTReader (org.locationtech.jts.io.WKTReader)5 AreaIndex (com.graphhopper.routing.util.AreaIndex)4 CustomArea (com.graphhopper.routing.util.CustomArea)3 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)3