Ejemplo n.º 1
0
    def __init__(self, elem, parent, parse_remote_metadata=False):
        """."""
        self.id = testXMLValue(elem.find(wfs_ns("Name")))
        self.title = testXMLValue(elem.find(wfs_ns("Title")))
        self.abstract = testXMLValue(elem.find(wfs_ns("Abstract")))
        self.keywords = extract_xml_list(elem.findall(wfs_ns("Keywords")))

        # bboxes
        self.boundingBox = None
        b = elem.find(wfs_ns("BoundingBox"))
        if b is not None:
            self.boundingBox = (
                float(b.attrib["minx"]),
                float(b.attrib["miny"]),
                float(b.attrib["maxx"]),
                float(b.attrib["maxy"]),
                b.attrib["SRS"],
            )
        self.boundingBoxWGS84 = None
        b = elem.find(wfs_ns("LatLongBoundingBox"))
        if b is not None:
            self.boundingBoxWGS84 = (
                float(b.attrib["minx"]),
                float(b.attrib["miny"]),
                float(b.attrib["maxx"]),
                float(b.attrib["maxy"]),
            )
        # crs options
        self.crsOptions = [Crs(srs.text) for srs in elem.findall(wfs_ns("SRS"))]

        # verbs
        self.verbOptions = [op.tag for op in parent.findall(wfs_ns("Operations/*"))]
        self.verbOptions + [op.tag for op in elem.findall(wfs_ns("Operations/*")) if op.tag not in self.verbOptions]

        # others not used but needed for iContentMetadata harmonisation
        self.styles = None
        self.timepositions = None

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall(wfs_ns("MetadataURL")):
            metadataUrl = {
                "type": testXMLValue(m.attrib["type"], attrib=True),
                "format": testXMLValue(m.find("Format")),
                "url": testXMLValue(m),
            }

            if metadataUrl["url"] is not None and parse_remote_metadata:  # download URL
                try:
                    content = urlopen(metadataUrl["url"])
                    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, err:
                    metadataUrl["metadata"] = None

            self.metadataUrls.append(metadataUrl)
Ejemplo n.º 2
0
    def __init__(self, element):
        self._root = element

        self.id = testXMLValue(self._root.attrib.get(nspath_eval('gml:id', namespaces)), True)
        self.description = testXMLValue(self._root.find(nspath_eval('gml:description', namespaces)))
        self.keywords = extract_xml_list(self._root.findall(nspath_eval('sml:keywords/sml:KeywordList/sml:keyword', namespaces)))

        self.documents = []
        for document in self._root.findall(nspath_eval('sml:documentation', namespaces)):
            self.documents.append(DocumentationMetadata(document))

        self.identifiers = {}
        for identifier in self._root.findall(nspath_eval('sml:identification/sml:IdentifierList/sml:identifier', namespaces)):
            ident = IdentifierMetadata(identifier)
            self.identifiers[ident.name] = ident

        self.contacts = {}
        for contact in self._root.findall(nspath_eval('sml:contact', namespaces)):
            cont = ContactMetadata(contact)
            self.contacts[cont.role] = cont

        self.classifiers = {}
        for classifier in self._root.findall(nspath_eval('sml:classification/sml:ClassifierList/sml:classifier', namespaces)):
            classi = ClassifierMetadata(classifier)
            self.classifiers[classi.name] = classi

        self.history = {}
        for event_member in self._root.findall(nspath_eval('sml:history/sml:EventList/sml:member', namespaces)):
            emm = EventMemberMetadata(event_member)
            if self.history.get(emm.name) is None:
                self.history[emm.name] = []
            self.history[emm.name] += emm.events
    
        self.components = {}
Ejemplo n.º 3
0
 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)))
Ejemplo n.º 4
0
 def __init__(self, infoset, version):
     self._root=infoset
     self.type = testXMLValue(self._root.find('Name'))
     self.version = version
     self.title = testXMLValue(self._root.find('Title'))
     self.abstract = testXMLValue(self._root.find('Abstract'))
     self.keywords = extract_xml_list(self._root.findall('KeywordList/Keyword'))
     self.accessconstraints = testXMLValue(self._root.find('AccessConstraints'))
     self.fees = testXMLValue(self._root.find('Fees'))
Ejemplo n.º 5
0
 def __init__(self, infoset, version):
     self._root = infoset
     self.type = testXMLValue(self._root.find(wfs_ns("Name")))
     self.version = version
     self.title = testXMLValue(self._root.find(wfs_ns("Title")))
     self.abstract = testXMLValue(self._root.find(wfs_ns("Abstract")))
     self.keywords = extract_xml_list(self._root.findall(wfs_ns("Keywords")))
     self.fees = testXMLValue(self._root.find(wfs_ns("Fees")))
     self.accessconstraints = testXMLValue(self._root.find(wfs_ns("AccessConstraints")))
