Git Product home page Git Product logo

osmplotr's Introduction

R build status codecov Project Status: Active

CRAN Downloads CRAN_Status_Badge

R package to produce visually impressive customisable images of OpenStreetMap (OSM) data downloaded internally from the overpass api. The above map was produced directly from osmplotr with no further modification. This README briefly demonstrates the following functionality:

1. Quick Introduction

2. Installation

3. A Simple Map

4. Highlighting Selected Areas

5. Highlighting Clusters

6. Highlighting Areas Bounded by Named Highways

7. Data Surfaces

8. Gallery


1. Quick Introduction

But first the easy steps to map making:

  1. Specify the bounding box for the desired region

    bbox <- get_bbox (c (-0.15, 51.5, -0.10, 51.52))
  2. Download the desired dataβ€”in this case, all building perimeters.

    dat_B <- extract_osm_objects (key = "building", bbox = bbox)
  3. Initiate an osm_basemap with desired background (bg) colour

    map <- osm_basemap (bbox = bbox, bg = "gray20")
  4. Overlay objects on plot in the desired colour.

    map <- add_osm_objects (map, dat_B, col = "gray40")
  5. Print the map to graphics device of choice

    print_osm_map (map)

2. Installation

First install the package

install.packages ("osmplotr")

or the development version

devtools::install_github ("ropensci/osmplotr")

And then load it in the usual way

library (osmplotr)

3. A Simple Map

Simple maps can be made by overlaying different kinds of OSM data in different colours:

dat_H <- extract_osm_objects (key = "highway", bbox = bbox)
dat_P <- extract_osm_objects (key = "park", bbox = bbox)
dat_G <- extract_osm_objects (key = "landuse", value = "grass", bbox = bbox)
map <- osm_basemap (bbox = bbox, bg = "gray20")
map <- add_osm_objects (map, dat_B, col = "gray40")
map <- add_osm_objects (map, dat_H, col = "gray80")
map <- add_osm_objects (map, dat_P, col = "darkseagreen")
map <- add_osm_objects (map, dat_G, col = "darkseagreen1")
print_osm_map (map)


4. Highlighting Selected Areas

osmplotr is primarily intended as a data visualisation tool, particularly through enabling selected regions to be highlighted. Regions can be defined according to simple point boundaries:

pts <- sp::SpatialPoints (cbind (
    c (-0.115, -0.13, -0.13, -0.115),
    c (51.505, 51.505, 51.515, 51.515)
))

OSM objects within the defined regions can then be highlighted with different colour schemes. cols defines colours for each group (with only one here), while bg defines the colour of the remaining, background area.

map <- osm_basemap (bbox = bbox, bg = "gray20")
map <- add_osm_groups (map, dat_B, groups = pts, cols = "orange", bg = "gray40")
map <- add_osm_objects (map, london$dat_P, col = "darkseagreen1")
map <- add_osm_groups (
    map,
    london$dat_P,
    groups = pts,
    cols = "darkseagreen1",
    bg = "darkseagreen",
    boundary = 0
)
print_osm_map (map)

Note the border = 0 argument on the last call divides the park polygons precisely along the border. The same map highlighted in dark-on-light:

map <- osm_basemap (bbox = bbox, bg = "gray95")
map <- add_osm_groups (map, dat_B, groups = pts, cols = "gray40", bg = "gray85")
map <- add_osm_groups (map, dat_H, groups = pts, cols = "gray20", bg = "gray70")
print_osm_map (map)


5. Highlighting Clusters

add_osm_groups also enables plotting an entire region as a group of spatially distinct clusters of defined colours. Groups can be defined by simple spatial points denoting their centres:

set.seed (2)
ngroups <- 12
x <- bbox [1, 1] + runif (ngroups) * diff (bbox [1, ])
y <- bbox [2, 1] + runif (ngroups) * diff (bbox [2, ])
groups <- cbind (x, y)
groups <- apply (groups, 1, function (i) {
    sp::SpatialPoints (matrix (i, nrow = 1, ncol = 2))
})

