Ejemplo n.º 1
0
    def save_hazard_layer(self, hazard_path):
        # download or copy hazard path/url
        # It is a single tif file
        if not hazard_path and not os.path.exists(self.hazard_path):
            raise IOError("Hazard file not specified")

        if hazard_path:
            temp_hazard = download_file(hazard_path)
            shutil.copy(temp_hazard, self.hazard_path)

        # copy qml and metadata
        shutil.copy(self.ash_fixtures_dir("hazard.qml"), self.working_dir_path("hazard.qml"))

        keyword_io = KeywordIO()

        keywords = {
            "hazard_category": u"single_event",
            "keyword_version": u"3.5",
            "title": u"Ash Fall",
            "hazard": u"volcanic_ash",
            "continuous_hazard_unit": u"centimetres",
            "layer_geometry": u"raster",
            "layer_purpose": u"hazard",
            "layer_mode": u"continuous",
        }

        hazard_layer = read_qgis_layer(self.hazard_path, "Ash Fall")
        keyword_io.write_keywords(hazard_layer, keywords)
Ejemplo n.º 2
0
    def save_hazard_layer(self, hazard_path):
        # download or copy hazard path/url
        # It is a single tif file
        if not hazard_path and not os.path.exists(self.hazard_path):
            raise IOError('Hazard file not specified')

        if hazard_path:
            temp_hazard = download_file(hazard_path)
            shutil.copy(temp_hazard, self.hazard_path)

        # copy qml and metadata
        shutil.copy(self.ash_fixtures_dir('hazard.qml'),
                    self.working_dir_path('hazard.qml'))

        keyword_io = KeywordIO()

        keywords = {
            'hazard_category': u'single_event',
            'keyword_version': u'3.5',
            'title': u'Ash Fall',
            'hazard': u'volcanic_ash',
            'continuous_hazard_unit': u'centimetres',
            'layer_geometry': u'raster',
            'layer_purpose': u'hazard',
            'layer_mode': u'continuous'
        }

        hazard_layer = read_qgis_layer(self.hazard_path, 'Ash Fall')
        keyword_io.write_keywords(hazard_layer, keywords)
Ejemplo n.º 3
0
def read_keywords_iso_metadata(metadata_url, keyword=None):
    """Read xml metadata of a layer"""
    filename = download_file(metadata_url)
    # add xml extension
    new_filename = filename + '.xml'
    shutil.move(filename, new_filename)
    keyword_io = KeywordIO()
    keywords = keyword_io.read_keywords_file(new_filename)
    if keyword:
        return keywords.get(keyword, None)
    return keywords
Ejemplo n.º 4
0
def read_keywords_iso_metadata(metadata_url, keyword=None):
    """Read xml metadata of a layer"""
    filename = download_file(metadata_url)
    # add xml extension
    new_filename = filename + '.xml'
    shutil.move(filename, new_filename)
    keyword_io = KeywordIO()
    keywords = keyword_io.read_keywords_file(new_filename)
    if keyword:
        return keywords.get(keyword, None)
    return keywords
Ejemplo n.º 5
0
def read_keywords_iso_metadata(metadata_url, keyword=None):
    """Read xml metadata of a layer

    :param keyword: Can be string or tuple containing keywords to search for
    :type keyword: str, (str, )

    :return: the keywords, or a dictionary with key-value pair
    """
    filename = download_file(metadata_url)
    # add xml extension
    new_filename = filename + '.xml'
    shutil.move(filename, new_filename)
    keywords = read_iso19115_metadata(new_filename)
    if keyword:
        if isinstance(keyword, tuple) or isinstance(keyword, list):
            ret_val = {}
            for key in keyword:
                ret_val[key] = keywords.get(key, None)
            return ret_val
        else:
            return keywords.get(keyword, None)
    return keywords
Ejemplo n.º 6
0
def read_keywords_iso_metadata(metadata_url, keyword=None):
    """Read xml metadata of a layer

    :param keyword: Can be string or tuple containing keywords to search for
    :type keyword: str, (str, )

    :return: the keywords, or a dictionary with key-value pair
    """
    filename = download_file(metadata_url)
    # add xml extension
    new_filename = filename + '.xml'
    shutil.move(filename, new_filename)
    keywords = read_iso19115_metadata(new_filename)
    if keyword:
        if isinstance(keyword, tuple) or isinstance(keyword, list):
            ret_val = {}
            for key in keyword:
                ret_val[key] = keywords.get(key, None)
            return ret_val
        else:
            return keywords.get(keyword, None)
    return keywords