/** * Set the coordinate reference system in which the coordinate is given. * * @param crs The new coordinate reference system, or {@code null}. * @throws MismatchedDimensionException if the specified CRS doesn't have the expected number of * dimensions. */ public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) throws MismatchedDimensionException { checkCoordinateReferenceSystemDimension(crs, getDimension()); this.crs = crs; }
/** * * <!-- begin-user-doc --> * ATTENTION: I'm assuming a LatLon envelope here. * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { List positions = node.getChildren("pos"); if (!positions.isEmpty() && (positions.size() == 2)) { Node n1 = (Node) positions.get(0); Node n2 = (Node) positions.get(1); GeneralDirectPosition p1 = (GeneralDirectPosition) n1.getValue(); GeneralDirectPosition p2 = (GeneralDirectPosition) n2.getValue(); GeneralEnvelope envelope = new GeneralEnvelope(p1, p2); if (p1.getDimension() == 2 && p2.getDimension() == 2) { envelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); return envelope; } else if (p1.getDimension() > 2 && p2.getDimension() > 2) { envelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84_3D); return envelope; } } if (!positions.isEmpty()) { throw new RuntimeException("Envelope can have only two coordinates"); } throw new RuntimeException("Could not find coordinates for envelope"); }
private static void expandEnvelopeOnExtremePoints( GeneralDirectPosition centerPt, GeneralEnvelope transformed, MathTransform geoToTarget, Envelope geoEnvelope) throws TransformException { GeneralDirectPosition workPoint = new GeneralDirectPosition(centerPt.getDimension()); double centerLon = centerPt.getOrdinate(0); double minLon = geoEnvelope.getMinimum(0); double maxLon = geoEnvelope.getMaximum(0); double minLat = geoEnvelope.getMinimum(1); double maxLat = geoEnvelope.getMaximum(1); if (minLon <= centerLon && centerLon <= maxLon) { // intersection at boundaries, south includeTransformedPoint(transformed, geoToTarget, workPoint, centerLon, minLat); // intersection at boundaries, north includeTransformedPoint(transformed, geoToTarget, workPoint, centerLon, maxLat); } double centerLat = centerPt.getOrdinate(1); if (minLat <= centerLat && centerLat <= maxLat) { // intersection at boundaries, west includeTransformedPoint(transformed, geoToTarget, workPoint, minLon, centerLat); // intersection at boundaries, east includeTransformedPoint(transformed, geoToTarget, workPoint, maxLon, centerLat); } }