I would like to connect google satellite map with borders in shp, in order to crop everything outside the city. I have shp file of Wroclaw city borders and code that downloads the satellite map from google maps. The middle of the map is known (lat = 51.1078852, lon = 17.0385376
), so maybe it is possible to somehow connect the two?
I found numerous ways to do that using other software like:
- Best way to overlay an ESRI shapefile on google maps?
- https://towardsdatascience.com/walkthrough-mapping-gis-data-in-python-92c77cd2b87a
But not Python. Here is a code that downloads Wroclaw satellite map (after chenging the API key):
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)