[R-sig-eco] Export Google Maps Route to R and get kilometers coordinates

Baldwin, Jim -FS jbaldwin at fs.fed.us
Wed Sep 19 14:17:26 CEST 2012


Because that road has a few bends, you'll need to get more points (just lat and long not necessarily KM) on that road just as you've done at the plaques.  That would give you a set of connected nodes (as suggested below by David Valentim Dias) that would better approximate the road.

Those (lat,long) pairs would be converted to UTM coordinates (which are in units of kilometers - using the PBSmapping package) from which you could calculate distance between each of those nodes.  The UTM's for each unit kilometer could then be linearly interpolated along those connected line segments.  Then you could convert back to (lat,long) for plotting.

Jim Baldwin
USDA Forest Service

-----Original Message-----
From: r-sig-ecology-bounces at r-project.org [mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of David Valentim Dias
Sent: Monday, September 17, 2012 8:30 PM
To: r-sig-ecology at r-project.org
Subject: Re: [R-sig-eco] Export Google Maps Route to R and get kilometers coordinates

Hi Ribas,

You can try using package rgdal for directly loading but I recommend opening in another GIS software (like Quantum GIS free like R) and exporting in .shp. You can create a node in each KM plate so you can loop in R getting lat and long from each node.

2012/9/17 Augusto Ribas <ribas.aca at gmail.com>

> Hello. I have the following problem.
> I have some data of fauna hit on a road in Brasil. The Road ES-060.
>
> The data is something like this:
>
> > head(dados)
>   species km
> 1    Sp 6 27
> 2    Sp 6 21
> 3    Sp 1 44
> 4    Sp 2 47
> 5    Sp 5 39
> 6    Sp 5 20
>
> Each line represent one dead individual, and has a register of it
> species and the kilometer of the road where it was found dead.
> I would like to do a plot of the deaths on a map, but i don't have the
> coordinates (latitude and longitude) of where km 27 is, for example.
> But looking in google maps, i was able to find the road, and i know
> some points of where the road is and its respective kilometer.
> Like this:
>
> > dados.pos
>         Lon       Lat            Local
> 1 -40.32012 -20.39675 Begin
> 2 -40.32477 -20.40193 KM 12
> 3 -40.39341 -20.54320 KM 30
> 4 -40.51056 -20.63095 KM 49
> 5 -40.55583 -20.73349 KM 66
> 6 -40.55161 -20.73921   End
>
> So Begin is around kilometer 11, end is around kilometer 67 (the range
> of the data), and using google street view, i could see plaques on the
> road telling me which kilometer some places is, so i can get some
> coordinates and which kilometer it represent.
>
> So if i could import a route from google maps as a polygon, from end
> to begin, i could try to determinate the coordinate of each kilometer.
> But i could not figure out how to export from google maps to R such
> information.
> These points i saved on google maps as an kml file and loaded on R,
> using getKMLcoordinates {maptools} function. But i'm stuck on how to
> proceed to the the coordinates of each kilometer of the road.
> Does anyone have some idea how would i be able to do something like
> this, if it is possible?
>
> Here goes some example data and a plot of the road and the points i
> show
> above:
>
> library(RgoogleMaps)
>
> #example of how data is organized
> species<-paste("Sp",1:6)
> km<-seq(11,67,by=1)
>
> dados<-data.frame(species=NA,km=NA)
> for(i in 1:20) {
>   dados[i,1]<-sample(species,1)
>   dados[i,2]<-sample(km,1)
>   }
>
> head(dados)
>
> #some points coordinates that i know
> dados.pos<-structure(list(Lon = c(-40.3201206572012,
> -40.3247698942156, -40.3934139596311, -40.5105609306218,
> -40.5558289282114, -40.551610815962), Lat = c(-20.3967530595136,
> -20.4019278830141, -20.5432001637965, -20.6309481844606,
> -20.733489883797, -20.7392078853725), Local = c("Begin", "KM 12", "KM
> 30", "KM 49", "KM 66", "End")), .Names = c("Lon", "Lat", "Local"),
> row.names = c(NA, -6L), class = "data.frame")
>
> dados.pos
>
> #one plot of the road and the know points lat = dados.pos[c(1,6),2]
> lon = dados.pos[c(1,6),1] center = c(lat=mean(lat), lon=mean(lon))
> zoom <- min(MaxZoom(range(lat), range(lon)))
>
> MyMap <- GetMap(center=center,zoom=zoom,maptype ="roadmap")
>
> PlotOnStaticMap(MyMap)
> TextOnStaticMap(MyMap,dados.pos[,2],dados.pos[,1],labels =
> dados.pos[,3])
>
> Thanks for your attention.
> Best Wishes - Augusto Ribas
>
>
>
>
> --
> Grato
> Augusto C. A. Ribas
>
> Site Pessoal: http://augustoribas.heliohost.org
> Lattes: http://lattes.cnpq.br/7355685961127056
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



--
Currículo: http://lattes.cnpq.br/7541377569511492

        [[alternative HTML version deleted]]





This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.



More information about the R-sig-ecology mailing list