I have a MODIS data. It is a hdf file (not hdf5). I can open it using ArcGIS and QGIS with no crs. When I use the following script, I get MissingCRS: CRS not found. Please set the CRS with 'rio.write_crs()'.
error. Since I cannot open the file, I cannot use rio.write_crs()
.
import rioxarray
modis_pre_path = "C:/Users/user/Desktop/modis.hdf"
modis_pre = rioxarray.open_rasterio(modis_pre_path)
How can I solve this issue?
The full traceback:
MissingCRS Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1520/3420315969.py in <module>
----> 1 modis_pre = rxr.open_rasterio(modis_pre_path)
2 type(modis_pre)
C:\OSGeo4W\apps\Python39\lib\site-packages\rioxarray\_io.py in open_rasterio(filename, parse_coordinates, chunks, cache, lock, masked, mask_and_scale, variable, group, default_name, decode_times, decode_timedelta, **open_kwargs)
926 # open the subdatasets if they exist
927 if riods.subdatasets:
--> 928 return _load_subdatasets(
929 riods=riods,
930 group=group,
C:\OSGeo4W\apps\Python39\lib\site-packages\rioxarray\_io.py in _load_subdatasets(riods, group, variable, parse_coordinates, chunks, cache, lock, masked, mask_and_scale, decode_times, decode_timedelta, **open_kwargs)
680 with rasterio.open(subdataset) as rds:
681 shape = rds.shape
--> 682 rioda: DataArray = open_rasterio( # type: ignore
683 subdataset,
684 parse_coordinates=shape not in dim_groups and parse_coordinates,
C:\OSGeo4W\apps\Python39\lib\site-packages\rioxarray\_io.py in open_rasterio(filename, parse_coordinates, chunks, cache, lock, masked, mask_and_scale, variable, group, default_name, decode_times, decode_timedelta, **open_kwargs)
1033 result.rio.write_crs(rio_crs, inplace=True)
1034 if has_gcps:
-> 1035 result.rio.write_gcps(*riods.gcps, inplace=True)
1036
1037 if chunks is not None:
C:\OSGeo4W\apps\Python39\lib\site-packages\rioxarray\rioxarray.py in write_gcps(self, gcps, gcp_crs, grid_mapping_name, inplace)
1226 data_obj = self._get_obj(inplace=True)
1227
-> 1228 data_obj = data_obj.rio.write_crs(
1229 gcp_crs, grid_mapping_name=grid_mapping_name, inplace=inplace
1230 )
C:\OSGeo4W\apps\Python39\lib\site-packages\rioxarray\rioxarray.py in write_crs(self, input_crs, grid_mapping_name, inplace)
485
486 if data_obj.rio.crs is None:
--> 487 raise MissingCRS(
488 "CRS not found. Please set the CRS with 'rio.write_crs()'."
489 )
MissingCRS: CRS not found. Please set the CRS with 'rio.write_crs()'.