Beispiel #1
0
    def to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        eainfo = xml_utils.xml_node('eainfo')

        #only output the first detailed if it has content
        if self.detaileds and self.detaileds[0].has_content():
            detailed_xml = self.detaileds[0].to_xml()
            eainfo.append(detailed_xml)

        #the remaining detaileds will get output regardless
        for detailed in self.detaileds[1:]:
            detailed_xml = detailed.to_xml()
            eainfo.append(detailed_xml)

        eaover_str = self.ui.fgdc_eaover.toPlainText()
        eadetcit_str = self.ui.fgdc_eadetcit.toPlainText()

        if eaover_str or eadetcit_str:
            overview = xml_utils.xml_node('overview', parent_node=eainfo)
            eaover = xml_utils.xml_node('eaover', text=eaover_str, parent_node=overview)
            eadetcit = xml_utils.xml_node('eadetcit', text=eadetcit_str, parent_node=overview)

        return eainfo
Beispiel #2
0
    def to_xml(self):
        """
        encapsulates the QPlainTextEdit text in an element tag

        Returns
        -------
        descript element tag in xml tree
        """
        descript = xml_utils.xml_node(tag="descript")

        abstract = xml_utils.xml_node(tag="abstract")
        abstract.text = self.findChild(QPlainTextEdit, "fgdc_abstract").toPlainText()
        descript.append(abstract)

        purpose = xml_utils.xml_node(tag="purpose")
        purpose.text = self.findChild(QPlainTextEdit, "fgdc_purpose").toPlainText()
        descript.append(purpose)

        supplinf_str = self.ui.fgdc_supplinf.toPlainText()
        if supplinf_str:
            upplinf = xml_utils.xml_node(
                "supplinf", text=supplinf_str, parent_node=descript
            )

        return descript
Beispiel #3
0
def azimuthal_equidistant(params):
    """
    returns lxml nodes that contain projection parameters for fgdc Azimuthal Equidistant projection

    longcm = Longitude of Central Meridian
    latprjo = Latitude of Projection Origin
    feast = False Easting
    fnorth = False Northing

    Parameters
    ----------
    params : dictionary
            geospatial parameters returned from get_params
    Returns
    -------
    lxml nodes for fgdc Azimuthal Equidistant projection
    """

    # This section should probably be handled in a different function?
    # planar = xml_node('planar')
    # mapproj = xml_node('mapproj', parent_node=planar)
    # mapprojn = xml_node('mapprojn', params['mapprojn'], mapproj)

    azimequi = xml_node('azimequi')
    longcm = xml_node('longcm', params['longcm'], azimequi)
    latprjo = xml_node('latprjo', params['latprjo'], azimequi)
    feast = xml_node('feast', params['feast'], azimequi)
    fnorth = xml_node('fnorth', params['fnorth'], azimequi)
    return azimequi
Beispiel #4
0
def albers_conic_equal_area(params):
    """
    returns lxml nodes that contain projection parameters for fgdc Albers Conic Equal Area projection

    stdparll = First standard parallel
    stdparl_2 = Second standard parallel (if exists)
    longcm = Longitude of Central Meridian
    latprjo = Latitude of Projection Origin
    feast = False Easting
    fnorth = False Northing

    Parameters
    ----------
    params : dictionary
            geospatial parameters returned from get_params

    Returns
    -------
    lxml nodes for fgdc Albers Conic Equal Area projection
    """
    albers = xml_node('albers')
    stdparll = xml_node('stdparll', params['stdparll'], albers)
    if params['stdparl_2']:
        stdparll_2 = xml_node('stdparll', params['stdparl_2'], albers)

    for item in ['longcm', 'latprjo', 'feast', 'fnorth']:
        xml_node(item, params[item], albers)
    return albers
