pynhd.core#

Base classes for PyNHD functions.

Module Contents#

class pynhd.core.AGRBase(base_url, layer=None, outfields='*', crs=DEF_CRS, outformat='json')#

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.

bygeom(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(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(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(url)#

Get a list of valid layers.

Parameters

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

Returns

dict – A dictionary of valid layers.

property service_info#

Get the service information.

class pynhd.core.GeoConnex(item=None)#

Access to the GeoConnex API.

Notes

The geometry field of the query can be a Polygon, MultiPolygon, or tuple/list of length 4 (bbox) in EPSG:4326 CRS. They should be within the extent of the GeoConnex endpoint.

Parameters

item (str, optional) – The target endpoint to query, defaults to None.

property item#

Return the name of the endpoint.

query(kwds, skip_geometry=False)#

Query the GeoConnex endpoint.

class pynhd.core.ScienceBase#

Access and explore files on ScienceBase.

static get_children(item)#

Get children items of an item.

static get_file_urls(item)#

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

pynhd.core.stage_nhdplus_attrs(parquet_path=None)#

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.

Returns

pandas.DataFrame – The staged data as a DataFrame.