Skip to content

Using gcps with rio.reproject #339

@oarcher

Description

@oarcher

Hi, this is my first question here:

I'd like to be able to use gcps for reproject, like rasterio is able to do.

My goal is to plot a sentinel-1 image on a map, with geoviews.

My first guess was to use:

rasterize(gv.load_tiff(filename))

But this doesn't works, because the tiff has no transform. However, it has some gcps, and it is correctly mapped in qgis.

I was not able to find any solution to do the reprojection with rioxarray, so I've ended in a pure rasterio solution, converting to rioxarray at the end:

# 100% rasterio
src = rasterio.open(filename)
gcps, src_crs = src.get_gcps()
destination = np.zeros((5000,5000)) 
dest, transform = rasterio.warp.reproject(src.read(1), destination, gcps=gcps, src_crs=src_crs, dst_crs=src_crs)

# to rioxarray
dn = xr.DataArray(dest, dims=['y','x'])
dn = dn.rio.write_crs(src_crs)
dn = dn.rio.write_transform(transform)
dn = dn.assign_coords(x=(transform * (dn.x, dn.y[0]))[0] , y=(transform * (dn.x[0], dn.y))[1]) 

# plot with geoviews
rasterize(gv.Image(dn))

My input image is pretty big (25000 * 15000), so ideally, the reprojection should be done with dask (#119)

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalIdea for a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions