Skip to content

How to use rasterio read gdal dataset created in memory? #3011

Answered by sgillies
sqwev asked this question in Q&A
Discussion options

You must be logged in to vote

I ran this on my macbook. osgeo.gdal and rasterio are installed from conda-forge, the latest of each. If you installed from a different conda channel, it would be good to reinstall from conda-forge.

import uuid
from osgeo import gdal
import rasterio

# create gdal dataset in memory
mem_driver = gdal.GetDriverByName('MEM')
ds = mem_driver.Create('', 16, 16, 1, gdal.GDT_Byte)
# ds.SetProjection(projection)
# ds.SetGeoTransform(geoTransform)

# create 
vsi_mem_file_path = f'/vsimem/{uuid.uuid4().hex}.tif'
gdal.GetDriverByName('GTiff').CreateCopy(vsi_mem_file_path, ds)

# test if gdal can open
print(f"vsi_mem_file_path : {vsi_mem_file_path }")
test_ds = gdal.Open(vsi_mem_file_path )
print(f"t…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sqwev
Comment options

@sgillies
Comment options

Answer selected by sqwev
@sqwev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants