コード例 #1
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
 def __init__(self, elem):
     """."""
     self.name = xmltag_split(elem.tag)
     # formatOptions
     self.formatOptions = [f.text for f in elem.findall(nspath('Format', WMS_NAMESPACE))]
     self.methods = []
     for verb in elem.findall(nspath('DCPType/HTTP/*', WMS_NAMESPACE)):
         url = verb.find(nspath('OnlineResource', WMS_NAMESPACE)).attrib['{http://www.w3.org/1999/xlink}href']
         self.methods.append({'type': xmltag_split(verb.tag), 'url': url})
コード例 #2
0
ファイル: wfs200.py プロジェクト: roomthily/pipeline-demo
    def _getStoredQueries(self):
        ''' gets descriptions of the stored queries available on the server '''
        sqs=[]
        #This method makes two calls to the WFS - one ListStoredQueries, and one DescribeStoredQueries. The information is then
        #aggregated in 'StoredQuery' objects
        method=nspath('Get')
        
        #first make the ListStoredQueries response and save the results in a dictionary if form {storedqueryid:(title, returnfeaturetype)}
        try:
            base_url = next((m.get('url') for m in self.getOperationByName('ListStoredQueries').methods if m.get('type').lower() == method.lower()))
        except StopIteration:
            base_url = self.url

        request = {'service': 'WFS', 'version': self.version, 'request': 'ListStoredQueries'}
        encoded_request = urlencode(request)
        u = urlopen(base_url, data=encoded_request, timeout=self.timeout)
        tree=etree.fromstring(u.read())
        tempdict={}       
        for sqelem in tree[:]:
            title=rft=id=None
            id=sqelem.get('id')
            for elem in sqelem[:]:
                if elem.tag==nspath('Title', WFS_NAMESPACE):
                    title=elem.text
                elif elem.tag==nspath('ReturnFeatureType', WFS_NAMESPACE):
                    rft=elem.text
            tempdict[id]=(title,rft)        #store in temporary dictionary
        
        #then make the DescribeStoredQueries request and get the rest of the information about the stored queries 
        try:
            base_url = next((m.get('url') for m in self.getOperationByName('DescribeStoredQueries').methods if m.get('type').lower() == method.lower()))
        except StopIteration:
            base_url = self.url
        request = {'service': 'WFS', 'version': self.version, 'request': 'DescribeStoredQueries'}
        encoded_request = urlencode(request)
        u = urlopen(base_url, data=encoded_request, timeout=to)
        tree=etree.fromstring(u.read())
        tempdict2={} 
        for sqelem in tree[:]:
            params=[] #list to store parameters for the stored query description
            id =sqelem.get('id')
            for elem in sqelem[:]:
                if elem.tag==nspath('Abstract', WFS_NAMESPACE):
                    abstract=elem.text
                elif elem.tag==nspath('Parameter', WFS_NAMESPACE):
                    newparam=Parameter(elem.get('name'), elem.get('type'))
                    params.append(newparam)
            tempdict2[id]=(abstract, params) #store in another temporary dictionary
        
        #now group the results into StoredQuery objects:
        for key in tempdict.keys(): 
            abstract='blah'
            parameters=[]
            sqs.append(StoredQuery(key, tempdict[key][0], tempdict[key][1], tempdict2[key][0], tempdict2[key][1]))
        return sqs
コード例 #3
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
 def __init__(self, infoset,namespace=DEFAULT_OWS_NAMESPACE):
     self._root = infoset
     val = self._root.find(util.nspath('ProviderName', namespace))
     self.name = util.testXMLValue(val)
     self.contact = ServiceContact(infoset, namespace)
     val = self._root.find(util.nspath('ProviderSite', namespace))
     if val is not None:
         urlattrib=val.attrib[util.nspath('href', XLINK_NAMESPACE)]
         self.url = util.testXMLValue(urlattrib, True)
     else:
         self.url =None
コード例 #4
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
 def __init__(self, elem):
     """."""
     self.name = xmltag_split(elem.tag)
     # formatOptions
     self.formatOptions = [
         f.text for f in elem.findall(nspath('Format', WMS_NAMESPACE))
     ]
     self.methods = []
     for verb in elem.findall(nspath('DCPType/HTTP/*', WMS_NAMESPACE)):
         url = verb.find(nspath(
             'OnlineResource',
             WMS_NAMESPACE)).attrib['{http://www.w3.org/1999/xlink}href']
         self.methods.append({'type': xmltag_split(verb.tag), 'url': url})
コード例 #5
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
    def __init__(self,infoset,namespace=DEFAULT_OWS_NAMESPACE): 
        self._root = infoset

        val = self._root.find(util.nspath('Title', namespace))
        self.title = util.testXMLValue(val)

        val = self._root.find(util.nspath('Abstract', namespace))
        self.abstract = util.testXMLValue(val)

        self.keywords = []
        for f in self._root.findall(util.nspath('Keywords/Keyword', namespace)):
            if f.text is not None:
                self.keywords.append(f.text)
    

        val = self._root.find(util.nspath('AccessConstraints', namespace))
        self.accessconstraints = util.testXMLValue(val)

        val = self._root.find(util.nspath('Fees', namespace))
        self.fees = util.testXMLValue(val)

        val = self._root.find(util.nspath('ServiceType', namespace))
        self.type = util.testXMLValue(val)
        self.service=self.type #alternative? keep both?discuss

        val = self._root.find(util.nspath('ServiceTypeVersion', namespace))
        self.version = util.testXMLValue(val)

        self.profiles = []
        for p in self._root.findall(util.nspath('Profile', namespace)):
            self.profiles.append(util.testXMLValue(val))
コード例 #6
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
 def __init__(self, infoset):
     self._root = infoset
     name = self._root.find(nspath('ContactInformation/ContactPersonPrimary/ContactOrganization', WMS_NAMESPACE))
     if name is not None:
         self.name = name.text
     else:
         self.name = None
     self.url = self._root.find(nspath('OnlineResource', WMS_NAMESPACE)).attrib.get('{http://www.w3.org/1999/xlink}href', '')
     # contact metadata
     contact = self._root.find(nspath('ContactInformation', WMS_NAMESPACE))
     # sometimes there is a contact block that is empty, so make
     # sure there are children to parse
     if contact is not None and contact[:] != []:
         self.contact = ContactMetadata(contact)
     else:
         self.contact = None
