[gdal-dev] vrt guidance: 31 band classified raster

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] vrt guidance: 31 band classified raster

mhw-at-yg

Hello gdal-dev, it's been a long time!  I'm happy to be digging into raster data building again for a change, but could use some nudges in the right direction(s).

 

A few weeks ago Nasa released Landsat-derived Annual Dominant Land Cover Across ABoVE Core Domain, 1984-2014.

 

It’s composed of 175 geotiff images, with each file containing 31 bands which in turn correspond to a single year in the 1984-2014 period. Each band is 8bit unsigned integer with values from 1 to 15 and 255 as nodata. Each integer value corresponds to a class such as “Evergreen Forest”, “Herbaceous”, “Water” and so on.

 

I’ve been successful in manually building a VRT file using Category element for the classes and ColorTable entry for a palette – but only for a single band.

 

My question is: how to properly apply this to all bands? Do I need duplicate category and colortable elements to every single VRTRasterBand element or is there a smart way to define it once and then refer to it like a variable?  Am I even approaching this the right way?

 

It was quite a bit of work to get this far and I’m not looking forward to doing this 30 more times.

 

Sample vrt and simplified source is attached.

 

Matt Wilkie

Geomatics Analyst

Environment | Information Management & Technology

T 867-667-8133 | Yukon.ca

 


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

scratch.0.tif (47K) Download Attachment
scratch_manually_built.vrt (27K) Download Attachment
-Matt
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

Stephen Woodbridge-4
Matt,

Have you tried create a cascading VRT, where the first VRT composites
all the GTiff files into a single virtual raster and then reference the
composite in another VRT that assigns colortable. I think this should
work nicely.

-Steve W

On 10/3/2019 7:01 PM, [hidden email] wrote:

>
> Hello gdal-dev, it's been a long time!  I'm happy to be digging into
> raster data building again for a change, but could use some nudges in
> the right direction(s).
>
> A few weeks ago Nasa released Landsat-derived Annual Dominant Land
> Cover Across ABoVE Core Domain, 1984-2014
> <https://daac.ornl.gov/ABOVE/guides/Annual_Landcover_ABoVE.html>.
>
> It’s composed of 175 geotiff images, with each file containing 31
> bands which in turn correspond to a single year in the 1984-2014
> period. Each band is 8bit unsigned integer with values from 1 to 15
> and 255 as nodata. Each integer value corresponds to a class such as
> “Evergreen Forest”, “Herbaceous”, “Water” and so on.
>
> I’ve been successful in manually building a VRT file using Category
> element for the classes and ColorTable entry for a palette – but only
> for a single band.
>
> My question is: how to properly apply this to all bands? Do I need
> duplicate category and colortable elements to every single
> VRTRasterBand element or is there a smart way to define it once and
> then refer to it like a variable?  Am I even approaching this the
> right way?
>
> It was quite a bit of work to get this far and I’m not looking forward
> to doing this 30 more times.
>
> Sample vrt and simplified source is attached.
>
> *Matt Wilkie*
>
> Geomatics Analyst
>
> Environment | Information Management & Technology
>
> T 867-667-8133 | Yukon.ca <http://yukon.ca/>
>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> https://lists.osgeo.org/mailman/listinfo/gdal-dev


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

mhw-at-yg
> Have you tried create a cascading VRT, where the first VRT composites
> all the GTiff files into a single virtual raster and then reference the
> composite in another VRT that assigns colortable.

Hmm, I hadn't thought about cascading; didn't know that was possible. I'd
still need 31 vrt's though right? 1 for each band.  

-Matt




--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
-Matt
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

Even Rouault-2
On vendredi 4 octobre 2019 08:25:49 CEST mhw-at-yg wrote:
> > Have you tried create a cascading VRT, where the first VRT composites
> > all the GTiff files into a single virtual raster and then reference the
> > composite in another VRT that assigns colortable.
>
> Hmm, I hadn't thought about cascading; didn't know that was possible. I'd
> still need 31 vrt's though right? 1 for each band.

I don't see VRT cascading of any help here, from what I've understood of your
use case. I think you have no other choice than replicating <Category> and
<ColorTable> in all <VRTRasterBand>

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

mhw-at-yg
> I don't see VRT cascading of any help here, from what I've understood of
your
> use case. I think you have no other choice than replicating <Category> and
> <ColorTable> in all <VRTRasterBand>

Ok. Thanks for confirming my understanding.

Next question: It appears that <Category> <ColorTable> are order-of-index
based. Meaning that: if "Evergreen" is first element in the category list it
is matched to the first element in the color list. So there is no way in vrt
to specify a lookup table of style "name == pixel_value" like the below?

  Pixel_Value       Category      
 ------------- ------------------
            1   Evergreen Forest  
            2   Deciduous Forest  
          ...                    
           14   Barren            
           15   Water  


I've worked around this by inserting an "n/a" category and 0,0,0 colour
table as first line in each. Without that in qgis and arcmap everything is
shifted by one and 'Deciduous' is assigned to pixel value 1 and 'Water' to
14.

-Matt





-----
-Matt
--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
-Matt
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

Even Rouault-2
On vendredi 4 octobre 2019 12:44:18 CEST mhw-at-yg wrote:

> > I don't see VRT cascading of any help here, from what I've understood of
>
> your
>
> > use case. I think you have no other choice than replicating <Category> and
> > <ColorTable> in all <VRTRasterBand>
>
> Ok. Thanks for confirming my understanding.
>
> Next question: It appears that <Category> <ColorTable> are order-of-index
> based. Meaning that: if "Evergreen" is first element in the category list it
> is matched to the first element in the color list. So there is no way in
> vrt to specify a lookup table of style "name == pixel_value" like the
> below?
>
>   Pixel_Value       Category
>  ------------- ------------------
>             1   Evergreen Forest
>             2   Deciduous Forest
>           ...
>            14   Barren
>            15   Water
>
>
> I've worked around this by inserting an "n/a" category and 0,0,0 colour
> table as first line in each. Without that in qgis and arcmap everything is
> shifted by one and 'Deciduous' is assigned to pixel value 1 and 'Water' to
> 14.
>

You could also potentially use a raster attribute table. See
GDALRasterAttributeTable in https://gdal.org/drivers/raster/vrt.html
The documentation is a bit loose.
The values for Type and Usage match the enumerations at
https://github.com/OSGeo/gdal/blob/master/gdal/gcore/gdal.h#L1189

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: vrt guidance: 31 band classified raster

mhw-at-yg
> You could also potentially use a raster attribute table. See
> GDALRasterAttributeTable in https://gdal.org/drivers/raster/vrt.html

Yeah, loose is right. ;-)  This is what I think I've puzzled out:

<http://osgeo-org.1560.x6.nabble.com/file/t192661/2019-10-04_15_29_23-Book1_-_Excel.png>



would be expressed as:




Type 2 means it's a string (GFT_String)
Usage 2 means this is the name of the class (GFU_Name)

Type 0 means a non-decimal number (GFT_Integer)
Usage 5 means use for pixels matching this value from the intersecting row
(GFU_MinMax)

Am I on the right track?

-Matt



-----
-Matt
--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
-Matt