Helper functions for sampling points on a road network and downloading associated Google Streetview images.
I am providing code in this repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not from my employer (Facebook).
mkdir streetviewSampler
cd streetviewSampler
virtualenv -p python2.7 env
source env/bin/activate
git clone https://github.com/robolyst/streetview.git env/lib/python2.7/site-packages/streetview
pip install requests pillow
PYTHONPATH
environment variable to pick up virtualenv packages:export PYTHONPATH=env/lib/python2.7/site-packages
mkdir -p env/lib/R/site-library
export R_LIBS=env/lib/R/site-library
devtools::install_github("rstudio/reticulate")
reticulate::py_eval('sys.path.insert(0, "env/lib/python2.7/site-packages")')
streetview <- reticulate::import("streetview")
devtools::install_github('bogdanstate/streetview-sampler')
library('rgdal')
system("wget http://www.dot.ca.gov/hq/tsip/gis/datalibrary/zip/highway/ScenicHwys2014.zip")
system("unzip ScenicHwys2014.zip -d ScenicHwys2014")
sldf <- readOGR('ScenicHwys2014', 'ScenicHwys2014')
library('streetviewSampler')
panoids <- sample_panoids(sldf, mc.cores=4, type='random', n=1)
head(panoids)
The result is a table containing information about: - the sampled lat/lons from the street network. - the resolved lat/lons from the Google Streetview metadata API endpoint. - the panoids (which you can use to download Streetview images with an R package like googleway, or using robolyst/streetview. - whatever other data was contained in the SpatialLinesDataFrame object you provided.
To see where the sampled points are located, type the following into your R console (after having executed the previous commands):
system("wget http://www.dot.ca.gov/hq/tsip/gis/datalibrary/zip/highway/shn2016v2_Segments.zip")
system("unzip shn2016v2_Segments.zip -d shn2016v2_Segments")
roads <- readOGR('shn2016v2_Segments', 'shn2016v2_Segments')
plot(roads, col='gray')
plot(sldf, add=T, col='black')
sp <- SpatialPointsDataFrame(panoids[,.(lon, lat)], panoids)
plot(sp, add=T, col='red')
The visualization should look something like this:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.