[Talk-cz] batch wms download tiles

Tomas Kolda kolda na web2net.cz
Pondělí Září 22 21:12:46 UTC 2008


Tady je skript se kterym jsem downloadnul UHUL lesy. 

T 


Jachym Cepicky writes: 

> http://tilecache.org by nepomohlo? 
> 
> j 
> 
> 2008/9/22 hanoj <ehanoj na gmail.com>:
>> Ahoj
>> nemate nekdo napsany skript (treba bash, python, perl) pro stahovani
>> vetsich oblasti pomoci WMS? Napr ten co byl u UHUL lesu. 
>>
>> diky 
>>
>> hanoj 
>>
>> _______________________________________________
>> Talk-cz mailing list
>> Talk-cz na openstreetmap.org
>> http://lists.openstreetmap.org/listinfo/talk-cz 
>>
>  
> 
> 
> -- 
> Jachym Cepicky
> e-mail: jachym.cepicky gmail com
> URL: http://les-ejk.cz
> GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub 
> 
> _______________________________________________
> Talk-cz mailing list
> Talk-cz na openstreetmap.org
> http://lists.openstreetmap.org/listinfo/talk-cz
 

------------- další část ---------------
import urllib, os.path

from PIL import Image



crRect = (12, 51.1, 19, 48.5)



def getMapSize():

    return (1 + int((crRect[2] - crRect[0]) / 0.1),

            1 + int((crRect[1] - crRect[3]) / 0.1))



def tile2wgs(x, y):

    return (crRect[0] + x * 0.1, crRect[1] - y * 0.1,

            crRect[0] + (x + 1) * 0.1, crRect[1] - (y + 1) * 0.1)



def getFilename(x, y):

    return os.path.join("cache", "%03dx%03d.png" % (x, y))



def cacheImage(x, y):

    filename = getFilename(x, y)

    if os.path.isfile(filename):

        return

    rect = tile2wgs(x, y)

    print "Downloading ", x, y

    url = "http://geoportal2.uhul.cz/cgi-bin/oprl.asp?SERVICE=WMS&VERSION=1.1.1&" + \

          "REQUEST=GetMap&SRS=EPSG:4326&LAYERS=Les_OPRL&STYLES=default&FORMAT=image/png&" + \

          "TRANSPARENT=TRUE&BBOX=%.1f,%.1f,%.1f,%.1f&WIDTH=2000&HEIGHT=2000" % \

          (rect[0], rect[3], rect[2], rect[1])

    data = urllib.urlopen(url).read()

    f = open(filename, "wb")

    f.write(data)

    f.close()



def main():

    (w, h) = getMapSize()

    for x in range(w):

        for y in range(8, h):

            cacheImage(x, y)



if __name__ == '__main__':

    main()



Další informace o konferenci talk-cz