Welcome to GeoRasters’s documentation!¶
-
georasters.
map_pixel
(point_x, point_y, cellx, celly, xmin, ymax)[source]¶ - Usage:
- map_pixel(xcoord, ycoord, x_cell_size, y_cell_size, xmin, ymax)
- where:
xmin is leftmost X coordinate in system
ymax is topmost Y coordinate in system
- Example:
raster = HMISea.tif
ndv, xsize, ysize, geot, projection, datatype = get_geo_info(raster)
row, col = map_pixel(x,y,geot[1],geot[-1], geot[0],geot[3])
-
georasters.
map_pixel_inv
(row, col, cellx, celly, xmin, ymax)[source]¶ - Usage:
- map_pixel(xcoord, ycoord, x_cell_size, y_cell_size, xmin, ymax)
- where:
xmin is leftmost X coordinate in system
ymax is topmost Y coordinate in system
- Example:
raster = HMISea.tif
ndv, xsize, ysize, geot, projection, datatype = get_geo_info(raster)
row, col = map_pixel(x,y,geot[1],geot[-1], geot[0],geot[3])
-
georasters.
aggregate
(raster, ndv, block_size)[source]¶ Aggregate raster to smaller resolution, by adding cells. Usage:
aggregate(raster, ndv, block_size)- where:
raster is a Numpy array created by importing the raster (e.g. geotiff)
ndv is the NoData Value for the raster (can be read using the get_geo_info function)
block_size is a duple of factors by which the raster will be shrinked
- Example:
raster = HMISea.tif
ndv, xsize, ysize, geot, projection, datatype = get_geo_info(raster)
costs = load_tiff(raster)
costs2=aggregate(costs, ndv, (10,10))
-
georasters.
create_geotiff
(name, Array, driver, ndv, xsize, ysize, geot, projection, datatype, band=1)[source]¶ Creates new geotiff from array
-
georasters.
align_rasters
(raster, alignraster, how=<numpy.ma.core._frommethod object>, cxsize=None, cysize=None, masked=False)[source]¶ Align two rasters so that data overlaps by geographical location Usage: (alignedraster_o, alignedraster_a, geot_a) = AlignRasters(raster, alignraster, how=np.mean)
- where:
raster: string with location of raster to be aligned
alignraster: string with location of raster to which raster will be aligned
how: function used to aggregate cells (if the rasters have different sizes)
It is assumed that both rasters have the same size
-
georasters.
load_tiff
(file)[source]¶ Load a geotiff raster keeping ndv values using a masked array
- Usage:
- data = load_tiff(file)
-
georasters.
union
(rasters)[source]¶ Union of rasters
- Usage:
- union(rasters)
- where:
- rasters is a list of GeoRaster objects
-
class
georasters.
GeoRaster
(raster, geot, nodata_value=nan, fill_value=-10000000000.0, projection=None, datatype=None)[source]¶ GeoRaster class to create and handle GIS rasters. Eash GeoRaster object is a numpy masked array + geotransfrom + nodata_value
- Usage:
- geo=GeoRaster(raster, geot, nodata_value=ndv)
- where
- raster: Numpy masked array with the raster data,
- which could be loaded with the load_tiff(file)
geot: GDAL Geotransformation nodata_value: No data value in raster, optional
-
aggregate
(block_size)[source]¶ Returns copy of raster aggregated to smaller resolution, by adding cells.
-
apply
(func, *args, **kwargs)[source]¶ Returns the value of applying function func on the raster data
func: Python function *args: Arguments of function **kwargs: Additional arguments of function
-
argmax
(axis=None, out=None)[source]¶ Return indices of the maximum values along the given axis.
Refer to numpy.argmax for full documentation.
numpy.argmax : equivalent function
-
argmin
(axis=None, out=None)[source]¶ Return indices of the minimum values along the given axis of a.
Refer to numpy.argmin for detailed documentation.
numpy.argmin : equivalent function
-
block_reduce
(block_size, how=func)[source]¶ Returns copy of raster aggregated to smaller resolution, by adding cells. Default: func=np.ma.mean
-
clip
(shp, keep=False, *args, **kwargs)[source]¶ Clip raster using shape, where shape is either a GeoPandas DataFrame, shapefile, or some other geometry format used by python-raster-stats
Returns list of GeoRasters or Pandas DataFrame with GeoRasters and additional information
Usage:
clipped = geo.clip(shape, keep=False)
where: keep: Boolean (Default False), returns Georasters and Geometry information
-
distance
(sources, destinations, x='x', y='y', isolation=True, export_raster=False, export_shape=False, routes=False, path='./')[source]¶ Compute cost distance measured from each start point to all end points. The function returns the distances between the start point and the end points as a Pandas dataframe. Additionally, for each start point it computes the level of isolation, i.e. its average travel distance to all other locations
-
extract
(x, y, radius=r)[source]¶ Return subraster of raster geo around location (x,y) with radius r where (x,y) and r are in the same coordinate system as geo
-
flatten
(order='C')[source]¶ Return a copy of the array collapsed into one dimension.
- order : {‘C’, ‘F’, ‘A’}, optional
- Whether to flatten in C (row-major), Fortran (column-major) order, or preserve the C/Fortran ordering from a. The default is ‘C’.
-
map_pixel
(point_x, point_y)[source]¶ Return value of raster in location Note: (point_x, point_y) must belong to the geographic coordinate system and the coverage of the raster
-
map_pixel_location
(point_x, point_y)[source]¶ geo.map_pixel(point_x, point_y)
Return value of raster in location
-
map_vector
(x, **kvars)[source]¶ Create new GeoRaster, which has its data replaced by x Useful to map output of PySal analyses, e.g. spatial autocorrelation values, etc.
Usage: raster2 = map_vector(x, raster) where
raster: GeoRaster x: Numpy array of data with same length as non-missing values in raster,
i.e., len(x) == np.sum(raster.mask==False)
-
max
(axis=None, out=None)[source]¶ Return the maximum along a given axis.
Refer to numpy.amax for full documentation.
numpy.amax : equivalent function
-
mcp
(*args, **kwargs)[source]¶ Setup MCP_Geometric object from skimage for optimal travel time computations
-
mean
(axis=None, dtype=None, out=None)[source]¶ Returns the average of the array elements along given axis.
Refer to numpy.mean for full documentation.
numpy.mean : equivalent function
-
median
(axis=None, out=None, overwrite_input=False)[source]¶ - axis : int, optional
- Axis along which the medians are computed. The default (axis=None) is to compute the median along a flattened version of the array.
- out : ndarray, optional
- Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output, but the type (of the output) will be cast if necessary.
- overwrite_input : bool, optional
- If True, then allow use of memory of input array (a) for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. Note that, if overwrite_input is True and the input is not already an ndarray, an error will be raised.
-
min
(axis=None, out=None)[source]¶ Return the minimum along a given axis.
Refer to numpy.amin for full documentation.
numpy.amin : equivalent function
-
prod
(axis=None, dtype=None, out=None)[source]¶ Return the product of the array elements over the given axis
Refer to numpy.prod for full documentation.
numpy.prod : equivalent function
-
pysal_G
(**kwargs)[source]¶ Compute Getis and Ord’s G for GeoRaster
Usage: geo.pysal_G(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.G See help(gr.raster_weights), help(pysal.G) for options
-
pysal_G_Local
(star=False, **kwargs)[source]¶ Compute Local G or G* measures of local spatial autocorrelation for GeoRaster
Usage: geo.pysal_Moran(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.G_Local See help(gr.raster_weights), help(pysal.G_Local) for options
-
pysal_Gamma
(**kwargs)[source]¶ Compute Gamma Index of Spatial Autocorrelation for GeoRaster
Usage: geo.pysal_Gamma(permutations = 1000, rook=True, operation=’c’)
arguments passed to raster_weights() and pysal.Gamma See help(gr.raster_weights), help(pysal.Gamma) for options
-
pysal_Geary
(**kwargs)[source]¶ Compute Geary’s C for GeoRaster
Usage: geo.pysal_C(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.Geary See help(gr.raster_weights), help(pysal.Geary) for options
-
pysal_Join_Counts
(**kwargs)[source]¶ Compute join count statistics for GeoRaster
Usage: geo.pysal_Join_Counts(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.Join_Counts See help(gr.raster_weights), help(pysal.Join_Counts) for options
-
pysal_Moran
(**kwargs)[source]¶ Compute Moran’s I measure of global spatial autocorrelation for GeoRaster
Usage: geo.pysal_Moran(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.Moran See help(gr.raster_weights), help(pysal.Moran) for options
-
pysal_Moran_Local
(**kwargs)[source]¶ Compute Local Moran’s I measure of local spatial autocorrelation for GeoRaster
Usage: geo.pysal_Moran_Local(permutations = 1000, rook=True)
arguments passed to raster_weights() and pysal.Moran_Local See help(gr.raster_weights), help(pysal.Moran_Local) for options
-
raster_weights
(**kwargs)[source]¶ Compute neighbor weights for GeoRaster. See help(gr.raster_weights) for options
Usage: geo.raster_weights(rook=True)
-
resize
(new_shape, order=0, mode='constant', cval=np.nan, preserve_range=True)[source]¶ Returns resized georaster
-
resize_old
(block_size, order=0, mode='constant', cval=False)[source]¶ geo.resize(new_shape, order=0, mode=’constant’, cval=np.nan, preserve_range=True)
Returns resized georaster
-
stats
(shp, stats='mean', add_stats=None, raster_out=True, *args, **kwargs)[source]¶ Compute raster statistics for a given geometry in shape, where shape is either a GeoPandas DataFrame, shapefile, or some other geometry format used by python-raster-stats. Runs python-raster-stats in background (additional help and info can be found there)
Returns dataframe with statistics and clipped raster
Usage:
df = geo.stats(shape, stats=stats, add_stats=add_stats)
where: raster_out: If True (Default), returns clipped Georasters
-
std
(axis=None, dtype=None, out=None, ddof=0)[source]¶ Returns the standard deviation of the array elements along given axis.
Refer to numpy.std for full documentation.
numpy.std : equivalent function
-
sum
(axis=None, dtype=None, out=None)[source]¶ Return the sum of the array elements over the given axis.
Refer to numpy.sum for full documentation.
numpy.sum : equivalent function
-
to_geopandas
(**kwargs)[source]¶ Convert GeoRaster to GeoPandas DataFrame, which can be easily exported to other types of files and used to do other types of operations. The DataFrame has the geometry (Polygon), row, col, value, x, and y values for each cell
-
to_pandas
(**kwargs)[source]¶ Convert GeoRaster to Pandas DataFrame, which can be easily exported to other types of files The DataFrame has the row, col, value, x, and y values for each cell
-
georasters.
merge
(rasters)[source]¶ Merges GeoRasters, same as union Usage:
merge(rasters)- where
- rasters is a list of GeoRaster objects
-
georasters.
to_pandas
(raster, name='value')[source]¶ Convert GeoRaster to Pandas DataFrame, which can be easily exported to other types of files The DataFrame has the row, col, value, x, and y values for each cell Usage:
df = gr.to_pandas(raster)
-
georasters.
to_geopandas
(raster, **kwargs)[source]¶ Convert GeoRaster to GeoPandas DataFrame, which can be easily exported to other types of files and used to do other types of operations. The DataFrame has the geometry (Polygon), row, col, value, x, and y values for each cell Usage:
df = gr.to_geopandas(raster)
-
georasters.
from_pandas
(df, value='value', x='x', y='y', cellx=None, celly=None, xmin=None, ymax=None, geot=None, nodata_value=None, projection=None, datatype=None)[source]¶ Creates a GeoRaster from a Pandas DataFrame. Useful to plot or export data to rasters. Usage:
- raster = from_pandas(df, value=’value’, x=’x’, y=’y’, cellx= cellx, celly=celly,
- xmin=xmin, ymax=ymax, geot=geot, nodata_value=ndv, projection=projection, datatype=datatype)
Although it does not require all the inputs, it is highly recommended to include the geographical information, so that the GeoRaster is properly constructed. As usual, the information can be added afterwards directly to the GeoRaster.
-
georasters.
raster_weights
(raster, rook=False, transform='r', **kwargs)[source]¶ Construct PySal weights for rasters It drops weights for all cells that have no data or are Inf/NaN Usage:
w = raster_weights(raster, rook=False, transform=’r’, **kwargs)
- where
- raster: (Masked) Numpy array for which weights are to be constructed rook: Boolean, type of contiguity. Default is queen. For rook, rook = True **kwargs are defined by and passed to pysal.lat2W. See help(pysal.lat2W)
-
georasters.
map_vector
(x, raster, **kvars)[source]¶ Create new GeoRaster, which has its data replaced by x Useful to map output of PySal analyses, e.g. spatial autocorrelation values, etc.
Usage: raster2 = map_vector(x, raster) where
raster: GeoRaster x: Numpy array of data with same length as non-missing values in raster,
i.e., len(x) == np.sum(raster.mask==False)
-
georasters.
align_georasters
(raster, alignraster, how=<function mean>, cxsize=None, cysize=None)[source]¶ Align two rasters so that data overlaps by geographical location Usage: (alignedraster_o, alignedraster_a) = AlignRasters(raster, alignraster, how=np.mean) where
raster: string with location of raster to be aligned alignraster: string with location of raster to which raster will be aligned how: function used to aggregate cells (if the rasters have different sizes)It is assumed that both rasters have the same size