gazar.grid

gazar.grid.utm_proj_from_latlon(latitude, longitude, as_wkt=False, as_osr=False)[source]

Returns UTM projection information from a latitude, longitude corrdinate pair.

Parameters:
  • latitude (float) – The center latitude.
  • longitude (float) – The center longitude.
  • as_wkt (bool, optional) – If True, will return the WKT projection string.
  • as_osr (bool, optional) – If True, will return the osr.SpatialReference() object.
Returns:

Defaults to the proj.4 string.

Return type:

str or osr.SpatialReference()

gazar.grid.geotransform_from_yx(y_arr, x_arr, y_cell_size=None, x_cell_size=None)[source]

Calculates geotransform from arrays of y and x coords. Assumes Y max and X min are at [0,0].

Parameters:
  • y_arr (numpy.array()) – Array of latitudes or y coordinates.
  • x_arr (numpy.array()) – Array of longitudes or x coordinates.
  • y_cell_size (float, optional) – Y cell size in projected coordinates.
  • x_cell_size (float, optional) – X cell size from projected coordinates.
Returns:

geotransform: (x_min, x_cell_size, x_skew, y_max, y_skew, -y_cell_size)

Return type:

tuple

gazar.grid.resample_grid(original_grid, match_grid, to_file=False, output_datatype=None, resample_method=<Mock id='139641521305488'>, as_gdal_grid=False)[source]

This function resamples a grid and outputs the result to a file.

Based on: http://stackoverflow.com/questions/10454316/how-to-project-and-
resample-a-grid-to-match-another-grid-with-gdal-python
Parameters:
  • original_grid (str or gdal.Dataset() or GDALGrid()) – The original grid dataset.
  • match_grid (str or gdal.Dataset() or GDALGrid()) – The grid to match.
  • to_file (str or bool, optional) – Default is False, which returns an in memory grid. If str, it writes to file.
  • output_datatype (osgeo.gdalconst(), optional) – A valid datatype from gdalconst (Ex. gdalconst.GDT_Float32).
  • resample_method (osgeo.gdalconst(), optional) – A valid resample method from gdalconst. Default is gdalconst.GRA_Average.
  • as_gdal_grid (bool, optional) – Return as GDALGrid(). Default is False.
Returns:

If to_file is a str, then it returns None. Otherwise, if to_file is False then it returns a gdal.Dataset() unless as_gdal_grid is True. Then, it returns GDALGrid().

Return type:

None or gdal.Dataset() or GDALGrid()

gazar.grid.gdal_reproject(src, dst=None, src_srs=None, dst_srs=None, epsg=None, error_threshold=0.125, resampling=<Mock id='139641521305616'>, as_gdal_grid=False)[source]

Reproject a raster image.

Based on: https://github.com/OpenDataAnalytics/
gaia/blob/master/gaia/geo/gdal_functions.py
Parameters:
  • src (str or gdal.Dataset() or GDALGrid()) – The source image.
  • dst (str, optional) – The filepath of the output image to write to.
  • src_srs (osr.SpatialReference(), optional) – The source image projection.
  • dst_srs (osr.SpatialReference(), optional) – The destination projection. If not provided, the code will use epsg.
  • epsg (int, optional) – The EPSG code to reproject to. If not provided, the code will use dst_srs.
  • error_threshold (float, optional) – Default is 0.125 (same as gdalwarp commandline).
  • resampling (osgeo.gdalconst()) – Method to use for resampling. Default method is gdalconst.GRA_NearestNeighbour.
  • as_gdal_grid (bool, optional) – Return as GDALGrid(). Default is False.
Returns:

By default, it returns gdal.Dataset. It will return GDALGrid() if as_gdal_grid is True.

Return type:

gdal.Dataset() or GDALGrid()