Search in sources :

Example 26 with Geometry

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

the class PredicateTest method testGeospatialEvaluatorPointRadiusContains.

@Test
public void testGeospatialEvaluatorPointRadiusContains() throws Exception {
    LOGGER.debug("**************************  START: testGeospatialEvaluator_PointRadius_Contains()  ***********************");
    // WKT specifies points in LON LAT order
    String geometryWkt = "POINT (44.5 34.5)";
    String operation = "point_radius";
    // 0.6 degrees
    double distance = 0.6 * NM_PER_DEG_LAT * METERS_PER_NM;
    // latitude in
    // meters
    double radiusInDegrees = (distance * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
    LOGGER.debug("distance (in meters) = " + distance + ",   radiusInDegrees = " + radiusInDegrees);
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, radiusInDegrees);
    Geometry geoCriteria = predicate.getGeoCriteria();
    LOGGER.debug("geoCriteria.toText() = {}", geoCriteria.toText());
    String geospatialXml = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"BGE-1\">\n" + "    <gml:exterior>\n" + "        <gml:LinearRing>\n" + "            <gml:pos>34.0 44.0</gml:pos>\n" + "            <gml:pos>33.0 44.0</gml:pos>\n" + "            <gml:pos>33.0 45.0</gml:pos>\n" + "            <gml:pos>34.0 45.0</gml:pos>\n" + "            <gml:pos>34.0 44.0</gml:pos>\n" + "        </gml:LinearRing>\n" + "    </gml:exterior>\n" + "</gml:Polygon>";
    Geometry input = GeospatialEvaluator.buildGeometry(geospatialXml);
    LOGGER.debug("input.toText() = {}", input.toText());
    GeospatialEvaluationCriteria gec = new GeospatialEvaluationCriteriaImpl(geoCriteria, operation, input, radiusInDegrees);
    boolean status = GeospatialEvaluator.evaluate(gec);
    assertTrue(status);
    LOGGER.debug("**************************  END: testGeospatialEvaluator_PointRadius_Contains()  ***********************");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeospatialEvaluationCriteria(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) GeospatialEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl) Test(org.junit.Test)

Example 27 with Geometry

use of com.vividsolutions.jts.geom.Geometry 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 28 with Geometry

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

the class SolrFilterDelegate method operationToQuery.

private SolrQuery operationToQuery(String operation, String propertyName, String wkt) {
    String geoIndexName = getMappedPropertyName(propertyName, AttributeFormat.GEOMETRY, false);
    if (!StringUtils.isNotEmpty(wkt)) {
        throw new UnsupportedOperationException("Wkt should not be null or empty.");
    }
    String geoQuery = geoIndexName + ":\"" + operation + "(" + fixSelfIntersectingGeometry(wkt) + ")\"";
    Geometry pnt = getGeometry(wkt);
    if (pnt != null) {
        updateDistanceSort(propertyName, pnt.getCentroid());
    }
    return new SolrQuery(geoQuery);
}
Also used : JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 29 with Geometry

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

the class CswFilterFactory method getEnvelopeFromWkt.

private Envelope getEnvelopeFromWkt(String wkt) {
    Geometry geo = getGeometryFromWkt(wkt);
    Envelope envelope = geo.getEnvelopeInternal();
    return envelope;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 30 with Geometry

use of com.vividsolutions.jts.geom.Geometry 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)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)123 WKTReader (com.vividsolutions.jts.io.WKTReader)35 Test (org.junit.Test)31 Coordinate (com.vividsolutions.jts.geom.Coordinate)23 Point (com.vividsolutions.jts.geom.Point)21 ParseException (com.vividsolutions.jts.io.ParseException)19 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)14 Envelope (com.vividsolutions.jts.geom.Envelope)13 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)13 WKTWriter (com.vividsolutions.jts.io.WKTWriter)13 ArrayList (java.util.ArrayList)12 LineString (com.vividsolutions.jts.geom.LineString)10 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)9 Metacard (ddf.catalog.data.Metacard)9 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Optional (com.google.common.base.Optional)6 IOException (java.io.IOException)6 RevFeature (org.locationtech.geogig.api.RevFeature)6 JtsGeometry (org.locationtech.spatial4j.shape.jts.JtsGeometry)6 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)5