def get_namespaces_io100(): n = Namespaces() ns = n.get_namespaces(["ogc","swes","sml","xlink","xsi"]) ns["ows"] = n.get_namespace("ows110") ns["sos"] = n.get_namespace("sos20") ns["gml"] = n.get_namespace("gml32") ns["om"] = n.get_namespace("om20") ns['swe'] = 'http://www.opengis.net/swe/2.0' ns["sams"] = "http://www.opengis.net/samplingSpatial/2.0" ns["sf"] = "http://www.opengis.net/sampling/2.0" return ns
def add_namespaces(root, ns_keys): if isinstance(ns_keys, six.string_types): ns_keys = [ns_keys] namespaces = Namespaces() ns_keys = [(x, namespaces.get_namespace(x)) for x in ns_keys] if etree.__name__ != 'lxml.etree': # We can just add more namespaces when not using lxml. # We can't re-add an existing namespaces. Get a list of current # namespaces in use existing_namespaces = set() for elem in root.getiterator(): if elem.tag[0] == "{": uri, tag = elem.tag[1:].split("}") existing_namespaces.add(namespaces.get_namespace_from_url(uri)) for key, link in ns_keys: if link is not None and key not in existing_namespaces: root.set("xmlns:%s" % key, link) return root else: # lxml does not support setting xmlns attributes # Update the elements nsmap with new namespaces new_map = root.nsmap for key, link in ns_keys: if link is not None: new_map[key] = link # Recreate the root element with updated nsmap new_root = etree.Element(root.tag, nsmap=new_map) # Carry over attributes for a, v in list(root.items()): new_root.set(a, v) # Carry over children for child in root: new_root.append(deepcopy(child)) return new_root
import six from owslib.etree import etree from owslib.util import (openURL, ServiceException, testXMLValue, extract_xml_list, xmltag_split, OrderedDict, nspath, bind_url) from owslib.util import nspath from owslib.fgdc import Metadata from owslib.iso import MD_Metadata from owslib.crs import Crs from owslib.namespaces import Namespaces from owslib.map.common import WMSCapabilitiesReader from owslib.util import log n = Namespaces() WMS_NAMESPACE = n.get_namespace("wms") OGC_NAMESPACE = n.get_namespace('ogc') class WebMapService_1_3_0(object): def __getitem__(self, name): ''' check contents dictionary to allow dict like access to service layers ''' if name in self.__getattribute__('contents'): return self.__getattribute__('contents')[name] else: raise KeyError("No content named %s" % name) def __init__(self, url,
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["dif","fes","gml","ogc","xs","xsi"]) ns[None] = n.get_namespace("ogc") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces("dif") ns[None] = n.get_namespace("dif") return ns
from owslib.util import nspath, testXMLValue from owslib.crs import Crs from owslib.feature import WebFeatureService_ from owslib.namespaces import Namespaces #other imports import cgi from cStringIO import StringIO from urllib import urlencode from urllib2 import urlopen import logging from owslib.util import log n = Namespaces() WFS_NAMESPACE = n.get_namespace("wfs20") OWS_NAMESPACE = n.get_namespace("ows110") OGC_NAMESPACE = n.get_namespace("ogc") GML_NAMESPACE = n.get_namespace("gml") FES_NAMESPACE = n.get_namespace("fes") class ServiceException(Exception): pass class WebFeatureService_2_0_0(WebFeatureService_): """Abstraction for OGC Web Feature Service (WFS). Implements IWebFeatureService. """
import six from owslib.etree import etree from owslib.util import (openURL, ServiceException, testXMLValue, extract_xml_list, xmltag_split, OrderedDict, nspath, bind_url) from owslib.util import nspath from owslib.fgdc import Metadata from owslib.iso import MD_Metadata from owslib.crs import Crs from owslib.namespaces import Namespaces from owslib.map.common import WMSCapabilitiesReader from owslib.util import log n = Namespaces() WMS_NAMESPACE = n.get_namespace("wms") OGC_NAMESPACE = n.get_namespace('ogc') class WebMapService_1_3_0(object): def __getitem__(self, name): ''' check contents dictionary to allow dict like access to service layers ''' if name in self.__getattribute__('contents'): return self.__getattribute__('contents')[name] else: raise KeyError("No content named %s" % name) def __init__(self, url, version='1.3.0', xml=None, username=None,
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["fes","ogc","om","gml32","sml","swe20","swes","xlink"]) ns["ows"] = n.get_namespace("ows110") ns["sos"] = n.get_namespace("sos20") return ns
# Contact email: [email protected] # # ============================================================================= """ Set of functions, which are suitable for DescribeFeatureType parsing and generating layer schema description compatible with `fiona` """ import sys from urllib.parse import urlencode, parse_qsl from owslib.etree import etree from owslib.namespaces import Namespaces from owslib.util import which_etree, findall, Authentication, openURL MYNS = Namespaces() XS_NAMESPACE = MYNS.get_namespace("xs") GML_NAMESPACES = ( MYNS.get_namespace("gml"), MYNS.get_namespace("gml311"), MYNS.get_namespace("gml32"), ) def get_schema( url, typename, version="1.0.0", timeout=30, headers=None, username=None, password=None, auth=None ): """Parses DescribeFeatureType response and creates schema compatible with :class:`fiona` :param str url: url of the service :param str version: version of the service
class EsaCciCatalogueService: def __init__(self, catalogue_url: str): self._catalogue_url = catalogue_url self._catalogue = None self._catalogue_service = None self._namespaces = Namespaces() def reset(self): self._catalogue = None self._catalogue_service = None def getrecords(self, monitor: Monitor = Monitor.NONE): if not self._catalogue_service: self._init_service() if not self._catalogue: self._build_catalogue(monitor.child(1)) return self._catalogue def _build_catalogue(self, monitor: Monitor = Monitor.NONE): self._catalogue = {} catalogue_metadata = {} start_position = 0 max_records = _CSW_MAX_RESULTS matches = -1 while True: # fetch record metadata self._catalogue_service.getrecords2( esn='full', outputschema=self._namespaces.get_namespace('gmd'), startposition=start_position, maxrecords=max_records) if matches == -1: # set counters, start progress monitor matches = self._catalogue_service.results.get('matches') if matches == 0: break monitor.start(label="Fetching catalogue data... (%d records)" % matches, total_work=ceil(matches / max_records)) catalogue_metadata.update(self._catalogue_service.records) monitor.progress(work=1) # bump counters start_position += max_records if start_position > matches: break self._catalogue = { record.identification.uricode[0]: { 'abstract': record.identification.abstract, 'bbox_minx': record.identification.bbox.minx if record.identification.bbox else None, 'bbox_miny': record.identification.bbox.miny if record.identification.bbox else None, 'bbox_maxx': record.identification.bbox.maxx if record.identification.bbox else None, 'bbox_maxy': record.identification.bbox.maxy if record.identification.bbox else None, 'creation_date': next( iter(e.date for e in record.identification.date if e and e.type == 'creation'), None), 'publication_date': next( iter(e.date for e in record.identification.date if e and e.type == 'publication'), None), 'title': record.identification.title, 'data_sources': record.identification.uricode[1:], 'licences': record.identification.uselimitation, 'temporal_coverage_start': record.identification.temporalextent_start, 'temporal_coverage_end': record.identification.temporalextent_end } for record in catalogue_metadata.values() if record.identification and len(record.identification.uricode) > 0 } monitor.done() def _init_service(self): if self._catalogue: return if not self._catalogue_service: self._catalogue_service = CatalogueServiceWeb( url=self._catalogue_url, timeout=_CSW_TIMEOUT, skip_caps=True)
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["gm03"]) ns[None] = n.get_namespace("gm03") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["fes", "ogc", "xsi", "om20", "gml32", "sa", "sml", "swe20", "swes", "xlink"]) ns["ows"] = n.get_namespace("ows110") ns["sos"] = n.get_namespace("sos20") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["ogc", "sml", "gml", "sos", "swe", "xlink"]) ns["ows"] = n.get_namespace("ows110") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["ogc"]) ns[None] = n.get_namespace("ogc") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces( ["gco", "gmd", "gml", "gml32", "gmx", "gts", "srv", "xlink"]) ns[None] = n.get_namespace("gmd") return ns
Set of functions, which are suitable for DescribeFeatureType parsing and generating layer schema description compatible with `fiona` """ import cgi, sys from owslib.util import openURL try: from urllib import urlencode except ImportError: from urllib.parse import urlencode from owslib.etree import etree from owslib.namespaces import Namespaces from owslib.util import which_etree, findall MYNS = Namespaces() XS_NAMESPACE = MYNS.get_namespace('xs') GML_NAMESPACES = (MYNS.get_namespace('gml'), MYNS.get_namespace('gml311'), MYNS.get_namespace('gml32')) def get_schema(url, typename, version='1.0.0', timeout=30, username=None, password=None): """Parses DescribeFeatureType response and creates schema compatible with :class:`fiona` :param str url: url of the service :param str version: version of the service
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["gco","gmd","gml","gml32","gmx","gts","srv","xlink"]) ns["che"] = 'http://www.geocat.ch/2008/che' ns[None] = n.get_namespace("gmd") return ns
import cgi from cStringIO import StringIO from urllib import urlencode from urllib2 import urlopen from owslib.util import openURL, testXMLValue, extract_xml_list, ServiceException, xmltag_split from owslib.etree import etree from owslib.fgdc import Metadata from owslib.iso import MD_Metadata from owslib.crs import Crs from owslib.feature import WebFeatureService_ from owslib.namespaces import Namespaces from owslib.util import log from _socket import timeout n = Namespaces() WFS_NAMESPACE = n.get_namespace("wfs") OGC_NAMESPACE = n.get_namespace("ogc") #TODO: use nspath in util.py def nspath(path, ns=WFS_NAMESPACE): """ Prefix the given path with the given namespace identifier. Parameters ---------- path : string ElementTree API Compatible path expression ns : string The XML namespace. Defaults to WFS namespace.
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["ogc"]) ns[None] = n.get_namespace("ogc") return ns
API for OGC Web Services Common (OWS) constructs and metadata. OWS Common: http://www.opengeospatial.org/standards/common Currently supports version 1.1.0 (06-121r3). """ from __future__ import absolute_import, division, print_function from owslib.etree import etree from owslib import crs, util from owslib.namespaces import Namespaces n = Namespaces() OWS_NAMESPACE_1_0_0 = n.get_namespace("ows") OWS_NAMESPACE_1_1_0 = n.get_namespace("ows110") OWS_NAMESPACE_2_0 = n.get_namespace("ows200") XSI_NAMESPACE = n.get_namespace("xsi") XLINK_NAMESPACE = n.get_namespace("xlink") DEFAULT_OWS_NAMESPACE = OWS_NAMESPACE_1_1_0 # Use this as default for OWSCommon objects class OwsCommon(object): """Initialize OWS Common object""" def __init__(self, version): self.version = version if version == "1.0.0": self.namespace = OWS_NAMESPACE_1_0_0
Set of functions, which are suitable for DescribeFeatureType parsing and generating layer schema description compatible with `fiona` """ import cgi, sys from owslib.util import openURL try: from urllib import urlencode except ImportError: from urllib.parse import urlencode from owslib.etree import etree from owslib.namespaces import Namespaces from owslib.util import which_etree, findall MYNS = Namespaces() XS_NAMESPACE = MYNS.get_namespace('xs') GML_NAMESPACES = (MYNS.get_namespace('gml'), MYNS.get_namespace('gml311'), MYNS.get_namespace('gml32')) def get_schema(url, typename, version='1.0.0', timeout=30, username=None, password=None): """Parses DescribeFeatureType response and creates schema compatible with :class:`fiona` :param str url: url of the service :param str version: version of the service :param str typename: name of the layer :param int timeout: request timeout """
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["dif", "fes", "gml", "ogc", "xs", "xsi"]) ns[None] = n.get_namespace("ogc") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["atom", "dc", "gml", "gml32", "xlink"]) ns.update(add_namespaces) ns[None] = n.get_namespace("atom") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces("dif") ns[None] = n.get_namespace("dif") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["gm03"]) ns[None] = n.get_namespace("gm03") return ns
Currently supports version 1.1.0 (06-121r3). """ from __future__ import (absolute_import, division, print_function) import logging from owslib.etree import etree from owslib import crs, util from owslib.namespaces import Namespaces LOGGER = logging.getLogger(__name__) n = Namespaces() OWS_NAMESPACE_1_0_0 = n.get_namespace("ows") OWS_NAMESPACE_1_1_0 = n.get_namespace("ows110") OWS_NAMESPACE_2_0_0 = n.get_namespace("ows200") XSI_NAMESPACE = n.get_namespace("xsi") XLINK_NAMESPACE = n.get_namespace("xlink") DEFAULT_OWS_NAMESPACE=OWS_NAMESPACE_1_1_0 #Use this as default for OWSCommon objects class OwsCommon(object): """Initialize OWS Common object""" def __init__(self,version): self.version = version if version == '1.0.0': self.namespace = OWS_NAMESPACE_1_0_0 elif version == '1.1.0': self.namespace = OWS_NAMESPACE_1_1_0
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["gco","gmd","gml","gml32","gmx","gts","srv","xlink"]) ns[None] = n.get_namespace("gmd") return ns
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["atom", "dc", "gml", "gml32", "xlink"]) ns.update(add_namespaces) ns[None] = n.get_namespace("atom") return ns
#other imports from six import PY2 from six.moves import cStringIO as StringIO try: from urllib import urlencode except ImportError: from urllib.parse import urlencode from urllib import unquote_plus import logging from owslib.util import log n = Namespaces() WFS_NAMESPACE = n.get_namespace("wfs20") OWS_NAMESPACE = n.get_namespace("ows110") OGC_NAMESPACE = n.get_namespace("ogc") GML_NAMESPACE = n.get_namespace("gml") FES_NAMESPACE = n.get_namespace("fes") class ServiceException(Exception): pass class WebFeatureService_2_0_0(WebFeatureService_): """Abstraction for OGC Web Feature Service (WFS). Implements IWebFeatureService. """
from urllib.parse import urlencode from owslib.util import openURL, testXMLValue, extract_xml_list, ServiceException, xmltag_split from owslib.etree import etree from owslib.fgdc import Metadata from owslib.iso import MD_Metadata from owslib.crs import Crs from owslib.namespaces import Namespaces from owslib.util import log from owslib.feature.schema import get_schema from owslib.feature.common import WFSCapabilitiesReader, \ AbstractContentMetadata import pyproj n = Namespaces() WFS_NAMESPACE = n.get_namespace("wfs") OGC_NAMESPACE = n.get_namespace("ogc") #TODO: use nspath in util.py def nspath(path, ns=WFS_NAMESPACE): """ Prefix the given path with the given namespace identifier. Parameters ---------- path : string ElementTree API Compatible path expression ns : string The XML namespace. Defaults to WFS namespace.
def get_namespaces(): n = Namespaces() ns = n.get_namespaces(["ogc","sa","sml","gml","sos","swe","xlink"]) ns["ows"] = n.get_namespace("ows110") return ns
generating layer schema description compatible with `fiona` """ import cgi, sys from owslib.util import openURL try: from urllib import urlencode except ImportError: from urllib.parse import urlencode from owslib.etree import etree from owslib.namespaces import Namespaces from owslib.util import which_etree, findall MYNS = Namespaces() XS_NAMESPACE = MYNS.get_namespace("xs") GML_NAMESPACES = (MYNS.get_namespace("gml"), MYNS.get_namespace("gml311"), MYNS.get_namespace("gml32")) def get_schema(url, typename, version="1.0.0", timeout=30): """Parses DescribeFeatureType response and creates schema compatible with :class:`fiona` :param str url: url of the service :param str version: version of the service :param str typename: name of the layer :param int timeout: request timeout """ url = _get_describefeaturetype_url(url, version, typename) res = openURL(url, timeout=timeout)