コード例 #7
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
    def __init__(self,
                 url,
                 version='1.3.0',
                 xml=None,
                 username=None,
                 password=None,
                 parse_remote_metadata=False):
        """Initialize."""
        self.url = url
        self.username = username
        self.password = password
        self.version = version
        self._capabilities = None

        # Authentication handled by Reader
        reader = WMSCapabilitiesReader(self.version,
                                       url=self.url,
                                       un=self.username,
                                       pw=self.password)
        if xml:  # read from stored xml
            self._capabilities = reader.readString(xml)
        else:  # read from server
            self._capabilities = reader.read(self.url)

        # avoid building capabilities metadata if the response is a ServiceExceptionReport
        se = self._capabilities.find(nspath('ServiceException', WMS_NAMESPACE))
        if se is not None:
            err_message = str(se.text).strip()
            raise ServiceException(err_message, xml)

        # build metadata objects
        self._buildMetadata(parse_remote_metadata)
コード例 #8
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
    def __init__(self, url, version='1.3.0', xml=None,
                 username=None, password=None, parse_remote_metadata=False):
        """Initialize."""
        self.url = url
        self.username = username
        self.password = password
        self.version = version
        self._capabilities = None

        # Authentication handled by Reader
        reader = WMSCapabilitiesReader(self.version, url=self.url,
                                       un=self.username, pw=self.password)
        if xml:  # read from stored xml
            self._capabilities = reader.readString(xml)
        else:  # read from server
            self._capabilities = reader.read(self.url)

        # avoid building capabilities metadata if the response is a ServiceExceptionReport
        se = self._capabilities.find(nspath('ServiceException', WMS_NAMESPACE))
        if se is not None:
            err_message = str(se.text).strip()
            raise ServiceException(err_message, xml)

        # build metadata objects
        self._buildMetadata(parse_remote_metadata)
コード例 #9
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
    def _buildMetadata(self, parse_remote_metadata=False):
        ''' set up capabilities metadata objects '''
        # serviceIdentification metadata
        serviceelem = self._capabilities.find(nspath('Service', WMS_NAMESPACE))
        self.identification = ServiceIdentification(serviceelem, self.version)

        # serviceProvider metadata
        self.provider = ServiceProvider(serviceelem)

        # serviceOperations metadata
        self.operations = []
        for elem in self._capabilities.find(
                nspath('Capability/Request', WMS_NAMESPACE))[:]:
            self.operations.append(OperationMetadata(elem))

        # serviceContents metadata: our assumption is that services use a top-level
        # layer as a metadata organizer, nothing more.
        self.contents = {}
        caps = self._capabilities.find(nspath('Capability', WMS_NAMESPACE))

        # recursively gather content metadata for all layer elements.
        # To the WebMapService.contents store only metadata of named layers.
        def gather_layers(parent_elem, parent_metadata):
            for index, elem in enumerate(
                    parent_elem.findall(nspath('Layer', WMS_NAMESPACE))):
                cm = ContentMetadata(
                    elem,
                    parent=parent_metadata,
                    index=index + 1,
                    parse_remote_metadata=parse_remote_metadata)
                if cm.id:
                    if cm.id in self.contents:
                        warnings.warn(
                            'Content metadata for layer "%s" already exists. Using child layer'
                            % cm.id)
                    self.contents[cm.id] = cm
                gather_layers(elem, cm)

        gather_layers(caps, None)

        # exceptions
        self.exceptions = [
            f.text for f in self._capabilities.findall(
                nspath('Capability/Exception/Format', WMS_NAMESPACE))
        ]
コード例 #10
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
 def gather_layers(parent_elem, parent_metadata):
     for index, elem in enumerate(parent_elem.findall(nspath('Layer', WMS_NAMESPACE))):
         cm = ContentMetadata(elem, parent=parent_metadata, index=index + 1,
                              parse_remote_metadata=parse_remote_metadata)
         if cm.id:
             if cm.id in self.contents:
                 warnings.warn('Content metadata for layer "%s" already exists. Using child layer' % cm.id)
             self.contents[cm.id] = cm
         gather_layers(elem, cm)
コード例 #11
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, elem):
        name = elem.find(
            nspath('ContactPersonPrimary/ContactPerson', WMS_NAMESPACE))
        if name is not None:
            self.name = name.text
        else:
            self.name = None
        email = elem.find('ContactElectronicMailAddress')
        if email is not None:
            self.email = email.text
        else:
            self.email = None
        self.address = self.city = self.region = None
        self.postcode = self.country = None

        address = elem.find(nspath('ContactAddress', WMS_NAMESPACE))
        if address is not None:
            street = address.find(nspath('Address', WMS_NAMESPACE))
            if street is not None:
                self.address = street.text

            city = address.find(nspath('City', WMS_NAMESPACE))
            if city is not None:
                self.city = city.text

            region = address.find(nspath('StateOrProvince', WMS_NAMESPACE))
            if region is not None:
                self.region = region.text

            postcode = address.find(nspath('PostCode', WMS_NAMESPACE))
            if postcode is not None:
                self.postcode = postcode.text

            country = address.find(nspath('Country', WMS_NAMESPACE))
            if country is not None:
                self.country = country.text

        organization = elem.find(
            nspath('ContactPersonPrimary/ContactOrganization', WMS_NAMESPACE))
        if organization is not None:
            self.organization = organization.text
        else:
            self.organization = None

        position = elem.find(nspath('ContactPosition', WMS_NAMESPACE))
        if position is not None:
            self.position = position.text
        else:
            self.position = None
