Created
December 14, 2012 21:33
-
-
Save alexstorer/4288832 to your computer and use it in GitHub Desktop.
Download images from the streetview API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # An R Script to do some scraping | |
| getSearchString <- function(loc,heading,pitch) { | |
| s <- paste('http://maps.googleapis.com/maps/api/streetview?size=640x640', | |
| paste('location=',loc,sep=''), | |
| paste('heading=',heading,sep=''), | |
| paste('pitch=',pitch,sep=''), | |
| 'sensor=false', | |
| sep = '&') | |
| s <- gsub(' ','%20',s) | |
| } | |
| getAllLocations <- function(lat1,lon1,lat2,lon2,N) { | |
| latseq <- seq(lat1,lat2,length.out=N) | |
| lonseq <- seq(lon1,lon2,length.out=N) | |
| df <- data.frame(lat=latseq,lon=lonseq) | |
| } | |
| getSearchStringLatLon <- function(lat,lon,heading,pitch) { | |
| s <- paste('http://maps.googleapis.com/maps/api/streetview?size=640x640', | |
| paste('location=',lat,' ',lon,sep=''), | |
| paste('heading=',heading,sep=''), | |
| paste('pitch=',pitch,sep=''), | |
| 'sensor=false', | |
| sep = '&') | |
| s <- gsub(' ','%20',s) | |
| } | |
| downloadAllLatLon <- function(lat1,lon1,lat2,lon2,N,basestr) { | |
| df <- getAllLocations(lat1,lon1,lat2,lon2,N) | |
| pitch <- 10 | |
| all_headings <- seq(-90,90,30) | |
| for (i in seq(N)){ | |
| for (heading in seq(length(all_headings))) { | |
| s <- getSearchStringLatLon(df$lat[i],df$lon[i],all_headings[heading],pitch) | |
| download.file(s,paste(basestr, | |
| sprintf('%03d',i), | |
| sprintf('%03d',heading), | |
| '.jpg', | |
| sep='_')) | |
| } | |
| } | |
| } | |
| # test download all | |
| lat1 <- 41.876862 | |
| lon1 <- -87.632736 | |
| lat2 <- 41.876879 | |
| lon2 <- -87.631515 | |
| downloadAllLatLon(lat1,lon1,lat2,lon2,3,'chicagotest') | |
| # do a test | |
| for (i in seq(0,360,10)) { | |
| s <- getSearchString('1737 Cambridge St., Cambridge MA',i,10) | |
| fname <- paste('foo',sprintf('%03d',i),'.jpg',sep='') | |
| download.file(s,fname) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment