Robinlovelace / Creating-maps-in-R

Introductory tutorial on graphical display of geographical information in R.
https://cran.r-project.org/other-docs.html
568 stars 341 forks source link

creating map with gps data ... #53

Closed jud-mog closed 6 years ago

jud-mog commented 6 years ago

is it possible to create maps in R based only on gps data (longitude and latitude) and one or two variables of interest ? when doing this tutorial, I wonder how can I generate all the extension files used like for the file "london_sport". I am just starting to use "creating maps function" in R. Thanks !

Robinlovelace commented 6 years ago

It certainly is. I would suggest switching to using sf if you're new to spatial data as it has some advantages over the sp package taught in this tutorial. Check this out as a starting point sf objects http://geocompr.robinlovelace.net/spatial-class.html and this on reading-in data (mentions gpx): http://geocompr.robinlovelace.net/read-write.html

Reproducible example showing how to load and create maps with gpx data from OSM:

library(sf)                                                                         
#> Linking to GEOS 3.5.1, GDAL 2.2.2, proj.4 4.9.2
download.file("https://www.openstreetmap.org/trace/1619756/data", "Sheff2leeds.gpx")
st_layers("Sheff2leeds.gpx")                                                        
#> Driver: GPX 
#> Available layers:
#>     layer_name     geometry_type features fields
#> 1    waypoints             Point        0     23
#> 2       routes       Line String        0     12
#> 3       tracks Multi Line String        1     12
#> 4 route_points             Point        0     25
#> 5 track_points             Point     6085     26
route = st_read("Sheff2leeds.gpx", layer = "tracks")                                
#> Reading layer `tracks' from data source `/tmp/Rtmpb4EGb8/Sheff2leeds.gpx' using driver `GPX'
#> Simple feature collection with 1 feature and 12 fields
#> geometry type:  MULTILINESTRING
#> dimension:      XY
#> bbox:           xmin: -1.50362 ymin: 53.40529 xmax: -1.411626 ymax: 53.65617
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
plot(route)                                                                         
#> Warning: plotting the first 9 out of 12 attributes; use max.plot = 12 to
#> plot all


# also try:                                                                         
library(tmap)                                                                       
qtm(route)                                                                          

ttm()                                                                               
#> tmap mode set to interactive viewing
qtm(route)                                                                          

