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 (
strorlist, optional) – Target field name(s), default to “*” i.e., all the fields.crs (
str,int, orpyproj.CRS, optional) – Target spatial reference, default toEPSG:4326outformat (
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 (
Polygonortuple) – 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
geometryfield of the query can be a Polygon, MultiPolygon, or tuple/list of length 4 (bbox) inEPSG:4326CRS. They should be within the extent of the GeoConnex endpoint.- Parameters:
The item (service endpoint) to query. Valid endpoints are –
hu02for Two-digit Hydrologic Regionshu04for Four-digit Hydrologic Subregionhu06for Six-digit Hydrologic Basinshu08for Eight-digit Hydrologic Subbasinshu10for Ten-digit Watershedsnat_aqfor National Aquifers of the United States fromUSGS National Water Information System National Aquifer code list.
principal_aqfor Principal Aquifers of the United States from2003 USGS data release
sec_hydrg_regfor Secondary Hydrogeologic Regions of theConterminous United States from 2018 USGS data release
gagesfor US Reference Stream Gauge Monitoring Locationsmainstemsfor US Reference Mainstem Riversstatesfor U.S. Statescountiesfor U.S. Countiesaiannhfor Native American Landscbsafor U.S. Metropolitan and Micropolitan Statistical Areasua10for Urbanized Areas and Urban Clusters (2010 Census)placesfor U.S. legally incororated and Census designated placespwsfor U.S. Public Water Systemsdamsfor 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 Basinc CQL2 queries. For more information and examples visit this link. 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: GeoType, geometry2: GeoType | None = ..., predicate: str = ..., crs: CRSType = ..., skip_geometry: Literal[False] = False) geopandas.GeoDataFrame#
- bygeometry(geometry1: GeoType, geometry2: GeoType | None = ..., predicate: str = ..., crs: CRSType = ..., skip_geometry: Literal[True] = True) pandas.DataFrame
Query the GeoConnex endpoint by geometry.
- Parameters:
geometry1 (
Polygonortupleoffloat) – 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 (
Polygonortupleoffloat, 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,equals,disjoint,touches,within,overlaps,crossesandcontains.crs (
intorstrorpyproj.CRS, optional) – The CRS of the polygon, by defaultEPSG:4326. If the input is ageopandas.GeoDataFrameorgeopandas.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.
- byid(feature_name: str, feature_ids: list[str] | str, skip_geometry: Literal[False] = False) geopandas.GeoDataFrame#
- byid(feature_name: str, feature_ids: list[str] | str, skip_geometry: Literal[True]) pandas.DataFrame
Query the GeoConnex endpoint.
- Parameters:
- Returns:
geopandas.GeoDataFrame– The query result as ageopandas.GeoDataFrameor apandas.DataFrame.
- byitem(item_id)#
Query the GeoConnex endpoint by an item ID.
- Parameters:
item_id (
str) – The ID of the item to query. Note that this GeoConnex’s item ID which is not necessarily the same as the provider’s item ID. For example, for querying gages, the item ID is not the same as the USGS gage ID but for querying HUC02, the item ID is the same as the HUC02 ID.- Returns:
geopandas.GeoDataFrame– The query result as ageopandas.GeoDataFrame.- Return type: