Extracting raster attribute table from raster using gdalinfo

user308827
_rat = subprocess.check_output('gdalinfo -json ' + dataset_uri, shell=True)

I want to extract the raster attribute table of a .tif file. In the command above, I am able to get the info into _rat but not sure how to extract the rat section from _rat. Any suggestions?

Logan Byers

In your code, _rat is a string that is valid JSON. You can convert that JSON into a python dict that will allow you to access the elements with ease. gdalinfo doesn't provide the full raster attribute table as I recall, but there is still band-level statistics that are meaningful.

import json
import subprocess

dataset_uri = 'input.tif'
_rat = subprocess.check_output('gdalinfo -json ' + dataset_uri, shell=True)
data = json.loads(_rat) # load json string into dictionary
print data

# to get band-level data
bands = data['bands']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to legend a raster using directly the raster attribute table and displaying the legend only for class displayed in the raster?

From Dev

Extracting pixels from a raster based on specific value of another raster using R

From Dev

Raster to table using r

From Dev

Using a raster attribute from a multi-attribute raster for colour levels in a plot in R

From Dev

Extracting a value from a raster for a specific point based on the closest cell value using r

From Dev

Extracting raster values, from maximum, to cumulatively sum to x

From Dev

Look up table using large raster (in R)

From Dev

Look up table using large raster (in R)

From Dev

Raster overlay from a matrix

From Dev

Extracting points that belong to a certain area of a RasterLayer (raster)

From Dev

Error while extracting netcdf files into raster

From Java

How to get the RGBA color table of a singleband raster using R?

From Dev

How to extract values from a raster using polygons with the R stars package?

From Dev

How to extract values from a raster using polygons with the R stars package?

From Dev

Issue using saveRDS() with raster objects

From Dev

Using R to change raster projection

From Dev

How to extract varname from raster?

From Dev

How to extract varname from raster?

From Dev

Clump raster values depending on class attribute

From Dev

Clump raster values depending on class attribute

From Dev

R: Crop GeoTiff Raster using packages "rgdal" and "raster"

From Dev

subsetting raster stack by index using cell values of another raster

From Dev

How to show all column names in a raster using raster package in r

From Dev

How to extract raster layer names from raster stack R?

From Dev

Extracting data from attribute using regex

From Dev

extracting raster files by matching their name with the other list of names

From Dev

Resample raster

From Dev

Extracting data from a table using javascript

From Dev

Extracting Table from HANA using R

Related Related

  1. 1

    How to legend a raster using directly the raster attribute table and displaying the legend only for class displayed in the raster?

  2. 2

    Extracting pixels from a raster based on specific value of another raster using R

  3. 3

    Raster to table using r

  4. 4

    Using a raster attribute from a multi-attribute raster for colour levels in a plot in R

  5. 5

    Extracting a value from a raster for a specific point based on the closest cell value using r

  6. 6

    Extracting raster values, from maximum, to cumulatively sum to x

  7. 7

    Look up table using large raster (in R)

  8. 8

    Look up table using large raster (in R)

  9. 9

    Raster overlay from a matrix

  10. 10

    Extracting points that belong to a certain area of a RasterLayer (raster)

  11. 11

    Error while extracting netcdf files into raster

  12. 12

    How to get the RGBA color table of a singleband raster using R?

  13. 13

    How to extract values from a raster using polygons with the R stars package?

  14. 14

    How to extract values from a raster using polygons with the R stars package?

  15. 15

    Issue using saveRDS() with raster objects

  16. 16

    Using R to change raster projection

  17. 17

    How to extract varname from raster?

  18. 18

    How to extract varname from raster?

  19. 19

    Clump raster values depending on class attribute

  20. 20

    Clump raster values depending on class attribute

  21. 21

    R: Crop GeoTiff Raster using packages "rgdal" and "raster"

  22. 22

    subsetting raster stack by index using cell values of another raster

  23. 23

    How to show all column names in a raster using raster package in r

  24. 24

    How to extract raster layer names from raster stack R?

  25. 25

    Extracting data from attribute using regex

  26. 26

    extracting raster files by matching their name with the other list of names

  27. 27

    Resample raster

  28. 28

    Extracting data from a table using javascript

  29. 29

    Extracting Table from HANA using R

HotTag

Archive