Beispiel #5
0
    def _to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        rdom = xml_utils.xml_node('rdom')
        rdommin = xml_utils.xml_node('rdommin',
                                     text=self.ui.fgdc_rdommin.text(),
                                     parent_node=rdom)
        rdommax = xml_utils.xml_node('rdommax',
                                     text=self.ui.fgdc_rdommax.text(),
                                     parent_node=rdom)

        if self.ui.fgdc_attrunit.text():
            attrunit = xml_utils.xml_node('attrunit',
                                          text=self.ui.fgdc_attrunit.text(),
                                          parent_node=rdom)

        if self.ui.fgdc_attrmres.text():
            attrmres = xml_utils.xml_node('attrmres',
                                          text=self.ui.fgdc_attrmres.text(),
                                          parent_node=rdom)

        return rdom
Beispiel #6
0
    def to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        taxoncl = xml_utils.xml_node("taxoncl")
        taxonrn = xml_utils.xml_node("taxonrn",
                                     text=self.ui.fgdc_taxonrn.text(),
                                     parent_node=taxoncl)
        taxonrv = xml_utils.xml_node("taxonrv",
                                     text=self.ui.fgdc_taxonrv.text(),
                                     parent_node=taxoncl)

        common_names = [c.text() for c in self.commons.get_widgets()]
        for common_name in common_names:
            if common_name:
                common = xml_utils.xml_node("common",
                                            text=common_name,
                                            parent_node=taxoncl)

        for child_taxoncl in self.child_taxoncl:
            taxoncl.append(child_taxoncl.to_xml())

        return taxoncl
Beispiel #7
0
def lambert_conformal_conic(params):
    """
    returns lxml nodes that contain projection parameters for fgdc Lambert Conformal Conic projection

    stdparll = First standard parallel
    stdparl_2 = Second standard parallel (if exists)
    longcm = Longitude of Central Meridian
    latprjo = Latitude of Projection Origin
    feast = False Easting
    fnorth = False Northing

    Parameters
    ----------
    params : dictionary
            geospatial parameters returned from get_params

    Returns
    -------
    lxml nodes for fgdc Lambert Conformal Conic projection
    """
    lambertc = xml_node('lambertc')
    stdparll = xml_node('stdparll', params['stdparll'], lambertc)
    if params['stdparl_2']:
        stdparll_2 = xml_node('stdparll', params['stdparl_2'], lambertc)

    for item in ['longcm', 'latprjo', 'feast', 'fnorth']:
        xml_node(item, params[item], lambertc)
    return lambertc
Beispiel #8
0
def _gen_fgdc_taxonomy_section(taxon, include_common_names=False,
                               include_tsns=[]):
    taxonomicclassification = xml_utils.xml_node(tag="taxoncl")
    taxrankname = xml_utils.xml_node(tag="taxonrn")
    taxrankname.text = taxon.taxon_name
    taxonomicclassification.append(taxrankname)

    taxrankvalue = xml_utils.xml_node(tag="taxonrv")
    taxrankvalue.text = taxon.taxon_value
    taxonomicclassification.append(taxrankvalue)

    if include_common_names and taxon.tsn:
        try:
            df = get_common_names_tsn(taxon.tsn)
            if 'language' in df.columns:
                for common_name in df.query('language == "English"').commonName:
                    applicable_common_name = xml_utils.xml_node(tag="common")
                    applicable_common_name.text = common_name
                    taxonomicclassification.append(applicable_common_name)
        except (ValueError, IndexError):
            pass

    if str(taxon.tsn) in include_tsns:
        tsn_common_name = xml_utils.xml_node(tag="common")
        tsn_common_name.text = "TSN: {}".format(taxon.tsn)
        taxonomicclassification.append(tsn_common_name)

    for child in taxon.children:
        child_node = _gen_fgdc_taxonomy_section(child, include_common_names,
                                                include_tsns=include_tsns)
        taxonomicclassification.append(child_node)

    return taxonomicclassification
