2025-01-02 22:07:10 -06:00
#!/usr/bin/env nix-shell
2025-01-02 22:34:29 -06:00
#!nix-shell --quiet -p python312 -p python312Packages.pillow -i python
2025-01-02 22:07:10 -06:00
# https://svc.pictometry.com/Image/D2B06344-7A2D-5BD0-FC89-DFDDC9888C41/wmts?SERVICE=WMTS&REQUEST=GetCapabilities
import os
import urllib . request
2025-01-02 22:34:29 -06:00
from PIL import Image
2025-01-02 23:14:29 -06:00
from concurrent . futures import ThreadPoolExecutor
2025-01-02 22:07:10 -06:00
MAX_ZOOM = 20
2025-01-02 23:14:29 -06:00
def download_all ( ) :
current , total = 0 , ( 4 * * ( MAX_ZOOM - 11 ) - 1 ) / / 3
with ThreadPoolExecutor ( ) as executor :
for z in range ( 12 , MAX_ZOOM + 1 ) :
scale = 2 * * ( z - 12 )
start_x = 985 * scale
start_y = 1432 * scale
for x in range ( start_x , start_x + scale ) :
for y in range ( start_y , start_y + scale ) :
executor . submit ( download_image , z , x , y , total , current )
current + = 1
2025-01-02 22:07:10 -06:00
2025-01-02 23:14:29 -06:00
def download_image ( z , x , y , total , current ) :
progress = f " [ { current : 0 { len ( str ( total ) ) } d } / { total } ] "
2025-01-02 23:23:45 -06:00
url = f " https://svc.pictometry.com/Image/D2B06344-7A2D-5BD0-FC89-DFDDC9888C41/wmts/PICT-MNITAS23-EDVs7UTOVt/default/GoogleMapsCompatible/ { z } / { x } / { y } .jpg "
file = os . path . normpath ( os . path . join ( os . path . dirname ( __file__ ) , f " ../satellite/ { z } / { x } / { y } .jpg " ) )
2025-01-02 23:14:29 -06:00
os . makedirs ( os . path . dirname ( file ) , exist_ok = True )
if os . path . isfile ( file ) :
try : # does it already exist and look good?
Image . open ( file ) . verify ( ) # CRC check on PNGs; nothing on other file types? https://pillow.readthedocs.io/en/latest/_modules/PIL/PngImagePlugin.html#ChunkStream.verify
print ( f " { progress } { file } already exists; skipping " )
return
except OSError as e :
print ( f " { progress } replacing corrupt { file } " )
else :
print ( f " { progress } downloading { file } " )
urllib . request . urlretrieve ( url , file )
download_all ( )