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

VARI formula parser error #52

Closed orkunasa closed 4 years ago

orkunasa commented 4 years ago

Hello,

When I applied VARI formula on the tails, returns 400 bad request error. How can i solve this problem? Min and max functions may solve this problem; however, they are not implemented right now.

VARI Formula: (Green - Red) / (Green + Red - Blue)

My Tile URL: http://127.0.0.1:8080/raster/algebra/{z}/{x}/{y}.png?layers=r:0=1,g:1=1,b:2=1&alpha&formula=(r-g)/(r+g-b)

Bands:

Screenshot from 2020-08-21 16-10-53

Thank you.

yellowcap commented 4 years ago

Try different variable names for the bands. The key names r, g, b are "reserved" for RGB mode, if the endpoint detects these exact names, it will try to interpret the data as RGB rendering mode. So try calling the layers a,b,c instead or something similar. Maybe this solves the problem.

For instance, the following could work:

http://127.0.0.1:8080/raster/algebra/{z}/{x}/{y}.png?layers=red:0=1,green:1=1,blue:2=1&alpha&formula=(red-green)/(red+green-blue)

orkunasa commented 4 years ago

Thanks for the answer @yellowcap

Unfortunately, It didn't work. I think there is a problem with result of the (red+green) operation. I handled this problem changing formula: (red-green)/(red+(green-blue))

My URL: http://127.0.0.1:8080/raster/algebra/{z}/{x}/{y}.png?layers=red:0=1,green:1=1,blue:2=1&alpha&formula=(red-green)/(red+(green-blue))&colormap={"continuous":true,"range":[-1,1], "to":[0,104,55], "from":[165,0,38], "over":[249,247,174]}'

Screenshot from 2020-08-22 00-52-02

The pixel values of the VARI image should be between [-1, 1]. But they are not. So same part of the image come transparent. Do you have any idea how can i scale the result?

Thank you.

yellowcap commented 4 years ago

I don't think that the VARI index is always between -1 and 1. If in your formula red = 100, green = 0, and blue = 50, the result is 2 right?

The raster formula rendering is transparent if the values fall outside of the range parameter that is indicated.

On a side note, the reference I found for this index used (green- red), your formula is (red - green).

https://www.harrisgeospatial.com/docs/BroadbandGreenness.html#Visible

orkunasa commented 4 years ago

You're right! Thank you for your help.