Beispiel #9
0
    def to_xml(self):
        """
        encapsulates the QPlainTextEdit text in an element tag

        Returns
        -------
        procstep element tag in xml tree
        """
        keywords = xml_utils.xml_node('keywords')

        if self.ui.theme_tabs.isTabEnabled(0):
            theme = xml_utils.xml_node('theme', parent_node=keywords)
            themekt = xml_utils.xml_node('themekt',
                                         text=self.ui.fgdc_themekt.text(),
                                         parent_node=theme)
            for isokw in self.iso_kws.get_widgets():
                themekey = xml_utils.xml_node('themekey', text=isokw.ui.fgdc_themekey.currentText(),
                                           parent_node=theme)

        for theme in self.thesauri:
            theme_xml = theme.to_xml()
            if theme_xml.xpath('themekt')[0].text == 'None' and \
                    len(theme_xml.xpath('themekey')) == 1 and \
                    theme_xml.xpath('themekey')[0].text is None and \
                    len(self.thesauri) >= 2:
                # Skip themes that still have the default thesaurus ('None')
                # with no keywords entered,
                # when they added an additional thesaurus
                pass
            else:
                keywords.append(theme_xml)

        return keywords
Beispiel #10
0
    def to_xml(self):
        """
        encapsulates the QPlainTextEdit text in an element tag

        Returns
        -------
        possacc element tag in xml tree
        """
        possacc = xml_utils.xml_node(tag="posacc")
        horizpa = xml_utils.xml_node(tag="horizpa")
        horizpar = xml_utils.xml_node(tag="horizpar")
        horizpar_text = self.findChild(QPlainTextEdit,
                                       "fgdc_horizpa").toPlainText()
        if len(horizpar_text) > 0:
            horizpar.text = horizpar_text
            horizpa.append(horizpar)
            possacc.append(horizpa)

        vertacc = xml_utils.xml_node(tag="vertacc")
        vertaccr = xml_utils.xml_node(tag="vertaccr")
        vertaccr_text = self.findChild(QPlainTextEdit,
                                       "fgdc_vertacc").toPlainText()
        if len(vertaccr_text) > 0:
            vertaccr.text = vertaccr_text
            vertacc.append(vertaccr)
            possacc.append(vertacc)
        return possacc
Beispiel #11
0
    def _to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        eainfo = xml_utils.xml_node('eainfo')

        #TODO add some logic to not include these when they haven't been used.
        detailed = self.detailed._to_xml()
        eainfo.append(detailed)

        eaover_str = self.ui.fgdc_eaover.toPlainText()
        eadetcit_str = self.ui.fgdc_eaover.toPlainText()

        if eaover_str or eadetcit_str:
            overview = xml_utils.xml_node('overview', parent_node=eainfo)
            eaover = xml_utils.xml_node('eaover',
                                        text=eaover_str,
                                        parent_node=overview)
            eadetcit = xml_utils.xml_node('eadetcit',
                                          text=eadetcit_str,
                                          parent_node=overview)

        return eainfo
def equidistant_conic(params):
    """
    returns lxml nodes that contain projection parameters for fgdc Equidistant Conic projection

    stdparll = First standard parallel
    stdparl_2 = Second standard parallel (if exists)
    longcm = Longitude of Central Meridian
    latprjo = Latitude of Projection Origin
    feast = False Easting
    fnorth = False Northing

    Parameters
    ----------
    params : dictionary
            geospatial parameters returned from get_params

    Returns
    -------
    lxml nodes for fgdc Equidistant Conic projection
    """

    equicon = xml_node('equicon')
    stdparll = xml_node('stdparll', params['stdparll'], equicon)
    if params['stdparll_2'] is not 'Unknown':
        stdparll_2 = xml_node('stdparll', params['stdparll_2'], equicon)

    for item in ['longcm', 'latprjo', 'feast', 'fnorth']:
        xml_node(item, params[item], equicon)
    return equicon
Beispiel #13
0
def spatial_ref(fname, feature_class=None):
    """
    Returns the ogr spatial reference object for a given filename

    Parameters
    ----------
    fname : str
            The filename and path to the file to open
    feature_class : str (optional)
            If the fname is a file geodatabase then
            the feature class name is required

    Returns
    -------
    ogr spatial reference object
    """
    layer = get_layer(fname)

    params = get_params(layer)

    spref = xml_node('spref')
    horizsys = xml_node('horizsys', parent_node=spref)

    if not params['mapprojn']:
        georaphic_node = geographic(params)
        horizsys.append(geographic_node)
        geodetic_node = geodetic(params)
        horizsys.append(geodetic_node)