Ejemplo n.º 6
0
    def __init__(self, elem, parent, parse_remote_metadata=False):
        """."""
        self.id = testXMLValue(elem.find(wfs_ns('Name')))
        self.title = testXMLValue(elem.find(wfs_ns('Title')))
        self.abstract = testXMLValue(elem.find(wfs_ns('Abstract')))
        self.keywords = extract_xml_list(elem.findall(wfs_ns('Keywords')))

        # bboxes
        self.boundingBox = None
        b = elem.find(wfs_ns('BoundingBox'))
        if b is not None:
            self.boundingBox = (float(b.attrib['minx']),float(b.attrib['miny']),
                    float(b.attrib['maxx']), float(b.attrib['maxy']),
                    b.attrib['SRS'])
        self.boundingBoxWGS84 = None
        b = elem.find(wfs_ns('LatLongBoundingBox'))
        if b is not None:
            self.boundingBoxWGS84 = (
                    float(b.attrib['minx']),float(b.attrib['miny']),
                    float(b.attrib['maxx']), float(b.attrib['maxy']),
                    )
        # crs options
        self.crsOptions = [Crs(srs.text) for srs in elem.findall(wfs_ns('SRS'))]

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

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall(wfs_ns('MetadataURL')):
            metadataUrl = {
                'type': testXMLValue(m.attrib['type'], attrib=True),
                'format': testXMLValue(m.find('Format')),
                'url': testXMLValue(m)
            }

            if metadataUrl['url'] is not None and parse_remote_metadata:  # download URL
                try:
                    content = urlopen(metadataUrl['url'])
                    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, err:
                    metadataUrl['metadata'] = None

            self.metadataUrls.append(metadataUrl)
Ejemplo n.º 7
0
 def __init__(self, infoset, version):
     self._root=infoset
     self.type = testXMLValue(self._root.find(wfs_ns('Name')))
     self.version = version
     self.title = testXMLValue(self._root.find(wfs_ns('Title')))
     self.abstract = testXMLValue(self._root.find(wfs_ns('Abstract')))
     self.keywords = extract_xml_list(self._root.findall(wfs_ns('Keywords')))
     self.fees = testXMLValue(self._root.find(wfs_ns('Fees')))
     self.accessconstraints = testXMLValue(self._root.find(wfs_ns('AccessConstraints')))
Ejemplo n.º 8
0
    def __init__(self, element, namespace=None):
        self._root = element

        self.title    = testXMLValue(self._root.find(nsp('Title', namespace)))
        self.abstract = testXMLValue(self._root.find(nsp('Abstract', namespace)))
        self.keywords = extract_xml_list(self._root.findall(nsp('Keywords/Keyword', namespace)))
        self.accessconstraints = testXMLValue(self._root.find(nsp('AccessConstraints', namespace)))
        self.fees = testXMLValue(self._root.find(nsp('Fees', namespace)))
        self.type = testXMLValue(self._root.find(nsp('ServiceType', namespace)))
        self.service = self.type # LOOK: duplicate type as service here
        self.version = testXMLValue(self._root.find(nsp('ServiceTypeVersion', namespace)))
        self.profile = testXMLValue(self._root.find(nsp('Profile', namespace)))
Ejemplo n.º 9
0
    def __init__(self, element):
        self.keywords    = extract_xml_list(element.findall(nsp('sml:keywords/sml:KeywordList/sml:keyword')))

        self.identifiers = {}
        for identifier in element.findall(nsp('sml:identification/sml:IdentifierList/sml:identifier')):
            ident = Identifier(identifier)
            self.identifiers[ident.name] = ident

        self.classifiers = {}
        for classifier in element.findall(nsp('sml:classification/sml:ClassifierList/sml:classifier')):
            classi = Classifier(classifier)
            self.classifiers[classi.name] = classi
Ejemplo n.º 10
0
    def __init__(self, element):
        self.keywords    = extract_xml_list(element.findall(nsp('sml:keywords/sml:KeywordList/sml:keyword')))

        self.identifiers = {}
        for identifier in element.findall(nsp('sml:identification/sml:IdentifierList/sml:identifier')):
            ident = Identifier(identifier)
            self.identifiers[ident.name] = ident

        self.classifiers = {}
        for classifier in element.findall(nsp('sml:classification/sml:ClassifierList/sml:classifier')):
            classi = Classifier(classifier)
            self.classifiers[classi.name] = classi
