Exemple #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)
Exemple #2
0
    def __get_schema(*args, **kwargs):
        file_path = getattr(request.module, "location_wfs_describefeaturetype")
        with open(file_path, 'r') as f:
            data = f.read()
            if type(data) is not bytes:
                data = data.encode('utf-8')

        root = etree.fromstring(data)

        typename = root.find(
            './{http://www.w3.org/2001/XMLSchema}element').get('name')

        if ":" in typename:
            typename = typename.split(":")[1]
        type_element = findall(
            root,
            "{http://www.w3.org/2001/XMLSchema}element",
            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)