Beispiel #1
0
def do_work_item(planner, coord, descr):
    print "do work item", coord
    zoomlevel, mx1, my1, mx2, my2 = coord
    assert mx1 % tilepixelsize == 0
    assert mx2 % tilepixelsize == 0
    assert my1 % tilepixelsize == 0
    assert my2 % tilepixelsize == 0

    metax1 = descr['metax1']
    metax2 = descr['metax2']
    metay1 = descr['metay1']
    metay2 = descr['metay2']
    render_tma = descr['render_tma']
    maxy = mapper.max_merc_y(zoomlevel)
    maxx = mapper.max_merc_x(zoomlevel)

    im = generate_big_tile(
        (mx2 - mx1 + metax1 + metax2, my2 - my1 + metay1 + metay2),
        mx1 - metax1,
        my1 - metay1,
        zoomlevel,
        osmdraw=render_tma,
        tma=render_tma)
    cadir = planner.get_cachedir()
    subwork = []
    for j in xrange(0, 2048, tilepixelsize):
        for i in xrange(0, 2048, tilepixelsize):

            if mx1 + i + tilepixelsize > maxx:
                continue
            if my1 + j + tilepixelsize > maxy:
                continue

            #dirpath=get_dirpath(cadir,zoomlevel,mx1+i,my1+j)
            #if not os.path.exists(dirpath):
            #    try:
            #        os.makedirs(dirpath)
            #    except Exception:
            #        pass #probably raise, dir now exists

            #p=get_path(cadir,zoomlevel,mx1+i,my1+j)

            view = im.crop(
                (metax1 + i, metay1 + j, metax1 + i + 256, metay1 + j + 256))
            io = StringIO.StringIO()
            view.save(io, 'png')
            io.seek(0)
            data = io.read()
            subwork.append((zoomlevel, mx1 + i, my1 + j, data))
    planner.finish_work(coord, subwork)
Beispiel #2
0
def do_work_item(planner,coord,descr):
    print "do work item",coord
    zoomlevel,mx1,my1,mx2,my2=coord
    assert mx1%tilepixelsize==0
    assert mx2%tilepixelsize==0
    assert my1%tilepixelsize==0
    assert my2%tilepixelsize==0
    
    metax1=descr['metax1']
    metax2=descr['metax2']
    metay1=descr['metay1']
    metay2=descr['metay2']
    render_tma=descr['render_tma']
    maxy=mapper.max_merc_y(zoomlevel)
    maxx=mapper.max_merc_x(zoomlevel)
    
    im=generate_big_tile((mx2-mx1+metax1+metax2,my2-my1+metay1+metay2),mx1-metax1,my1-metay1,zoomlevel,osmdraw=render_tma,tma=render_tma)
    cadir=planner.get_cachedir()            
    subwork=[]
    for j in xrange(0,2048,tilepixelsize):
        for i in xrange(0,2048,tilepixelsize):
            
            if mx1+i+tilepixelsize>maxx:
                continue
            if my1+j+tilepixelsize>maxy:
                continue
                
            #dirpath=get_dirpath(cadir,zoomlevel,mx1+i,my1+j)
            #if not os.path.exists(dirpath):
            #    try:
            #        os.makedirs(dirpath)
            #    except Exception:
            #        pass #probably raise, dir now exists
            
            #p=get_path(cadir,zoomlevel,mx1+i,my1+j)

            view = im.crop((metax1+i,metay1+j,metax1+i+256,metay1+j+256))
            io=StringIO.StringIO()
            view.save(io,'png')
            io.seek(0)
            data=io.read()
            subwork.append((zoomlevel,mx1+i,my1+j,data))
    planner.finish_work(coord,subwork)