def mapproj(params):
    mapproj_node = xml_node('mapproj')

    fgdc_name, function = lookup_fdgc_projname(params['projection_name'])
    mapprojn = xml_node('mapprojn', text=fgdc_name, parent_node=mapproj_node)
    prj_node = function(params)
    mapproj_node.append(prj_node)
    return mapproj_node
Beispiel #15
0
    def _to_xml(self):
        # add code here to translate the form into xml representation
        idinfo_node = xml_utils.xml_node('idinfo')

        citation_node = xml_utils.xml_node('citation', parent_node=idinfo_node)
        citeinfo_node = self.citation._to_xml()
        citation_node.append(citeinfo_node)
        idinfo_node.append(citation_node)

        descript_node = xml_utils.xml_node('descript', parent_node=idinfo_node)
        abstract_node = self.abstract._to_xml()
        descript_node.append(abstract_node)
        purpose_node = self.purpose._to_xml()
        descript_node.append(purpose_node)
        supplinf_node = self.supplinf._to_xml()
        if supplinf_node.text is not None:
            descript_node.append(supplinf_node)

        idinfo_node.append(descript_node)

        timeperd_node = self.timeperd._to_xml()
        idinfo_node.append(timeperd_node)

        status_node = self.status._to_xml()
        idinfo_node.append(status_node)

        spdom_node = self.root_widget.spatial_tab.spdom._to_xml()
        idinfo_node.append(spdom_node)

        keywords = self.keywords._to_xml()
        idinfo_node.append(keywords)

        if self.schema == 'bdp' and self.taxonomy.has_content():
            taxonomy = self.taxonomy._to_xml()
            idinfo_node.append(taxonomy)

        accconst_node = self.accconst._to_xml()
        idinfo_node.append(accconst_node)

        useconst_node = self.useconst._to_xml()
        idinfo_node.append(useconst_node)


        datacredit_node = self.datacredit._to_xml()
        if len(datacredit_node.text):
            idinfo_node.append(datacredit_node)

        if self.ptcontac.has_content():
            ptcontac = self.ptcontac._to_xml()
            idinfo_node.append(ptcontac)

        datacredit_node = self.datacredit._to_xml()
        if datacredit_node.text:
            idinfo_node.append(datacredit_node)

        return idinfo_node
Beispiel #16
0
    def _to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        edom = xml_utils.xml_node('edom')
        edomv = xml_utils.xml_node('edomv', text=self.ui.fgdc_edomv.text(), parent_node=edom)
        edomvd = xml_utils.xml_node('edomvd', text=self.ui.fgdc_edomvd.toPlainText(), parent_node=edom)
        edomvds = xml_utils.xml_node('edomvds', text=self.ui.fgdc_edomvds.text(), parent_node=edom)

        return edom
def utm(params):
    gridsys = xml_node('gridsys')
    gridsysn = xml_node('gridsysn',
                        text='Universal Transverse Mercator',
                        parent_node=gridsys)

    utm_node = xml_node('utm', parent_node=gridsys)
    utmzone = xml_node('utmzone', text=params['utmzone'], parent_node=utm_node)

    transmer = transverse_mercator(params)
    utm_node.append(transmer)

    return gridsys
 def _to_xml(self):
     """
     encapsulates the QTabWidget text for Metadata Time in an element tag
     Returns
     -------
     timeperd element tag in xml tree
     """
     codesetd = xml_utils.xml_node('codesetd')
     codesetn = xml_utils.xml_node('codesetn',
                                   text= self.ui.fgdc_codesetn.currentText(),
                                   parent_node=codesetd)
     codesetn = xml_utils.xml_node('codesets',
                                   text= self.ui.fgdc_codesets.text(),
                                   parent_node=codesetd)
     return codesetd
Beispiel #19
0
    def _to_xml(self):
        if self.shortname:
            proj_root = xml_utils.xml_node(self.shortname)

            for param in self.projection['elements']:
                widget = self.findChild(QLineEdit, "fgdc_" + param)
                if widget is not None:
                    xml_utils.xml_node(param,
                                       text=widget.text(),
                                       parent_node=proj_root)
                else:
                    xml_utils.xml_node(param, text='', parent_node=proj_root)
            return proj_root
        else:
            return None
