I cannot find an munich_1.tif. Instead I found a image DOP_20/4468260_5331209.tif in your repository. The image has a dimension of 16425x12760:
gdalinfo 4468260_5331209.tif
Driver: GTiff/GeoTIFF
Files: 4468260_5331209.tif
4468260_5331209.tif.ovr
Size is 16425, 12760
Coordinate System is:
PROJCS["DHDN / 3-degree Gauss-Kruger zone 4",
GEOGCS["DHDN",
DATUM["Deutsches_Hauptdreiecksnetz",
SPHEROID["Bessel 1841",6377397.155,299.1528128,
AUTHORITY["EPSG","7004"]],
TOWGS84[598.1,73.7,418.2,0.202,0.045,-2.455,6.7],
AUTHORITY["EPSG","6314"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4314"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",12],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",4500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AUTHORITY["EPSG","31468"]]
Origin = (4468259.984000000171363,5333761.273000000044703)
Pixel Size = (0.200000000000000,-0.200000000000000)
Metadata:
AREA_OR_POINT=Area
TIFFTAG_COPYRIGHT=*************************
TIFFTAG_DATETIME=07.05.2018 00:00:00
TIFFTAG_RESOLUTIONUNIT=3 (pixels/cm)
TIFFTAG_SOFTWARE=*************************
TIFFTAG_XRESOLUTION=250
TIFFTAG_YRESOLUTION=250
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 4468259.984, 5333761.273) ( 11d34'24.42"E, 48d 8'31.22"N)
Lower Left ( 4468259.984, 5331209.273) ( 11d34'25.11"E, 48d 7' 8.59"N)
Upper Right ( 4471544.984, 5333761.273) ( 11d37' 3.35"E, 48d 8'31.78"N)
Lower Right ( 4471544.984, 5331209.273) ( 11d37' 3.96"E, 48d 7' 9.15"N)
Center ( 4469902.484, 5332485.273) ( 11d35'44.21"E, 48d 7'50.19"N)
Band 1 Block=16425x8 Type=Byte, ColorInterp=Red
Overviews: 8213x6380, 4107x3190, 2054x1595, 1027x798, 514x399, 257x200
Band 2 Block=16425x8 Type=Byte, ColorInterp=Green
Overviews: 8213x6380, 4107x3190, 2054x1595, 1027x798, 514x399, 257x200
Band 3 Block=16425x8 Type=Byte, ColorInterp=Blue
Overviews: 8213x6380, 4107x3190, 2054x1595, 1027x798, 514x399, 257x200
According to the code in warp.py the operation is limited to a image size of 100000x100000 cells.
"""$ rio warp"""
...
Improper usage of rio-warp can lead to accidental creation of
extremely large datasets. We'll put a hard limit on the size of
datasets and raise a usage error if the limits are exceeded.
MAX_OUTPUT_WIDTH = 100000
MAX_OUTPUT_HEIGHT = 100000
So the source dimension 16425x12760 should not be an issue. When I install the environment on Ubuntu 18.04 - 64 bit with
pip3 install rasterio
pip3 install rio_tiler
,download the DOP_20 image and call my the example code
#!/usr/bin/env python3
from rio_tiler.io import COGReader
import rio_tiler
FILE='DOP_20/4468260_5331209.tif'
with COGReader(FILE) as image:
print(image)
I get no error during the image open step.
COGReader(\
bounds=(11.572063386087754, 48.11813315397459, \
11.61637335456606, 48.14123922531762), \
filepath='DOP_20/4468260_5331209.tif', \
dataset=<open DatasetReader \
name='DOP_20/4468260_5331209.tif' \
mode='r'>, \
tms=<TileMatrixSet \
title='Google Maps Compatible for the World' \
identifier='WebMercatorQuad'>, \
minzoom=13, \
maxzoom=19, \
colormap={}, \
nodata=None, \
unscale=None, \
resampling_method=None, \
vrt_options=None, \
post_process=None, \
_kwargs={})
IMO you try to transform the image, with some code not explained in your question. Can you provide this code and the parameter set for the warp call.
Review
I assume you have copied the image DOP_20/4468260_5331209.tif else where and renamed it. The image has some more metadata in the directory DOP_20:
4468260_5331209.tfw
4468260_5331209.tif
4468260_5331209.tif.ovr
4468260_5331209.txt
4468260_5331209.wld
I've read the data from the original DOP_20 directory and got no error, while your copy make some trouble with the rastreio. To make the Geotif portable and self contained with the overview images, you could use the commands gdal_translate and gdaladdo:
gdal_translate -co BIGTIF=YES \
-co COMPRESS=LZW \
-co SPARSE_OK=TRUE \
-co TILED=yes \
-co BLOCKXSIZE=1024 \
-co BLOCKYSIZE=1024 \
4468260_5331209.tif \
4468260_5331209.blocks.tif
gdaladdo -r lanczos 4468260_5331209.blocks.tif 2 4 8 16 32 64
When I read your script right, then you try to split the image into 256x256 tiles driven by your text file. The script triggers for all entries exceptions the exception TileOutsideBounds.
~/Source/IfGDV-GSE/Test-Tile/tiling$ ./script.py
278707
181023
EXCEPT: TileOutsideBounds
...
Here is your adopted script:
#!/usr/bin/env python3
from rio_tiler.io import COGReader
import os
import rio_tiler
import pandas as pd
import time
from PIL import Image
Preparation -------------------------------------
PRJ_DIR=$HOME/Source/IfGDV-GSE/Test-Tile
mv tiling-20211210T084355Z-001.zip $PRJ_DIR
unzip $PRJ_DIR/tiling-20211210T084355Z-001.zip
cd $PRJ_DIR/tiling
mkdir result
gdal_translate -co BIGTIF=YES -co COMPRESS=LZW -co SPARSE_OK=TRUE -co TILED=yes -co BLOCKXSIZE=1024 -co BLOCKYSIZE=1024 munich_20cm.tif munich_20cm.blocks.tif
gdaladdo -r lanczos munich_20cm.blocks.tif 2 4 8 16 32 64
mv script.txt script.py
dos2unix script.py
chmod 755 script.py
emacs -nw script.py
--------------------------------------------------
add shebang #!/usr/bin/env python3
add some variables
HOME = os.environ.get('HOME')
WORK_DIR = HOME+'/Source/IfGDV-GSE/Test-Tile/tiling/'
DST_PATH = WORK_DIR+'result/'
SRC_LIST = WORK_DIR+'new_munich.txt'
SRC_IMAGE = WORK_DIR+'munich_20cm.tif'
SRC_IMAGE = WORK_DIR+'munich_20cm.blocks.tif'
SRC_FILE = open(SRC_LIST, 'r')
SRC_POINTS = SRC_FILE.readlines()
image = COGReader(SRC_IMAGE)
number = len(SRC_POINTS)
for coordinates in SRC_POINTS:
x = int(coordinates.split(',')[0])
y = int(coordinates.split(',')[1])
print(x)
print(y)
z = 19
number -= 1
try:
filename = DST_PATH + str(x) +'/' + str(y) + '.png'
print(filename)
img = image.tile(x, y, z, tilesize=256)
buff = img.render()
# check for existence of the direction
x_direction = os.path.join(DST_PATH, str(x))
if os.path.exists(x_direction) == False:
os.mkdir(x_direction)
with open(os.path.join(x_direction, str(y) + '.png'), "wb") as f:
f.write(buff)
#os.remove(filename)
except rio_tiler.errors.TileOutsideBounds:
print("EXCEPT: TileOutsideBounds")
rasterioand andrio_tilerviapip3on Ubuntu 18.04, and changed as mentioned above the file name becausemunich_1.tifwas not in theDOP_20directory. Where does yourmunich_1.tifcomes from? Is it the same files aDOP_20/4468260_5331209.tifor is it a larger file not in providedDOP_20remote directory? – huckfinn Dec 09 '21 at 08:37gdalinfo munich_1.tif. – huckfinn Dec 09 '21 at 11:21