Search in sources :

Example 1 with CoordinateTransformer

use of io.georocket.util.CoordinateTransformer in project georocket by georocket.

the class BoundingBoxIndexerFactory method compileQuery.

@Override
public JsonObject compileQuery(String search) {
    CoordinateReferenceSystem crs = null;
    String crsCode = null;
    String co;
    int index = search.lastIndexOf(':');
    if (index > 0) {
        crsCode = search.substring(0, index);
        co = search.substring(index + 1);
    } else {
        co = search;
    }
    double[] points = Arrays.stream(co.split(",")).map(String::trim).mapToDouble(Double::parseDouble).toArray();
    if (crsCode != null) {
        try {
            crs = CRS.decode(crsCode);
        } catch (FactoryException e) {
            throw new RuntimeException(String.format("CRS %s could not be parsed: %s", crsCode, e.getMessage()), e);
        }
    } else if (defaultCrs != null) {
        try {
            crs = CoordinateTransformer.decode(defaultCrs);
        } catch (FactoryException e) {
            throw new RuntimeException(String.format("Default CRS %s could not be parsed: %s", defaultCrs, e.getMessage()), e);
        }
    }
    if (crs != null) {
        try {
            CoordinateTransformer transformer = new CoordinateTransformer(crs);
            points = transformer.transform(points, -1);
        } catch (FactoryException e) {
            throw new RuntimeException(String.format("CRS %s could not be parsed: %s", crsCode, e.getMessage()), e);
        } catch (TransformException e) {
            throw new RuntimeException(String.format("Coordinates %s could not be " + "transformed to %s: %s", co, crsCode, e.getMessage()), e);
        }
    }
    double minX = points[0];
    double minY = points[1];
    double maxX = points[2];
    double maxY = points[3];
    JsonArray coordinates = new JsonArray();
    coordinates.add(new JsonArray().add(minX).add(maxY));
    coordinates.add(new JsonArray().add(maxX).add(minY));
    return geoShapeQuery("bbox", shape("envelope", coordinates), "intersects");
}
Also used : JsonArray(io.vertx.core.json.JsonArray) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateTransformer(io.georocket.util.CoordinateTransformer) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

CoordinateTransformer (io.georocket.util.CoordinateTransformer)1 JsonArray (io.vertx.core.json.JsonArray)1 FactoryException (org.opengis.referencing.FactoryException)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 TransformException (org.opengis.referencing.operation.TransformException)1