Exemple #1
0
def get_metadata_from_layer(layer):
    """Get ows metadata from one layer

    Input
        layer: Layer object. It is assumed that it has the extra attribute
               data_type which is either raster or vector
    """

    # Create empty metadata dictionary
    metadata = {}

    # Metadata specific to layer types
    metadata['layer_type'] = layer.datatype
    if layer.datatype == 'raster':
        geotransform = extract_geotransform(layer)
        metadata['geotransform'] = geotransform
        metadata['resolution'] = geotransform2resolution(
            geotransform,
            # Get both resx
            # and resy
            isotropic=False)
    else:
        metadata['resolution'] = None
        metadata['geotransform'] = None

    # Metadata common to both raster and vector data
    metadata['bounding_box'] = layer.boundingBoxWGS84
    metadata['title'] = layer.title  # This maybe overwritten by keyword
    metadata['id'] = layer.id

    # Extract keywords
    keyword_dict = {}
    if not hasattr(layer, 'keywords'):
        msg = 'No keywords in %s. Submit patch to OWSLib maintainers.' % layer
        raise Exception(msg)
    else:
        for keyword in layer.keywords:
            if keyword is not None:
                for keyword_string in keyword.split(','):
                    if ':' in keyword_string:
                        key, value = keyword_string.strip().split(':')
                        keyword_dict[key] = value
                    else:
                        keyword_dict[keyword_string] = None

    # Add resolution (as a string with one element) so that layer "remembers"
    # its original resolution,
    # FIXME (Ole): What is the best way of collapsing 2D resolution to
    # one number - resx and resy are not always identical!
    if metadata['resolution'] is not None:
        keyword_dict['resolution'] = str(metadata['resolution'][0])

    # FIXME (Ole): The statement below does not raise an Exception,
    # and nothing is written to the log file. See issue #170
    #raise Exception('weird')

    # Record all keywords as part of the metadata and return
    metadata['keywords'] = keyword_dict
    return metadata
Exemple #2
0
Fichier : io.py Projet : AIFDR/riab
def get_metadata_from_layer(layer):
    """Get ows metadata from one layer

    Input
        layer: Layer object. It is assumed that it has the extra attribute
               data_type which is either raster or vector
    """

    # Create empty metadata dictionary
    metadata = {}

    # Metadata specific to layer types
    metadata['layer_type'] = layer.datatype
    if layer.datatype == 'raster':
        geotransform = extract_geotransform(layer)
        metadata['geotransform'] = geotransform
        metadata['resolution'] = geotransform2resolution(geotransform,
                                                         # Get both resx
                                                         # and resy
                                                         isotropic=False)
    else:
        metadata['resolution'] = None
        metadata['geotransform'] = None

    # Metadata common to both raster and vector data
    metadata['bounding_box'] = layer.boundingBoxWGS84
    metadata['title'] = layer.title  # This maybe overwritten by keyword
    metadata['id'] = layer.id

    # Extract keywords
    keyword_dict = {}
    if not hasattr(layer, 'keywords'):
        msg = 'No keywords in %s. Submit patch to OWSLib maintainers.' % layer
        raise Exception(msg)
    else:
        for keyword in layer.keywords:
            if keyword is not None:
                for keyword_string in keyword.split(','):
                    if ':' in keyword_string:
                        key, value = keyword_string.strip().split(':')
                        keyword_dict[key] = value
                    else:
                        keyword_dict[keyword_string] = None

    # Add resolution (as a string with one element) so that layer "remembers"
    # its original resolution,
    # FIXME (Ole): What is the best way of collapsing 2D resolution to
    # one number - resx and resy are not always identical!
    if metadata['resolution'] is not None:
        keyword_dict['resolution'] = str(metadata['resolution'][0])

    # FIXME (Ole): The statement below does not raise an Exception,
    # and nothing is written to the log file. See issue #170
    #raise Exception('weird')

    # Record all keywords as part of the metadata and return
    metadata['keywords'] = keyword_dict
    return metadata
Exemple #3
0
    def get_resolution(self, isotropic=False, native=False):
        """Get raster resolution as a 2-tuple (resx, resy)

        Input
            isotropic: If True, verify that dx == dy and return dx
                       If False return 2-tuple (dx, dy)
            native: Optional flag. If True, return native resolution if
                                   available. Otherwise return actual.
        """

        # Get actual resolution first
        try:
            res = geotransform2resolution(self.geotransform,
                                          isotropic=isotropic)
        except Exception, e:
            msg = ('Resolution for layer %s could not be obtained: %s '
                   % (self.get_name(), str(e)))
            raise Exception(msg)