Beispiel #3
0
def generate_work_packages(tma,
                           blobs,
                           cachedir,
                           maxzoomlevel=13,
                           meta=0,
                           cutoff=8):
    meta = meta  #Change back to if using mapnik
    #if meta==0:
    #    print "\n\n\n\n\n=====================================================================\nWARNING! meta==0!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"
    packcnt = 0
    for zoomlevel in xrange(maxzoomlevel + 1):
        if zoomlevel <= cutoff:
            lat1, lon1, lat2, lon2 = latlon_limits_hd()
        else:
            lat1, lon1, lat2, lon2 = latlon_limits()

        lat1 = float(lat1)
        lat2 = float(lat2)
        lon1 = float(lon1)
        lon2 = float(lon2)

        maxy = mapper.max_merc_y(zoomlevel)
        maxx = mapper.max_merc_x(zoomlevel)
        hd = False
        if zoomlevel <= cutoff:
            hd = True
        limitx1, limity1, limitx2, limity2 = merc_limits(zoomlevel, hd=hd)
        assert limitx2 > limitx1
        assert limity2 > limity1
        print "Limits: %f,%f - %f,%f" % (limitx1, limity1, limitx2, limity2)
        blobs[zoomlevel] = BlobFile(
            os.path.join(cachedir, "level" + str(zoomlevel)), zoomlevel,
            limitx1, limity1, limitx2, limity2, 'w')

        for my1 in xrange(limity1, limity2, 2048):

            for mx1 in xrange(limitx1, limitx2, 2048):
                already = True
                for i in xrange(0, 2048, 256):
                    for j in xrange(0, 2048, 256):
                        if blobs[zoomlevel].get_tile(mx1 + i, my1 + j) == None:
                            already = False
                            break
                if already:
                    print "Already have %d,%d,%d" % (mx1, my1, zoomlevel)
                    continue
                print "Creating new tile %d,%d,%d (tma=%s)" % (mx1, my1,
                                                               zoomlevel, tma)

                mx2 = mx1 + 2048
                my2 = my1 + 2048
                if my2 > maxy:
                    my2 = maxy
                if mx2 > maxx:
                    mx2 = maxx
                if my1 >= meta:
                    metay1 = meta
                else:
                    metay1 = 0
                if mx1 >= meta:
                    metax1 = meta
                else:
                    metax1 = 0
                if my2 <= maxy - meta:
                    metay2 = meta
                else:
                    metay2 = 0
                if mx2 <= maxx - meta:
                    metax2 = meta
                else:
                    metax2 = 0

                latb, lona = mapper.merc2latlon((mx1, my1), zoomlevel)
                lata, lonb = mapper.merc2latlon((mx2, my2), zoomlevel)
                if latb < lat1: continue
                if lata > lat2: continue
                if lonb < lon1: continue
                if lona > lon2: continue

                coord = (zoomlevel, mx1, my1, mx2, my2)

                packcnt += 1
                yield (coord,
                       dict(checkedout=None,
                            metax1=metax1,
                            metay1=metay1,
                            metax2=metax2,
                            metay2=metay2,
                            render_tma=tma))
    print "Finished initializing work. Created %d work items. Cutoff=%d" % (
        packcnt, cutoff)
Beispiel #4
0
def generate_work_packages(tma,blobs,cachedir,maxzoomlevel=13,meta=0,cutoff=8):
    meta=meta #Change back to if using mapnik
    #if meta==0:
    #    print "\n\n\n\n\n=====================================================================\nWARNING! meta==0!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"
    packcnt=0
    for zoomlevel in xrange(maxzoomlevel+1):
        if zoomlevel<=cutoff:
            lat1,lon1,lat2,lon2=latlon_limits_hd()
        else:
            lat1,lon1,lat2,lon2=latlon_limits()
        
        lat1=float(lat1)
        lat2=float(lat2)
        lon1=float(lon1)
        lon2=float(lon2)
        
        maxy=mapper.max_merc_y(zoomlevel)
        maxx=mapper.max_merc_x(zoomlevel)
        hd=False
        if zoomlevel<=cutoff:
            hd=True
        limitx1,limity1,limitx2,limity2=merc_limits(zoomlevel,hd=hd)
        assert limitx2>limitx1
        assert limity2>limity1
        print "Limits: %f,%f - %f,%f"%(limitx1,limity1,limitx2,limity2)
        blobs[zoomlevel]=BlobFile(os.path.join(cachedir,"level"+str(zoomlevel)),zoomlevel,
            limitx1,limity1,limitx2,limity2,'w')
            
        for my1 in xrange(limity1,limity2,2048):

            for mx1 in xrange(limitx1,limitx2,2048):
                already=True
                for i in xrange(0,2048,256):
                    for j in xrange(0,2048,256):
                        if blobs[zoomlevel].get_tile(mx1+i,my1+j)==None:
                            already=False
                            break
                if already:
                    print "Already have %d,%d,%d"%(mx1,my1,zoomlevel)
                    continue
                print "Creating new tile %d,%d,%d (tma=%s)"%(mx1,my1,zoomlevel,tma)
                                
                mx2=mx1+2048
                my2=my1+2048
                if my2>maxy:
                    my2=maxy
                if mx2>maxx:
                    mx2=maxx
                if my1>=meta:
                    metay1=meta
                else:
                    metay1=0
                if mx1>=meta:
                    metax1=meta
                else:
                    metax1=0
                if my2<=maxy-meta:
                    metay2=meta
                else:
                    metay2=0
                if mx2<=maxx-meta:
                    metax2=meta
                else:
                    metax2=0
                    
                latb,lona=mapper.merc2latlon((mx1,my1),zoomlevel)
                lata,lonb=mapper.merc2latlon((mx2,my2),zoomlevel)
                if latb<lat1: continue
                if lata>lat2: continue
                if lonb<lon1: continue                
                if lona>lon2: continue                                
                    
                coord=(zoomlevel,mx1,my1,mx2,my2)

                packcnt+=1
                yield (coord,dict(
                           checkedout=None,
                           metax1=metax1,
                           metay1=metay1,
                           metax2=metax2,
                           metay2=metay2,
                           render_tma=tma
                           ))
    print "Finished initializing work. Created %d work items. Cutoff=%d"%(packcnt,cutoff)