Subsetting function#
- subset_data(filename, bbox=None, track_points=None, bounding_geom=None, boundary_type='rectangular', buffer=0, clip=False, outfile=None)#
Subsets a spatial dataset to an area of interest.
Allowable data formats are those supported by GeoPandas; for more information see Reading spatial data with GeoPandas
- There are three subsetting options:
Specify a bounding box: Provide coordinates for a bounding box. (Use the
bboxargument.)Provide animal track data: Provide a csv file of Movebank animal track data, and a boundary will be drawn that encompasses all of the track points.(Use the
track_pointsargument).Provide another shapefile for subsetting: A boundary will be drawn around the features in this shapefile. For example, you could a provide a shapefile with a bounding polygon for a region of interest. (Use the
bounding_geomargument)
- If using
track_pointsorbounding_geom, you can also specify: Whether the bounding shape should be rectangular, a convex hull, or an exact geometry (Use the
boundary_typeargument.)A buffer size around the track points or shape of interest (Use the
bufferargument.)
The newly subsetted shapefile is returned as a GeoDataFrame, and is optionally written out to a new shapefile.
- Parameters:
filename (str) – Path to data file to subset
bbox (list or tuple, optional) – Bounding box coordinates for the subset. Should be specified in the format
(long_min, lat_min, long_max, lat_max).track_points (str, optional) – Path to csv file with animal track points. Latitude and longitude must be labeled as “location_lat” and “location_long”.
bounding_geom (str, optional) – Path to shapefile with bounding geometry.
boundary_type (str, optional) – Specifies whether the bounding shape should be rectangular (
boundary_type= 'rectangular'), convex hull(boundary_type = 'convex_hull'), or the exact bounding geometry (boundary_type='mask').boundary_type='mask'can only be used ifbounding_geomis provided. By default ‘rectangular’.buffer (float, optional) – Buffer size around the track points or bounding geometry, relative to the extent of the track points or bounding geometry. By default 0. Note that using a buffer will slow down processing.
clip (bool, optional) – Whether or not to clip the subsetted data to the specified boundary (i.e., cut off intersected features at the boundary edge). By default False.
outfile (str, optional) – Path to write the subsetted .shp file, if specified. Use
.shp.zipas the extension to write a zipped shapefile. If no path is specified, the subsetted data won’t be written out to a file.
- Returns:
geopandas GeoDataFrame – GeoDataFrame with the subsetted data
geopandas GeoDataFrame – GeoDataFrame with the bounding geometry
Todo
Add option to subset from an exact boundary, rather than a convex hull
Add examples section