コード例 #12
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
    def __init__(self, elem):
        name = elem.find(nspath('ContactPersonPrimary/ContactPerson', WMS_NAMESPACE))
        if name is not None:
            self.name = name.text
        else:
            self.name = None
        email = elem.find('ContactElectronicMailAddress')
        if email is not None:
            self.email = email.text
        else:
            self.email = None
        self.address = self.city = self.region = None
        self.postcode = self.country = None

        address = elem.find(nspath('ContactAddress', WMS_NAMESPACE))
        if address is not None:
            street = address.find(nspath('Address', WMS_NAMESPACE))
            if street is not None:
                self.address = street.text

            city = address.find(nspath('City', WMS_NAMESPACE))
            if city is not None:
                self.city = city.text

            region = address.find(nspath('StateOrProvince', WMS_NAMESPACE))
            if region is not None:
                self.region = region.text

            postcode = address.find(nspath('PostCode', WMS_NAMESPACE))
            if postcode is not None:
                self.postcode = postcode.text

            country = address.find(nspath('Country', WMS_NAMESPACE))
            if country is not None:
                self.country = country.text

        organization = elem.find(nspath('ContactPersonPrimary/ContactOrganization', WMS_NAMESPACE))
        if organization is not None:
            self.organization = organization.text
        else:
            self.organization = None

        position = elem.find(nspath('ContactPosition', WMS_NAMESPACE))
        if position is not None:
            self.position = position.text
        else:
            self.position = None
コード例 #13
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
        self.exceptions = []

        if hasattr(elem, 'getroot'):
            elem = elem.getroot()
            
        for i in elem.findall(util.nspath('Exception', namespace)):
            tmp = {}
            val = i.attrib.get('exceptionCode')
            tmp['exceptionCode'] = util.testXMLValue(val, True)
            val = i.attrib.get('locator')
            tmp['locator'] = util.testXMLValue(val, True)
            val = i.find(util.nspath('ExceptionText', namespace))
            tmp['ExceptionText'] = util.testXMLValue(val)
            self.exceptions.append(tmp)

        # set topmost stacktrace as return message
        self.code = self.exceptions[0]['exceptionCode']
        self.locator = self.exceptions[0]['locator']
        self.msg = self.exceptions[0]['ExceptionText']
        self.xml = etree.tostring(elem)
コード例 #14
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
 def __init__(self, infoset):
     self._root = infoset
     name = self._root.find(
         nspath(
             'ContactInformation/ContactPersonPrimary/ContactOrganization',
             WMS_NAMESPACE))
     if name is not None:
         self.name = name.text
     else:
         self.name = None
     self.url = self._root.find(nspath(
         'OnlineResource',
         WMS_NAMESPACE)).attrib.get('{http://www.w3.org/1999/xlink}href',
                                    '')
     # contact metadata
     contact = self._root.find(nspath('ContactInformation', WMS_NAMESPACE))
     # sometimes there is a contact block that is empty, so make
     # sure there are children to parse
     if contact is not None and contact[:] != []:
         self.contact = ContactMetadata(contact)
     else:
         self.contact = None
コード例 #15
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
 def __init__(self, infoset, version):
     self._root = infoset
     self.type = testXMLValue(self._root.find(nspath('Name', WMS_NAMESPACE)))
     self.version = version
     self.title = testXMLValue(self._root.find(nspath('Title', WMS_NAMESPACE)))
     self.abstract = testXMLValue(self._root.find(nspath('Abstract', WMS_NAMESPACE)))
     self.keywords = extract_xml_list(self._root.findall(nspath('KeywordList/Keyword', WMS_NAMESPACE)))
     self.accessconstraints = testXMLValue(self._root.find(nspath('AccessConstraints', WMS_NAMESPACE)))
     self.fees = testXMLValue(self._root.find(nspath('Fees', WMS_NAMESPACE)))
