pygeoogc.core#

Base classes and function for REST, WMS, and WMF services.

Module Contents#

class pygeoogc.core.ArcGISRESTfulBase(base_url, layer=None, outformat='geojson', outfields='*', crs=DEF_CRS, max_workers=1, verbose=False, disable_retry=False)#

Access to an ArcGIS REST 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 (int, optional) – Target layer number, defaults to None. If None layer number must be included as after the last / in base_url.

  • 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 geojson. It defaults to esriSpatialRelIntersects.

  • outfields (str or list) – The output fields to be requested. Setting * as outfields requests all the available fields which is the default setting.

  • crs (str, optional) – The spatial reference of the output data, defaults to EPSG:4326

  • max_workers (int, optional) – Max number of simultaneous requests, default to 2. Note that some services might face issues when several requests are sent simultaneously and will return the requests partially. It’s recommended to avoid using too many workers unless you are certain the web service can handle it.

  • verbose (bool, optional) – If True, prints information about the requests and responses, defaults to False.

  • disable_retry (bool, optional) – If True in case there are any failed queries, no retrying attempts is done and object IDs of the failed requests is saved to a text file which its path can be accessed via self.failed_path.

esri_query(geom, geo_crs=DEF_CRS)#

Generate geometry queries based on ESRI template.

get_features(featureids, return_m=False, return_geom=True)#

Get features based on the feature IDs.

Parameters
  • featureids (list) – List of feature IDs.

  • 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

dict – (Geo)json response from the web service.

get_response(url, payloads, method='GET')#

Send payload and get the response.

initialize_service()#

Initialize the RESTFul service.

partition_oids(oids)#

Partition feature IDs based on self.max_nrecords.

retry_failed_requests()#

Retry failed requests.

class pygeoogc.core.RESTValidator#

Validate ArcGISRESTful inputs.

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 (int, optional) – Target layer number, defaults to None. If None layer number must be included as after the last / in base_url.

  • 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 geojson.

  • outfields (str or list) – The output fields to be requested. Setting * as outfields requests all the available fields which is the default setting.

  • crs (str, optional) – The spatial reference of the output data, defaults to EPSG:4326

  • max_workers (int, optional) – Max number of simultaneous requests, default to 2. Note that some services might face issues when several requests are sent simultaneously and will return the requests partially. It’s recommended to avoid using too many workers unless you are certain the web service can handle it.

  • verbose (bool, optional) – If True, prints information about the requests and responses, defaults to False.

  • disable_retry (bool, optional) – If True in case there are any failed queries, no retrying attempts is done and object IDs of the failed requests is saved to a text file which its path can be accessed via self.failed_path.

class pygeoogc.core.WFSBase#

Base class for WFS service.

Parameters
  • url (str) – The base url for the WFS service, for examples: https://hazards.fema.gov/nfhl/services/public/NFHL/MapServer/WFSServer

  • layer (str) – The layer from the service to be downloaded, defaults to None which throws an error and includes all the available layers offered by the service.

  • outformat (str) –

    The data format to request for data from the service, defaults to None which

    throws an error and includes all the available format offered by the service.

  • version (str, optional) – The WFS service version which should be either 1.0.0, 1.1.0, or 2.0.0. Defaults to 2.0.0.

  • crs (str, optional) – The spatial reference system to be used for requesting the data, defaults to epsg:4326.

  • read_method (str, optional) – Method for reading the retrieved data, defaults to json. Valid options are json, binary, and text.

  • max_nrecords (int, optional) – The maximum number of records in a single request to be retrieved from the service, defaults to 1000. If the number of requested records is greater than this value, the query will be split into multiple requests.

get_validnames()#

Get valid column names for a layer.

validate_wfs()#

Validate input arguments with the WFS service.

class pygeoogc.core.WMSBase#

Base class for accessing a WMS service.

Parameters
  • url (str) – The base url for the WMS service e.g., https://www.mrlc.gov/geoserver/mrlc_download/wms

  • layers (str or list) – A layer or a list of layers from the service to be downloaded. You can pass an empty string to get a list of available layers.

  • outformat (str) – The data format to request for data from the service. You can pass an empty string to get a list of available output formats.

  • version (str, optional) – The WMS service version which should be either 1.1.1 or 1.3.0, defaults to 1.3.0.

  • crs (str, optional) – The spatial reference system to be used for requesting the data, defaults to epsg:4326.

get_validlayers()#

Get the layers supported by the WMS service.

validate_wms()#

Validate input arguments with the WMS service.

pygeoogc.core.validate_version(val, valid_versions)#

Validate version from a list of valid versions.

Parameters
  • val (str) – Input version value.

  • valid_versions (list of str) – List of valid versions.

Returns

str – Validated version value.