{"id":356,"date":"2013-04-15T04:40:37","date_gmt":"2013-04-15T04:40:37","guid":{"rendered":"http:\/\/blog.fellstat.com\/?p=356"},"modified":"2013-04-15T04:40:37","modified_gmt":"2013-04-15T04:40:37","slug":"the-openstreetmap-package-opens-up","status":"publish","type":"post","link":"https:\/\/blog.fellstat.com\/?p=356","title":{"rendered":"The OpenStreetMap Package Opens Up"},"content":{"rendered":"<p>A new version of the <a href=\"http:\/\/cran.r-project.org\/web\/packages\/OpenStreetMap\/index.html\">OpenStreetMap package<\/a> is now up on CRAN, and should\u00a0propagate\u00a0to all the mirrors in the next few days. The primary purpose of the package is to provide high resolution map\/satellite imagery for use in your R plots. The package supports base graphics and ggplot2, as well as transformations between spatial coordinate systems.<\/p>\n<p>The bigest change in the new version is the addition of dozens of tile servers, giving the user the option of many different map looks, including those from Bing, MapQuest and Apple.<\/p>\n<pre>nm = c(\"osm\", \"maptoolkit-topo\",\n\"waze\", \"mapquest\", \"mapquest-aerial\",\n\"bing\", \"stamen-toner\", \"stamen-terrain\",\n\"stamen-watercolor\", \"osm-german\", \"osm-wanderreitkarte\",\n\"mapbox\", \"esri\", \"esri-topo\",\n\"nps\", \"apple-iphoto\", \"skobbler\",\n \"opencyclemap\", \"osm-transport\",\n\"osm-public-transport\", \"osm-bbike\", \"osm-bbike-german\")\n\npng(width=1200,height=2200)\npar(mfrow=c(6,4))\nfor(i in 1:length(nm)){\n\tprint(nm[i])\n\tmap = openmap(c(lat= 38.05025395161289,   lon= -123.03314208984375),\n\t\t\tc(lat= 36.36822190085111,   lon= -120.69580078125),\n\t\t\tminNumTiles=9,type=nm[i])\n\tplot(map)\n\ttitle(nm[i],cex.main=4)\n}\ndev.off()<\/pre>\n<p><a href=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/Rplot001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-357\" title=\"Maps supported by OpenStreetMap\" src=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/Rplot001-558x1024.png\" alt=\"\" width=\"550\" height=\"1009\" \/><\/a>You can also render maps from <a href=\"http:\/\/www.cloudmade.com\">cloudmade.com<\/a> which hosts tons of map tilings. Simply set the &#8220;type&#8221; parameter to &#8220;cloudmade-&lt;id&gt;&#8221; where &lt;id&gt; is the cloudmade identifier for the map you want to use. Here is a sample:<\/p>\n<pre>nm = c(\"cloudmade-2\",\"cloudmade-999\",\"cloudmade-998\",\n\"cloudmade-7\",\"cloudmade-1960\",\"cloudmade-1155\",\n\"cloudmade-12284\")\n#setCloudMadeKey(\"&lt;your key&gt;\")\npng(\"RPlot002.png\",width=1300,height=800)\npar(mfrow=c(2,4))\nfor(i in 1:length(nm)){\n\tprint(nm[i])\n\tmap = openmap(c(lat= 38.05025395161289,   lon= -123.03314208984375),\n\t\t\tc(lat= 36.36822190085111,   lon= -120.69580078125),\n\t\t\tminNumTiles=9,type=nm[i])\n\tplot(map)\n\ttitle(nm[i],cex.main=4)\n}\ndev.off()<\/pre>\n<p><a href=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/RPlot002.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-358\" title=\"Cloudmade maps\" src=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/RPlot002-1024x630.png\" alt=\"\" width=\"550\" height=\"338\" \/><\/a>Maps are initially put in a sperical mercator projection which is the standard for most (all?) map tiling systems, but can easily be translated to long-lat (or any other projection) using the openproj function. Maps can be plotted in ggplot2 using the autoplot function.<\/p>\n<pre>mapLatLon = openproj(map)\nautoplot(mapLatLon)<\/pre>\n<p><a href=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/tmp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-359\" title=\"ggplot2 plot in long-lat coordinates\" src=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/tmp-300x224.png\" alt=\"\" width=\"300\" height=\"224\" \/><\/a>The package also has a Java GUI to help with map type selection, and specification of coordinates to bound your map. clicking on the map will give you the latitude and longitude of the point clicked.<\/p>\n<pre>launchMapHelper()<\/pre>\n<p><a href=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/JGRScreenSnapz032.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-362\" title=\"JMapViewer Demo\" src=\"http:\/\/blog.fellstat.com\/wp-content\/uploads\/2013\/04\/JGRScreenSnapz032-300x267.png\" alt=\"\" width=\"300\" height=\"267\" \/><\/a><\/p>\n<p>Probably the main alternative to OpenStreetMap is the ggmap package. ggmap is an\u00a0excellent\u00a0package, and it is somewhat unfortunate that there is a significant duplication of effort between it and OpenStreetMap. That said, there are some differences that may help you decide which to use:<\/p>\n<p>Reasons to favor OpenStreetMap:<\/p>\n<ul>\n<li><strong>More maps:<\/strong> OpenStreetMap supports more map types.<\/li>\n<li><strong>Better image resolution:<\/strong> ggmap only fetches one png from the server, and thus is limited to the\u00a0resolution\u00a0of that png, whereas OpenStreetMap can download many map tiles and stich them together to get an arbitrarily high image resolution.<\/li>\n<li><strong>Transformations:<\/strong> OpenStreetMap can be used with any map coordinate system, whereas ggmap is limited to long-lat.<\/li>\n<li><strong>Base graphics:<\/strong>\u00a0Both packages support ggplot2, but OpenStreetMap also supports base graphics.<\/li>\n<\/ul>\n<div>Reasons to favor ggmap:<\/div>\n<div>\n<ul>\n<li><strong>No Java\u00a0dependency:<\/strong> ggmap does not require Java to be installed.<\/li>\n<li><strong>Geocoding:<\/strong> ggmap has functions to do reverse geo coding.<\/li>\n<li><strong>Google maps:<\/strong> While OpenStreetMap has more map types, it currently does not support google maps.<\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A new version of the OpenStreetMap package is now up on CRAN, and should\u00a0propagate\u00a0to all the mirrors in the next few days. The primary purpose of the package is to provide high resolution map\/satellite imagery for use in your R plots. The package supports base graphics and ggplot2, as well as transformations between spatial coordinate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6,9],"tags":[],"class_list":["post-356","post","type-post","status-publish","format-standard","hentry","category-openstreetmap","category-r","category-spatial"],"_links":{"self":[{"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":0,"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fellstat.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}