utils¶
This module contains various i/o and utility functions
Functions
add_polyline(track, gdf) |
Updates a geopandas dataframe with a polyline. |
calculate_hillshade(img[, az, elev_angle]) |
Calculates hillshade |
plot_map(raster[, loc, title, figsize, …]) |
Basic raster plot. |
plot_network(df[, save]) |
Plots network |
pt2rc(pts, profile) |
Returns row and column. |
rc2pt(rc, profile) |
Returns the center x, y coordinates of cells at (row, column) locations. |
read_raster(fn) |
Reads raster into a 2D numpy array. |
-
read_raster(fn)[source]¶ Reads raster into a 2D numpy array.
Parameters: fn (string) – path to raster image (assume geotiff) Returns: - ras (2D numpy array) – raster
- profile (dictionary) – raster geospatial information
-
add_polyline(track, gdf)[source]¶ Updates a geopandas dataframe with a polyline.
Parameters: - track (list of tuples) – list of coordinates representing a polyline
- gdf (geodataframe) –
Returns: gdf – Updated geodataframe
Return type: geodataframe
-
rc2pt(rc, profile)[source]¶ Returns the center x, y coordinates of cells at (row, column) locations.
Parameters: - rc (list) – list of rows and column pairs
- profile (dictionary) – raster geospatial information
Returns: pts – list of tuples representing (x,y) coordinates
Return type: list
-
pt2rc(pts, profile)[source]¶ Returns row and column.
Parameters: - pts (shapely point) – points
- profile (dictionary) – raster geospatial information
Returns: r,c – rows and columns
Return type: tuple of numpy arrays
Notes
Expects the point column of a geopandas dataframe and returns the rows and columns for each point. No checks on whether points are within bounding box.
-
plot_map(raster, loc=None, title=None, figsize=(5, 5), cmap='viridis', cbar=False, save=None, **kwother)[source]¶ Basic raster plot.
Parameters: - raster (dictionary) –
dictionary must have at least two entries:
- ’ras’: 2D numpy array representing a raster
- **’profile’: raster information (as derived from rasterio)
- Optional entries are:
- ’bground’: a 2D numpy array representing a background raster. Typically a hillshade.
- ’paths’: dataframe representing a network of paths as obtained from
calculate_paths()
- loc (dictionary or geodataframe, optional) –
used to identify point locations. if dictionary then it must have at least two entries:
- ’df’: geopandas framework holding point data.
- ’label’: name of the column in ‘df’ used to label points.
- title (string, optional) – if not empty then title to be used when displaying ras
- figsize (tuple) – Size of figure. Default: (5,5)
- cmap (string) – name of the matplotlib colormap. Default: ‘viridis’
- cbar (boolean) – if True colorbar is displayed. Default: False
- save (string, optional) – if not empty then name of the output image. Default: None
- raster (dictionary) –
-
calculate_hillshade(img, az=135, elev_angle=40)[source]¶ Calculates hillshade
Parameters: - img (2D numpy array) – array with elevation values
- az (float) – Horizontal direction of the source of light (degrees). Default: 135 degrees
- elev_angle (float) – elevation angle of the source of light (degrees). Default: 40 degrees
-
plot_network(df, save=None)[source]¶ Plots network
Parameters: - df (dataframe) – contains the ids of origin and destination of each path in the network
- save (string) – filename (‘.png’ added). Default: None
Notes
The dataframe above is the output from running
generate.network_layout(). To save output user must supply filename. An image file with ‘.png’ extension will be saved to local directory.