Beispiel #1
0
    def open(self) -> Iterator[GeoRasterReader]:
        """Context manager which returns a :class:`BandDataSource`"""

        activate_from_config()  # check if settings changed and apply new

        lock = self._lock
        locked = False if lock is None else lock.acquire(blocking=True)

        try:
            _LOG.debug("opening %s", self.filename)
            with rasterio.DatasetReader(rasterio.path.parse_path(
                    str(self.filename)),
                                        sharing=False) as src:
                override = False

                transform = src.transform
                if transform.is_identity:
                    override = True
                    transform = self.get_transform(src.shape)

                try:
                    crs = _rasterio_crs(src)
                except ValueError:
                    override = True
                    crs = self.get_crs()

                bandnumber = self.get_bandnumber(src)
                band = rasterio.band(src, bandnumber)
                nodata = src.nodatavals[band.bidx - 1] if src.nodatavals[
                    band.bidx - 1] is not None else self.nodata
                nodata = num2numpy(nodata, band.dtype)

                if locked:
                    locked = False
                    lock.release()

                if override:
                    warnings.warn(
                        f"""Broken/missing geospatial data was found in file:
"{self.filename}"
Will use approximate metadata for backwards compatibility reasons (#673).
This behaviour is deprecated. Future versions will raise an error.""",
                        category=DeprecationWarning)
                    yield OverrideBandDataSource(band,
                                                 nodata=nodata,
                                                 crs=crs,
                                                 transform=transform,
                                                 lock=lock)
                else:
                    yield BandDataSource(band, nodata=nodata, lock=lock)

        except Exception as e:
            _LOG.error("Error opening source dataset: %s", self.filename)
            raise e
        finally:
            if locked:
                lock.release()
Beispiel #2
0
def _read_file(source, geobox, band, no_data, resampling):
    # Read our data
    with rio.DatasetReader(rio.path.parse_path(source.filename),
                           sharing=False) as src:
        dst = read_with_reproject(src,
                                  geobox,
                                  dst_nodata=no_data,
                                  src_nodata_fallback=no_data,
                                  band=source.get_bandnumber(),
                                  resampling=resampling)
    return dst
Beispiel #3
0
 def action(url, *args):
     url = rasterio.parse_path(url)
     with local_env():
         with rasterio.DatasetReader(url, sharing=False) as src:
             return fn(src, *args, **kwargs)
Beispiel #4
0
 def read_from_url(url):
     url = rasterio.parse_path(url)
     with rasterio.DatasetReader(url, sharing=False) as src:
         return extractor(src, coord=coord)
Beispiel #5
0
 def proc(url, userdata):
     with rasterio.DatasetReader(parse_path(url),
                                 sharing=False) as f:
         on_file_cbk(f, userdata)