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 bbox argument.)

  • 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_points argument).

  • 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_geom argument)

If using track_points or bounding_geom, you can also specify:
  • Whether the bounding shape should be rectangular, a convex hull, or an exact geometry (Use the boundary_type argument.)

  • A buffer size around the track points or shape of interest (Use the buffer argument.)

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 if bounding_geom is 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.zip as 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