def open(self, driver=None, width=None, height=None, count=None, crs=None, transform=None, dtype=None, nodata=None, sharing=False, **kwargs): """Open the file and return a Rasterio dataset object. If data has already been written, the file is opened in 'r' mode. Otherwise, the file is opened in 'w' mode. Parameters ---------- Note well that there is no `path` parameter: a `MemoryFile` contains a single dataset and there is no need to specify a path. Other parameters are optional and have the same semantics as the parameters of `rasterio.open()`. """ mempath = _UnparsedPath(self.name) if self.closed: raise OSError("I/O operation on closed file.") if len(self) > 0: log.debug("VSI path: {}".format(mempath.path)) return DatasetReader(mempath, driver=driver, sharing=sharing, **kwargs) else: writer = get_writer_for_driver(driver) return writer(mempath, 'w+', driver=driver, width=width, height=height, count=count, crs=crs, transform=transform, dtype=dtype, nodata=nodata, sharing=sharing, **kwargs)
def open(self, driver=None, sharing=False, **kwargs): """Open the file and return a Rasterio dataset object. The provided file-like object is assumed to be readable. Writing is currently not supported. Parameters are optional and have the same semantics as the parameters of `rasterio.open()`. """ mempath = _UnparsedPath(self.name) if self.closed: raise IOError("I/O operation on closed file.") # Assume we were given a non-empty file-like object log.debug("VSI path: {}".format(mempath.path)) return DatasetReader(mempath, driver=driver, sharing=sharing, **kwargs)
def open(self, path, driver=None, sharing=False, **kwargs): """Open a dataset within the zipped stream. Parameters ---------- path : str Path to a dataset in the zip file, relative to the root of the archive. Other parameters are optional and have the same semantics as the parameters of `rasterio.open()`. Returns ------- A Rasterio dataset object """ zippath = _UnparsedPath('/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))) if self.closed: raise OSError("I/O operation on closed file.") return DatasetReader(zippath, driver=driver, sharing=sharing, **kwargs)
def test_unparsed_path_name(): """An unparsed path's name property is correct""" assert _UnparsedPath('/vsifoo/bar/tif').name == '/vsifoo/bar/tif'
def test_path_as_vsi_unparsed(): """Correctly make GDAL filename from unparsed path""" assert _UnparsedPath("foo").as_vsi() == "foo"