コード例 #16
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE): 
        self.minx = None
        self.miny = None
        self.maxx = None
        self.maxy = None

        val = elem.attrib.get('crs')
        if val is not None:
            self.crs = crs.Crs(val)
        else:
            self.crs = None

        val = elem.attrib.get('dimensions')
        if val is not None:
            self.dimensions = int(util.testXMLValue(val, True))
        else:  # assume 2
            self.dimensions = 2

        val = elem.find(util.nspath('LowerCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.minx, self.miny = xy[1], xy[0] 
                else:
                    self.minx, self.miny = xy[0], xy[1]

        val = elem.find(util.nspath('UpperCorner', namespace))
        tmp = util.testXMLValue(val)
        if tmp is not None:
            xy = tmp.split()
            if len(xy) > 1:
                if self.crs is not None and self.crs.axisorder == 'yx':
                    self.maxx, self.maxy = xy[1], xy[0]
                else:
                    self.maxx, self.maxy = xy[0], xy[1]
コード例 #17
0
ファイル: wfs200.py プロジェクト: roomthily/pipeline-demo
    def _buildMetadata(self, parse_remote_metadata=False):
        '''set up capabilities metadata objects: '''
        
        #serviceIdentification metadata
        serviceidentelem=self._capabilities.find(nspath('ServiceIdentification'))
        self.identification=ServiceIdentification(serviceidentelem)  
        #need to add to keywords list from featuretypelist information:
        featuretypelistelem=self._capabilities.find(nspath('FeatureTypeList', ns=WFS_NAMESPACE))
        featuretypeelems=featuretypelistelem.findall(nspath('FeatureType', ns=WFS_NAMESPACE))
        for f in featuretypeelems:  
            kwds=f.findall(nspath('Keywords/Keyword',ns=OWS_NAMESPACE))
            if kwds is not None:
                for kwd in kwds[:]:
                    if kwd.text not in self.identification.keywords:
                        self.identification.keywords.append(kwd.text)
	
   
        #TODO: update serviceProvider metadata, miss it out for now
        serviceproviderelem=self._capabilities.find(nspath('ServiceProvider'))
        self.provider=ServiceProvider(serviceproviderelem)   
        
        #serviceOperations metadata 
        self.operations=[]
        
        for elem in self._capabilities.find(nspath('OperationsMetadata'))[:]:
            if elem.tag !=nspath('ExtendedCapabilities'):
                self.operations.append(OperationsMetadata(elem))
                   
        #serviceContents metadata: our assumption is that services use a top-level 
        #layer as a metadata organizer, nothing more. 
        
        self.contents={} 
        featuretypelist=self._capabilities.find(nspath('FeatureTypeList',ns=WFS_NAMESPACE))
        features = self._capabilities.findall(nspath('FeatureTypeList/FeatureType', ns=WFS_NAMESPACE))
        for feature in features:
            cm=ContentMetadata(feature, featuretypelist, parse_remote_metadata)
            self.contents[cm.id]=cm       
        
        #exceptions
        self.exceptions = [f.text for f \
                in self._capabilities.findall('Capability/Exception/Format')]
コード例 #18
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
        if 'name' not in elem.attrib: # This is not a valid element
            return
        self.name = elem.attrib['name']
        self.formatOptions = ['text/xml']
        parameters = []
        self.methods = []
        self.constraints = []

        for verb in elem.findall(util.nspath('DCP/HTTP/*', namespace)):
            url = util.testXMLAttribute(verb, util.nspath('href', XLINK_NAMESPACE))
            if url is not None:
                verb_constraints = [Constraint(conts, namespace) for conts in verb.findall(util.nspath('Constraint', namespace))]
                self.methods.append({'constraints' : verb_constraints, 'type' : util.xmltag_split(verb.tag), 'url': url})

        for parameter in elem.findall(util.nspath('Parameter', namespace)):
            if namespace == OWS_NAMESPACE_1_1_0:
                parameters.append((parameter.attrib['name'], {'values': [i.text for i in parameter.findall(util.nspath('AllowedValues/Value', namespace))]}))
            else:
                parameters.append((parameter.attrib['name'], {'values': [i.text for i in parameter.findall(util.nspath('Value', namespace))]}))
        self.parameters = dict(parameters)

        for constraint in elem.findall(util.nspath('Constraint', namespace)):
            self.constraints.append(Constraint(constraint, namespace))
コード例 #19
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
 def gather_layers(parent_elem, parent_metadata):
     for index, elem in enumerate(
             parent_elem.findall(nspath('Layer', WMS_NAMESPACE))):
         cm = ContentMetadata(
             elem,
             parent=parent_metadata,
             index=index + 1,
             parse_remote_metadata=parse_remote_metadata)
         if cm.id:
             if cm.id in self.contents:
                 warnings.warn(
                     'Content metadata for layer "%s" already exists. Using child layer'
                     % cm.id)
             self.contents[cm.id] = cm
         gather_layers(elem, cm)
コード例 #20
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
    def _buildMetadata(self, parse_remote_metadata=False):
        ''' set up capabilities metadata objects '''
        # serviceIdentification metadata
        serviceelem = self._capabilities.find(nspath('Service', WMS_NAMESPACE))
        self.identification = ServiceIdentification(serviceelem, self.version)

        # serviceProvider metadata
        self.provider = ServiceProvider(serviceelem)

        # serviceOperations metadata
        self.operations = []
        for elem in self._capabilities.find(nspath('Capability/Request', WMS_NAMESPACE))[:]:
            self.operations.append(OperationMetadata(elem))

        # serviceContents metadata: our assumption is that services use a top-level
        # layer as a metadata organizer, nothing more.
        self.contents = {}
        caps = self._capabilities.find(nspath('Capability', WMS_NAMESPACE))

        # recursively gather content metadata for all layer elements.
        # To the WebMapService.contents store only metadata of named layers.
        def gather_layers(parent_elem, parent_metadata):
            for index, elem in enumerate(parent_elem.findall(nspath('Layer', WMS_NAMESPACE))):
                cm = ContentMetadata(elem, parent=parent_metadata, index=index + 1,
                                     parse_remote_metadata=parse_remote_metadata)
                if cm.id:
                    if cm.id in self.contents:
                        warnings.warn('Content metadata for layer "%s" already exists. Using child layer' % cm.id)
                    self.contents[cm.id] = cm
                gather_layers(elem, cm)
        gather_layers(caps, None)

        # exceptions
        self.exceptions = [f.text for f
                           in self._capabilities.findall(nspath('Capability/Exception/Format',
                                                         WMS_NAMESPACE))]
コード例 #21
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
 def __init__(self, infoset, version):
     self._root = infoset
     self.type = testXMLValue(self._root.find(nspath('Name',
                                                     WMS_NAMESPACE)))
     self.version = version
     self.title = testXMLValue(
         self._root.find(nspath('Title', WMS_NAMESPACE)))
     self.abstract = testXMLValue(
         self._root.find(nspath('Abstract', WMS_NAMESPACE)))
     self.keywords = extract_xml_list(
         self._root.findall(nspath('KeywordList/Keyword', WMS_NAMESPACE)))
     self.accessconstraints = testXMLValue(
         self._root.find(nspath('AccessConstraints', WMS_NAMESPACE)))
     self.fees = testXMLValue(self._root.find(nspath('Fees',
                                                     WMS_NAMESPACE)))
コード例 #22
0
ファイル: wfs200.py プロジェクト: roomthily/pipeline-demo
    def getfeature(self, typename=None, filter=None, bbox=None, featureid=None,
                   featureversion=None, propertyname=None, maxfeatures=None,storedQueryID=None, storedQueryParams={},
                   method='Get', outputFormat=None, startindex=None):
        """Request and return feature data as a file-like object.
        #TODO: NOTE: have changed property name from ['*'] to None - check the use of this in WFS 2.0
        Parameters
        ----------
        typename : list
            List of typenames (string)
        filter : string 
            XML-encoded OGC filter expression.
        bbox : tuple
            (left, bottom, right, top) in the feature type's coordinates == (minx, miny, maxx, maxy)
        featureid : list
            List of unique feature ids (string)
        featureversion : string
            Default is most recent feature version.
        propertyname : list
            List of feature property names. '*' matches all.
        maxfeatures : int
            Maximum number of features to be returned.
        method : string
            Qualified name of the HTTP DCP method to use.
        outputFormat: string (optional)
            Requested response format of the request.
        startindex: int (optional)
            Start position to return feature set (paging in combination with maxfeatures)

        There are 3 different modes of use

        1) typename and bbox (simple spatial query)
        2) typename and filter (==query) (more expressive)
        3) featureid (direct access to known features)
        """
        url = data = None
        if typename and type(typename) == type(""):
            typename = [typename]
        if method.upper() == "GET":
            (url) = self.getGETGetFeatureRequest(typename, filter, bbox, featureid,
                                                 featureversion, propertyname,
                                                 maxfeatures, storedQueryID,
                                                 storedQueryParams, outputFormat, 'Get', startindex)
            if log.isEnabledFor(logging.DEBUG):
                log.debug('GetFeature WFS GET url %s'% url)
        else:
            (url,data) = self.getPOSTGetFeatureRequest()


        # If method is 'Post', data will be None here
        u = urlopen(url, data, self.timeout)
        
        # check for service exceptions, rewrap, and return
        # We're going to assume that anything with a content-length > 32k
        # is data. We'll check anything smaller.
        try:
            length = int(u.info()['Content-Length'])
            have_read = False
        except KeyError:
            data = u.read()
            have_read = True
            length = len(data)
     
        if length < 32000:
            if not have_read:
                data = u.read()

            try:
                tree = etree.fromstring(data)
            except BaseException:
                # Not XML
                return StringIO(data)
            else:
                if tree.tag == "{%s}ServiceExceptionReport" % OGC_NAMESPACE:
                    se = tree.find(nspath('ServiceException', OGC_NAMESPACE))
                    raise ServiceException(str(se.text).strip())
                else:
                    return StringIO(data)
        else:
            if have_read:
                return StringIO(data)
            return u
コード例 #23
0
ファイル: wfs200.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, elem, parent, parse_remote_metadata=False, timeout=30):
        """."""
        self.id = elem.find(nspath('Name',ns=WFS_NAMESPACE)).text
        self.title = elem.find(nspath('Title',ns=WFS_NAMESPACE)).text
        abstract = elem.find(nspath('Abstract',ns=WFS_NAMESPACE))
        if abstract is not None:
            self.abstract = abstract.text
        else:
            self.abstract = None
        self.keywords = [f.text for f in elem.findall(nspath('Keywords',ns=WFS_NAMESPACE))]

        # bboxes
        self.boundingBoxWGS84 = None
        b = elem.find(nspath('WGS84BoundingBox',ns=OWS_NAMESPACE))
        if b is not None:
            lc = b.find(nspath("LowerCorner",ns=OWS_NAMESPACE))
            uc = b.find(nspath("UpperCorner",ns=OWS_NAMESPACE))
            ll = [float(s) for s in lc.text.split()]
            ur = [float(s) for s in uc.text.split()]
            self.boundingBoxWGS84 = (ll[0],ll[1],ur[0],ur[1])

        # there is no such think as bounding box
        # make copy of the WGS84BoundingBox
        self.boundingBox = (self.boundingBoxWGS84[0],
                            self.boundingBoxWGS84[1],
                            self.boundingBoxWGS84[2],
                            self.boundingBoxWGS84[3],
                            Crs("epsg:4326"))
        # crs options
        self.crsOptions = [Crs(srs.text) for srs in elem.findall(nspath('OtherCRS',ns=WFS_NAMESPACE))]
        defaultCrs =  elem.findall(nspath('DefaultCRS',ns=WFS_NAMESPACE))
        if len(defaultCrs) > 0:
            self.crsOptions.insert(0,Crs(defaultCrs[0].text))


        # verbs
        self.verbOptions = [op.tag for op \
            in parent.findall(nspath('Operations/*',ns=WFS_NAMESPACE))]
        self.verbOptions + [op.tag for op \
            in elem.findall(nspath('Operations/*',ns=WFS_NAMESPACE)) \
            if op.tag not in self.verbOptions]
        
        #others not used but needed for iContentMetadata harmonisation
        self.styles=None
        self.timepositions=None
        self.defaulttimeposition=None

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall('MetadataURL'):
            metadataUrl = {
                'type': testXMLValue(m.attrib['type'], attrib=True),
                'format': m.find('Format').text.strip(),
                'url': testXMLValue(m.find('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href'], attrib=True)
            }

            if metadataUrl['url'] is not None and parse_remote_metadata:  # download URL
                try:
                    content = urllib2.urlopen(metadataUrl['url'], timeout=timeout)
                    doc = etree.parse(content)
                    try:  # FGDC
                        metadataUrl['metadata'] = Metadata(doc)
                    except:  # ISO
                        metadataUrl['metadata'] = MD_Metadata(doc)
                except Exception:
                    metadataUrl['metadata'] = None

            self.metadataUrls.append(metadataUrl)
コード例 #24
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
 def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE):
     self.name    = elem.attrib.get('name')
     self.values  = [i.text for i in elem.findall(util.nspath('Value', namespace))]
     self.values += [i.text for i in elem.findall(util.nspath('AllowedValues/Value', namespace))]
