pynhd.core#
Base classes for PyNHD functions.
Module Contents#
- class pynhd.core.AGRBase(base_url, layer=None, outfields='*', crs=4326, 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
orlist
, optional) – Target field name(s), default to “*” i.e., all the fields.crs (
str
,int
, orpyproj.CRS
, optional) – Target spatial reference, default toEPSG: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 tojson
.
- bygeom(geom, geo_crs=4326, 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
ortuple
) – 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 toTrue
.
- Returns:
geopandas.GeoDataFrame
– The requested features as a GeoDataFrame.- Return type:
- byids(field, fids, return_m=False, return_geom=True)#
Get features based on a list of field IDs.
- Parameters:
- Returns:
geopandas.GeoDataFrame
– The requested features as a GeoDataFrame.- Return type:
- 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:
- Returns:
geopandas.GeoDataFrame
– The requested features as a GeoDataFrame.- Return type:
- static get_validlayers(url)#
Get a list of valid layers.
- property service_info: ServiceInfo#
Get the service information.
- class pynhd.core.GeoConnex(item=None, dev=False, max_nfeatures=10000)#
Access to the GeoConnex API.
Notes
The
geometry
field of the query can be a Polygon, MultiPolygon, or tuple/list of length 4 (bbox) inEPSG:4326
CRS. They should be within the extent of the GeoConnex endpoint.- Parameters:
The item (service endpoint) to query. Valid endpoints are –
hu02
for Two-digit Hydrologic Regionshu04
for Four-digit Hydrologic Subregionhu06
for Six-digit Hydrologic Basinshu08
for Eight-digit Hydrologic Subbasinshu10
for Ten-digit Watershedsnat_aq
for National Aquifers of the United States fromUSGS National Water Information System National Aquifer code list.
principal_aq
for Principal Aquifers of the United States from2003 USGS data release
sec_hydrg_reg
for Secondary Hydrogeologic Regions of theConterminous United States from 2018 USGS data release
gages
for US Reference Stream Gauge Monitoring Locationsmainstems
for US Reference Mainstem Riversstates
for U.S. Statescounties
for U.S. Countiesaiannh
for Native American Landscbsa
for U.S. Metropolitan and Micropolitan Statistical Areasua10
for Urbanized Areas and Urban Clusters (2010 Census)places
for U.S. legally incororated and Census designated placespws
for U.S. Public Water Systemsdams
for US Reference Dams
dev (
bool
, optional) – Whether to use the development endpoint, defaults toFalse
.max_nfeatures (
int
, optional) – The maximum number of features to request from the service, defaults to 10000.
- bybox(bbox, skip_geometry=False)#
Query the GeoConnex endpoint by bounding box.
- Parameters:
- Returns:
geopandas.GeoDataFrame
– The query result as ageopandas.GeoDataFrame
.- Return type:
- bycql(cql_dict: dict[str, Any], skip_geometry: Literal[False] = False) geopandas.GeoDataFrame #
- bycql(cql_dict: dict[str, Any], skip_geometry: Literal[True]) pandas.DataFrame
Query the GeoConnex endpoint.
Notes
GeoConnex only supports simple CQL queries. For more information and examples visit https://portal.ogc.org/files/96288#simple-cql-JSON. Use this for non-spatial queries, since there’s a dedicated method for spatial queries,
bygeometry()
.- Parameters:
- Returns:
geopandas.GeoDataFrame
– The query result as ageopandas.GeoDataFrame
.
- byfilter(filter_str, skip_geometry=False)#
Query the GeoConnex endpoint.
Notes
GeoConnex only supports simple CQL queries. For more information and examples visit https://portal.ogc.org/files/96288
- Parameters:
- Returns:
geopandas.GeoDataFrame
– The query result as ageopandas.GeoDataFrame
.- Return type:
- bygeometry(geometry1: GTYPE, geometry2: GTYPE | None = ..., predicate: str = ..., crs: CRSTYPE = ..., skip_geometry: Literal[False] = False) geopandas.GeoDataFrame #
- bygeometry(geometry1: GTYPE, geometry2: GTYPE | None = ..., predicate: str = ..., crs: CRSTYPE = ..., skip_geometry: Literal[True] = True) pandas.DataFrame
Query the GeoConnex endpoint by geometry.
- Parameters:
geometry1 (
Polygon
ortuple
offloat
) – The first geometry or bounding boxes to query. A bounding box is a tuple of length 4 in the form of(xmin, ymin, xmax, ymax)
. For example, an spatial query for a single geometry would beINTERSECTS(geom, geometry1)
.geometry2 (
Polygon
ortuple
offloat
, optional) – The second geometry or bounding boxes to query. A bounding box is a tuple of length 4 in the form of(xmin, ymin, xmax, ymax)
. Default isNone
. For example, an spatial query for a two geometries would beCROSSES(geometry1, geometry2)
.predicate (
str
, optional) – The predicate to use, by defaultintersects
. Supported predicates areintersects
,within
,contains
,overlaps
,crosses
,disjoint
,touches
, andequals
.crs (
int
orstr
orpyproj.CRS
, optional) – The CRS of the polygon, by defaultEPSG:4326
. If the input is ageopandas.GeoDataFrame
orgeopandas.GeoSeries
, this argument will be ignored.skip_geometry (
bool
, optional) – IfTrue
, no geometry will not be returned.
- Returns:
geopandas.GeoDataFrame
– The query result as ageopandas.GeoDataFrame
.