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");
}
Aggregations