Download Street View Images¶
zensvi.download: A module to download street view images
This tutorial demostrates how to use ZenSVI to download street view image from Mapillary, KartaView, and Amsterdam.
Mapillary¶
You can use zensvi to download Mapillary street view images in four different ways:
by latitude and longitude of a location
by a csv file with latitude and longitude of several locations
by a shapefile covering the area for downloading, points(e.g. several locations), polyline(e.g. road networks), or polygon(e.g. area boundary) are supported.
by a place name that works on OpenStreetMap
Preparation¶
# If zen-svi is not installed
%pip install --upgrade zensvi
import zensvi
print(zensvi.__version__)
# Prepare downloading module
from zensvi.download import MLYDownloader
import os
# Input Mapillary API key
mly_api_key = "Your_Mapillary_API_key" # Please register your own Mapillary API key ("Client Token") at https://www.mapillary.com/dashboard/developers,
downloader = MLYDownloader(mly_api_key=mly_api_key)
# Output directory(folder) to save the SVI images
output_folder = "./download_SVI_images"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
To download SVI images, you can use one of the following methods:¶
Latitude and longitude of a location
# Input latitude and longitude of a location
lat=1.290270
lon=103.851959
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, lat=lat, lon=lon, buffer=buffer)
Getting pids...
Loading cache files: 0it [00:00, ?it/s]
[Vector Tiles API] Fetching 1 tile for images ...
Processing tiles: 100%|██████████| 1/1 [00:04<00:00, 4.69s/it]
Filtering data: 100%|██████████| 53610/53610 [00:00<00:00, 662375.58it/s]
The panorama IDs have been saved to download_SVI_images/mly_pids.csv
The cache directory for tiles has been deleted
Getting urls for batch #1: 100%|██████████| 10/10 [00:01<00:00, 9.78it/s]
Getting urls by batch size 10: 100%|██████████| 1/1 [00:01<00:00, 1.04s/it]
Downloading images for batch #1: 100%|██████████| 10/10 [00:01<00:00, 9.69it/s]
Downloading images by batch size 10: 100%|██████████| 1/1 [00:01<00:00, 1.05s/it]
The cache directory has been deleted
CSV file with latitude and longitude of several locations
# Input path to CSV file /home/yihan/IPYNB_Yihan/ZenSVI/CSV_ZenSVI_test.csv
input_csv_file="path/to/csv_file.csv"
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, input_csv_file=input_csv_file, buffer=buffer)
Shapefile containing the location information, points, polyline, or polygon are supported
# Input path to shapefile
input_shp_file="path_to_shp_file"
# Setting downloading buffer size in meters around the input location
buffer = 1
# Start downloading
downloader.download_svi(output_folder, input_shp_file=input_shp_file, buffer=buffer)
Place Name that works on OpenStreetMap
# Input the Place Name, for example "NUS, Singapore"
input_place_name="Chinatown, Singapore"
# Setting downloading buffer size in meters around the input location
buffer = 0
# Start downloading
downloader.download_svi(output_folder, input_place_name=input_place_name)
KartaView¶
For downloading images from KartaView, utilize the KartaViewDownloader, similar to Mapillary, you can download KartaView Street Views in four ways:
by latitude and longitude of a location
by a csv file with latitude and longitude of several locations
by a shapefile covering the area for downloading, points(e.g. several locations), polyline(e.g. road networks), or polygon(e.g. area boundary) are supported.
by a place name that works on OpenStreetMap
Preparation¶
# If zen-svi is not installed
%pip install --upgrade zensvi
import zensvi
print(zensvi.__version__)
# Prepare downloading module, KartaView dataset does not require API key
from zensvi.download import KVDownloader
import os
# Output directory(folder) to save the SVI images
output_folder = "./download_SVI_images"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
downloader = KVDownloader(
log_path="path_to_the_log_file.log", # path to the log file
)
Latitude and longitude of a location
# Input latitude and longitude of a location
lat=1.296339198344591
lon=103.77095139306607
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, lat=lat, lon=lon, buffer=buffer)
CSV file with latitude and longitude of several locations
# Input path to CSV file /home/yihan/IPYNB_Yihan/ZenSVI/CSV_ZenSVI_test.csv
input_csv_file="path/to/csv_file.csv"
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, input_csv_file=input_csv_file, buffer=buffer)
Shapefile containing the location information, points, polyline, or polygon are supported
# Input path to shapefile
input_shp_file="path_to_shp_file"
# Setting downloading buffer size in meters around the input location
buffer = 1
# Start downloading
downloader.download_svi(output_folder, input_shp_file=input_shp_file, buffer=buffer)
Place Name that works on OpenStreetMap
# Input the Place Name, for example "NUS, Singapore"
input_place_name="Chinatown, Singapore"
# Setting downloading buffer size in meters around the input location
buffer = 0
# Start downloading
downloader.download_svi(output_folder, input_place_name=input_place_name)
Amsterdam¶
For downloading images from Amsterdam, utilize the AMSDownloader:, similar to Mapillary, you can download KartaView Street Views in four ways:
by latitude and longitude of a location
by a csv file with latitude and longitude of several locations
by a shapefile covering the area for downloading, points(e.g. several locations), polyline(e.g. road networks), or polygon(e.g. area boundary) are supported.
by a place name that works on OpenStreetMap
Preparation¶
# If zen-svi is not installed
%pip install --upgrade zensvi
import zensvi
print(zensvi.__version__)
# Prepare downloading module, Amsterdam dataset does not require API key
from zensvi.download import AMSDownloader
import os
# Output directory(folder) to save the SVI images
output_folder = "./download_SVI_images"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
downloader = AMSDownloader()
Latitude and longitude of a location
# Input latitude and longitude of a location
lat=52.366554089348334
lon=4.894944584367074
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, lat=lat, lon=lon, buffer=buffer)
Getting pids: 100%|██████████| 1/1 [00:00<00:00, 1.22it/s]
Downloading images and metadata: 100%|██████████| 25/25 [00:05<00:00, 4.46it/s]
Metadata saved to download_SVI_images/ams_pids.csv
CSV file with latitude and longitude of several locations
# Input path to CSV file /home/yihan/IPYNB_Yihan/ZenSVI/CSV_ZenSVI_test.csv
input_csv_file="path/to/csv_file.csv"
# Setting downloading buffer size in meters around the input location, buffer cannot be 0
buffer = 10
# Start downloading
downloader.download_svi(output_folder, input_csv_file=input_csv_file, buffer=buffer)
Shapefile containing the location information, points, polyline, or polygon are supported
# Input path to shapefile
input_shp_file="path_to_shp_file"
# Setting downloading buffer size in meters around the input location
buffer = 1
# Start downloading
downloader.download_svi(output_folder, input_shp_file=input_shp_file, buffer=buffer)
Place Name that works on OpenStreetMap
# Input the Place Name, for example "Amsterdam" or "Grand Hotel, Amsterdam, Netherlands"
input_place_name="Amsterdam"
# Setting downloading buffer size in meters around the input location
buffer = 10
# Start downloading
downloader.download_svi(output_folder, input_place_name=input_place_name)