gdal icon indicating copy to clipboard operation
gdal copied to clipboard

gdal2tiles visible tile borders

Open alacst opened this issue 4 years ago • 10 comments

Hey,

I've noticed a possible error in gdal2tiles. I'm trying to create png tiles from a png base. It's a small area but I need high zoom level (21-22). Using the generated viewer pages, some of the tile borders are visible. When comparing to the base image, the differences are more salient. The covered area is located in the UK. gdal_translate: gdal_translate -of vrt -a_srs EPSG:32630 -gcp /*adding 3 gcps here*/ base.png base.vrt and then gdal2tiles: gdal2tiles --xyz -r near -z 9-21 base.vrt targetdir

Pic from openlayers: kép Vertical tile border visible (~middle).

Base compared to the created tile: Tile kép Base kép

Not all tiles affected, I'd say around 20%.

Operating system

Win 10 Pro

GDAL version and provenance

3.1.4.

alacst avatar Nov 30 '20 10:11 alacst

By looking at the bright pixel in the middle of the samples it seems like the tile on the righ side is pushed one pixel row to the left so that on column of pixels get clipped. The blue arrows show columns which look similar to me.

similar_pixel_columns

Is the image labeled as "base" base.png or the georeferenced file base.vrt? Setting QGIS project into EPSG:3857 and opening base.vrt with it should show the effect of warping with the GCPs but without clipping into tiles.

jratike80 avatar Nov 30 '20 13:11 jratike80

the image is the base.png. I've opened the vrt in QGIS, and the rendered picture is identical to the base png here.

alacst avatar Nov 30 '20 13:11 alacst

Good. Just to be sure, did you also configure QGIS project into EPSG:3857 to force it to warp from 32630 into 3857 just like gdal2tiles is warping with your command?

jratike80 avatar Nov 30 '20 13:11 jratike80

Honestly, I'm kinda unsure. These things are pretty new to me. I've added the vrt to QGIS and then in the right bottom corner I switched to 3857

alacst avatar Nov 30 '20 13:11 alacst

That's exactly the way to make it to warp into 3857.

jratike80 avatar Nov 30 '20 13:11 jratike80

I have the same problem. I'm using version 3.1.3. This issue has been brought up in #3162 and #1087. I tried different resampling methods (default, antialias, cubic) and also tried the --config GDAL_PDF_DPI 1200 mentioned in #3162 with different resampling methods but nothing seems to improve it. I also tried pre-warping the input file to EPSG:4326 but also no luck. Here's an example of what I get: tiles

DFyson avatar Dec 02 '20 02:12 DFyson

I think I'm having the same problem here, it appears that the resampling around tile edges is doing something odd. Here's one example using -r near which causes one or more lines of pixels to be repeated. image Note that the process I'm using here is:

  1. gdalwarp to reproject my original raster to web mercator with some oversampling, using -r cubic. Output tif looks as expected.
  2. gdaldem to colorize. Output tif looks as expected.
  3. gdal2tiles with -r near

I'm using GDAL 3.7.0.

jcary741 avatar Apr 26 '24 14:04 jcary741

With some experimentation, I was able to determine the issue was due to the first gdalwarp reprojection not using the same origin / resolution as was later used by gdal2tiles. I ended up importing the GlobalMercator class from gdal2tiles.py to compute the extent of the base zoom level tiles, then using that to compute the final resolution and passing that to gdalwarp via -ts {width_in_px} {height_in_px} -te {...bounds_in_meters}. In combination with using -r near for both gdalwarp and gdal2tiles.

I wish gdal2tiles just supported colorization as part of the tiling process, as that would really simplify this type of workflow.

jcary741 avatar Apr 29 '24 19:04 jcary741

@jcary741 I'm running into the same issue. Do you have any code you could share?

timgilbertson-os avatar Jun 05 '24 14:06 timgilbertson-os

Unfortunately, I can't share any more than I already have. Sorry.

jcary741 avatar Jun 05 '24 14:06 jcary741