Calling add_osm_groups with no bg argument forces all points lying outside those defined groups to be allocated to the nearest groups, and thus produces an inclusive grouping extending across an entire region.

map <- osm_basemap (bbox = bbox, bg = "gray20")
map <- add_osm_groups (
    map,
    dat_B,
    groups = groups,
    cols = rainbow (length (groups)),
    border_width = 2
)
print_osm_map (map)


6. Highlighting Areas Bounded by Named Highways

An alternative way of defining highlighted groups is by naming the highways encircling desired regions.

# These highways extend beyond the previous, smaller bbox
bbox_big <- get_bbox (c (-0.15, 51.5, -0.10, 51.52))
highways <- c (
    "Davies.St", "Berkeley.Sq", "Berkeley.St", "Piccadilly",
    "Regent.St", "Oxford.St"
)
highways1 <- connect_highways (highways = highways, bbox = bbox_big)
highways <- c ("Regent.St", "Oxford.St", "Shaftesbury")
highways2 <- connect_highways (highways = highways, bbox = bbox_big)
highways <- c (
    "Piccadilly", "Shaftesbury.Ave", "Charing.Cross.R",
    "Saint.Martin", "Trafalgar.Sq", "Cockspur.St",
    "Pall.Mall", "St.James"
)
highways3 <- connect_highways (highways = highways, bbox = bbox_big)
highways <- c (
    "Charing.Cross", "Duncannon.St", "Strand", "Aldwych",
    "Kingsway", "High.Holborn", "Shaftesbury.Ave"
)
highways4 <- connect_highways (highways = highways, bbox = bbox_big)
highways <- c (
    "Kingsway", "Holborn", "Farringdon.St", "Strand",
    "Fleet.St", "Aldwych"
)
highways5 <- connect_highways (highways = highways, bbox = bbox_big)
groups <- list (highways1, highways2, highways3, highways4, highways5)

And then passing these lists of groups returned by connect_highways to add_osm_groups, this time with some Wes Anderson flair.

map <- osm_basemap (bbox = bbox, bg = "gray20")
library (wesanderson)
cols <- wes_palette ("Darjeeling", 5)
map <- add_osm_groups (
    map,
    dat_B,
    groups = groups,
    boundary = 1,
    cols = cols,
    bg = "gray40",
    colmat = FALSE
)
map <- add_osm_groups (
    map,
    dat_H,
    groups = groups,
    boundary = 0,
    cols = cols,
    bg = "gray70",
    colmat = FALSE
)
print_osm_map (map)


7. Data Surfaces

Finally, osmplotr contains a function add_osm_surface that spatially interpolates a given set of spatial data points and colours OSM objects according to a specified colour gradient. This is illustrated here with the volcano data projected onto the bbox.

x <- seq (bbox [1, 1], bbox [1, 2], length.out = dim (volcano) [1])
y <- seq (bbox [2, 1], bbox [2, 2], length.out = dim (volcano) [2])
xy <- cbind (rep (x, dim (volcano) [2]), rep (y, each = dim (volcano) [1]))
z <- as.numeric (volcano)
dat <- data.frame (x = xy [, 1], y = xy [, 2], z = z)
map <- osm_basemap (bbox = bbox, bg = "gray20")
cols <- gray (0:50 / 50)
map <- add_osm_surface (map, dat_B, dat = dat, cols = cols)
# Darken cols by ~20%
map <- add_osm_surface (
    map,
    dat_H,
    dat = dat,
    cols = adjust_colours (cols, -0.2)
)
map <- add_colourbar (map, cols = cols, zlims = range (volcano))
map <- add_axes (map)
print_osm_map (map)


8. Gallery

Got a nice osmplotr map? Please contribute in one of the following ways:

  1. Fork repo, add link to README.md/.Rmd, and send pull request; or

  2. Open issue with details; or

  3. Send email to address in DESCRIPTION.


See package vignettes (basic maps and data maps) for a lot more detail and further capabilities of osmplotr. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.


ropensci_footer

osmplotr's People

Contributors