コード例 #25
0
ファイル: ows.py プロジェクト: roomthily/pipeline-demo
    def __init__(self, infoset,namespace=DEFAULT_OWS_NAMESPACE):
        self._root = infoset
        val = self._root.find(util.nspath('ProviderName', namespace))
        self.name = util.testXMLValue(val)
        
        self.organization=util.testXMLValue(self._root.find(util.nspath('ContactPersonPrimary/ContactOrganization', namespace)))
        
        val = self._root.find(util.nspath('ProviderSite', namespace))
        if val is not None:
            self.site = util.testXMLValue(val.attrib.get(util.nspath('href', XLINK_NAMESPACE)), True)
        else:
            self.site = None

        val = self._root.find(util.nspath('ServiceContact/Role', namespace))
        self.role = util.testXMLValue(val)

        val = self._root.find(util.nspath('ServiceContact/IndividualName', namespace))
        self.name = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/PositionName', namespace))
        self.position = util.testXMLValue(val)
 
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Phone/Voice', namespace))
        self.phone = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Phone/Facsimile', namespace))
        self.fax = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/DeliveryPoint', namespace))
        self.address = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/City', namespace))
        self.city = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/AdministrativeArea', namespace))
        self.region = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/PostalCode', namespace))
        self.postcode = util.testXMLValue(val)

        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/Country', namespace))
        self.country = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/Address/ElectronicMailAddress', namespace))
        self.email = util.testXMLValue(val)

        val = self._root.find(util.nspath('ServiceContact/ContactInfo/OnlineResource', namespace))
        if val is not None:
            self.url = util.testXMLValue(val.attrib.get(util.nspath('href', XLINK_NAMESPACE)), True)
        else:
            self.url = None

        val = self._root.find(util.nspath('ServiceContact/ContactInfo/HoursOfService', namespace))
        self.hours = util.testXMLValue(val)
    
        val = self._root.find(util.nspath('ServiceContact/ContactInfo/ContactInstructions', namespace))
        self.instructions = util.testXMLValue(val)
