Beispiel #1
0
    def _get_data(self, filename, when):
        """
        Return numpy masked array corresponding to damage result.

        The file named filename is extracted from the result to a
        temporary directory and read via gdal. Filename must be the name
        of a gdal readable dataset inside the result zip file.
        """
        fieldmap = {
            'before': self.zip_risk_a,
            'after': self.zip_risk_b,
        }
        field = fieldmap[when]

        with zipfile.ZipFile(field) as archive:
            tempdir = tempfile.mkdtemp()
            archive.extract(filename, tempdir)
            filepath = os.path.join(tempdir, filename)
            dataset = gdal_open(filepath)
            geotransform = dataset.GetGeoTransform()
            data = utils.ds2ma(dataset)
            dataset = None  # Should closes the file
            os.remove(filepath)
            os.rmdir(tempdir)
            return dict(data=data, geotransform=geotransform)
Beispiel #2
0
    def get_data(self, filename):
        """
        Return numpy masked array corresponding to damage result.

        The file named filename is extracted from the result to a
        temporary directory and read via gdal. Filename must be the name
        of a gdal readable dataset inside the result zip file.
        """
        with zipfile.ZipFile(self.result) as archive:
            tempdir = tempfile.mkdtemp()
            archive.extract(filename, tempdir)
            filepath = os.path.join(tempdir, filename)
            dataset = gdal.Open(filepath)
            data = utils.ds2ma(dataset)
            dataset = None  # Should closes the file
            os.remove(filepath)
            os.rmdir(tempdir)
            return data