beemyfriend avatar brry avatar jeroen avatar mgehling avatar mpadge avatar richardbeare avatar rubak avatar thierryo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osmplotr's Issues

Displaying ocean

Hi,
I'm wondering about the best way to display ocean. I'm aware of the coastline tag for key "natural". However this returns a mix of polygons and lines and it is not obvious how to fill the appropriate category.

Thanks

How to download relational tags in bounding box

First I'd like to say great package - many thanks for developing this!

As the below code shows it works to download parts of Hackney's road network, which is very useful!

The issue is that many of the paths I'm interested in are referenced only as relations, such as "London Cycle Route Network 9" and I cannot find a way to download these from in your methods. I read with interest your vignette which suggests that you will be fixing an issue related to relations soon (with an example of rivers) and I just wondered if that will solve my issue of not being able to download the cycle path relations. Hopefully the screenshot (see relation description bottom left) and code below should clarify what I'm trying to do.

cycleway

# devtools::install_github("mpadge/osmplotr")
library(osmplotr)
library(tmap)

b = bb("Hackney, London")
b = as.vector(b)
class(b)

h = extract_osm_objects(key = "highway", bbox =  b)
summary(h)

# download the cycleways/cyclable routes
hc = extract_osm_objects(key = "highway", value = "cycleway", bbox = b)
hlcn = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("lcn", "yes"))
hlcn9 = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("lcn_ref", "9"))
hlcna = extract_osm_objects(key = "highway", bbox =  b, extra_pairs = c("Cycle Route", "London Cycle Network Route 9"))

plot(h)
plot(hc, add = T, col = "red", lwd = 2)
plot(hlcn, add = T, col = "green", lwd = 3)
plot(hlcn9, add = T, col = "green", lwd = 3)

Many thanks, it's really useful in any case!

Licence

Would it make sense to add a paragraph about rights of use of obtained maps somewhere in the docs? I'm thinking of that because I think the two advantages of using this package to produce basemaps is:

  • Customization!

  • Open data!

And I'd like to add something about how the second point means you can legally do more with the map you obtain than if you made a map using a Google background (if I'm correct).

git repo title

@sckott , could you please edit the title of my git repo to reflect text in DESCRIPTION?
(It would of course be good for repo owner to be able to do this themselves, but I guess that'd be nigh on impossible without allowing that ability for all ropensci repos, which'd obviously be unwise.) Thanks!

fix osm_line2poly

@richardbeare I've gone through most of your code and vignette with this commit. Note the following in relation to your vignette:

  1. osmdata::opq() now accepts explicit timeout (and memsize) arguments, but these actually aren't needed here. It should just work as is, and does for me, so no need to distract readers of vignette with that stuff
  2. I've removed most of the data you previously had (all of the highways), because this made the plot too large to include in an R package. We really only need the coastal data to illustrate the functionality, and I actually think this really aids the focus of the whole thing.
  3. This should actually make it small enough to include as data within the package, thereby enabling the vignette to actually be run without the graphs.

Now to the issue here which I'd love your help with:

tidy line2poly.R

I'm guessing you don't work with a code linter? Most of the changes I've made are just standard lintr suggestions, with a few extra personal things (more whitespace; vertical alignment of curly braces). I also put all separate functions out into the main function space. However, in it's current form this function no longer works. Can you just have a fish around to ensure that it all works. I think one problem is with the bbox interpretation - you often presume it has a fixed, matrix form with names rows and columns, yet there are no checks for this. Could you just write a small function to force any differently-formed bbox args into this form? (Or some equivalent way of dealing with this). Thanks in advance, and thanks for all the help here - very much appreciated!

sf geometry class warning