コード例 #26
0
ファイル: wms130.py プロジェクト: b-cube/pipeline-demo
    def __init__(self, elem, parent=None, index=0, parse_remote_metadata=False, timeout=30):
        if strip_ns(elem.tag) != 'Layer':
            raise ValueError('%s should be a Layer' % (elem,))

        self.parent = parent
        if parent:
            self.index = "%s.%d" % (parent.index, index)
        else:
            self.index = str(index)

        self.id = self.name = testXMLValue(elem.find(nspath('Name', WMS_NAMESPACE)))

        # layer attributes
        self.queryable = int(elem.attrib.get('queryable', 0))
        self.cascaded = int(elem.attrib.get('cascaded', 0))
        self.opaque = int(elem.attrib.get('opaque', 0))
        self.noSubsets = int(elem.attrib.get('noSubsets', 0))
        self.fixedWidth = int(elem.attrib.get('fixedWidth', 0))
        self.fixedHeight = int(elem.attrib.get('fixedHeight', 0))

        # title is mandatory property
        self.title = None
        title = testXMLValue(elem.find(nspath('Title', WMS_NAMESPACE)))
        if title is not None:
            self.title = title.strip()

        self.abstract = testXMLValue(elem.find(nspath('Abstract', WMS_NAMESPACE)))

        # bboxes
        boxes = elem.findall(nspath('BoundingBox', WMS_NAMESPACE))
        self.boundingBoxes = []
        for b in boxes:
            try:
                # sometimes the SRS attribute is (wrongly) not provided
                srs = b.attrib['CRS']
            except KeyError:
                srs = None
            self.boundingBoxes.append((
                float(b.attrib['minx']),
                float(b.attrib['miny']),
                float(b.attrib['maxx']),
                float(b.attrib['maxy']),
                srs,
            ))
        if self.parent:
            if hasattr(self.parent, 'boundingBox'):
                self.boundingBoxes.append(self.parent.boundingBox)

        self.boundingBoxes = list(set(self.boundingBoxes))

        # ScaleHint
        sh = elem.find(nspath('ScaleHint', WMS_NAMESPACE))
        self.scaleHint = None
        if sh is not None:
            if 'min' in sh.attrib and 'max' in sh.attrib:
                self.scaleHint = {'min': sh.attrib['min'], 'max': sh.attrib['max']}

        attribution = elem.find(nspath('Attribution', WMS_NAMESPACE))
        self.attribution = {}
        if attribution is not None:
            title = attribution.find(nspath('Title', WMS_NAMESPACE))
            url = attribution.find(nspath('OnlineResource', WMS_NAMESPACE))
            logo = attribution.find(nspath('LogoURL', WMS_NAMESPACE))
            if title is not None:
                self.attribution['title'] = title.text
            if url is not None:
                self.attribution['url'] = url.attrib['{http://www.w3.org/1999/xlink}href']
            if logo is not None:
                self.attribution['logo_size'] = (
                    int(logo.attrib['width']),
                    int(logo.attrib['height'])
                )
                self.attribution['logo_url'] = logo.find(
                    nspath('OnlineResource', WMS_NAMESPACE)
                ).attrib['{http://www.w3.org/1999/xlink}href']

        b = elem.find(nspath('EX_GeographicBoundingBox', WMS_NAMESPACE))
        if b is not None:
            west_longitude = b.find(nspath('westBoundLongitude', WMS_NAMESPACE))
            east_longitude = b.find(nspath('eastBoundLongitude', WMS_NAMESPACE))
            south_latitude = b.find(nspath('southBoundLatitude', WMS_NAMESPACE))
            north_latitude = b.find(nspath('northBoundLatitude', WMS_NAMESPACE))
            self.boundingBoxWGS84 = (
                float(west_longitude.text if west_longitude is not None else ''),
                float(south_latitude.text if south_latitude is not None else ''),
                float(east_longitude.text if east_longitude is not None else ''),
                float(north_latitude.text if north_latitude is not None else ''),
            )
        elif self.parent:
            self.boundingBoxWGS84 = self.parent.boundingBoxWGS84
        else:
            self.boundingBoxWGS84 = None

        # TODO: get this from the bbox attributes instead (deal with parents)
        # SRS options
        self.crsOptions = []

        # Copy any parent SRS options (they are inheritable properties)
        if self.parent:
            self.crsOptions = list(self.parent.crsOptions)

        # Look for SRS option attached to this layer
        if elem.find(nspath('CRS', WMS_NAMESPACE)) is not None:
            # some servers found in the wild use a single SRS
            # tag containing a whitespace separated list of SRIDs
            # instead of several SRS tags. hence the inner loop
            for srslist in map(lambda x: x.text, elem.findall(nspath('CRS', WMS_NAMESPACE))):
                if srslist:
                    for srs in srslist.split():
                        self.crsOptions.append(srs)

        # Get rid of duplicate entries
        self.crsOptions = list(set(self.crsOptions))

        # Set self.crsOptions to None if the layer (and parents) had no SRS options
        if len(self.crsOptions) == 0:
            # raise ValueError('%s no SRS available!?' % (elem,))
            # Comment by D Lowe.
            # Do not raise ValueError as it is possible that a layer is purely a parent layer and does not have SRS specified. Instead set crsOptions to None
            # Comment by Jachym:
            # Do not set it to None, but to [], which will make the code
            # work further. Fixed by anthonybaxter
            self.crsOptions = []

        # Styles
        self.styles = {}

        # Copy any parent styles (they are inheritable properties)
        if self.parent:
            self.styles = self.parent.styles.copy()

        # Get the styles for this layer (items with the same name are replaced)
        for s in elem.findall(nspath('Style', WMS_NAMESPACE)):
            name = s.find(nspath('Name', WMS_NAMESPACE))
            title = s.find(nspath('Title', WMS_NAMESPACE))
            if name is None or title is None:
                raise ValueError('%s missing name or title' % (s,))
            style = {'title': title.text}
            # legend url
            legend = s.find(nspath('LegendURL/OnlineResource', WMS_NAMESPACE))
            if legend is not None:
                style['legend'] = legend.attrib['{http://www.w3.org/1999/xlink}href']
            self.styles[name.text] = style

        # keywords
        self.keywords = [f.text for f in elem.findall(nspath('KeywordList/Keyword', WMS_NAMESPACE))]

        # timepositions - times for which data is available.
        # return a tuple (for now) of (default, positions)
        self.timepositions = []
        for extent in elem.findall(nspath('Extent', WMS_NAMESPACE)):
            if extent.attrib.get("name").lower() == 'time':
                if extent.text:
                    timeposition = extent.text
                    defaulttimeposition = extent.attrib.get("default", '')
                    self.timepositions.append((defaulttimeposition, timeposition))

        # Elevations - available vertical levels
        self.elevations = None
        for extent in elem.findall(nspath('Extent', WMS_NAMESPACE)):
            if extent.attrib.get("name").lower() == 'elevation':
                if extent.text:
                    self.elevations = extent.text.split(',')
                    break

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall(nspath('MetadataURL', WMS_NAMESPACE)):
            metadataUrl = {
                'type': testXMLValue(m.attrib['type'], attrib=True),
                'format': testXMLValue(m.find(nspath('Format', WMS_NAMESPACE))),
                'url': testXMLValue(m.find(nspath('OnlineResource', WMS_NAMESPACE)).attrib['{http://www.w3.org/1999/xlink}href'], attrib=True)
            }

            if metadataUrl['url'] is not None and parse_remote_metadata:  # download URL
                try:
                    content = urllib2.urlopen(metadataUrl['url'], timeout=timeout)
                    doc = etree.parse(content)
                    if metadataUrl['type'] is not None:
                        if metadataUrl['type'] == 'FGDC':
                            metadataUrl['metadata'] = Metadata(doc)
                        if metadataUrl['type'] == 'TC211':
                            metadataUrl['metadata'] = MD_Metadata(doc)
                except Exception:
                    metadataUrl['metadata'] = None

            self.metadataUrls.append(metadataUrl)

        # DataURLs
        self.dataUrls = []
        for m in elem.findall(nspath('DataURL', WMS_NAMESPACE)):
            dataUrl = {
                'format': m.find(nspath('Format', WMS_NAMESPACE)).text.strip(),
                'url': m.find(nspath('OnlineResource', WMS_NAMESPACE)).attrib['{http://www.w3.org/1999/xlink}href']
            }
            self.dataUrls.append(dataUrl)

        self.layers = []
        for child in elem.findall(nspath('Layer', WMS_NAMESPACE)):
            self.layers.append(ContentMetadata(child, self))