mapview::mapview(route)                                                             
Session info ``` r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.5.1 (2018-07-02) #> system x86_64, linux-gnu #> ui X11 #> language en_GB:en #> collate en_GB.UTF-8 #> tz Europe/London #> date 2018-07-13 #> Packages ----------------------------------------------------------------- #> package * version date source #> backports 1.1.2 2017-12-13 CRAN (R 3.5.0) #> base * 3.5.1 2018-07-03 local #> base64enc 0.1-3 2015-07-28 CRAN (R 3.5.0) #> class 7.3-14 2015-08-30 cran (@7.3-14) #> classInt 0.2-3 2018-04-16 cran (@0.2-3) #> codetools 0.2-15 2016-10-05 CRAN (R 3.5.0) #> colorspace 1.3-2 2016-12-14 CRAN (R 3.5.0) #> compiler 3.5.1 2018-07-03 local #> crosstalk 1.0.0 2016-12-21 cran (@1.0.0) #> curl 3.2 2018-03-28 CRAN (R 3.5.0) #> datasets * 3.5.1 2018-07-03 local #> DBI 1.0.0 2018-05-02 CRAN (R 3.5.0) #> devtools 1.13.5 2018-02-18 CRAN (R 3.5.0) #> dichromat 2.0-0 2013-01-24 CRAN (R 3.1.1) #> digest 0.6.15 2018-01-28 CRAN (R 3.5.0) #> e1071 1.6-8 2017-02-02 cran (@1.6-8) #> evaluate 0.10.1 2017-06-24 cran (@0.10.1) #> foreach 1.4.4 2017-12-12 cran (@1.4.4) #> gdalUtils 2.0.1.14 2018-04-23 cran (@2.0.1.1) #> graphics * 3.5.1 2018-07-03 local #> grDevices * 3.5.1 2018-07-03 local #> grid 3.5.1 2018-07-03 local #> htmltools 0.3.6.9001 2018-06-17 Github (rstudio/htmltools@3aee819) #> htmlwidgets 1.2 2018-04-19 cran (@1.2) #> httpuv 1.4.3 2018-05-10 CRAN (R 3.5.0) #> httr 1.3.1 2017-08-20 cran (@1.3.1) #> iterators 1.0.9 2017-12-12 cran (@1.0.9) #> jsonlite 1.5 2017-06-01 CRAN (R 3.5.0) #> KernSmooth 2.23-15 2015-06-29 cran (@2.23-15) #> knitr 1.20 2018-02-20 CRAN (R 3.5.0) #> later 0.7.3 2018-06-08 CRAN (R 3.5.0) #> lattice 0.20-35 2017-03-25 CRAN (R 3.5.0) #> leaflet 2.0.1 2018-06-04 cran (@2.0.1) #> lwgeom 0.1-4 2018-01-28 CRAN (R 3.5.0) #> magrittr 1.5 2014-11-22 CRAN (R 3.5.0) #> mapview 2.4.0 2018-04-28 cran (@2.4.0) #> memoise 1.1.0 2017-04-21 CRAN (R 3.5.0) #> methods * 3.5.1 2018-07-03 local #> mime 0.5 2016-07-07 CRAN (R 3.5.0) #> munsell 0.5.0 2018-06-12 CRAN (R 3.5.0) #> plyr 1.8.4 2016-06-08 CRAN (R 3.5.0) #> png 0.1-7 2013-12-03 cran (@0.1-7) #> promises 1.0.1 2018-04-13 CRAN (R 3.5.0) #> R.methodsS3 1.7.1 2016-02-16 cran (@1.7.1) #> R.oo 1.22.0 2018-04-22 cran (@1.22.0) #> R.utils 2.6.0 2017-11-05 cran (@2.6.0) #> R6 2.2.2 2017-06-17 cran (@2.2.2) #> raster 2.6-7 2017-11-13 cran (@2.6-7) #> RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.5.0) #> Rcpp 0.12.17 2018-05-18 cran (@0.12.17) #> rgdal 1.3-3 2018-06-22 cran (@1.3-3) #> rgeos 0.3-28 2018-06-08 cran (@0.3-28) #> rmarkdown 1.10 2018-06-11 cran (@1.10) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.5.0) #> satellite 1.0.1 2017-10-18 cran (@1.0.1) #> scales 0.5.0 2017-08-24 CRAN (R 3.5.0) #> sf * 0.6-3 2018-05-17 cran (@0.6-3) #> shiny 1.1.0 2018-05-17 CRAN (R 3.5.0) #> sp 1.3-1 2018-06-05 CRAN (R 3.5.0) #> spData 0.2.9.1 2018-06-22 Github (nowosad/spData@26b5fd5) #> spDataLarge 0.2.7.0 2018-06-13 Github (nowosad/spDataLarge@9ae9dcb) #> stats * 3.5.1 2018-07-03 local #> stats4 3.5.1 2018-07-03 local #> stringi 1.2.3 2018-06-12 cran (@1.2.3) #> stringr 1.3.1 2018-05-10 cran (@1.3.1) #> tmap * 2.0 2018-07-03 Github (mtennekes/tmap@7c52292) #> tmaptools 2.0 2018-07-03 Github (mtennekes/tmaptools@38bfb35) #> tools 3.5.1 2018-07-03 local #> units 0.6-0 2018-06-09 cran (@0.6-0) #> utils * 3.5.1 2018-07-03 local #> viridisLite 0.3.0 2018-02-01 CRAN (R 3.5.0) #> webshot 0.5.0 2017-11-29 CRAN (R 3.5.0) #> withr 2.1.2 2018-03-15 CRAN (R 3.5.0) #> XML 3.98-1.11 2018-06-11 cran (@3.98-1.) #> xml2 1.2.0 2018-01-24 CRAN (R 3.5.0) #> xtable 1.8-2 2016-02-05 CRAN (R 3.5.0) #> yaml 2.1.19 2018-05-01 CRAN (R 3.5.0) ```