示例#1
0
def get_remote_schema(url, typename, version='1.0.0'):
    """Copy the owslib.feature.schema.get_schema method to be able to
    monkeypatch the openURL request in tests.

    Parameters
    ----------
    url : str
        Base URL of the WFS service.
    typename : str
        Typename of the feature type to get the schema of.
    version : str
        Version of WFS to use. Defaults to 1.0.0

    Returns
    -------
    dict
        Schema of the given WFS layer.

    """
    url = _get_describefeaturetype_url(url, version, typename)
    res = __get_remote_describefeaturetype(url)
    root = etree.fromstring(res)

    if ':' in typename:
        typename = typename.split(':')[1]
    type_element = findall(root, '{%s}element' % XS_NAMESPACE,
                           attribute_name='name', attribute_value=typename)[0]
    complex_type = type_element.attrib['type'].split(":")[1]
    elements = _get_elements(complex_type, root)
    nsmap = None
    if hasattr(root, 'nsmap'):
        nsmap = root.nsmap
    return _construct_schema(elements, nsmap)
示例#2
0
def get_namespace(wfs, layer):
    """Request the namespace associated with a layer by performing a
    DescribeFeatureType request.

    Parameters
    ----------
    wfs : owslib.wfs.WebFeatureService
        WFS service to use, associated with the layer.
    layer : str
        Workspace-qualified name of the layer to get the namespace of (
        typename).

    Returns
    -------
    namespace : str
        URI of the namespace associated with the given layer.

    """
    from owslib.feature.schema import _get_describefeaturetype_url
    url = _get_describefeaturetype_url(url=wfs.url, version='1.1.0',
                                       typename=layer)
    schema = __get_remote_describefeaturetype(url)
    tree = etree.fromstring(schema)
    namespace = tree.attrib.get('targetNamespace', None)
    return namespace