コード例 #27
0
ファイル: wfs200.py プロジェクト: roomthily/pipeline-demo
 def getpropertyvalue(self, query=None, storedquery_id=None, valuereference=None, typename=None, method=nspath('Get'),**kwargs):
     ''' the WFS GetPropertyValue method'''
     try:
         base_url = next((m.get('url') for m in self.getOperationByName('GetPropertyValue').methods if m.get('type').lower() == method.lower()))
     except StopIteration:
         base_url = self.url
     request = {'service': 'WFS', 'version': self.version, 'request': 'GetPropertyValue'}
     if query:
         request['query'] = str(query)
     if valuereference: 
         request['valueReference'] = str(valuereference)
     if storedquery_id: 
         request['storedQuery_id'] = str(storedquery_id)
     if typename:
         request['typename']=str(typename)
     if kwargs:
         for kw in kwargs.keys():
             request[kw]=str(kwargs[kw])
     encoded_request=urlencode(request)
     u = urlopen(base_url + encoded_request)
     return u.read()
コード例 #28
0
ファイル: wms130.py プロジェクト: roomthily/pipeline-demo
    def __init__(self,
                 elem,
                 parent=None,
                 index=0,
                 parse_remote_metadata=False,
                 timeout=30):
        if strip_ns(elem.tag) != 'Layer':
            raise ValueError('%s should be a Layer' % (elem, ))

        self.parent = parent
        if parent:
            self.index = "%s.%d" % (parent.index, index)
        else:
            self.index = str(index)

        self.id = self.name = testXMLValue(
            elem.find(nspath('Name', WMS_NAMESPACE)))

        # layer attributes
        self.queryable = int(elem.attrib.get('queryable', 0))
        self.cascaded = int(elem.attrib.get('cascaded', 0))
        self.opaque = int(elem.attrib.get('opaque', 0))
        self.noSubsets = int(elem.attrib.get('noSubsets', 0))
        self.fixedWidth = int(elem.attrib.get('fixedWidth', 0))
        self.fixedHeight = int(elem.attrib.get('fixedHeight', 0))

        # title is mandatory property
        self.title = None
        title = testXMLValue(elem.find(nspath('Title', WMS_NAMESPACE)))
        if title is not None:
            self.title = title.strip()

        self.abstract = testXMLValue(
            elem.find(nspath('Abstract', WMS_NAMESPACE)))

        # bboxes
        boxes = elem.findall(nspath('BoundingBox', WMS_NAMESPACE))
        self.boundingBoxes = []
        for b in boxes:
            try:
                # sometimes the SRS attribute is (wrongly) not provided
                srs = b.attrib['CRS']
            except KeyError:
                srs = None
            self.boundingBoxes.append((
                float(b.attrib['minx']),
                float(b.attrib['miny']),
                float(b.attrib['maxx']),
                float(b.attrib['maxy']),
                srs,
            ))
        if self.parent:
            if hasattr(self.parent, 'boundingBox'):
                self.boundingBoxes.append(self.parent.boundingBox)

        self.boundingBoxes = list(set(self.boundingBoxes))

        # ScaleHint
        sh = elem.find(nspath('ScaleHint', WMS_NAMESPACE))
        self.scaleHint = None
        if sh is not None:
            if 'min' in sh.attrib and 'max' in sh.attrib:
                self.scaleHint = {
                    'min': sh.attrib['min'],
                    'max': sh.attrib['max']
                }

        attribution = elem.find(nspath('Attribution', WMS_NAMESPACE))
        self.attribution = {}
        if attribution is not None:
            title = attribution.find(nspath('Title', WMS_NAMESPACE))
            url = attribution.find(nspath('OnlineResource', WMS_NAMESPACE))
            logo = attribution.find(nspath('LogoURL', WMS_NAMESPACE))
            if title is not None:
                self.attribution['title'] = title.text
            if url is not None:
                self.attribution['url'] = url.attrib[
                    '{http://www.w3.org/1999/xlink}href']
            if logo is not None:
                self.attribution['logo_size'] = (int(logo.attrib['width']),
                                                 int(logo.attrib['height']))
                self.attribution['logo_url'] = logo.find(
                    nspath('OnlineResource', WMS_NAMESPACE)
                ).attrib['{http://www.w3.org/1999/xlink}href']

        b = elem.find(nspath('EX_GeographicBoundingBox', WMS_NAMESPACE))
        if b is not None:
            west_longitude = b.find(nspath('westBoundLongitude',
                                           WMS_NAMESPACE))
            east_longitude = b.find(nspath('eastBoundLongitude',
                                           WMS_NAMESPACE))
            south_latitude = b.find(nspath('southBoundLatitude',
                                           WMS_NAMESPACE))
            north_latitude = b.find(nspath('northBoundLatitude',
                                           WMS_NAMESPACE))
            self.boundingBoxWGS84 = (
                float(
                    west_longitude.text if west_longitude is not None else ''),
                float(
                    south_latitude.text if south_latitude is not None else ''),
                float(
                    east_longitude.text if east_longitude is not None else ''),
                float(
                    north_latitude.text if north_latitude is not None else ''),
            )
        elif self.parent:
            self.boundingBoxWGS84 = self.parent.boundingBoxWGS84
        else:
            self.boundingBoxWGS84 = None

        # TODO: get this from the bbox attributes instead (deal with parents)
        # SRS options
        self.crsOptions = []

        # Copy any parent SRS options (they are inheritable properties)
        if self.parent:
            self.crsOptions = list(self.parent.crsOptions)

        # Look for SRS option attached to this layer
        if elem.find(nspath('CRS', WMS_NAMESPACE)) is not None:
            # some servers found in the wild use a single SRS
            # tag containing a whitespace separated list of SRIDs
            # instead of several SRS tags. hence the inner loop
            for srslist in map(lambda x: x.text,
                               elem.findall(nspath('CRS', WMS_NAMESPACE))):
                if srslist:
                    for srs in srslist.split():
                        self.crsOptions.append(srs)

        # Get rid of duplicate entries
        self.crsOptions = list(set(self.crsOptions))

        # Set self.crsOptions to None if the layer (and parents) had no SRS options
        if len(self.crsOptions) == 0:
            # raise ValueError('%s no SRS available!?' % (elem,))
            # Comment by D Lowe.
            # Do not raise ValueError as it is possible that a layer is purely a parent layer and does not have SRS specified. Instead set crsOptions to None
            # Comment by Jachym:
            # Do not set it to None, but to [], which will make the code
            # work further. Fixed by anthonybaxter
            self.crsOptions = []

        # Styles
        self.styles = {}

        # Copy any parent styles (they are inheritable properties)
        if self.parent:
            self.styles = self.parent.styles.copy()

        # Get the styles for this layer (items with the same name are replaced)
        for s in elem.findall(nspath('Style', WMS_NAMESPACE)):
            name = s.find(nspath('Name', WMS_NAMESPACE))
            title = s.find(nspath('Title', WMS_NAMESPACE))
            if name is None or title is None:
                raise ValueError('%s missing name or title' % (s, ))
            style = {'title': title.text}
            # legend url
            legend = s.find(nspath('LegendURL/OnlineResource', WMS_NAMESPACE))
            if legend is not None:
                style['legend'] = legend.attrib[
                    '{http://www.w3.org/1999/xlink}href']
            self.styles[name.text] = style

        # keywords
        self.keywords = [
            f.text
            for f in elem.findall(nspath('KeywordList/Keyword', WMS_NAMESPACE))
        ]

        # timepositions - times for which data is available.
        # return a tuple (for now) of (default, positions)
        self.timepositions = []
        for extent in elem.findall(nspath('Extent', WMS_NAMESPACE)):
            if extent.attrib.get("name").lower() == 'time':
                if extent.text:
                    timeposition = extent.text
                    defaulttimeposition = extent.attrib.get("default", '')
                    self.timepositions.append(
                        (defaulttimeposition, timeposition))

        # Elevations - available vertical levels
        self.elevations = None
        for extent in elem.findall(nspath('Extent', WMS_NAMESPACE)):
            if extent.attrib.get("name").lower() == 'elevation':
                if extent.text:
                    self.elevations = extent.text.split(',')
                    break

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall(nspath('MetadataURL', WMS_NAMESPACE)):
            metadataUrl = {
                'type':
                testXMLValue(m.attrib['type'], attrib=True),
                'format':
                testXMLValue(m.find(nspath('Format', WMS_NAMESPACE))),
                'url':
                testXMLValue(m.find(nspath('OnlineResource', WMS_NAMESPACE)).
                             attrib['{http://www.w3.org/1999/xlink}href'],
                             attrib=True)
            }

            if metadataUrl[
                    'url'] is not None and parse_remote_metadata:  # download URL
                try:
                    content = urllib2.urlopen(metadataUrl['url'],
                                              timeout=timeout)
                    doc = etree.parse(content)
                    if metadataUrl['type'] is not None:
                        if metadataUrl['type'] == 'FGDC':
                            metadataUrl['metadata'] = Metadata(doc)
                        if metadataUrl['type'] == 'TC211':
                            metadataUrl['metadata'] = MD_Metadata(doc)
                except Exception:
                    metadataUrl['metadata'] = None

            self.metadataUrls.append(metadataUrl)

        # DataURLs
        self.dataUrls = []
        for m in elem.findall(nspath('DataURL', WMS_NAMESPACE)):
            dataUrl = {
                'format':
                m.find(nspath('Format', WMS_NAMESPACE)).text.strip(),
                'url':
                m.find(nspath('OnlineResource', WMS_NAMESPACE)).
                attrib['{http://www.w3.org/1999/xlink}href']
            }
            self.dataUrls.append(dataUrl)

        self.layers = []
        for child in elem.findall(nspath('Layer', WMS_NAMESPACE)):
            self.layers.append(ContentMetadata(child, self))