def vsi_path(path, archive, scheme): """Convert a parsed path to a GDAL VSI path **DEPRECATED** Parameters ---------- path : str The path part of a parsed path. archive : str The archive part of a parsed path. scheme : str The scheme part of a parsed path. Returns ------- str """ warnings.warn( "This function will be removed in version 1.0", RasterioDeprecationWarning ) if archive or scheme: return future_vsi_path(ParsedPath(path, archive, scheme)) else: return future_vsi_path(UnparsedPath(path))
def open(self, driver=None, width=None, height=None, count=None, crs=None, transform=None, dtype=None, nodata=None, **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()`. """ vsi_path = UnparsedPath(self.name) if self.closed: raise IOError("I/O operation on closed file.") if self.exists(): log.debug("VSI path: {}".format(vsi_path.path)) return DatasetReader(vsi_path, driver=driver, **kwargs) else: writer = get_writer_for_driver(driver) return writer(vsi_path, 'w+', driver=driver, width=width, height=height, count=count, crs=crs, transform=transform, dtype=dtype, nodata=nodata, **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, **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. Returns ------- A Rasterio dataset object """ vsi_path = UnparsedPath('/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))) if self.closed: raise IOError("I/O operation on closed file.") return DatasetReader(vsi_path, driver=driver, **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 """ vsi_path = UnparsedPath('/vsizip{0}/{1}'.format(self.name, path.lstrip('/'))) if self.closed: raise IOError("I/O operation on closed file.") return DatasetReader(vsi_path, 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"
def test_vsi_path_unparsed(): """Correctly make GDAL filename from unparsed path""" assert vsi_path(UnparsedPath("foo")) == "foo"