How to convert geotiffs programmatically to cogs
See original GitHub issueAfter I have verified the successful run of the command line rio cogeo example.tif example_cog_raw.tif --cog-profile raw
then I’m trying to use the function cog_translate
programmatically.
This snippet is failing:
cog_img = "cog" + "_" + name # name is for instance example.tif
cog_profile = cog_profiles.get('raw')
cog_profile.update(dict(BIGTIFF=os.environ.get("BIGTIFF", "IF_SAFER")))
block_size = 512
config = dict(
NUM_THREADS=8,
GDAL_TIFF_INTERNAL_MASK=os.environ.get("GDAL_TIFF_INTERNAL_MASK", True),
GDAL_TIFF_OVR_BLOCKSIZE=os.environ.get("GDAL_TIFF_OVR_BLOCKSIZE", block_size),
)
cog_translate(
img,
cog_img,
cog_profile,
None,
None,
None,
6,
config
)
where img
the binary image file which is properly opened previously by rasterio and checked for being or not a COG.
The error stack trace is:
File "/Users/geobart/Development/CallForCode/cog-k8s/app/api_views.py", line 87, in post
block_size = 512
File "/Users/geobart/pyenv/cog-k8s-2pcfZKQH/lib/python3.6/site-packages/rio_cogeo/cogeo.py", line 52, in cog_translate
with rasterio.open(src_path) as src:
File "/Users/geobart/.pyenv/versions/3.6.2/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/Users/geobart/pyenv/cog-k8s-2pcfZKQH/lib/python3.6/site-packages/rasterio/__init__.py", line 178, in fp_reader
dataset = memfile.open()
File "/Users/geobart/pyenv/cog-k8s-2pcfZKQH/lib/python3.6/site-packages/rasterio/env.py", line 360, in wrapper
return f(*args, **kwds)
File "/Users/geobart/pyenv/cog-k8s-2pcfZKQH/lib/python3.6/site-packages/rasterio/io.py", line 132, in open
writer = get_writer_for_driver(driver)
File "/Users/geobart/pyenv/cog-k8s-2pcfZKQH/lib/python3.6/site-packages/rasterio/io.py", line 179, in get_writer_for_driver
if driver_can_create(driver):
File "rasterio/_base.pyx", line 112, in rasterio._base.driver_can_create
File "rasterio/_base.pyx", line 95, in rasterio._base.driver_supports_mode
AttributeError: 'NoneType' object has no attribute 'encode'
Do you have any hints on the cause of the error and if I’m using cogeo in a wrong way?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
GeoExamples - Cloud Optimized GeoTIFF tutorial
The easiest way to create a COG is using the GDAL command line interface. If the GeoTIFF data is created from a script...
Read more >An Introduction to Cloud Optimized GeoTIFFS (COGs) Part 2
An Introduction to Cloud Optimized GeoTIFFS (COGs) Part 2: Converting Regular GeoTIFFs into COGs. last updated: November 01, 2022.
Read more >Working with Geospatial data — Part:4, Cloud Optimized ...
CoG converter — This will convert your standard GeoTIFF file to Cloud optimized GeoTIFF. Repo link; Tiling — This repo will help you...
Read more >Programmatic Access to OpenTopography's Cloud Optimized ...
Programmatic Access to OpenTopography's Cloud Optimized GeoTIFF (COG) Global ... gpd.read_file(river) #Convert the river centerline to the same coordinate ...
Read more >Cloud Optimized GeoTIFF
A Cloud Optimized GeoTIFF (COG) is a regular GeoTIFF file, aimed at being hosted on a HTTP file server, with an internal organization...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @vincentsarago, I think doing that server side is a little bit different. I found out the way to get it done through a
MemoryFile
instance and the trick to use the first item in the listfiles
. The working snippet is below for those interested later:Nice @vincentsarago, many thanks indeed. Btw I wanted to come and say hello in Bucharest but the time was very tight. I’ll do definitively next time 😉