-
Hi there @snowman2 I would like to do this - where I open the path to a single landsat band, and crop the data from_disk to conserve memory. See code below which I believe can be more efficient band_path = 'path/to/tif/here'
# Open the data - i'd rather clip here so i can take advantage of from_disk
# I'm not clipping because it's not accepting my crs object as i thought it might - user error?
band = rxr.open_rasterio(band_path,
masked=True) #.rio.clip(crop_bound_box[0], ## ideally i'd chain this all together for efficiency
# from_disk=True,
# crs=crop_bound.crs).squeeze()
# Reproject the GDF data for clippping - here you NEED the CRS from the raster opened above
# Could I somehow skip opening the raster just to get that CRS?
if crop_bound.crs != band.rio.crs:
crop_bound = crop_bound.to_crs(band.rio.crs)
# Turn bounding box (extent) into a shapely object for clipping
crop_bound_box = [box(*crop_bound.bounds.loc[0])]
# Clip the data but given i opened it above i'm using more memory / resources
band_crop = band.rio.clip(crop_bound_box, all_touched=True, from_disk=True) What is the most efficient approach here? Is there a way to access the CRS of a tif file without opening it? Many thanks for any ideas. OH NOTE: i am getting an error when i provide the CRS to the clip function. but i think before I go down that rabbit hole i'll see if there is a better approach first. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
The Note: rioxarray/rioxarray/raster_array.py Lines 700 to 707 in 2049384 geopandas also skips re-projecting if the CRS are the same:https://github.com/geopandas/geopandas/blob/fdf1fd7390752f37cbb1085fda2f7cf1c5ae4ebc/geopandas/array.py#L791-L793 |
Beta Was this translation helpful? Give feedback.
The
crs
kwarg represents the CRS input of the geometries and will handle reprojecting the geometries for you.rioxarray
usesGDAL
andgeopandas
usespyproj
to transform the points, so the speed/results may vary between the two methods.Note:
rioxarray
only re-projects the geometries if the CRS are not the same:rioxarray/rioxarray/raster_array.py
Lines 700 to 707 in 2049384
geopandas
al…