gazar.shape¶
-
gazar.shape.
reproject_layer
(in_path, out_path, out_spatial_ref)[source]¶ Reprojects a shapefile layer.
- Based on: https://pcjericks.github.io/
- py-gdalogr-cookbook/projection.html
Parameters:
-
gazar.shape.
rasterize_shapefile
(shapefile_path, out_raster_path=None, shapefile_attribute=None, x_cell_size=None, y_cell_size=None, x_num_cells=None, y_num_cells=None, match_grid=None, raster_wkt_proj=None, convert_to_utm=False, raster_dtype=<Mock id='139641514044944'>, raster_nodata=-9999, as_gdal_grid=False)[source]¶ Convert shapefile to raster from specified attribute
Parameters: - shapefile_path (
str
) – Path to shapefile. - out_raster_path (
str
, optional) – Path to raster to be generated. - shapefile_attribute (
str
, optional) – Attribute to be rasterized. - x_cell_size (float, optional) – Longitude cell size in output projection.
- y_cell_size (float, optional) – Latitude cell size in output projection.
- x_num_cells (int, optional) – Number of cells in latitude.
- y_num_cells (int, optional) – Number of cells in longitude.
- match_grid (str or
gdal.Dataset()
orGDALGrid()
, optional) – Grid to match for output. - raster_wkt_proj (
str
, optional) – WKT projections string for output grid. - convert_to_utm (bool, optional) – Convert grid to UTM automatically. Default is False.
- raster_dtype (
osgeo.gdalconst()
) – Output grid datatype (GDT). Default is gdal.GDT_Int32. - raster_nodata (float or int, optional) – No data value for output raster. Default is -9999,
- as_gdal_grid (bool, optional) – Return as
GDALGrid()
. Default is False.
Returns: It will return
GDALGrid()
if as_gdal_grid is True. Otherwise, it will not return anything.Return type: None or
GDALGrid()
Example Default:
from gloot.grid import rasterize_shapefile shapefile_path = 'shapefile.shp' new_grid = 'new_grid.tif' rasterize_shapefile(shapefile_path, new_grid, x_num_cells=50, y_num_cells=50, raster_nodata=0, )
Example GDALGrid to ASCII with UTM:
from gazar.grid import rasterize_shapefile shapefile_path = 'shapefile.shp' new_grid = 'new_grid.asc' gr = rasterize_shapefile(shapefile_path, x_num_cells=50, y_num_cells=50, raster_nodata=0, convert_to_utm=True, as_gdal_grid=True, ) gr.to_grass_ascii(new_grid, print_nodata=False)
- shapefile_path (