Use GCPs to reproject a ndarray


Shaunak De
 

Hello All, 

I have GCPs associated with a GeoTIFF as follows:

GroundControlPoint(row=0.0, col=0.0, x=14.674978814299008, y=69.61799429448102, z=-3.898888826370239e-05, id='1', info=''),
 GroundControlPoint(row=0.0, col=299.55555555555554, x=14.689285403048489, y=69.61991548229533, z=-3.908667713403702e-05, id='2', info=''),

and the CRS associated is "EPSG: 4326". I want to write a NumPy array with dimensions (12120, 2696) as a geotiff. I was trying to use rasterio.warp.reproject to accomplish this as follows:

warp.reproject(source=numpy_array_with_daya, gcps=gcps, src_crs=gcp_crs, dst_crs=rio.crs.CRS.from_string('EPSG:4326'))

I run into this error:

AttributeError: 'NoneType' object has no attribute 'xoff'

I experimented a bit with the reproject function, but haven't been able to fully understand how to use it well. One of the things I tried was to specify "dst_transform" (computed from the calculate_default_transform function etc. and had a bit more luck producing an output at all, but I don't think I fully understand how this function works. Any help or pointers to documentation would be greatly appreciated.


Sean Gillies
 

Hi,

On Fri, Aug 6, 2021 at 9:20 PM <shaunakde@...> wrote:
Hello All, 

I have GCPs associated with a GeoTIFF as follows:

GroundControlPoint(row=0.0, col=0.0, x=14.674978814299008, y=69.61799429448102, z=-3.898888826370239e-05, id='1', info=''),
 GroundControlPoint(row=0.0, col=299.55555555555554, x=14.689285403048489, y=69.61991548229533, z=-3.908667713403702e-05, id='2', info=''),

and the CRS associated is "EPSG: 4326". I want to write a NumPy array with dimensions (12120, 2696) as a geotiff. I was trying to use rasterio.warp.reproject to accomplish this as follows:

warp.reproject(source=numpy_array_with_daya, gcps=gcps, src_crs=gcp_crs, dst_crs=rio.crs.CRS.from_string('EPSG:4326'))

I run into this error:

AttributeError: 'NoneType' object has no attribute 'xoff'

I experimented a bit with the reproject function, but haven't been able to fully understand how to use it well. One of the things I tried was to specify "dst_transform" (computed from the calculate_default_transform function etc. and had a bit more luck producing an output at all, but I don't think I fully understand how this function works. Any help or pointers to documentation would be greatly appreciated.


If you're specifying dst_transform, then you are using the reproject function correctly. We don't have specific documentation for this use case, but it is continuously tested: https://github.com/mapbox/rasterio/blob/02d65cfd16decc2c923413df9f8b67433699d64c/tests/test_warp.py#L1508.

Can you try calculating a dst_transform using https://rasterio.readthedocs.io/en/stable/api/rasterio.transform.html#rasterio.transform.from_gcps ? The usage would be like this:

warp.reproject(source=numpy_array_with_daya, gcps=gcps, src_crs=gcp_crs, dst_crs="EPSG:4326", dst_transform=transform.from_gcps(gcps))

--
Sean Gillies