def get_tiles_by_pixel(tilePixel): """ 下载该点之上的瓦片 :param lat: :param lon: :return: """ """get pixel coordinates""" # tilePixel = quadkey.TileSystem.geo_to_pixel((lat, lon), tileZoom) # print(tilePixel) pixel = tilePixel geo = quadkey.TileSystem.pixel_to_geo(pixel, tileZoom) # 计算四键 qk = quadkey.from_geo(geo, tileZoom) # 四键 qkStr = str(qk) # qkArray = [] for index in range(tileZoom): qkArray.append(qkStr[0:index + 1]) print(qkArray) # 存放路径 for qk in qkArray: # db位置 dbPath = "%s/%s.db" % (bingTilesDir, int(qk) % 199 ) print(dbPath) if (os.path.exists(dbPath) == False): # os.mkdir(dbPath) dbutil.create_db(dbPath) # 下载影像 if (dbutil.is_exists(dbPath, qk)): # already downloaded dbutil.save_images(dbPath, qk) ok = 1 else: print("下载中", end='') url = tileUrlTemplate.replace("{subdomain}", imageDomains[0]) url = url.replace("{quadkey}", qk) url = "%s&key=%s" % (url, secrets.bingKey) response = requests.get(url, stream=True) print(response) dbutil.insert(dbPath, qk, response.content) del response
def get_tiles(lat, lon): """ 下载该点之上的瓦片 :param lat: :param lon: :return: """ """get pixel coordinates""" tilePixel = quadkey.TileSystem.geo_to_pixel((lat, lon), tileZoom) print(tilePixel) pixel = tilePixel geo = quadkey.TileSystem.pixel_to_geo(pixel, tileZoom) # 计算四键 qk = quadkey.from_geo(geo, tileZoom) # 四键 qkStr = str(qk) # qkArray = [] for index in range(tileZoom): qkArray.append(qkStr[0:index + 1]) print(qkArray) # 存放路径 for qk in qkArray: # 下载影像 tileFileName = "%s/%s.jpg" % (bingTilesDir, qk) if (os.path.exists(tileFileName)): # already downloaded ok = 1 else: print("下载中", end='') url = tileUrlTemplate.replace("{subdomain}", imageDomains[0]) url = url.replace("{quadkey}", qk) url = "%s&key=%s" % (url, secrets.bingKey) response = requests.get(url, stream=True) print(response) with open(tileFileName, 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response # 应该添加一个随机暂停 neededTile = True
tilePixel = quadkey.TileSystem.geo_to_pixel(qkRoot.to_geo(), qkRoot.level) tileRootDir = os.path.split(root)[0] # stick the adjacent tiles together to make larger images up to max # image size. maxImageSize = 256 * 3 maxTileCount = maxImageSize // 256 count = 0 image = np.zeros([maxImageSize, maxImageSize, 3], dtype=np.uint8) for x in range(maxTileCount): for y in range(maxTileCount): pixel = (tilePixel[0] + 256 * x, tilePixel[1] + 256 * y) geo = quadkey.TileSystem.pixel_to_geo(pixel, qkRoot.level) qk = quadkey.from_geo(geo, qkRoot.level) qkStr = str(qk) tileCacheDir = os.path.join(tileRootDir, qkStr[-3:]) tileFileName = "%s/%s.jpg" % (tileCacheDir, qkStr) if (os.path.exists(tileFileName)): try: image[y * 256:(y + 1) * 256, x * 256:(x + 1) * 256, 0:3] = io.imread(tileFileName) count += 1 except: # try to get the tile again next time. os.remove(tileFileName)
print("%s " % (fullPath), end='') neededTile = False for row in csveader: print(row[0]) print(row[1]) tilePixel = quadkey.TileSystem.geo_to_pixel( (float(row[0]), float(row[1])), cfg.tileZoom) for x in range(-2, 3): for y in range(-2, 3): pixel = (tilePixel[0] + 256 * x, tilePixel[1] + 256 * y) geo = quadkey.TileSystem.pixel_to_geo( pixel, cfg.tileZoom) qk = quadkey.from_geo(geo, cfg.tileZoom) qkStr = str(qk) tileCacheDir = os.path.join(bingTilesDir, qkStr[-3:]) if (os.path.exists(tileCacheDir) == False): os.mkdir(tileCacheDir) tileFileName = "%s/%s.jpg" % (tileCacheDir, qkStr) if (os.path.exists(tileFileName)): # already downloaded ok = 1 else: print("T", end='')
bingTilesDir = os.path.join(rootTileDir, "bing") if (os.path.exists(bingTilesDir) == False): os.mkdir(bingTilesDir) """get pixel coordinates""" tilePixel = quadkey.TileSystem.geo_to_pixel((lat, lon), tileZoom) print(tilePixel) input('go on') pixel = tilePixel geo = quadkey.TileSystem.pixel_to_geo(pixel, tileZoom) # 计算四键 qk = quadkey.from_geo(geo, tileZoom) # 四键 qkStr = str(qk) input('go on ') # qkArray = [] for index in range(tileZoom): qkArray.append(qkStr[0:index + 1]) print(qkArray) # 存放文件夹路径 tileCacheDirArray = [] # 创建所需的文件夹