pynhd.core

Base classes for PyNHD functions.

Module Contents

class pynhd.core.AGRBase(base_url, layer=None, outfields='*', crs=DEF_CRS, outformat='json', expire_after=EXPIRE, disable_caching=False)

Base class for getting geospatial data from a ArcGISRESTful service.

Parameters
  • base_url (str, optional) – The ArcGIS RESTful service url. The URL must either include a layer number after the last / in the url or the target layer must be passed as an argument.

  • layer (str, optional) – A valid service layer. To see a list of available layers instantiate the class without passing any argument.

  • outfields (str or list, optional) – Target field name(s), default to “*” i.e., all the fields.

  • crs (str, optional) – Target spatial reference, default to EPSG:4326

  • outformat (str, optional) – One of the output formats offered by the selected layer. If not correct a list of available formats is shown, defaults to json.

  • expire_after (int, optional) – Expiration time for response caching in seconds, defaults to -1 (never expire).

  • disable_caching (bool, optional) – If True, disable caching requests, defaults to False.

bygeom(self, geom, geo_crs=DEF_CRS, sql_clause='', distance=None, return_m=False, return_geom=True)

Get feature within a geometry that can be combined with a SQL where clause.

Parameters
  • geom (Polygon or tuple) – A geometry (Polygon) or bounding box (tuple of length 4).

  • geo_crs (str) – The spatial reference of the input geometry.

  • sql_clause (str, optional) – A valid SQL 92 WHERE clause, defaults to an empty string.

  • distance (int, optional) – The buffer distance for the input geometries in meters, default to None.

  • return_m (bool, optional) – Whether to activate the Return M (measure) in the request, defaults to False.

  • return_geom (bool, optional) – Whether to return the geometry of the feature, defaults to True.

Returns

geopandas.GeoDataFrame – The requested features as a GeoDataFrame.

byids(self, field, fids, return_m=False, return_geom=True)

Get features based on a list of field IDs.

Parameters
  • field (str) – Name of the target field that IDs belong to.

  • fids (str or list) – A list of target field ID(s).

  • return_m (bool) – Whether to activate the Return M (measure) in the request, defaults to False.

  • return_geom (bool, optional) – Whether to return the geometry of the feature, defaults to True.

Returns

geopandas.GeoDataFrame – The requested features as a GeoDataFrame.

bysql(self, sql_clause, return_m=False, return_geom=True)

Get feature IDs using a valid SQL 92 WHERE clause.

Notes

Not all web services support this type of query. For more details look here

Parameters
  • sql_clause (str) – A valid SQL 92 WHERE clause.

  • return_m (bool) – Whether to activate the measure in the request, defaults to False.

  • return_geom (bool, optional) – Whether to return the geometry of the feature, defaults to True.

Returns

geopandas.GeoDataFrame – The requested features as a GeoDataFrame.

get_validlayers(self, url)

Get a list of valid layers.

Parameters

url (str) – The URL of the ArcGIS REST service.

Returns

dict – A dictionary of valid layers.

class pynhd.core.ScienceBase

Access and explore files on ScienceBase.

Parameters
  • expire_after (int, optional) – Expiration time for response caching in seconds, defaults to -1 (never expire).

  • disable_caching (bool, optional) – If True, disable caching requests, defaults to False.

get_children(self, item)

Get children items of an item.

get_file_urls(self, item)

Get download and meta URLs of all the available files for an item.

pynhd.core.stage_nhdplus_attrs(parquet_path=None, expire_after=EXPIRE, disable_caching=False)

Stage the NHDPlus Attributes database and save to nhdplus_attrs.parquet.

More info can be found here.

Parameters
  • parquet_path (str or Path) – Path to a file with .parquet extension for saving the processed to disk for later use.

  • expire_after (int, optional) – Expiration time for response caching in seconds, defaults to -1 (never expire).

  • disable_caching (bool, optional) – If True, disable caching requests, defaults to False.

Returns

pandas.DataFrame – The staged data as a DataFrame.