【发布时间】:2020-07-28 02:28:29
【问题描述】:
我想将谷歌卫星地图与 shp 中的边界连接起来,以便裁剪城外的所有内容。我有Wroclaw city borders 的shp 文件和从谷歌地图下载卫星地图的代码。地图的中间是已知的 (lat = 51.1078852, lon = 17.0385376),所以也许有可能以某种方式将两者联系起来?
我发现了许多使用其他软件的方法,例如:
- Best way to overlay an ESRI shapefile on google maps?
- https://towardsdatascience.com/walkthrough-mapping-gis-data-in-python-92c77cd2b87a
但不是 Python。 这是下载弗罗茨瓦夫卫星地图的代码(在 chenging API 密钥之后):
import requests
import shutil
#API
with open('apikey.txt') as f:
apikey = f.readline()
f.close
lat = 51.1078852
lon = 17.0385376
zoom = 14
size_tile_x, size_tile_y = 1024, 1024
scale = 2
format_image='png'
maptype='satellite'
style=''
url_s = f"https://maps.googleapis.com/maps/api/staticmap?key={apikey}&scale={scale}¢er={lat},{lon}&zoom={zoom}&format={format_image}&maptype={maptype}{style}&size={size_tile_x}x{size_tile_y}"
r = requests.get(url_s, stream=True, headers={'User-agent': 'Mozilla/5.0'})
name = 'Map.png'
if r.status_code == 200:
with open(name, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
【问题讨论】:
标签: python google-maps shapefile