def down_square(zl,x,y,pms,ams,cnt=8): start = time.time() print "Downloading square ({0},{1}) {2}x{2} images".format(x,y,cnt) skip=0 missing=0 for yi in range(y,y+cnt): for xi in range(x,x+cnt): if not os.path.isfile(FILEIMGTMP.format(zl,x,y,xi,yi)): max_try = 3 ret = -1 while (ret != 0): ret = pms.down_tile(zl,xi,yi, FILEIMGTMP.format(zl,x,y,xi,yi)) if ret == 1: print "Waiting 3s for re-download" max_try -= 1 time.sleep(3) if ret == 2: if ams is not None: while (ret != 0): ret = ams.down_tile(zl,xi,yi, FILEIMGTMP.format(zl,x,y,xi,yi)) if ret == 1: print "Waiting 3s for re-download (alternative source)" max_try -= 1 time.sleep(3) if ret == 2 or ret == 3 or max_try == 0: print "Download failed - exiting" sys.exit(1) missing+=1 else: lat, tmp, lng, tmp = mercator.get_tile_box(zl,xi,yi) print "Missing tile ("+str(xi)+","+str(yi)+" - GPS: "+str(lat)+" "+str(lng)+"). Download failed - exiting" sys.exit(1) if ret == 3 or max_try == 0: print "Download failed - exiting" sys.exit(1) else: skip+=1 if missing: print "- missing",missing,"of",cnt*cnt,"(downloaded from alternative source)" if skip: print "- skipped",skip,"of",cnt*cnt,"(already downloaded)" else: print "Downloading took", time.time()-start, "s"
FILEIMG=OUTTEX+"/"+FILEBASE+".png" FILEPOL=OUTPOL+"/"+FILEBASE+".pol" print "--- Mercators" xy1=mercator.get_lat_lng_tile(Lat1,Lng1,Zl) print 'x1=',xy1[0],'y1=',xy1[1] xyr1=((int(xy1[0])/8)*8, (int(xy1[1])/8)*8) print 'xr1=',xyr1[0],'yr1=',xyr1[1] xy2=mercator.get_lat_lng_tile(Lat2,Lng2,Zl) print 'x2=',xy2[0],'y2=',xy2[1] xyr2=((int(xy2[0])/8)*8, (int(xy2[1])/8)*8) print 'xr2=',xyr2[0],'yr2=',xyr2[1] print "--- Min/Max Lat/Lng" latlng1=mercator.get_tile_box(Zl,xyr1[0],xyr1[1]) latlng2=mercator.get_tile_box(Zl,xyr2[0],xyr2[1]) print latlng1 print latlng2 print "--- Processing" if not os.path.isdir(OUTPUT):os.mkdir(OUTPUT) if not os.path.isdir(OUTTEX):os.mkdir(OUTTEX) if not os.path.isdir(OUTTMP):os.mkdir(OUTTMP) if args.wed_import: if not os.path.isdir(OUTDSF):os.mkdir(OUTDSF) if not os.path.isdir(OUTPOL):os.mkdir(OUTPOL) fman = ForkManager(args.dds_maxcpu)