return fromTargetType(object);
}
BoundingBoxType fromTargetType(Object object) throws WPSException {
Ows11Factory factory = Ows11Factory.eINSTANCE;
BoundingBoxType bbox = factory.createBoundingBoxType();
// basic conversion and collect the crs
CoordinateReferenceSystem crs = null;
if (object instanceof Envelope) {
Envelope env = (Envelope) object;
if(object instanceof ReferencedEnvelope) {
ReferencedEnvelope re = (ReferencedEnvelope) object;
crs = re.getCoordinateReferenceSystem();
}
bbox.setLowerCorner(Arrays.asList(env.getMinX(), env.getMinY()));
bbox.setUpperCorner(Arrays.asList(env.getMaxX(), env.getMaxY()));
} else if (org.opengis.geometry.Envelope.class.isAssignableFrom(getType())) {
org.opengis.geometry.Envelope env = (org.opengis.geometry.Envelope) object;
crs = env.getCoordinateReferenceSystem();
bbox.setLowerCorner(Arrays.asList(env.getLowerCorner().getCoordinate()));
bbox.setUpperCorner(Arrays.asList(env.getUpperCorner().getCoordinate()));
} else {
throw new WPSException("Failed to convert from " + object
+ " to an OWS 1.1 Bounding box type");
}
// handle the EPSG code
if(crs != null) {
try {
Integer code = CRS.lookupEpsgCode(crs, false);
if(code != null) {
bbox.setCrs("EPSG:" + code);
}
} catch(Exception e) {
throw new WPSException("Could not lookup epsg code for " + crs, e);
}
}