GDALGrid¶
GDALGrid¶
A Python wrapper for the gdal.Dataset()
with additionaly functonality.
-
class
gazar.grid.
GDALGrid
(grid_file, prj_file=None)[source]¶ Wrapper for
gdal.Dataset()
withosr.SpatialReference()
object.Parameters: - grid_file – The grid file to be wrapped.
- prj_file (
str
, optional) – Path to projection file.
-
bounds
(as_geographic=False, as_utm=False, as_projection=None)[source]¶ Returns bounding coordinates for the dataset.
Parameters: Returns: (x_min, x_max, y_min, y_max) Bounds for the grid in the format
Return type:
-
coord2pixel
(x_coord, y_coord)[source]¶ Returns base-0 raster index using global coordinates to pixel center
Parameters: Returns: (col, row) - The 0-based column and row index of the pixel.
Return type:
-
get_val
(x_pixel, y_pixel, band=1)[source]¶ Returns value of raster
Parameters: Returns: Return type: object dtype
-
get_val_coord
(x_coord, y_coord, band=1)[source]¶ Returns value of raster from a projected coordinate point.
Parameters: Returns: Return type: object dtype
-
get_val_latlon
(longitude, latitude, band=1)[source]¶ Returns value of raster from a latitude and longitude point.
Parameters: Returns: Return type: object dtype
-
latlon
¶ Returns latitude and longitude arrays representing the grid.
Returns: - proj_lats (
numpy.array()
) – The latitude array. - proj_lons (
numpy.array()
) – The longitude array.
- proj_lats (
-
lonlat2pixel
(longitude, latitude)[source]¶ Returns base-0 raster index using longitude and latitude of pixel center
Parameters: Returns: (col, row) - The 0-based column and row index of the pixel.
Return type:
-
np_array
(band=1, masked=True)[source]¶ Returns the raster band as a numpy array.
Parameters: - band (obj:int, optional) – Band number (1-based). Default is 1. If ‘all’, it will return all of the data as a 3D array.
- masked (bool, optional) – If True, will return the array masked with the NoData value. Default is True.
Returns: Return type: numpy.array()
ornumpy.ma.array()
-
num_bands
¶ int – number of bands in raster
-
pixel2coord
(col, row)[source]¶ Returns global coordinates to pixel center using base-0 raster index.
Parameters: Returns: (x_coord, y_coord) - The x, y coordinate of the pixel center in the dataset’s projection.
Return type:
-
pixel2lonlat
(col, row)[source]¶ Returns latitude and longitude to pixel center using base-0 raster index
Parameters: Returns: (longitude, latitude) - The lat, lon of the pixel center in the dataset’s projection.
Return type:
-
proj
¶ func – pyproj.Proj – Proj4 object
-
to_arc_ascii
(file_path, band=1, print_nodata=True)[source]¶ Writes data to Arc ASCII file format.
Parameters:
-
to_grass_ascii
(file_path, band=1, print_nodata=True)[source]¶ Writes data to GRASS ASCII file format.
Parameters:
-
to_polygon
(out_shapefile, band=1, fieldname='DN', self_mask=None)[source]¶ Converts the raster to a polygon.
- https://svn.osgeo.org/gdal/trunk/gdal/swig/python/scripts
- /gdal_polygonize.py
- https://stackoverflow.com/questions/25039565
- /create-shapefile-from-tif-file-using-gdal
Parameters:
-
to_projection
(dst_proj, resampling=<Mock id='140107904794704'>)[source]¶ Reproject dataset to new projection.
Parameters: dst_proj ( osr.SpatialReference()
) – Output projection.Returns: Return type: GDALGrid()
-
x_coords
¶ Returns x coordinate array representing the grid. Use method from: https://github.com/pydata/xarray/pull/1712
Returns: x_coords – The X coordinate array. Return type: numpy.array()
-
x_size
¶ int – size of x dimensions
-
y_coords
¶ Returns y coordinate array representing the grid. Use method from: https://github.com/pydata/xarray/pull/1712
Returns: y_coords – The Y coordinate array. Return type: numpy.array()
-
y_size
¶ int – size of y dimensions
ArrayGrid¶
Class for constructing a GDALGrid from an array.
-
class
gazar.grid.
ArrayGrid
(in_array, wkt_projection, geotransform, gdal_dtype=<Mock id='140107904795024'>, nodata_value=None)[source]¶ Bases:
gazar.grid.GDALGrid
Loads
numpy.array()
into aGDALGrid()
.Parameters: - in_array (
numpy.array()
) – 2D or 3D array of data. - wkt_projection (
str
) – WKT projection string. - geotransform (
tuple
) – Geotransform for array. - gdal_dtype (
gdalconst()
, optional) – The data type of the in_array for GDAL. Default is gdalconst.GDT_Float32. - nodata_value (int or float, optional) – The value used in the grid for NoData. Default is None.
- in_array (