-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add src_geoloc_array kwarg to reproject and _reproject #2884
Conversation
Plus an experimental _xygrid method for datasets. Resolves #2883
So far, so good. We have a limited capability to warp datasets and arrays using a pair of numpy arrays that hold coordinates. For example, here is the output raster from |
Two thoughts:
|
@snowman2 absolutely yes to both! Helping users avoid conflicting input (gcps and geolocation arrays, for example) is another TODO. One approach to that would be to change from 4 different geolocation keyword arguments to a single one, but I'm not sure about doing that now. |
Datacube has the concept of a |
We have nice classes in transform.py for
|
Also to consider: opendatacube/datacube-core#1457. |
@@ -223,6 +223,7 @@ def _reproject( | |||
num_threads=1, | |||
warp_mem_limit=0, | |||
working_data_type=0, | |||
src_geoloc_array=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few usability notes (context in GDAL RFC #4):
kwargs
should disallow the use ofMETHOD=GEOLOC_ARRAY
andSRC_GEOLOC_ARRAY
.- Is the intention to support
PIXEL_STEP
andLINE_STEP
viakwargs
? These seem like key parameters for some users.PIXEL_OFFSET
andLINE_OFFSET
seem less useful, but worth supporting for completeness. - It is possible to assign a geolocation array to the target image using the
DST_GEOLOC_ARRAY
transformer option. Ifkwargs
is passed along correctly it seems like this should work if the caller configures things correctly, but it may be worth thinking about whether or not this should be more officially supported, or explicitly disallowed. - It is possible for the input image to have
GEOLOCATION
metadata set. This is a special metadata domain likeRPC
, and normally points to an external dataset. Another useful pattern is to construct a geolocation array, attachGEOLOCATION
metadata, and omit the*_DATASET
metadata items. This dataset can then be applied to any dataset of the right shape without having to manage geolocation metadata on the primary image dataset. Is Rasterio's stance that this metadata will be ignored, and users must manually load it and craft an appropriate call toreproject()
? - Rasterio must be able to read and write
GEOLOCATION
metadata, otherwise the library cannot be used to craft an image whose geolocation is provided by a geolocation array. I think I confirmed this works, but IMO should be intentionally tested. - A geolocation can include an optional
Z_BAND
, although I suspect this is ignored by the geolocation array transformer, and exists to provide a mechanism to include elevation for use elsewhere.
Scope for 1.4.0: A geoloc array transformer as discussed above, but none of the extra features from your usability notes @pl-kevinwurster. We can add those later if needed. |
@sgillies sounds good – thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
Thanks @snowman2. Though I liked the idea of grouping source geolocation parameters into one, it's not a good fit. GDAL's warper can't use our Python transformers. It needs GCPs and RPCs attached to a dataset. I'm against using the classes only as containers. Last thing I want to do here is add support to |
Sorry to jump in here, but I found this PR from @snowman2's linking to it in rioxarray issues/PRs. Do I understand this PR and the GDAL RFC 4 correctly that this would allow non-uniformly spaced coordinate arrays in warping/resampling operations? For example, satellite-based instrument data where the spacing of the pixels depends on the scanning pattern of the instrument and geometry of the Earth. |
Rasterio 1.3 can warp (reproject) rasters using crs and transform, ground control point, or rational polynomial coefficient inputs that are not stored on the source raster. Like this:
For 1.4, let's add external geolocation arrays (https://gdal.org/development/rfc/rfc4_geolocate.html) to the mix.
Proposed usage is this:
where
xs
andys
are 2-D arrays of x and y coordinates respectively. Appropriate arrays can be computed using rasterio and numpy objects. For example, full resolution arrays can be generated for a rasterio dataset like this:Lower resolution arrays are acceptable, too. They will give slightly different results.
Internally, these arrays are copied so that they can be accessed via a single pointer using a GDAL MEM dataset. A copy could be avoided if a 3-D array is passed in (that's a TODO).
The GDAL API for configuration geolocation arrays is detailed at https://gdal.org/api/gdal_alg.html#_CPPv432GDALCreateGenImgProjTransformer212GDALDatasetH12GDALDatasetHPPc.
On the command line, rio-warp could be extended with a
--geoloc-dataset
option specifying a 2-band dataset file containing the equivalent data. There's a chance thatrio warp --to SRC_GEOLOC_ARRAY=FILENAME
(whereFILENAME
is a 2-band raster dataset containing x and y coordinates) works right now (with GDAL >= 3.5.2).Resolves #2883