Search in sources :

Example 36 with Point

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

the class SolrFilterDelegate method nearestNeighbor.

@Override
public SolrQuery nearestNeighbor(String propertyName, String wkt) {
    Geometry geo = getGeometry(wkt);
    if (geo != null) {
        Point pnt;
        if (isPoint(geo)) {
            pnt = (Point) geo;
        } else {
            pnt = geo.getCentroid();
        }
        SolrQuery query = null;
        if (null != pnt) {
            String nearestNeighborQuery = geoPointToCircleQuery(propertyName, NEAREST_NEIGHBOR_DISTANCE_LIMIT, pnt);
            updateDistanceSort(propertyName, pnt);
            query = new SolrQuery(nearestNeighborQuery);
        }
        return query;
    } else {
        throw new UnsupportedOperationException("Unable to read given WKT: " + 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 37 with Point

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

the class SolrFilterDelegate method dwithin.

@Override
public SolrQuery dwithin(String propertyName, String wkt, double distance) {
    Geometry geo = getGeometry(wkt);
    if (geo != null) {
        double distanceInDegrees = metersToDegrees(distance);
        if (isPoint(geo)) {
            Point pnt = (Point) geo;
            String pointRadiusQuery = geoPointToCircleQuery(propertyName, distanceInDegrees, pnt);
            updateDistanceSort(propertyName, pnt);
            return new SolrQuery(pointRadiusQuery);
        } else {
            Geometry bufferGeo = geo.buffer(distanceInDegrees, QUADRANT_SEGMENTS);
            String bufferWkt = WKT_WRITER.write(bufferGeo);
            return operationToQuery(INTERSECTS_OPERATION, propertyName, bufferWkt);
        }
    } else {
        throw new UnsupportedOperationException("Unable to read given WKT: " + 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 38 with Point

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

the class Wfs20JTStoGML321Converter method convertToMultiPointType.

public static MultiPointType convertToMultiPointType(MultiPoint multiPoint, String srsName) {
    MultiPointType multiPointType = GML320_OBJECT_FACTORY.createMultiPointType();
    for (int i = 0; i < multiPoint.getNumGeometries(); i++) {
        Point point = (Point) multiPoint.getGeometryN(i);
        PointPropertyType pointPropertyType = GML320_OBJECT_FACTORY.createPointPropertyType();
        pointPropertyType.setPoint(convertToPointType(point, srsName));
        multiPointType.getPointMember().add(pointPropertyType);
    }
    multiPointType.setSrsName(srsName);
    return multiPointType;
}
Also used : Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) PointPropertyType(net.opengis.gml.v_3_2_1.PointPropertyType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 39 with Point

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

the class TwitterFilterVisitor method visit.

/**
     * Intersects filter maps to a Polygon or BBox Spatial search criteria.
     */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.trace("ENTERING: Intersects 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 Intersects filter is supported");
        }
    } else {
        LOGGER.warn(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: Intersects 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 40 with Point

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

the class KMLTransformerImpl method createKmlGeo.

private Geometry createKmlGeo(com.vividsolutions.jts.geom.Geometry geo) throws CatalogTransformerException {
    Geometry kmlGeo = null;
    if (Point.class.getSimpleName().equals(geo.getGeometryType())) {
        Point jtsPoint = (Point) geo;
        kmlGeo = KmlFactory.createPoint().addToCoordinates(jtsPoint.getX(), jtsPoint.getY());
    } else if (LineString.class.getSimpleName().equals(geo.getGeometryType())) {
        LineString jtsLS = (LineString) geo;
        de.micromata.opengis.kml.v_2_2_0.LineString kmlLS = KmlFactory.createLineString();
        List<Coordinate> kmlCoords = kmlLS.createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsLS.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlLS;
    } else if (Polygon.class.getSimpleName().equals(geo.getGeometryType())) {
        Polygon jtsPoly = (Polygon) geo;
        de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
        List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsPoly.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlPoly;
    } else if (geo instanceof GeometryCollection) {
        List<Geometry> geos = new ArrayList<Geometry>();
        for (int xx = 0; xx < geo.getNumGeometries(); xx++) {
            geos.add(createKmlGeo(geo.getGeometryN(xx)));
        }
        kmlGeo = KmlFactory.createMultiGeometry().withGeometry(geos);
    } else {
        throw new CatalogTransformerException("Unknown / Unsupported Geometry Type '" + geo.getGeometryType() + "'. Unale to preform KML Transform.");
    }
    return kmlGeo;
}
Also used : CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Point(com.vividsolutions.jts.geom.Point) Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) List(java.util.List) ArrayList(java.util.ArrayList) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

Point (com.vividsolutions.jts.geom.Point)48 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 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)10 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 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 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3