You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Calculate latitude and longitudes for each grid cell
35
-
lat, lon = transformer.transform(x2d, y2d)
35
+
lat, lon = transform.transform(x2d, y2d)
36
36
```
37
37
38
38
## Discussion
39
-
The workflow above assumes that the NetCDF files is CF-compliant and has a `grid_mapping` variable and projected coordinates defined. See the `rioxarray`[CRS management documentation](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#) if this is not the case.
39
+
The workflow above assumes that the NetCDF file is CF-compliant and has a `grid_mapping` variable and projected coordinates defined. See the `rioxarray`[CRS management documentation](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#) if this is not the case.
40
40
41
41
If the dataset `rio.crs` is not set, the `source_crs` could be defined using the EPSG code or other projection information directly, without having to set the dataset crs.
Copy file name to clipboardExpand all lines: nsidc-data-cookbook/how-to-guides/netcdf_cf.qmd
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
2
title: "How do I get the bounding box of a NetCDF file in latitude and longitude?"
3
3
author: Andrew P. Barrett
4
-
date: last_modified
4
+
date: last-modified
5
5
---
6
6
7
7
## Problem
8
-
My data are in a NetCDF file but there are no latitude and longitude coordinates. How do I find the bounding box in latitude and longitude?.
8
+
My data are in a NetCDF file but there are no latitude and longitude coordinates. How do I find the bounding box in latitude and longitude?
9
9
10
10
## Solution
11
11
### Using xarray and rioxarray
@@ -29,7 +29,7 @@ ds.rio.transform_bounds(4326)
29
29
30
30
As of [CF v1.8](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.10/cf-conventions.html#grid-mappings-and-projections), latitude and longitude coordinate variables are no longer required in CF-compliant NetCDF files, as long as projected horizontal spatial coordinates (e.g. `x` and `y`, or `easting` and `northing`) and a `grid_mapping` variable is provided. The `grid_mapping` variable defines the coordinate reference system (CRS) of the projected horizontal coordinates.
31
31
32
-
The easiest, and frankly best, way to read and work with NetCDF files is to use `xarray`. `rioxarray` extends the `xarray` package to use CRS and make geospatial tasks, such as reprojecting and regridding, easier. By setting the keyword `decode-coords='all'`, `rioxarray` searches the `xarray.DataArray` or `xarray.Dataset` for the CRS. `rioxarray` also determines the `transform` or `geotransform`, which defines the image CRS that transforms cell coordiates (column and row) into projected coordinates (x, y). The `transform` is calculated from the coordinates of the data. See the `rioxarray`[documentaton](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#) for more details.
32
+
The easiest, and frankly best, way to read and work with NetCDF files is to use `xarray`. `rioxarray` extends the `xarray` package to use CRS and make geospatial tasks, such as reprojecting and regridding, easier. By setting the keyword `decode-coords='all'`, `rioxarray` searches the `xarray.DataArray` or `xarray.Dataset` for the CRS. `rioxarray` also determines the `transform` or `geotransform`, which defines the image CRS that transforms cell coordinates (column and row) into projected coordinates (x, y). The `transform` is calculated from the coordinates of the data. See the `rioxarray`[documentaton](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#) for more details.
33
33
34
34
Both these spatial coordinates can be accessed as follows:
If this information is not found, all is not lost. [`rio.write_crs`](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#Setting-the-CRS) and [`rio.write_transform`](https://corteva.github.io/rioxarray/stable/getting_started/crs_management.html#Setting-the-transform-of-the-dataset) can be used to set the CRS and the transform of the dataset.
52
52
53
-
Once these variables are set, the horizontal spatial bounds of the dataset can be queried as described above. If all you want is the bounds in projected coordinates. These can be accessed using `ds.rio.bounds()`.
53
+
Once these variables are set, the horizontal spatial bounds of the dataset can be queried as described above. If all you want is the bounds in projected coordinates, these can be accessed using `ds.rio.bounds()`.
0 commit comments