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

Landsat NDVI. #26

Closed winsento closed 6 years ago

winsento commented 6 years ago

I have GeoTIFF with 2-bands from Landsat 8. Im try to generate NDVI via raster algebra.

GET parameters for layer and formula like this:

'layers=nir:1=5,red:0=5&formula=(nir-red)/(nir+red)'

But (nir-red) - return empty raster tile.

Raster here: LC08_L1TP_177024_20170922_20170922_01_RT.TIF.zip

yellowcap commented 6 years ago

did you try to display the data of each band? Try layers=x=5&formula=x, and layers=x:1=5&formula=x that should display a grayscale image of the first two bands. If that does not show anything, it is likely a data issue (i.e. you are looking at an empty tile, or tiles are not ingested properly)

winsento commented 6 years ago

All request from this list

layers=x=5&formula=x
layers=x:0=5&formula=x
layers=x:1=5&formula=x

show image in grayscale.

But layers=x:0=5,y:1=5&formula=x-y return blank transparented file.

winsento commented 6 years ago

sorry, i think problem in data. Looks like bands is similar.

Band 1 Block=8021x1 Type=Byte, ColorInterp=Gray
  Minimum=42.000, Maximum=255.000, Mean=125.312, StdDev=62.974
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=125.31222374066
    STATISTICS_MINIMUM=42
    STATISTICS_STDDEV=62.973673414911
Band 2 Block=8021x1 Type=Byte, ColorInterp=Undefined
  Minimum=42.000, Maximum=255.000, Mean=125.312, StdDev=62.974
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=125.31222374066
    STATISTICS_MINIMUM=42
    STATISTICS_STDDEV=62.973673414911

image

Issue can be closed.

winsento commented 6 years ago

@yellowcap The question is now different.

Im upload 2 bands (geotif) from Landsat 8. And apply formula layers=nir:0=7,red:0=8&formula=(nir-red)/(nir+red)

The result is displayed, but how can I assume the value of the pixel (result) is not in the range -1...1 how it should be.

Because if you apply a style, the following picture is shown: colormap={ "x>3500":"%23FF0000"}

image

When everything is decided, I will create pull request with example to the documentation.

yellowcap commented 6 years ago

For ndvi, a continuous color scheme is more appropriate (unless you want explicit class breaks of course). The continuous legend option is explained in the docs:

https://django-raster.readthedocs.io/en/stable/tms.html#continuous-color-schemes

For ndvi, can you try the following (red-yellow-green color scheme, range from -1 to 1):

query_param value
colormap {"continuous":true,"range":[-1,1],"from":[165,0,38],"to":[0,104,55],"over":[249,247,174]}
formula (B8-B4)/(B8+B4)

Remember you have to ensure that the url is correctly encoded so that the url is valid.

davo417 commented 3 years ago

Still ndvi calculation should not return values out of the -1, 1 range. I think that this is due a division problem when the pixel values are too small and GDAL get confused. Maybe applying a threshold to the bands will help in this case, if not you can always scale down the image to -1, 1 as the ndvi is just a relation and is not meant to express a concrete value.