gdalutils
is a small library to handle GDAL-based raster files
Just run this line after installing all dependencies
pip install git+https://github.com/jsosa/gdalutils.git
The module is loaded via
import gdalutils as gu
To read a raster directly from disk it can be done by
gu.get_data(filename)
It'll return a numpy.array
object
Geographical information can be read via
gu.get_geo(filename)
it'll return a Pyhton list
containing
- xmin
- ymin
- xmax
- ymax
- number of cells
x
direction - number of cells
y
direction - resolution
x
direction - resolution
y
direction - an array containing center coordiantes of
x
cells - an array containing center coordiantes of
y
cells - projection
- nodata value
Writing numpy.array
object is posible by calling
gu.write_raster(myarray, myraster, geo, fmt, nodata)
Where myarray
is a numpy.array
object, myraster
is a filename output, geo
is a list with geographical information identical to the one obtained with gu.get_geo
, fmt
is the format output: 'Float32'
, 'Float64'
, etc and nodata
is the NODATA value
Passing from a numpy.array
object to a pandas.Dataframe
object is posible by
array_to_pandas(dat, geo, val, symbol)
where dat
is the numpy.array
object, geo
is the list containing geographical information, val
is a value to be masked and symbol
is the logical symbol to be applied
Passing from pandas to array is also possible via
pandas_to_array(df, geo, nodata)