geodesign / django-raster

Django-raster allows you to create tiled map services (TMS) and raster map algebra end points for web maps. It is Python-based, and requires GeoDjango with a PostGIS backend.
BSD 3-Clause "New" or "Revised" License
96 stars 39 forks source link

Annotate RasterLayer queryset with pixel value #53

Open vtoupet opened 3 years ago

vtoupet commented 3 years ago

Hi,

is there a way to annotate a RasterLayer queryset with pixel value for given coordinates? If not, how would you do to retrieve pixel value for a bunch of RasterLayer in an effective manner?

Thanks.

yellowcap commented 3 years ago

The raster queryset does not support this kind of annotation. To retrieve the pixel value, django-raster has an url endpoint that you can use, see https://django-raster.readthedocs.io/en/stable/algebra.html#pixel-value-lookup.

But I suppose you want to to this server side. For this case the quickest way is probably to identify the RasterTile that intersects with your point, get the tile, and use an internal utility function from django-raster to get the correct pixel.

To get you started, here is the part of the view that selects the RasterTile index https://github.com/geodesign/django-raster/blob/master/raster/views.py#L141 , and here is the utility function to get a pixel value based on a GDALRaster object https://github.com/geodesign/django-raster/blob/master/raster/utils.py#L132

Hope this helps.