Closed mxkpp closed 1 year ago
I just noticed there's an open PR to update this part of the readme.
Please note that for DSS grids whose original CRS fails in rasterio to cast to wkt, the whole situation fails before it gets a chance to parse the custom profile dictionary provided to the save_tiff
method. See screenshot of traceback below.
In this case, the approach I suggested above, modifying dataset.raster._obj._crs
before calling save_tiff
, is the way to go.
Agreed. My correction would not fix if the DSS grid CRS code fails to parse to rasterio CRS wkt. My correction was only to fix the TypeError since the second argument for save_tiff was a rasterio profile rather than the crs code itself.
I was utilizing a more elaborate way of fixing this issue by not even calling the save_tiff method. dataset = dss_file_obj.read_grid(pathname) profile = { 'driver': 'GTiff', 'dtype': dataset.profile['opt_dtype'], 'width': dataset.width, 'height': dataset.height, 'count': 1, 'crs': crs_raster, 'transform': dataset.transform, 'nodata': -999 } with rasterio.open(save_file, 'w', **profile) as dst: dst.write(dataset.read(), 1)
But yeah the solution you presented would be much easier.
Also one of the reason I have noticed the crs.to_wkt fails is because the dss grid crs uses "metre" instead of "Meter" as units. if you still want to read the crs code from the dss grid one way that works is by replacing it from the string.
crs_raster = CRS.from_wkt(dataset.crs.replace('["metre",0.0]', '["Meter",1.0]'))
@KushalMBI glad there is more than one way to get around this. Thanks for sharing.
https://github.com/gyanz/pydsstools/blob/ef729616222d9ca8359fe4b80e29d69cc9150f6d/README.md?plain=1#L237
Should be like