I want to get just the Pixel size of a raster (in an automated workflow), and gdalinfo looks like the best tool for that; The trouble is that it gives a whole lot of info which I don't need.
So instead of using awk or some other logic for parsing the whole thing, is there a way of getting only the Pixel Size from gdalinfo?
Answer
Are you using Python for your automated workflow? Although you specify gdalinfo in your question, you can get the raster information using Python if you have the GDAL Python bindings set up.
# Imports
import gdal
# Open raster in ReadOnly mode
rast_src = ".../raster.tif"
rast_open = gdal.Open(rast_src, GA_ReadOnly)
# Get georeference information: this returns a list containing
# origin x, cell size (W-E),rotation, origin y, rotation, cell size (N-S)
rast_info = rast_open.GetGeoTransform()
# The origin is the top left of the image and the cell size is given in
# the x direction (W-E) and y direction (N-S).
res_x = rast_info[1]
res_y = rast_info[5]
Note that res_y will be negative as it is measured south from origin.
For more information on the GeoTransform object see the Getting Dataset Information section here: http://www.gdal.org/gdal_tutorial.html
The following tutorial essentially runs through this step by step and references some more useful online resources: http://geoinformaticstutorial.blogspot.co.uk/2012/09/reading-raster-data-with-python-and-gdal.html
No comments:
Post a Comment