private static boolean intersects( Envelope envelope, Code reqCRS, Envelope[] envs, LonLatEnvelope llEnv) throws UnknownCRSException { boolean res = false; String reqCRSCode = reqCRS.getCode(); try { if (envs == null || envs.length == 0) { Envelope latlonEnv = GeometryFactory.createEnvelope( llEnv.getMin().getX(), llEnv.getMin().getY(), llEnv.getMax().getX(), llEnv.getMax().getY(), CRSFactory.create("EPSG:4326")); if (!"EPSG:4326".equals(reqCRSCode)) { res = intersects(envelope, reqCRSCode, latlonEnv, "EPSG:4326"); } else { res = envelope.intersects(latlonEnv); } } else { for (int i = 0; i < envs.length && !res; i++) { if (intersects( envelope, reqCRSCode, envs[i], envs[i].getCoordinateSystem().getPrefixedName())) { res = true; break; } } } } catch (GeometryException ex) { LOG.logWarning("intersection test; translation into surface failed", ex); } catch (CRSException ex) { LOG.logWarning( "intersection test; transformation of reqeust envelope/valid area impossible", ex); } catch (CRSTransformationException ex) { LOG.logWarning("intersection test; transformation of reqeust envelope/valid area failed", ex); } return res; }
/** return the LonLatEnvelope of the entire image in "EPSG:4326" */ private Envelope getLLEAsEnvelope() { String code = getNativeSRSCode(); LonLatEnvelope lle = description.getLonLatEnvelope(); Envelope tmp = GeometryFactory.createEnvelope( lle.getMin().getX(), lle.getMin().getY(), lle.getMax().getX(), lle.getMax().getY(), null); try { if (!code.equals("EPSG:4326")) { GeoTransformer trans = new GeoTransformer(code); tmp = trans.transform(tmp, "EPSG:4326"); } } catch (Exception e) { LOGGER.logError(StringTools.stackTraceToString(e)); } return tmp; }