Expanding on #46, here is a suggestion to change a cryptic error to a useful warning.
Essence of the previous issue: if sf is not loaded, the subsetting method [.sf is not available and [.data.frame is used. This causes a cryptic error in
add_osm_objects -> get_obj_type -> tolower -> strsplit

Here's a MWE. Make sure sf is not loaded when runnning it:

library(osmplotr)
bbox <- get_bbox(c(12.5, 53.1, 12.6, 53.2))
dat_F <- extract_osm_objects(key="landuse", bbox=bbox, quiet=TRUE, value="forest")
map <- osm_basemap(bbox=bbox, bg='gray95')
map <- add_osm_objects(map, dat_F[1:10,], col='green')

Error in strsplit(class(obj$geometry)[i], "sfc_")[[1]] : 
  subscript out of bounds

I suggest adding a warning / error in get_obj_type in line 19

obj <- dat_F[1:10,]

if(!inherits(obj$geometry, "sfc")) warning("object class is sf, but the geometry",
  " column class is '", toString(class(obj$geometry)), "' instead of 'sfc'.\n",
  "This can occur e.g. after subsetting sf objects without the sf package loaded.")

geom_to_xy has no definition for multilinestring

library(osmplotr)
bbox <- get_bbox(c(12.481225, 53.169504, 12.681225, 53.269504)); bbox
dat_W <- extract_osm_objects(key="waterway", bbox=bbox, return_type="multilines")
map <- osm_basemap(bbox=bbox, bg='gray95')
map <- add_osm_objects(map=map, obj=dat_W, col="blue")
# Error in geom_to_xy(obj, obj_type) : object 'xy' not found
# obj_type is "multilinestring"

geom_to_xy has no code for obj_type=="multilinestring"
https://github.com/ropensci/osmplotr/blob/master/R/add-osm-objects.R#L218

Action needed before 2023-01-25: update osmplotr's dependencies as it cannot be built

πŸ‘‹ @mpadge!

Your osmplotr package cannot be built on R-universe as it depends on the deprecated spatial package rgeos. See for instance this write up by Jakub Nowosad to understand the changes in the R spatial ecosystem. πŸ—ΊοΈ

Please indicate us before January, the 25th whether you intend to update your package. If not, we will archive osmplotr* and remove it from rOpenSci registry. You do not need to make changes before January, the 25th; but you do need to drop us a line before then.

You can find help, among other places, in our Slack's workspace "spatial" and "package-maintenance" channels.

Thank you! πŸ™

*: We can unarchive the repository and transfer it to your own account, at your request. We won't shred it. 😸

@ropensci/admin

osm_line2poly limitations

Hi,
I don't have time to track this down at present, but the following bounding box leads to incorrect behaviour in osm_line2poly for this bit of coastline

bbox.F <- rbind(c(min= 144.75, max = 145.6),
                c(min= -38.41, max = -37.75))
rownames(bbox.F) <- c("x", "y")

I think the problem is cause by multiple cutting of peninsulas.

May be that the current approach is too simple, and that we need to do something quite complex, probably requiring sf, unfortunately.

add_osm_groups() doesn't seem to capture 'waterway'

I'm trying to isolate the Schuylkill River from the rest of my map. The following code works with add_osm_objects():

trial <- get_bbox(c(-75.1, 39.9, -75.2, 40.21))

schuylkill <- cbind(c(-75.16, -75, -75, -75.16),
                    c(39.9, 39.9, 40, 40))

dat_H <- extract_osm_objects(key = 'highway', bbox = trial)
dat_W <- extract_osm_objects(key = 'waterway',  bbox = trial, return_type = 'polygon')

osm_basemap(trial, bg = 'gray80') %>%
  add_osm_objects(dat_H) %>%
  add_osm_objects(dat_W,
                  col = 'blue') %>%
  add_axes() %>%
  print_osm_map()

working

However, when I try to isolate the river by using add_osm_groups(), the waterway is completely ignored. It neither turns blue (representing that it is part of the group) nor turns yellow (representing that it is not part of the group):


osm_basemap(trial, bg = 'gray80') %>%
  add_osm_objects(dat_H) %>%
  add_osm_groups(dat_W,
                groups = schuylkill,
                cols = 'blue',
                bg = 'yellow',
                boundary = 0,
                make_hull = T) %>%
  add_axes() %>%
  print_osm_map()

notworking

I'm confident that my grouping box is accurate. I am not sure what the issue is. Could it be with the feature type ('waterway') or am I missing something really obvious?

Error with print_osm_map

Noticed this while preparing a blog post that'll feature the very cool osmdata and osmplotr πŸ˜‰ I'm using ggplot2 latest version, maybe that's the issue, but I don't see anything amiss on CRAN. πŸ€”

library("osmplotr")
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
bbox <- get_bbox (c(-0.15, 51.5, -0.10, 51.52))
map <- osm_basemap (bbox = bbox, bg = 'gray20')
print_osm_map (map)
#> Error: Discrete value supplied to continuous scale

Created on 2018-07-09 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       Europe/Paris                
#>  date     2018-07-09
#> Packages -----------------------------------------------------------------
#>  package        * version    date       source                            
#>  abind            1.4-5      2016-07-21 CRAN (R 3.5.0)                    
#>  assertthat       0.2.0      2017-04-11 CRAN (R 3.5.0)                    
#>  backports        1.1.2      2017-12-13 CRAN (R 3.5.0)                    
#>  base           * 3.5.0      2018-04-23 local                             
#>  bindr            0.1.1      2018-03-13 CRAN (R 3.5.0)                    
#>  bindrcpp         0.2.2      2018-03-29 CRAN (R 3.5.0)                    
#>  class            7.3-14     2015-08-30 CRAN (R 3.5.0)                    
#>  colorspace       1.3-2      2016-12-14 CRAN (R 3.5.0)                    
#>  compiler         3.5.0      2018-04-23 local                             
#>  curl             3.2        2018-03-28 CRAN (R 3.5.0)                    
#>  datasets       * 3.5.0      2018-04-23 local                             
#>  deldir           0.1-15     2018-04-01 CRAN (R 3.5.0)                    
#>  devtools         1.13.5     2018-02-18 CRAN (R 3.5.0)                    
#>  digest           0.6.15     2018-01-28 CRAN (R 3.5.0)                    
#>  dplyr            0.7.5      2018-05-19 CRAN (R 3.5.0)                    
#>  e1071            1.6-8      2017-02-02 CRAN (R 3.5.0)                    
#>  evaluate         0.10.1     2017-06-24 CRAN (R 3.5.0)                    
#>  ggm              2.3        2015-01-21 CRAN (R 3.5.1)                    
#>  ggplot2          3.0.0      2018-07-03 CRAN (R 3.5.1)                    
#>  glue             1.2.0.9000 2018-06-28 Github (tidyverse/glue@a2c0f8b)   
#>  goftest          1.1-1      2017-04-03 CRAN (R 3.5.0)                    
#>  graphics       * 3.5.0      2018-04-23 local                             
#>  grDevices      * 3.5.0      2018-04-23 local                             
#>  grid             3.5.0      2018-04-23 local                             
#>  gtable           0.2.0      2016-02-26 CRAN (R 3.5.0)                    
#>  htmltools        0.3.6.9001 2018-06-16 Github (rstudio/htmltools@3aee819)
#>  httr             1.3.1      2017-08-20 CRAN (R 3.5.0)                    
#>  igraph           1.2.1      2018-03-10 CRAN (R 3.5.0)                    
#>  jsonlite         1.5        2017-06-01 CRAN (R 3.5.0)                    
#>  knitr            1.20       2018-02-20 CRAN (R 3.5.0)                    
#>  lattice          0.20-35    2017-03-25 CRAN (R 3.5.0)                    
#>  lazyeval         0.2.1      2017-10-29 CRAN (R 3.5.0)                    
#>  lubridate        1.7.4      2018-04-11 CRAN (R 3.5.0)                    
#>  magrittr         1.5        2014-11-22 CRAN (R 3.5.0)                    
#>  mapproj          1.2.6      2018-03-29 CRAN (R 3.5.0)                    
#>  maps             3.3.0      2018-04-03 CRAN (R 3.5.0)                    
#>  Matrix           1.2-14     2018-04-13 CRAN (R 3.5.0)                    
#>  memoise          1.1.0      2017-04-21 CRAN (R 3.5.0)                    
#>  methods        * 3.5.0      2018-04-23 local                             
#>  mgcv             1.8-23     2018-01-21 CRAN (R 3.5.0)                    
#>  munsell          0.5.0      2018-06-12 CRAN (R 3.5.0)                    
#>  nlme             3.1-137    2018-04-07 CRAN (R 3.5.0)                    
#>  osmdata          0.0.7      2018-05-17 CRAN (R 3.5.0)                    
#>  osmplotr       * 0.3.0.99   2018-07-09 local                             
#>  pillar           1.2.3      2018-05-25 CRAN (R 3.5.0)                    
#>  pkgconfig        2.0.1      2017-03-21 CRAN (R 3.5.0)                    
#>  plyr             1.8.4      2016-06-08 CRAN (R 3.5.0)                    
#>  polyclip         1.9-0      2018-06-14 CRAN (R 3.5.0)                    
#>  purrr            0.2.5      2018-05-29 CRAN (R 3.5.0)                    
#>  R6               2.2.2      2017-06-17 CRAN (R 3.5.0)                    
#>  Rcpp             0.12.17    2018-05-18 CRAN (R 3.5.0)                    
#>  rgeos            0.3-28     2018-06-08 CRAN (R 3.5.1)                    
#>  rlang            0.2.1      2018-05-30 CRAN (R 3.5.0)                    
#>  rmarkdown        1.10       2018-06-11 CRAN (R 3.5.0)                    
#>  rpart            4.1-13     2018-02-23 CRAN (R 3.5.0)                    
#>  rprojroot        1.3-2      2018-01-03 CRAN (R 3.4.3)                    
#>  rvest            0.3.2      2016-06-17 CRAN (R 3.4.0)                    
#>  scales           0.5.0      2017-08-24 CRAN (R 3.5.0)                    
#>  sp               1.3-1      2018-06-05 CRAN (R 3.5.0)                    
#>  spatstat         1.56-0     2018-06-15 CRAN (R 3.5.1)                    
#>  spatstat.data    1.3-1      2018-06-11 CRAN (R 3.5.1)                    
#>  spatstat.utils   1.8-2      2018-06-14 CRAN (R 3.5.1)                    
#>  stats          * 3.5.0      2018-04-23 local                             
#>  stringi          1.2.3      2018-06-12 CRAN (R 3.5.0)                    
#>  stringr          1.3.1      2018-05-10 CRAN (R 3.5.0)                    
#>  tensor           1.5        2012-05-05 CRAN (R 3.4.0)                    
#>  tibble           1.4.2      2018-01-22 CRAN (R 3.5.0)                    
#>  tidyselect       0.2.4      2018-02-26 CRAN (R 3.5.0)                    
#>  tools            3.5.0      2018-04-23 local                             
#>  utils          * 3.5.0      2018-04-23 local                             
#>  withr            2.1.2      2018-03-15 CRAN (R 3.4.4)                    
#>  xml2             1.2.0      2018-01-24 CRAN (R 3.5.0)                    
#>  yaml             2.1.19     2018-05-01 CRAN (R 3.5.0)

use vcr to mock tests

The problems highlighted in osmdata issues #126 and #128 are pervasive, and affect CRAN systems too, causing tests to fail. vcr is finally on CRAN, so can be used to mock tests far more neatly and comprehensively than current approach.

ggplot geoms

I've been thinking about testing some special geoms/stats for osm objects. There may be some useful benefits from doing things that way in terms of flexibility, but I've only written a couple previously so I'm not sure of the implications for how the rest of osmplotr works. e.g. might not be compatible with the mechanisms for supplying defaults.

if(nrow(NULL)==0) error in extract_osm_objects

If no data is returned for a given key in a bbox, a warning is intended.
In some cases there may be an error instead:

library(osmplotr)
bbox <- get_bbox(c(12.481225, 53.169504, 12.681225, 53.269504))
dat_W <- extract_osm_objects(key="waterway", bbox=bbox)
# if(nrow(obj) == 0) warning('No valid data returned')
# Error: argument is of length zero

This happens because obj is NULL, which it is because extract_osm_objects uses obj$osm_multipolygons instead of obj$lines (or obj$polygons) if 'waterway' %in% q_keys and for this particular bbox there are no multipols in OSM.

The solution to avoid the error is to use NROW instead of nrow:

nrow(NULL) ; NROW(NULL)
# returning NULL and 0, respectively

Before I submit a pull request:

  • should the default for waterway be obj$lines instead of obj$osm_multipolygons? (Or obj$polygons, which als has a few entries for this bbox?)
  • should the warning include No valid data returned. (Maybe try a different 'return_type').

I'm currently thinking "yes" for both, but am relatively new to the package and may be overlooking things.
Also, did I PR the other two things (#48, #49) the way you'd want them?

using sf operations

Hi,
More of a query really. I'm playing around applying sf operations to osmplotr data. But there seem to be problems having the packages loaded at the same time:

library(sf)
library(osmplotr)
data(london)
london$dat_BR
Error in .subset2(x, i, exact = exact) : 
  attempt to select less than one element in get1index

Any way to safely apply sf operations to the london data set, which appears to be set up using the sf structures?

Fix pkgdown configuration for reference

We get

 Error : In '_pkgdown.yml', topic must be a known selector function
βœ– Not 'osmplotr-package'

I think the easiest fix is to add

#' @keywords internal

for that topic then redocumenting.

Should load sf namespace when returning sf object

This thread https://stat.ethz.ch/pipermail/r-package-devel/2019q1/003473.html shows a problem: the osmplotr::extract_osm_objects() function can return an object inheriting from class "sf" even when the sf package with methods for that class is not loaded. This means that methods are not found, and (in this example) subsetting the object produces a bad result. (The full example is in https://gist.github.com/brry/7728b9b2d35afad7f1fc5978c3315009).

I can understand that you might not want to load sf unconditionally, but I believe this problem would be solved if any function that returns "sf" objects first does something like

if (!requireNamespace("sf"))
  warning("'sf' package is not available so \"sf\" methods will not work.")

If the load is successful, the methods will be defined.

Salvage performant/useful code from the overpass package

As part of a 'package race' with @timeportfolio and someone else, and partly instigated by me, the prolific @hrbrmstr created the overpass package: https://github.com/hrbrmstr/overpass

Serendipitously I met up with Bob at the #runconference and he gives us permission to 'pillage' his code for this. I suggest we do precisely that but use the more amicable term 'salvage' and give him full credit for the functions he created. No details here but if you check out the innards of those functions in overpass, there's some clever stuff going on - it even gives you a progress bar for some operations which is awesome!

Not sure if this is an issue for here your/our new project https://github.com/osmdatar/osmdatar but certain it's an issue worth raising that will lead to good things.

Archived on CRAN

osmplotr is archived on CRAN. Is the package still maintained?

omplotr admin access

@sckott Now that osmdata is out, I can finally get around to re-writing osmplotr properly. To do that, it'll help for me to have admin access to the repo, like I have for osmdata. Could you switch that on, please?

Question

Can I use a geom_sf layer on a map created with osmplotr? I'm trying the following.

bbox <- get_bbox (c(-0.13, 51.51, -0.11, 51.52))
dat_B <- extract_osm_objects (key = "building", bbox = bbox)
dat_H <- extract_osm_objects (key = "highway", bbox = bbox)

map <- bbox %>% 
  osm_basemap (bg = "gray20") %>% 
  add_osm_objects (dat_H, col = "gray70") %>% 
  add_osm_objects (dat_B, col = "gray40")

dt_points <- tibble(
  lng = c(-0.12,-0.125,-0.115),
  lat = c(51.515,51.5125,51.5175)
) %>%
  st_as_sf(coords = c("lng", "lat")) 

map +
  geom_sf(data = dt_points)

I'm getting Error: Discrete value supplied to continuous scale as error message, tho.

How to use the maps in RMarkdown

I am sorry if I missed something in the docs. To know how to integrate a map in an RMarkdown document, I had to look at the source of vignettes. Is the solution used in vignettes the simplest one? Then, is it documented somewhere? And last, could it be simplified? E.g. in order to be able to use maps like magick objects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.