diff --git a/Frequently_used_code/Contour_extraction.ipynb b/Frequently_used_code/Contour_extraction.ipynb index 31648bebb..1f6552121 100644 --- a/Frequently_used_code/Contour_extraction.ipynb +++ b/Frequently_used_code/Contour_extraction.ipynb @@ -76,7 +76,7 @@ "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "from affine import Affine\n", - "from datacube.utils.geometry import CRS\n", + "from datacube.utils.geometry import assign_crs\n", "\n", "sys.path.append('../Scripts')\n", "from dea_datahandling import load_ard\n", @@ -154,8 +154,7 @@ "\n", "# Modify CRS and transform attributes into a format that is\n", "# consistent with data loaded from `dc.load`\n", - "elevation_array.attrs['crs'] = CRS(elevation_array.crs[-9:])\n", - "elevation_array.attrs['transform'] = Affine(*elevation_array.transform)\n", + "elevation_array = assign_crs(elevation_array)\n", "\n", "# Print the data\n", "print(elevation_array)" diff --git a/Scripts/dea_spatialtools.py b/Scripts/dea_spatialtools.py index 2bab6596f..7a4dbd973 100644 --- a/Scripts/dea_spatialtools.py +++ b/Scripts/dea_spatialtools.py @@ -42,7 +42,7 @@ from skimage.measure import find_contours from shapely.geometry import LineString, MultiLineString, shape from datacube.helpers import write_geotiff -from datacube.utils.geometry import CRS, Geometry +from datacube.utils.geometry import CRS, Geometry, assign_crs def xr_vectorize(da, @@ -296,8 +296,8 @@ def xr_rasterize(gdf, name=name if name else None) # Add back crs if xarr.attrs doesn't have it - if 'crs' not in xarr.attrs: - xarr.attrs['crs'] = str(crs) + if xarr.geobox is None: + xarr = assign_crs(xarr, str(crs)) if export_tiff: print(f"Exporting GeoTIFF to {export_tiff}")