google-map-downloader
google-map-downloader copied to clipboard
错误的网络连接
关于谷歌地图源,可以给出一些链接吗? 我有一个坐标,19级的tile下载不下来。换了地图源还是不行 非常感谢
class Downloader(Thread): # multiple threads downloader def init(self, index, count, urls, datas, update): # index represents the number of threads downloading # count represents the total number of threads # urls represents the list of URLs nedd to be downloaded # datas represents the list of data need to be returned. super().init() self.urls = urls self.datas = datas self.index = index self.count = count self.update = update
def download(self, url):
agents = [
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.68',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36']
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.68'}
err = 0
# 当下载不了时,返回0
while err < 4:
try:
HEADERS.setdefault('User-Agent', agents[err])
header = ur.Request(url, headers=HEADERS)
data = ur.urlopen(header).read()
except:
err += 1
else:
return data
# raise Exception("Bad network link.")
return 0
def run(self):
for i, url in enumerate(self.urls):
if i % self.count != self.index:
continue
# 当i==index时,才跳过continue继续往下运行
if self.download(url) != 0:
self.datas[i] = self.download(url)
if mutex.acquire():
self.update()
mutex.release()
else:
self.datas[i] = 0
def main(left, top, right, bottom, zoom, name, wrongpath, filePath, style='s', server="Google China"): """ Download images based on spatial extent.
East longitude is positive and west longitude is negative.
North latitude is positive, south latitude is negative.
Parameters
----------
left, top : left-top coordinate, for example (100.361,38.866)
right, bottom : right-bottom coordinate
zoom:缩放等级
name:经纬度的txt文件绝对路径
wrongpath:存放下载不了的label的文件夹
filePath : File path for storing results, TIFF format
style :
m for map;
s for satellite;
y for satellite with label;
t for terrain;
p for terrain with label;
h for label;
source : Google China (default) or Google
"""
# ---------------------------------------------------------
# Get the urls of all tiles in the extent
urls = get_urls(left, top, right, bottom, zoom, server, style)
# Download tiles
datas = download_tiles(urls)
# 决定要不要整合数据
decision = 1
for index in range(len(datas)):
# 只有当列表中存在0时,才改变decision的值
if datas[index] == 0:
decision = 0
if decision == 1:
# Combine downloaded tile maps into one map
outpic = merge_tiles(datas, left, top, right, bottom, zoom)
outpic = outpic.convert('RGB')
r, g, b = cv2.split(np.array(outpic))
# Get the spatial information of the four corners of the merged map and use it for outputting
extent = getExtent(left, top, right, bottom, zoom, server)
gt = (extent['LT'][0], (extent['RB'][0] - extent['LT'][0]) / r.shape[1], 0, extent['LT'][1], 0,
(extent['RB'][1] - extent['LT'][1]) / r.shape[0])
saveTiff(r, g, b, gt, filePath)
else:
shutil.copy(name, wrongpath)