use of org.n52.io.crs.CRSUtils in project series-rest-api by 52North.
the class IoParameters method extendBy.
/**
* Extends the bounding box with the given point. If point is contained by this instance nothing is
* changed.
*
* @param point
* the point in CRS:84 which shall extend the bounding box.
*/
private void extendBy(Point point, BoundingBox bbox) {
if (bbox.contains(point)) {
return;
}
double llX = Math.min(point.getX(), bbox.getLowerLeft().getX());
double llY = Math.max(point.getX(), bbox.getUpperRight().getX());
double urX = Math.min(point.getY(), bbox.getLowerLeft().getY());
double urY = Math.max(point.getY(), bbox.getUpperRight().getY());
CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
bbox.setLl(crsUtils.createPoint(llX, llY, bbox.getSrs()));
bbox.setUr(crsUtils.createPoint(urX, urY, bbox.getSrs()));
}
use of org.n52.io.crs.CRSUtils in project series-rest-api by 52North.
the class IoParameters method mergeBounds.
private BoundingBox mergeBounds(BoundingBox bounds, BBox bboxBounds) {
if (bboxBounds == null) {
// nothing to merge
return bounds;
}
CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
Point lowerLeft = crsUtils.convertToPointFrom(bboxBounds.getLl());
Point upperRight = crsUtils.convertToPointFrom(bboxBounds.getUr());
if (bounds == null) {
BoundingBox parsed = new BoundingBox(lowerLeft, upperRight, CRSUtils.DEFAULT_CRS);
LOGGER.debug("Parsed bbox bounds: {}", parsed.toString());
return parsed;
} else {
extendBy(lowerLeft, bounds);
extendBy(upperRight, bounds);
LOGGER.debug("Merged bounds: {}", bounds.toString());
return bounds;
}
}
use of org.n52.io.crs.CRSUtils in project series-rest-api by 52North.
the class IoParameters method createBbox.
/**
* @return a {@link BBox} instance or <code>null</code> if no {@link #BBOX} parameter is present.
* @throws IoParseException
* if parsing parameter fails.
* @throws IoParseException
* if a requested {@value #CRS} object could not be created
*/
private BoundingBox createBbox() {
if (!containsParameter(BBOX)) {
return null;
}
String bboxValue = getAsString(BBOX);
CRSUtils crsUtils = CRSUtils.createEpsgForcedXYAxisOrder();
// Check if supplied in minx,miny,maxx,maxy format - else assume json
if (bboxMatching(bboxValue, 3)) {
String[] coordArray = bboxValue.split(SPLIT_REGEX);
Point lowerLeft = crsUtils.createPoint(Double.valueOf(coordArray[0].trim()), Double.valueOf(coordArray[1].trim()), CRSUtils.DEFAULT_CRS);
Point upperRight = crsUtils.createPoint(Double.valueOf(coordArray[2].trim()), Double.valueOf(coordArray[3].trim()), CRSUtils.DEFAULT_CRS);
return new BoundingBox(lowerLeft, upperRight, CRSUtils.DEFAULT_CRS);
}
try {
BBox bbox = handleJsonValueParseException(BBOX, BBox.class, this::parseJson);
return new BoundingBox(bbox.getLl(), bbox.getUr(), CRSUtils.DEFAULT_CRS);
} catch (IoParseException e) {
throw e.addHint(createInvalidParameterMessage(Parameters.BBOX)).addHint("Check http://epsg-registry.org for EPSG CRS definitions and codes.").addHint("(alternate format of 'llLon,llLat,urLon,urLat' couldn't be detected)");
}
}
use of org.n52.io.crs.CRSUtils in project series-rest-api by 52North.
the class Vicinity method calculateBounds.
/**
* Calculates bounding box with the given CRS context.
*
* @param crsUtils the reference context.
* @return a bounding rectangle.
* @throws IllegalStateException if invalid crs was set.
*/
public BoundingBox calculateBounds(CRSUtils crsUtils) {
double latInRad = Math.toRadians(center.getY());
final double latitudeDelta = WGS84Util.getLatitudeDelta(radius);
final double longitudeDelta = WGS84Util.getLongitudeDelta(latInRad, radius);
double llEasting = WGS84Util.normalizeLongitude(center.getX() - longitudeDelta);
double llNorthing = WGS84Util.normalizeLatitude(center.getY() - latitudeDelta);
double urEasting = WGS84Util.normalizeLongitude(center.getX() + longitudeDelta);
double urNorthing = WGS84Util.normalizeLatitude(center.getY() + latitudeDelta);
try {
if (crsUtils.isLatLonAxesOrder(crs)) {
Point ll = crsUtils.createPoint(llNorthing, llEasting, crs);
Point ur = crsUtils.createPoint(urNorthing, urEasting, crs);
return new BoundingBox(ll, ur, crs);
}
Point ll = crsUtils.createPoint(llEasting, llNorthing, crs);
Point ur = crsUtils.createPoint(urEasting, urNorthing, crs);
return new BoundingBox(ll, ur, crs);
} catch (FactoryException e) {
throw new IllegalStateException("Illegal CRS parameter: " + crs, e);
}
}
use of org.n52.io.crs.CRSUtils in project series-rest-api by 52North.
the class IoParameters method transformToInnerCrs.
/**
* @param point
* a GeoJSON point to be transformed to internally used CRS:84.
* @param crsUtils
* a reference helper.
* @return a transformed GeoJSON instance.
* @throws IoParseException
* if point could not be transformed, or if requested CRS object could not be created.
*/
private GeojsonPoint transformToInnerCrs(GeojsonPoint point, CRSUtils crsUtils) {
try {
Point toTransformed = crsUtils.convertToPointFrom(point, getCrs());
Point crs84Point = (Point) crsUtils.transformOuterToInner(toTransformed, getCrs());
return crsUtils.convertToGeojsonFrom(crs84Point);
} catch (TransformException e) {
throw new IoParseException("Could not transform to internally used CRS:84.", e);
} catch (FactoryException e) {
throw new IoParseException("Check if 'crs' parameter is a valid EPSG CRS. Was: '" + getCrs() + "'.", e);
}
}
Aggregations