Comments (9)
It works fine. At least it doesn't produce an alpha band which is my main problem.
$ gdalinfo --version
GDAL 3.4.0dev-8dddba9d9065bf0a2f41be1282ff2dba79c21797, released 2021/06/16
$ gdalwarp -of VRT -dstalpha original.tif out.vrt
Creating output file that is 8366P x 10042L.
Processing original.tif [1/1] : 0Using internal nodata values (e.g. 0) for image original.tif.
...10...20...30...40...50...60...70...80...90...100 - done.
$ gdal_translate -of COG -mask 4 out.vrt out.tif
Input file size is 8366, 10042
0...10...20...30...40...50...60...70...80...90...100 - done.
$ rio info out.tif | jq -c .mask_flags
[["per_dataset"],["per_dataset"],["per_dataset"],["per_dataset"]]
from rio-cogeo.
@vincentsarago you can reproduce it with publicly available dataset:
$ rio cogeo create --add-mask --use-cog-driver --web-optimized \
/vsicurl/https://github.com/mapbox/rasterio/blob/master/tests/data/RGB.byte.tif\?raw\=true rasterio.tif
$ rio info rasterio.tif | jq -c .mask_flags
[["per_dataset","alpha"],["per_dataset","alpha"],["per_dataset","alpha"],["all_valid"]]
from rio-cogeo.
Thanks for the report @drnextgis
That's an interesting issue. Going thought the code I can't find anything suspicious. Can you try doing the same with GDAL commands (use gdalwarp -of VRT -dstalpha in.tif out.vrt
+ gdal_translate -of COG -mask 4 out.vrt out.tif
, or something like this)
from rio-cogeo.
can you print the compression used for all the COG ?
from rio-cogeo.
$ rio info original.tif| jq -c .compress
null
$ rio info cogeo1.tif | jq -c .compress
"deflate"
$ rio info cogeo2.tif | jq -c .compress
"deflate"
$ rio info cogeo3.tif | jq -c .compress
"deflate"
$ rio info cogeo4.tif | jq -c .compress
"deflate"
$ rio info out.tif | jq -c .compress
null
from rio-cogeo.
@drnextgis is your file in byte
?
from rio-cogeo.
$ gdalinfo original.tif
Driver: GTiff/GeoTIFF
Files: original.tif
Size is 8366, 10042
Coordinate System is:
PROJCS["WGS 84 / UTM zone 38N",
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",45],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH],
AUTHORITY["EPSG","32638"]]
Origin = (615076.000000000000000,3441809.000000000000000)
Pixel Size = (1.000000000000000,-1.000000000000000)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 615076.000, 3441809.000) ( 46d12'24.08"E, 31d 6'16.19"N)
Lower Left ( 615076.000, 3431767.000) ( 46d12'19.96"E, 31d 0'50.06"N)
Upper Right ( 623442.000, 3441809.000) ( 46d17'39.83"E, 31d 6'13.13"N)
Lower Right ( 623442.000, 3431767.000) ( 46d17'35.41"E, 31d 0'47.01"N)
Center ( 619259.000, 3436788.000) ( 46d14'59.82"E, 31d 3'31.63"N)
Band 1 Block=8366x1 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=8366x1 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=8366x1 Type=Byte, ColorInterp=Blue
NoData Value=0
from rio-cogeo.
So this is a GDAL bug
$ gdalwarp -of VRT -dstalpha RGB.byte.tif RGB.byte.vrt
$ gdal_translate -of COG -mask 4 -co TILING_SCHEME=GoogleMapsCompatible RGB.byte.vrt RGB.cog.tif
$ rio info RGB.cog.tif | jq '.mask_flags' -c
>>> [["per_dataset","alpha"],["per_dataset","alpha"],["per_dataset","alpha"],["all_valid"]]
The problem is that GDAL will use an Alpha band when retrojecting the data to WebMercator
See https://gdal.org/drivers/raster/cog.html#reprojection-related-creation-options
ADD_ALPHA=YES/NO: Whether an alpha band is added in case of reprojection. Defaults to YES.
So by default, our mask band will be translated to an Alpha Band.
The only way you can keep the mask
is to use the JPEG compression (which anyway works better with internal mask than deflate dataset)
$ rio cogeo create --add-mask --web-optimized --use-cog-driver RGB.byte.tif rgb_cog_jpeg.tif -p jpeg
$ rio info rgb_cog_jpeg.tif | jq '.mask_flags' -c
[["per_dataset"],["per_dataset"],["per_dataset"]]
What's next
We could add warning if user use --add-mask
for gdal cog driver/web-optimized and non JPEG compression here https://github.com/cogeotiff/rio-cogeo/blob/master/rio_cogeo/cogeo.py#L356 🤷♂️
from rio-cogeo.
Thank you @vincentsarago for sorting this out!
from rio-cogeo.
Related Issues (20)
- Creating a COG in place rather than generating a new file? HOT 1
- add option to forward namespaced metadata
- add python 3.10 support
- All Console output is standard error HOT 6
- COG convesion succeeds with GDAL but not with rio-cogeo HOT 4
- Change folder of "execution" HOT 11
- NetCDF to CoG workflow
- GeoTIFF with invalidated optimizations shows up as valid HOT 1
- installation issues - coggeo command HOT 3
- limit pydantic to `1.0` HOT 3
- Shift/zoom after updating to >=4 HOT 2
- Pydantic 2.0 incompatible with morecantile HOT 1
- Unexpected GET Requests Count with web-optimized COG
- Clarify arguments used only when producing "web-optimized" COGs HOT 4
- set blocksize from the TileMatrixSet
- COG validation fails for files that are SPARSE and have sparse edge tiles in the overviews. HOT 4
- Colormap extended to 255 HOT 2
- cog drive in cog_translate function enforce creation of overviews
- Convert toCOG an in MemoryFile raster.
- do not wrap the input dataset in a WarpedVRT when it's not needed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rio-cogeo.