Beispiel #20
0
    def to_xml(self):
        """
        encapsulates the QPlainTextEdit text in an element tag

        Returns
        -------
        procstep element tag in xml tree
        """
        keywords = xml_utils.xml_node("keywords")

        if self.ui.rbtn_yes.isChecked():
            for place in self.thesauri:
                place_xml = place.to_xml()
                place_node = xml_utils.XMLNode(place_xml)
                if (
                    place_node.placekt.text == "None"
                    and len(place_node.xpath("placekey", as_list=True)) <= 1
                    and place_node.xpath("placekey", as_list=True)[0].text == ""
                    and len(self.thesauri) > 1
                ):
                    pass
                else:
                    keywords.append(place_xml)

        return keywords
Beispiel #21
0
    def to_xml(self):
        metadata_node = xml_utils.xml_node(tag='metadata')
        idinfo = self.idinfo.to_xml()
        metadata_node.append(idinfo)

        if self.use_dataqual:
            dataqual = self.dataqual.to_xml()
            metadata_node.append(dataqual)

        if self.spatial_tab.spdoinfo.has_content() and self.use_spatial:
            spdoinfo = self.spatial_tab.spdoinfo.to_xml()
            metadata_node.append(spdoinfo)

        if self.spatial_tab.spref.has_content() and self.use_spatial:
            spref = self.spatial_tab.spref.to_xml()
            metadata_node.append(spref)

        if self.eainfo.has_content() and self.use_eainfo:
            eainfo = self.eainfo.to_xml()
            metadata_node.append(eainfo)

        if self.use_distinfo:
            distinfo = self.distinfo.to_xml()
            metadata_node.append(distinfo)

        metainfo = self.metainfo.to_xml()
        metadata_node.append(metainfo)
        return metadata_node
Beispiel #22
0
def gen_taxonomy_section(keywords, tsns, include_common_names=False):
    taxonomy = xml_utils.xml_node(tag="taxonomy")
    keywtax = xml_utils.xml_node(tag="keywtax")
    taxonkt = xml_utils.xml_node(tag="taxonkt", text='None',
                                 parent_node=keywtax)


    for keyword in keywords:
        taxonkey = xml_utils.xml_node(tag="taxonkey", text=keyword,
                                      parent_node=keywtax)

    taxonomy.append(keywtax)

    taxoncl = gen_fgdc_taxoncl(tsns, include_common_names, include_tsns=tsns)
    taxonomy.append(taxoncl)
    return taxonomy
Beispiel #23
0
    def to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        keywtax = xml_utils.xml_node('keywtax')
        taxonkt = xml_utils.xml_node("taxonkt",
                                     text=self.ui.fgdc_themekt.text(),
                                     parent_node=keywtax)
        for keyword in self.get_keywords():
            taxonkey = xml_utils.xml_node('taxonkey', text=keyword,
                                          parent_node=keywtax)

        return keywtax
    def to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        attr = xml_utils.xml_node('attr')
        for i in range(self.ui.listWidget.count()):
            e = self.ui.listWidget.item(i)
            e2  = self.ui.listWidget.itemWidget(e)
            attrdomv = xml_utils.xml_node('attrdomv', parent_node=attr)
            e_node = e2.to_xml()
            attrdomv.append(e_node)

        return attr
Beispiel #25
0
    def _to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        detailed = xml_utils.xml_node('detailed')
        enttyp = xml_utils.xml_node('enttyp', parent_node=detailed)
        enttypl = xml_utils.xml_node('enttypl', text=self.ui.fgdc_enttypl.text(), parent_node=enttyp)
        enttypd = xml_utils.xml_node('enttypd', text=self.ui.fgdc_enttypd.toPlainText(), parent_node=enttyp)
        enttypds = xml_utils.xml_node('enttypds', text=self.ui.fgdc_enttypds.text(), parent_node=enttyp)

        attr = self.attributes._to_xml()
        for a in attr.xpath('attr'):
            detailed.append(a)
        return detailed
