google_streetview¶
A command line tool and module for Google Street View Image API.
google_streetview -h
google_streetview --location=46.414382,10.013988
google_streetview --pano=vPnURflnc8AZu5NMLYRddw
Setup¶
- A Google API developer key is required to use this package
- A Gmail account will also be required to create and access the developer key
- When asked to sign in, use your Gmail account for access
- Please note that usage of the Google Street View API may require a billing plan
Note: Instructions and links were written on March 5, 2019, and are subject to change depending on Google’s website and API.
Google API¶
An API developer key for the Google Application Programming Interface (API) can be setup with the following instructions:
- Enable Google Street View Image API
- Go to Google API Console Credentials
- Click Create Credentials -> API Key
- Set
key
by replacing “your_dev_key” with the API Key
google_streetview -s key="your_dev_key"
Usage¶
For help in the console, use:
google_streetview -h
Please ensure that the Setup section was completed:
google_streetview -s key="your_dev_key"
Image Search¶
Get street view image using the location argument --location
and providing <latitude>,<longitude>
values:
google_streetview --location=46.414382,10.013988
Get street view image using the panorama id argument --pano
:
google_streetview --pano=vPnURflnc8AZu5NMLYRddw
Multiple locations and panorama ids can be given by separating with ;
:
google_streetview --location=46.414382,10.013988;40.720032,-73.988354
google_streetview --pano=vPnURflnc8AZu5NMLYRddw;A1v2IdX_6HKnIQa2SPyyAg
Adjust size of the images up to 640 by 640 pixels with the --size
argument and providing <width>x<height>
values (the default is 640x640
):
google_streetview --location=46.414382,10.013988;40.720032,-73.988354 --size=200x200
Adjust the heading of the camera with the --heading
argument, where 0 and 360 are north, 90 is east, 180 is south, and 270 is west:
google_streetview --location=46.414382,10.013988 --heading=0
google_streetview --location=46.414382,10.013988 --heading=90
google_streetview --location=46.414382,10.013988 --heading=180
google_streetview --location=46.414382,10.013988 --heading=270
google_streetview --location=46.414382,10.013988 --heading=360
Adjust the image’s horizontal field of view with the --fov
argument, which represents zoom values of up to 120 (the default is 90
):
google_streetview --location=46.414382,10.013988 --fov=0
google_streetview --location=46.414382,10.013988 --fov=90
google_streetview --location=46.414382,10.013988 --fov=120
Adjust the camera’s up and down angle with the --pitch
argument, where positive values up to 90 degrees indicate straight up and negative values down to -90 indicate straight down (the default is 0
:
google_streetview --location=46.414382,10.013988 --pitch=0
google_streetview --location=46.414382,10.013988 --pitch=90
google_streetview --location=46.414382,10.013988 --pitch=-90
Save Results¶
Download street view images to “downloads” folder with the --save_downloads
argument:
google_streetview --location=46.414382,10.013988;40.720032,-73.988354 --save_downloads=downloads
Save metadata:
google_streetview --location=46.414382,10.013988 --save_metadata=metadata.json
google_streetview --pano=vPnURflnc8AZu5NMLYRddw --save_metadata=metadata.json
Save URL links:
google_streetview --location=46.414382,10.013988 --save_links=links.txt
google_streetview --pano=vPnURflnc8AZu5NMLYRdd --save_links=links.txt
Save links and metadata:
google_streetview --location=46.414382,10.013988 --save_links=links.txt --save_metadata=metadata.json
google_streetview --pano=vPnURflnc8AZu5NMLYRdd --save_links=links.txt --save_metadata=metadata.json
Multiple Arguments¶
Multiple arguments can be specified by separating parameter values with the semi-colon ;
seen in the heading
parameter:
google_streetview --location=46.414382,10.013988 --heading=0;90;180;270
Download the 360 panorama imagery for 2 locations using a field of vision fov
of 90, which provides 8 images (90 degree from fov
up to 270 degrees as 0 and 360 refer to the same heading
):
google_streetview --location=46.414382,10.013988;40.720032,-73.988354 --fov=90 --heading=0;90;180;270
Default Arguments¶
Default arguments persist even after the console is closed. Defaults enable user customization of the google_streetview command without a long list of arguments every call.
View the defaults:
google_streetview -v
Increase number of results previewed to 20
:
google_streetview -s option_preview=20
Turn off preview of results:
google_streetview -s option_silent=True
Set the fov
argument to default to 45
:
google_streetview -s fov=45
Set the heading
argument to default to 0
images:
google_streetview -s heading=0
Set to save a text file named links.txt
with result links whenever used:
google_streetview -s save_links=links.txt
Remove default arguments:
search_result -r option_preview
google_streetview -r option_silent
google_streetview -r fov
google_streetview -r heading
google_streetview -r save_links
Reset the defaults:
google_streetview -d
After resetting defaults, the developer key will have to be set again:
google_streetview -s key="your_dev_key"
Additional Arguments¶
A number of optional arguments defined using --
are not shown when using google_streetview -h
. These can be used with the same names as the paramters passed to Google’s Street View Image API:
google_streetview -a
For example, the digital signature for billing can be set by argument signature
which is a named paramter in the API:
google_streetview cat --signature="your_signature"
Module Import¶
The google_streetview package may also be used as a Python module:
# Import google_streetview for the api module
import google_streetview.api
# Define parameters for street view api
params = [{
'size': '600x300', # max 640x640 pixels
'location': '46.414382,10.013988',
'heading': '151.78',
'pitch': '-0.76',
'key': 'your_dev_key'
}]
# Create a results object
results = google_streetview.api.results(params)
# Download images to directory 'downloads'
results.download_links('downloads')
For more details on module usage, see the examples in api for single argument queries and helpers.api_list for multiple argument queries.
Modules¶
api¶
-
class
api.
results
(params, site_api='https://maps.googleapis.com/maps/api/streetview', site_metadata='https://maps.googleapis.com/maps/api/streetview/metadata')[source]¶ Google Street View Image API results.
Uses the Google Street View Image API to search for street level imagery.
- Args:
- params (listof dict):
- List of dict containing batch street view URL parameters.
- site_api(str):
- The site for the URL request (example: https://maps.googleapis.com/maps/api/streetview).
- site_metadata(str):
- The site for the URL metadata request (example: https://maps.googleapis.com/maps/api/streetview/metadata).
- Attributes:
- params (listof dict):
- Same as argument
params
for reference of inputs. - links (listof str):
- List of str containing street view URL requests.
- metadata (listof dict):
- Objects returned from street view metadata request.
- metadata_links (listof str):
- List of str containing street view URL metadata requests.
- Examples:
# Import google_streetview for the api module import google_streetview.api # Define parameters for street view api params = [{ 'size': '600x300', # max 640x640 pixels 'location': '46.414382,10.013988', 'heading': '151.78', 'pitch': '-0.76', 'key': 'your_dev_key' }] # Create a results object results = google_streetview.api.results(params) # Preview results results.preview() # Download images to directory 'downloads' results.download_links('downloads') # Save links results.save_links('links.txt') # Save metadata results.save_metadata('metadata.json')
-
download_links
(dir_path, metadata_file='metadata.json', metadata_status='status', status_ok='OK')[source]¶ Download Google Street View images from parameter queries if they are available.
- Args:
- dir_path (str):
- Path of directory to save downloads of images from
api.results
.links - metadata_file (str):
- Name of the file with extension to save the
api.results
.metadata - metadata_status (str):
- Key name of the status value from
api.results
.metadata response from the metadata API request. - status_ok (str):
- Value from the metadata API response status indicating that an image is available.
-
preview
(n=10, k=['date', 'location', 'pano_id', 'status'], kheader='pano_id')[source]¶ Print a preview of the request results.
- Args:
- n (int):
- Maximum number of requests to preview
- k (str):
- Keys in
api.results
.metadata to preview - kheader (str):
- Key in
api.results
.metadata[k
] to use as the header
-
save_links
(file_path)[source]¶ Saves a text file of the search result links.
Saves a text file of the search result links, where each link is saved in a new line. An example is provided below:
https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988&heading=151.78&pitch=-0.76&key=yourdevkey https://maps.googleapis.com/maps/api/streetview?size=600x300&location=41.403609,2.174448&heading=100&pitch=28&scale=2&key=yourdevkey
- Args:
- file_path (str):
- Path to the text file to save links to.
-
save_metadata
(file_path)[source]¶ Save Google Street View metadata from parameter queries.
- Args:
- file_path (str):
- Path of the file with extension to save the
api.results
.metadata
cli¶
-
cli.
run
(argv=['D:\\windows\\Users\\rrwen\\Anaconda3\\Scripts\\sphinx-build', '-b', 'html', 'docs/source', 'docs'])[source]¶ Runs the google_streetview command line tool.
This function runs the google_streetview command line tool in a terminal. It was intended for use inside a py file (.py) to be executed using python.
- Notes:
- Optional arguments with
ref_
are for thesite
andsite_metadata
parameters inapi.results
For distribution, this function must be defined in the following files:
# In 'google_streetview/google_streetview/__main__.py' from .cli import run run() # In 'google_streetview/google_streetview.py' from google_streetview.cli import run if __name__ == '__main__': run() # In 'google_streetview/__init__.py' __entry_points__ = {'console_scripts': ['google_streetview=google_streetview.cli:run']}
- Optional arguments with
Examples:
# Import google_streetview for the cli module import google_streetview.cli # Create command line arguments argv = [ 'cli.py', 'google', '--searchType=image', '--build_developerKey=your_dev_key', '--cx=your_cx_id' '--num=1' ] # Run command line google_streetview.cli.run(argv)
helpers¶
-
helpers.
api_list
(apiargs)[source]¶ Google Street View Image API results.
Constructs a list of Google Street View Image API queries from a dictionary.
- Args:
- apiargs (listof dict):
- Dict containing street view URL parameters.
Each parameter can have multiple values if separated by
;
.
- Returns:
- A
listof dict
containing single query requests per dictionary for Google Street View Image API. - Examples:
# Import google_streetview for the api and helper module import google_streetview.api import google_streetview.helpers # Create a dictionary with multiple parameters separated by ; apiargs = { 'location': '46.414382,10.013988;40.720032,-73.988354', 'size': '640x300;640x640', 'heading': '0;90;180;270', 'fov': '0;90;120', 'pitch': '-90;0;90' } # Get a list of all possible queries from multiple parameters api_list = google_streetview.helpers.api_list(apiargs) # Create a results object for all possible queries results = google_streetview.api.results(api_list) # Preview results results.preview() # Download images to directory 'downloads' results.download_links('downloads') # Save metadata results.save_metadata('metadata.json')