Search in sources :

Example 96 with Geometry

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

the class TestWfs10JTStoGML200Converter method testTwo.

@Test
public void testTwo() throws Exception {
    Geometry geometryFromWkt = getGeometryFromWkt(GEOMETRYCOLLECTION);
    String gml = Wfs10JTStoGML200Converter.convertGeometryCollectionToGML(geometryFromWkt);
    GeometryCollectionType geometryCollectionType = (GeometryCollectionType) Wfs10JTStoGML200Converter.convertGMLToGeometryType(gml, Wfs10Constants.GEOMETRY_COLLECTION);
    JAXBElement<GeometryCollectionType> jaxbElement = (JAXBElement<GeometryCollectionType>) Wfs10JTStoGML200Converter.convertGeometryTypeToJAXB(geometryCollectionType);
    assertFalse(jaxbElement == null);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollectionType(ogc.schema.opengis.gml.v_2_1_2.GeometryCollectionType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 97 with Geometry

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

the class GeoJsonMetacardTransformer method convertValue.

private static Object convertValue(Serializable value, AttributeType.AttributeFormat format) throws CatalogTransformerException {
    if (value == null) {
        return null;
    }
    switch(format) {
        case BOOLEAN:
            return value;
        case DATE:
            SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_8601_DATE_FORMAT);
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            return dateFormat.format((Date) value);
        case BINARY:
            byte[] bytes = (byte[]) value;
            String base64 = DatatypeConverter.printBase64Binary(bytes);
            return base64;
        case DOUBLE:
        case LONG:
        case FLOAT:
        case INTEGER:
        case SHORT:
        case STRING:
        case XML:
            return value.toString();
        case GEOMETRY:
            WKTReader reader = new WKTReader();
            try {
                Geometry geometry = reader.read(value.toString());
                CompositeGeometry geoJsonGeometry = CompositeGeometry.getCompositeGeometry(geometry);
                if (geoJsonGeometry == null) {
                    throw new CatalogTransformerException("Could not perform transform: unsupported geometry [" + value + "]");
                }
                return geoJsonGeometry.toJsonMap();
            } catch (ParseException e) {
                throw new CatalogTransformerException("Could not perform transform: could not parse geometry [" + value + "]", e);
            }
        case OBJECT:
        default:
            return null;
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) CompositeGeometry(ddf.geo.formatter.CompositeGeometry) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ParseException(com.vividsolutions.jts.io.ParseException) MimeTypeParseException(javax.activation.MimeTypeParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) SimpleDateFormat(java.text.SimpleDateFormat)

Example 98 with Geometry

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

the class TestGeoJsonInputTransformer method testLineStringGeo.

@Test
public void testLineStringGeo() throws IOException, CatalogTransformerException, ParseException {
    InputStream inputStream = new ByteArrayInputStream(sampleLineStringJsonText().getBytes());
    Metacard metacard = transformer.transform(inputStream);
    verifyBasics(metacard);
    WKTReader reader = new WKTReader();
    Geometry geometry = reader.read(metacard.getLocation());
    Coordinate[] coords = geometry.getCoordinates();
    assertThat(coords[0].x, is(30.0));
    assertThat(coords[0].y, is(10.0));
    assertThat(coords[1].x, is(10.0));
    assertThat(coords[1].y, is(30.0));
    assertThat(coords[2].x, is(40.0));
    assertThat(coords[2].y, is(40.0));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) Coordinate(com.vividsolutions.jts.geom.Coordinate) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 99 with Geometry

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

the class OverlayMetacardTransformer method parseBoundary.

private List<Vector> parseBoundary(String location) throws CatalogTransformerException {
    final Geometry geometry = parseGeometry(location);
    if (!canHandleGeometry(geometry)) {
        throw new CatalogTransformerException("The Image boundary is not a rectangle");
    }
    final Coordinate[] coordinates = geometry.getCoordinates();
    List<Vector> boundary = new ArrayList<>();
    // Using indices rather than for-each because the first coordinate is duplicated.
    for (int i = 0; i < 4; i++) {
        boundary.add(new BasicVector(new double[] { coordinates[i].x, coordinates[i].y }));
    }
    return boundary;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryUtils.parseGeometry(ddf.catalog.transformer.GeometryUtils.parseGeometry) GeometryUtils.canHandleGeometry(ddf.catalog.transformer.GeometryUtils.canHandleGeometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) BasicVector(org.la4j.vector.dense.BasicVector) Vector(org.la4j.Vector) BasicVector(org.la4j.vector.dense.BasicVector)

Example 100 with Geometry

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

the class PredicateTest method testGeospatialEvaluatorPointRadiusNotContains.

@Test
public void testGeospatialEvaluatorPointRadiusNotContains() throws Exception {
    LOGGER.debug("**************************  START: testGeospatialEvaluator_PointRadius_NotContains()  ***********************");
    // WKT specifies points in LON LAT order
    String geometryWkt = "POINT (44.5 34.5)";
    String operation = "point_radius";
    double distance = 5000.0;
    double radiusInDegrees = (distance * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
    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>24.0 22.0</gml:pos>\n" + "            <gml:pos>23.0 22.0</gml:pos>\n" + "            <gml:pos>23.0 24.0</gml:pos>\n" + "            <gml:pos>24.0 24.0</gml:pos>\n" + "            <gml:pos>24.0 22.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);
    assertFalse(status);
    LOGGER.debug("**************************  END: testGeospatialEvaluator_PointRadius_NotContains()  ***********************");
}
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)

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