Beispiel #26
0
    def to_xml(self):
        """
        encapsulates the QTabWidget text for Metadata Time in an element tag
        Returns
        -------
        timeperd element tag in xml tree
        """
        timeperd = xml_utils.xml_node('timeperd')
        timeinfo = self.timeinfo.to_xml()

        timeperd.append(timeinfo)

        current = xml_utils.xml_node('current',
                                     parent_node=timeperd,
                                     text=self.ui.fgdc_current.currentText())

        return timeperd
Beispiel #27
0
    def to_xml(self):
        if self.shortname:
            proj_root = xml_utils.xml_node(self.shortname)

            for param in self.projection["elements"]:
                widget = self.findChild(QLineEdit, "fgdc_" + param)
                if param == "stdparll_2":
                    param = "stdparll"
                if widget is not None:
                    xml_utils.xml_node(param,
                                       text=widget.text(),
                                       parent_node=proj_root)
                else:
                    xml_utils.xml_node(param, text="", parent_node=proj_root)
            return proj_root
        else:
            return None
Beispiel #28
0
def geographic(params):
    """

    Parameters
    ----------
    params : dict
            (returned from:

    Returns
    -------
    fgdc <geograph> element
    """
    geograph = xml_node("geograph")
    latres = xml_node("latres", params['latres'], geograph)
    longres = xml_node("longres", params['longres'], geograph)
    geounit = xml_node("geogunit", params['geogunit'], geograph)
    return geograph
Beispiel #29
0
    def to_xml(self):
        spdom = xml_node("spdom")

        if self.schema == "bdp":
            descgeog = xml_node("descgeog",
                                text=self.ui.fgdc_descgeog.text(),
                                parent_node=spdom)

        bounding = xml_node("bounding", parent_node=spdom)
        westbc = xml_node("westbc",
                          text=self.ui.fgdc_westbc.text(),
                          parent_node=bounding)
        eastbc = xml_node("eastbc",
                          text=self.ui.fgdc_eastbc.text(),
                          parent_node=bounding)
        northbc = xml_node("northbc",
                           text=self.ui.fgdc_northbc.text(),
                           parent_node=bounding)
        southbc = xml_node("southbc",
                           text=self.ui.fgdc_southbc.text(),
                           parent_node=bounding)

        if self.original_xml is not None:
            boundalt = xml_utils.search_xpath(self.original_xml,
                                              "bounding/boundalt")
            if boundalt is not None:
                spdom.append(deepcopy(boundalt))

            dsgpoly_list = xml_utils.search_xpath(self.original_xml,
                                                  "dsgpoly",
                                                  only_first=False)
            for dsgpoly in dsgpoly_list:
                spdom.append(deepcopy(dsgpoly))

        return spdom
Beispiel #30
0
    def to_xml(self):
        spdom = xml_node('spdom')

        if self.schema == 'bdp':
            descgeog = xml_node('descgeog',
                                text=self.ui.fgdc_descgeog.text(),
                                parent_node=spdom)

        bounding = xml_node('bounding', parent_node=spdom)
        westbc = xml_node('westbc',
                          text=self.ui.fgdc_westbc.text(),
                          parent_node=bounding)
        eastbc = xml_node('eastbc',
                          text=self.ui.fgdc_eastbc.text(),
                          parent_node=bounding)
        northbc = xml_node('northbc',
                           text=self.ui.fgdc_northbc.text(),
                           parent_node=bounding)
        southbc = xml_node('southbc',
                           text=self.ui.fgdc_southbc.text(),
                           parent_node=bounding)

        if self.original_xml is not None:
            boundalt = xml_utils.search_xpath(self.original_xml,
                                              'bounding/boundalt')
            if boundalt is not None:
                spdom.append(deepcopy(boundalt))

            dsgpoly_list = xml_utils.search_xpath(self.original_xml,
                                                  'dsgpoly',
                                                  only_first=False)
            for dsgpoly in dsgpoly_list:
                spdom.append(deepcopy(dsgpoly))

        return spdom