Georeferencing image data with HvPlot

I’ve got some hyperspectral satellite imagery that is off by 30-100m, which I can tell by the location of roads compared to Open Street Map.

I’d like to use the interactive capabilities of HoloViz to allow interactive creation of Ground Control Points (GCPs) that will then allow georeferencing via a tool like gdalwarp.

I’m basically planning on following the workflow here: Mastering GDAL Tools (Full Course Material)

I want to create a dataframe like:

pixel (column)	line (row)	X (Lon)	Y (Lat)
 418	        893	        70.5   15.23
 380	       2432	        70.12	5.24
3453	       2434	        90.43	5.74
3407	        895	        90.34	15.23
2662	        911	        85.22	15.25

I know I can return the lon,lat values of points clicked on using HoloViz, but how can I also return the pixel values?

1 Like

Pixel values are just index I think something like ds.where(lon=..., lat=..., drop=True) or python - How to get the coordinates of the maximum in xarray? - Stack Overflow

Doh! OMG. Where is that egg-on-face emoticon again?

Thanks Andrew!

2 Likes

Thinking about this some more, it’s easy if the coordinates lon,lat are 1D arrays, but if they are 2D arrays, and you are visualizing with hvplot.quadmesh, isn’t it a bit more tricky?

I would like to use pointDraw, and get pixel_row, pixel_col added to the dataframe. Like added to this example:
https://earthsim.holoviz.org/user_guide/Drawing_Tools.html

Pixel values must be the input to the calc to get lon,lat, but how do we return them?

Maybe you can try something like:

import xarray as xr
import holoviews as hv
import xoak
da = xr.tutorial.open_dataset('rasm')["Tair"].load().isel(time=0)

query_lats = [10.1, -2]
query_lons = [10, 19]
query_coords = np.stack((query_lats, query_lons)).T
lats_lons = np.vstack([da['yc'].values.ravel(), da['xc'].values.ravel()]).T
kdtree = cKDTree(lats_lons)
dist, index = kdtree.query(query_coords)
da_sel = da.stack({'index': ['y', 'x']}).isel(index=index).unstack()

I’m not asking this question correctly. To georeference an image, I need to use easy-to-identify lon,lat points (like the intersection of two roads on open street map), then determine the pixel values of those points on the image I’m trying to georeference.

So ideally, I’d have a tool where I overlay an image on open street map, then draw a line from the point on open street map to the point on the image. Then do that for O(10) points scattered around the image (like the points below). Then return the lon,lat values from open street map along with the pixel values from the image.