|
1 | 1 | /* |
2 | | - * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata |
| 2 | + * Copyright (c) 1998-2026 University Corporation for Atmospheric Research/Unidata |
3 | 3 | * See LICENSE for license information. |
4 | 4 | */ |
| 5 | + |
5 | 6 | package ucar.unidata.geoloc.projection; |
6 | 7 |
|
7 | 8 | import ucar.nc2.constants.CF; |
@@ -248,23 +249,59 @@ public double[][] latLonToProj(double[][] from, double[][] to, int latIndex, int |
248 | 249 |
|
249 | 250 |
|
250 | 251 | /** |
251 | | - * Set the center of the Longitude range. It is normalized to +/- 180. |
| 252 | + * Set the center longitude of this projection, normalizing it into the range [-180, 180]. |
| 253 | + * |
| 254 | + * <p> |
252 | 255 | * The cylinder is cut at the "seam" = centerLon +- 180. |
253 | 256 | * Use this to keep the Longitude values kept in the range [centerLon +-180], which |
254 | 257 | * makes seam handling easier. |
| 258 | + * {@link #latLonToProj} returns longitudes in the range |
| 259 | + * [{@code centerLon} - 180, {@code centerLon} + 180], so the center longitude controls where the |
| 260 | + * seam falls and therefore which longitude values are produced. |
| 261 | + * |
| 262 | + * <p> |
| 263 | + * This method always normalizes the supplied value to [-180, 180], which discards information |
| 264 | + * about grids whose longitude coordinates legitimately lie outside that range. To preserve |
| 265 | + * such information, use |
| 266 | + * {@link #setCenterLon(double, boolean)} with {@code normalize = false}. |
255 | 267 | * |
256 | | - * @param centerLon the center of the Longitude range. |
257 | | - * @return centerLon normalized to +/- 180. |
| 268 | + * @param centerLon the center of the longitude range, in degrees east. |
| 269 | + * @return centerLon normalized to [-180, 180]. |
| 270 | + * @deprecated use {@link #setCenterLon(double, boolean)} with {@code normalize = true} |
258 | 271 | */ |
| 272 | + @Deprecated |
259 | 273 | public double setCenterLon(double centerLon) { |
260 | | - this.centerLon = LatLonPoints.lonNormal(centerLon); |
| 274 | + return setCenterLon(centerLon, true); |
| 275 | + } |
| 276 | + |
| 277 | + /** |
| 278 | + * Set the center longitude of this projection, optionally normalizing it into the range [-180, 180]. |
| 279 | + * |
| 280 | + * <p> |
| 281 | + * The center longitude controls the location of the projection "seam" (at {@code centerLon} +/- 180). |
| 282 | + * This also means it controls the range of longitudes returned by the projection. When {@code normalize} |
| 283 | + * is {@code false}, the supplied value is stored as given. This allows the projection to |
| 284 | + * reproduce grid longitudes that lie outside [-180, 180]. |
| 285 | + * |
| 286 | + * @param centerLon the center of the longitude range, in degrees east. |
| 287 | + * @param normalize if {@code true}, normalize {@code centerLon} into [-180, 180]; if {@code false}, |
| 288 | + * store it unchanged. |
| 289 | + * @return the center longitude that was stored. |
| 290 | + */ |
| 291 | + public double setCenterLon(double centerLon, boolean normalize) { |
| 292 | + this.centerLon = normalize ? LatLonPoints.lonNormal(centerLon) : centerLon; |
261 | 293 | return this.centerLon; |
262 | 294 | } |
263 | 295 |
|
264 | 296 | /** |
265 | | - * Get the center of the Longitude range. It is normalized to +/- 180. |
| 297 | + * Get the center longitude of this projection, in degrees east. |
| 298 | + * |
| 299 | + * <p> |
| 300 | + * Note that this value is normalized to [-180, 180] only if it was set via |
| 301 | + * {@link #setCenterLon(double)} (or {@link #setCenterLon(double, boolean)} with |
| 302 | + * {@code normalize = true}). |
266 | 303 | * |
267 | | - * @return the center longitude |
| 304 | + * @return the center longitude. |
268 | 305 | */ |
269 | 306 | public double getCenterLon() { |
270 | 307 | return centerLon; |
|
0 commit comments