Ejemplo n.º 11
0
    def __init__(self, element):
        self._root = element

        self.id = testXMLValue(
            self._root.attrib.get(nspath_eval('gml:id', namespaces)), True)
        self.description = testXMLValue(
            self._root.find(nspath_eval('gml:description', namespaces)))
        self.keywords = extract_xml_list(
            self._root.findall(
                nspath_eval('sml:keywords/sml:KeywordList/sml:keyword',
                            namespaces)))

        self.documents = []
        for document in self._root.findall(
                nspath_eval('sml:documentation', namespaces)):
            self.documents.append(DocumentationMetadata(document))

        self.identifiers = {}
        for identifier in self._root.findall(
                nspath_eval(
                    'sml:identification/sml:IdentifierList/sml:identifier',
                    namespaces)):
            ident = IdentifierMetadata(identifier)
            self.identifiers[ident.name] = ident

        self.contacts = {}
        for contact in self._root.findall(
                nspath_eval('sml:contact', namespaces)):
            cont = ContactMetadata(contact)
            self.contacts[cont.role] = cont

        self.classifiers = {}
        for classifier in self._root.findall(
                nspath_eval(
                    'sml:classification/sml:ClassifierList/sml:classifier',
                    namespaces)):
            classi = ClassifierMetadata(classifier)
            self.classifiers[classi.name] = classi

        self.history = {}
        for event_member in self._root.findall(
                nspath_eval('sml:history/sml:EventList/sml:member',
                            namespaces)):
            emm = EventMemberMetadata(event_member)
            if self.history.get(emm.name) is None:
                self.history[emm.name] = []
            self.history[emm.name] += emm.events

        self.components = {}
Ejemplo n.º 12
0
 def __init__(self, infoset, version):
     self._root = infoset
     self.type = testXMLValue(
         self._root.find(subcommon.nspath('Name', WMS_NAMESPACE)))
     self.version = version
     self.title = testXMLValue(
         self._root.find(subcommon.nspath('Title', WMS_NAMESPACE)))
     self.abstract = testXMLValue(
         self._root.find(subcommon.nspath('Abstract', WMS_NAMESPACE)))
     self.keywords = extract_xml_list(
         self._root.findall(
             subcommon.nspath('KeywordList/Keyword', WMS_NAMESPACE)))
     self.accessconstraints = testXMLValue(
         self._root.find(
             subcommon.nspath('AccessConstraints', WMS_NAMESPACE)))
     self.fees = testXMLValue(
         self._root.find(subcommon.nspath('Fees', WMS_NAMESPACE)))
Ejemplo n.º 13
0
 def __init__(self, infoset):
     self._root = infoset
     self.name = testXMLValue(self._root.find(nspath('Name')))
     self.url = testXMLValue(self._root.find(nspath('OnlineResource')))
     self.keywords = extract_xml_list(self._root.find(nspath('Keywords')))
Ejemplo n.º 14
0
    def __init__(self, elem, parent=None, index=0, parse_remote_metadata=False):
        if 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('Name'))
        # title is mandatory property
        self.title = testXMLValue(elem.find('Title')).strip()
        self.abstract = testXMLValue(elem.find('Abstract'))
        
        # bboxes
        b = elem.find('BoundingBox')
        self.boundingBox = None
        if b is not None:
            try: #sometimes the SRS attribute is (wrongly) not provided
                srs=b.attrib['SRS']
            except KeyError:
                srs=None
            self.boundingBox = (
                float(b.attrib['minx']),
                float(b.attrib['miny']),
                float(b.attrib['maxx']),
                float(b.attrib['maxy']),
                srs,
                )
        elif self.parent:
            if hasattr(self.parent, 'boundingBox'):
                self.boundingBox = self.parent.boundingBox

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

        attribution = elem.find('Attribution')
        if attribution is not None:
            self.attribution = dict()
            title = attribution.find('Title')
            url = attribution.find('OnlineResource')
            logo = attribution.find('LogoURL')
            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('OnlineResource').attrib['{http://www.w3.org/1999/xlink}href']

        b = elem.find('LatLonBoundingBox')
        if b is not None:
            self.boundingBoxWGS84 = (
                float(b.attrib['minx']),
                float(b.attrib['miny']),
                float(b.attrib['maxx']),
                float(b.attrib['maxy']),
            )
        elif self.parent:
            self.boundingBoxWGS84 = self.parent.boundingBoxWGS84
        else:
            self.boundingBoxWGS84 = None
            
        #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('SRS') 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('SRS')):
                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
            self.crsOptions=None
            
        #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('Style'):
            name = s.find('Name')
            title = s.find('Title')
            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('LegendURL/OnlineResource')
            if legend is not None:
                style['legend'] = legend.attrib['{http://www.w3.org/1999/xlink}href']
            self.styles[name.text] = style

        # keywords
        self.keywords = extract_xml_list(elem.findall('KeywordList/Keyword'))

        # timepositions - times for which data is available.
        self.timepositions=None
        for extent in elem.findall('Extent'):
            if extent.attrib.get("name").lower() =='time':
                if extent.text:
                    self.timepositions=extent.text.split(',')
                    break

        # MetadataURLs
        self.metadataUrls = []
        for m in elem.findall('MetadataURL'):
            metadataUrl = {
                'type': testXMLValue(m.attrib['type'], attrib=True),
                'format': testXMLValue(m.find('Format')),
                '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'])
                    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, err:
                    metadataUrl['metadata'] = None

            self.metadataUrls.append(metadataUrl)
Ejemplo n.º 15
0
 def __init__(self, infoset):
     self._root = infoset
     self.name = testXMLValue(self._root.find(nspath('Name')))
     self.url = testXMLValue(self._root.find(nspath('OnlineResource')))
     self.keywords = extract_xml_list(self._root.find(nspath('Keywords')))