Search in sources :

Example 11 with Point

use of com.vividsolutions.jts.geom.Point in project ddf by codice.

the class SolrFilterDelegate method intersects.

@Override
public SolrQuery intersects(String propertyName, String wkt) {
    // error.
    if (StringUtils.isNotBlank(wkt) && wkt.toUpperCase().contains("POINT")) {
        Geometry geo = getGeometry(wkt);
        if (geo != null) {
            if (isPoint(geo)) {
                Point pnt = (Point) geo;
                String pointRadiusQuery = geoPointToCircleQuery(propertyName, DEFAULT_ERROR_IN_DEGREES, pnt);
                updateDistanceSort(propertyName, pnt);
                return new SolrQuery(pointRadiusQuery);
            }
            if (MultiPoint.class.getSimpleName().equals(geo.getGeometryType()) && geo.getCoordinates().length == 1) {
                Point pnt = GEOMETRY_FACTORY.createPoint(geo.getCoordinate());
                String pointRadiusQuery = geoPointToCircleQuery(propertyName, DEFAULT_ERROR_IN_DEGREES, pnt);
                updateDistanceSort(propertyName, pnt);
                return new SolrQuery(pointRadiusQuery);
            }
        }
    }
    return operationToQuery(INTERSECTS_OPERATION, propertyName, wkt);
}
Also used : JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 12 with Point

use of com.vividsolutions.jts.geom.Point 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("Geometry Operand from WKT [" + convertedWkt + "] is not supported.");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryOperand(net.opengis.filter.v_2_0_0.GeometryOperandsType.GeometryOperand) LineString(com.vividsolutions.jts.geom.LineString) LineString(com.vividsolutions.jts.geom.LineString) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 13 with Point

use of com.vividsolutions.jts.geom.Point 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(com.vividsolutions.jts.geom.MultiPoint) MultiLineString(com.vividsolutions.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(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

Example 14 with Point

use of com.vividsolutions.jts.geom.Point in project ddf by codice.

the class TwitterFilterVisitor method visit.

/**
     * Contains filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Contains filter, Object data) {
    LOGGER.trace("ENTERING: Contains filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl@64a7c45e</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        Object geometryExpression = literalWrapper.getValue();
        if (geometryExpression instanceof SurfaceImpl) {
            SurfaceImpl polygon = (SurfaceImpl) literalWrapper.evaluate(null);
            Point point = polygon.getJTSGeometry().getCentroid();
            longitude = point.getX();
            latitude = point.getY();
            radius = point.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else if (geometryExpression instanceof Polygon) {
            Polygon polygon = (Polygon) geometryExpression;
            Point centroid = polygon.getCentroid();
            longitude = centroid.getX();
            latitude = centroid.getY();
            radius = polygon.getBoundary().getLength() * 10;
            hasSpatial = true;
            filters.add(filter);
        } else {
            LOGGER.warn("Only POLYGON geometry WKT for Contains filter is supported");
        }
    } else {
        LOGGER.warn(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Contains filter");
    return super.visit(filter, data);
}
Also used : Literal(org.opengis.filter.expression.Literal) SurfaceImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 15 with Point

use of com.vividsolutions.jts.geom.Point in project ddf by codice.

the class TwitterFilterVisitor method visit.

/**
     * DWithin filter maps to a Point/Radius distance Spatial search criteria.
     */
@Override
public Object visit(DWithin filter, Object data) {
    LOGGER.trace("ENTERING: DWithin filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl@dc33f184</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        // Luckily we know what type the geometry expression should be, so
        // we
        // can cast it
        Point point = (Point) literalWrapper.evaluate(null);
        Coordinate coords = point.getCentroid().getCoordinate();
        double distance = filter.getDistance();
        LOGGER.debug("point: coords[0] = {},   coords[1] = {}", coords.x, coords.y);
        LOGGER.debug("radius = {}", distance);
        longitude = coords.x;
        latitude = coords.y;
        radius = distance / 1000;
        hasSpatial = true;
        filters.add(filter);
    } else {
        LOGGER.warn(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: DWithin filter");
    return super.visit(filter, data);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) Literal(org.opengis.filter.expression.Literal) Point(com.vividsolutions.jts.geom.Point)

Aggregations

Point (com.vividsolutions.jts.geom.Point)46 Coordinate (com.vividsolutions.jts.geom.Coordinate)20 Geometry (com.vividsolutions.jts.geom.Geometry)15 Test (org.junit.Test)12 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)11 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)9 Polygon (com.vividsolutions.jts.geom.Polygon)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)4 ParseException (com.vividsolutions.jts.io.ParseException)4 ArrayList (java.util.ArrayList)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 StringReader (java.io.StringReader)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3