diff --git a/docs/html/.buildinfo b/docs/html/.buildinfo index 51b04c69..0c7f2109 100644 --- a/docs/html/.buildinfo +++ b/docs/html/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: 1cb61a7d80e7be4eb9684952b9735c30 +config: 8113f10dd074ceb5d428a956dc416810 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/html/_modules/index.html b/docs/html/_modules/index.html index f7a6016a..d3b36d63 100644 --- a/docs/html/_modules/index.html +++ b/docs/html/_modules/index.html @@ -6,7 +6,7 @@
-
"""
import copy
-from abc import abstractmethod
from datetime import datetime
import numpy as np
@@ -261,12 +260,29 @@ Source code for rioxarray.rioxarray
self._crs = None
@property
- @abstractmethod
def crs(self):
""":obj:`rasterio.crs.CRS`:
- The projection of the dataset.
+ Retrieve projection from `xarray.DataArray` or `xarray.Dataset`
"""
- raise NotImplementedError
+ if self._crs is not None:
+ return None if self._crs is False else self._crs
+
+ try:
+ # look in grid_mapping
+ grid_mapping_coord = self._obj.attrs.get("grid_mapping", DEFAULT_GRID_MAP)
+ try:
+ crs_wkt = self._obj.coords[grid_mapping_coord].attrs["spatial_ref"]
+ except KeyError:
+ crs_wkt = self._obj.coords[grid_mapping_coord].attrs["crs_wkt"]
+ self.set_crs(crs_wkt, inplace=True)
+ except KeyError:
+ try:
+ # look in attrs for 'crs'
+ self.set_crs(self._obj.attrs["crs"], inplace=True)
+ except KeyError:
+ self._crs = False
+ return None
+ return self._crs
def _get_obj(self, inplace):
"""
@@ -364,10 +380,7 @@ Source code for rioxarray.rioxarray
data_obj[var].rio.update_attrs(
dict(grid_mapping=grid_mapping_name), inplace=True
)
- else:
- data_obj.rio.update_attrs(
- dict(grid_mapping=grid_mapping_name), inplace=True
- )
+ data_obj.rio.update_attrs(dict(grid_mapping=grid_mapping_name), inplace=True)
return data_obj
[docs] def set_attrs(self, new_attrs, inplace=False):
@@ -547,31 +560,6 @@ Source code for rioxarray.rioxarray
data_obj.rio.set_nodata(input_nodata, inplace=True)
return data_obj
- @property
- def crs(self):
- """:obj:`rasterio.crs.CRS`:
- Retrieve projection from `xarray.DataArray`
- """
- if self._crs is not None:
- return None if self._crs is False else self._crs
-
- try:
- # look in grid_mapping
- grid_mapping_coord = self._obj.attrs["grid_mapping"]
- try:
- crs_wkt = self._obj.coords[grid_mapping_coord].attrs["spatial_ref"]
- except KeyError:
- crs_wkt = self._obj.coords[grid_mapping_coord].attrs["crs_wkt"]
- self.set_crs(crs_wkt, inplace=True)
- except KeyError:
- try:
- # look in attrs for 'crs'
- self.set_crs(self._obj.attrs["crs"], inplace=True)
- except KeyError:
- self._crs = False
- return None
- return self._crs
-
@property
def encoded_nodata(self):
"""Return the encoded nodata value for the dataset if encoded."""
@@ -1225,11 +1213,19 @@ Source code for rioxarray.rioxarray
""":obj:`rasterio.crs.CRS`:
Retrieve projection from `xarray.Dataset`
"""
- if self._crs is None:
- try:
- self._crs = self._obj[self.vars[0]].rio.crs
- except IndexError:
- pass
+ if self._crs is not None:
+ return None if self._crs is False else self._crs
+ self._crs = super().crs
+ if self._crs is not None:
+ return self._crs
+ for var in self.vars:
+ crs = self._obj[var].rio.crs
+ if crs is not None:
+ self._crs = crs
+ break
+ else:
+ self._crs = False
+ return None
return self._crs
[docs] def reproject(
@@ -1455,7 +1451,7 @@ Navigation
modules |
- rioxarray 0.0.12 documentation »
+ rioxarray 0.0.13 documentation »
Module code »
diff --git a/docs/html/_sources/examples/crs_management.ipynb.txt b/docs/html/_sources/examples/crs_management.ipynb.txt
index 7af5748b..92bb1bef 100644
--- a/docs/html/_sources/examples/crs_management.ipynb.txt
+++ b/docs/html/_sources/examples/crs_management.ipynb.txt
@@ -20,7 +20,7 @@
"source": [
"If you have opened up a dataset and the Coordinate Reference System (CRS) is able to be determined, you can access it via the `rio.crs` accessor.\n",
"\n",
- "#### Search order for the CRS (DataArray):\n",
+ "#### Search order for the CRS (DataArray and Dataset):\n",
"1. Look in attributes (`attrs`) of your data array for the `grid_mapping` coordinate name.\n",
" Inside the `grid_mapping` coordinate first look for `spatial_ref` and second for `crs_wkt`.\n",
" This is in line with the Climate and Forecast (CF) conventions for storing the CRS.\n",
@@ -28,8 +28,9 @@
"\n",
"The value for the `crs` is anything accepted by `rasterio.crs.CRS.from_user_input()`\n",
"\n",
- "#### Search order for the CRS (Dataset):\n",
- "At this time, it pulls the CRS from the first variable of the dataset. This method for accessing the CRS is not recommended."
+ "#### Search order for the CRS for Dataset:\n",
+ "If the CRS is not found using the search methods above, it also searches the `data_vars` and uses the\n",
+ "first valid CRS found."
]
},
{
@@ -153,7 +154,7 @@
"source": [
"## Setting the CRS of the Dataset\n",
"\n",
- "Currently, you can use the `rio.set_crs` and `rio.write_crs` methods to set the CRS on your `xarray.Dataset` or `xarray.DataArray`. However, it is recommended to do CRS operations on the `xarray.DataArray`."
+ "Currently, you can use the `rio.set_crs` and `rio.write_crs` methods to set the CRS on your `xarray.Dataset` or `xarray.DataArray`."
]
},
{
diff --git a/docs/html/_sources/history.rst.txt b/docs/html/_sources/history.rst.txt
index 6117a2e3..d77191b6 100644
--- a/docs/html/_sources/history.rst.txt
+++ b/docs/html/_sources/history.rst.txt
@@ -1,6 +1,10 @@
History
=======
+0.0.13
+------
+- Improve CRS searching for xarray.Dataset & use default grid mapping name (pull #51)
+
0.0.12
------
- Use `xarray.open_rasterio()` for `rioxarray.open_rasterio()` with xarray<0.12.3 (pull #40)
diff --git a/docs/html/_static/documentation_options.js b/docs/html/_static/documentation_options.js
index b562bb38..64cd7a8d 100644
--- a/docs/html/_static/documentation_options.js
+++ b/docs/html/_static/documentation_options.js
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
- VERSION: '0.0.12',
+ VERSION: '0.0.13',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
diff --git a/docs/html/authors.html b/docs/html/authors.html
index 56601c7d..10698413 100644
--- a/docs/html/authors.html
+++ b/docs/html/authors.html
@@ -6,7 +6,7 @@
- Contributors ✨ — rioxarray 0.0.12 documentation
+ Contributors ✨ — rioxarray 0.0.13 documentation
@@ -34,7 +34,7 @@ Navigation
previous |
- rioxarray 0.0.12 documentation »
+ rioxarray 0.0.13 documentation »
@@ -115,7 +115,7 @@ Navigation
previous |
- rioxarray 0.0.12 documentation »
+ rioxarray 0.0.13 documentation »
@@ -220,7 +220,7 @@ Navigation
previous |
- rioxarray 0.0.12 documentation »
+ rioxarray 0.0.13 documentation »
@@ -393,7 +393,7 @@ Navigation
If you have opened up a dataset and the Coordinate Reference System (CRS) is able to be determined, you can access it via the rio.crs
accessor.
attrs
) of your data array for the grid_mapping
coordinate name. Inside the grid_mapping
coordinate first look for spatial_ref
and second for crs_wkt
. This is in line with the Climate and Forecast (CF) conventions for storing the CRS.crs
attribute and load in the CRS from there.The value for the crs
is anything accepted by rasterio.crs.CRS.from_user_input()
At this time, it pulls the CRS from the first variable of the dataset. This method for accessing the CRS is not recommended.
+If the CRS is not found using the search methods above, it also searches the data_vars
and uses the first valid CRS found.
[1]:
Currently, you can use the rio.set_crs
and rio.write_crs
methods to set the CRS on your xarray.Dataset
or xarray.DataArray
. However, it is recommended to do CRS operations on the xarray.DataArray
.
Currently, you can use the rio.set_crs
and rio.write_crs
methods to set the CRS on your xarray.Dataset
or xarray.DataArray
.
This sets the CRS on the rio
accessor without modifying the xarray.Dataset
or xarray.DataArray
.
[7]:
@@ -507,8 +507,8 @@ Table of Contents
crs
¶Retrieve projection from xarray.DataArray
-Type: | rasterio.crs.CRS |
-
---|
encoded_nodata
¶crs
¶The projection of the dataset.
+Retrieve projection from xarray.DataArray or xarray.Dataset