Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to download only $osm_lines and specific attributes? #144

Closed
ibarraespinosa opened this issue Oct 3, 2018 · 2 comments
Closed

How to download only $osm_lines and specific attributes? #144

ibarraespinosa opened this issue Oct 3, 2018 · 2 comments

Comments

@ibarraespinosa
Copy link

I'm starting to use your excellent package but I found that it download the whole information, consuming too much RAM. I just need osm_lines with the attributes "highway" and "maxspeed".

Is it possible to do that?

Thanks!

# gCO is just a spatial feature object
q0 <- opq(bbox = st_bbox(gCO))
q1 <- add_osm_feature(q0, key = 'name')
x <- osmdata_sf(q1)
osm <- x$osm_lines[, c("highway", "maxspeed")]
st <- c("motorway", "motorway_link", "trunk", "trunk_link", 
        "primary", "primary_link", "secondary", "secondary_link", 
        "tertiary", "tertiary_link")
osm <- osm[osm$highway %in% st, ]

My sessionInfo:

R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
 [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C               LC_TIME=pt_BR.UTF-8       
 [4] LC_COLLATE=pt_BR.UTF-8     LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=pt_BR.UTF-8   
 [7] LC_PAPER=pt_BR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sf_0.7-0      osmdata_0.0.7 vein_0.5.2   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.19      xml2_1.2.0        raster_2.6-7      magrittr_1.5      units_0.6-1      
 [6] rvest_0.3.2       eixport_0.3.5     lattice_0.20-35   R6_2.2.2          cptcity_1.0.3    
[11] stringr_1.3.1     httr_1.3.1        tools_3.4.4       grid_3.4.4        data.table_1.11.8
[16] e1071_1.6-8       DBI_1.0.0.9000    class_7.3-14      yaml_2.1.18       lwgeom_0.1-4     
[21] spData_0.2.8.3    curl_3.2          ncdf4_1.16        sp_1.3-1          stringi_1.2.4    
[26] compiler_3.4.4    classInt_0.2-3    jsonlite_1.5      lubridate_1.7.4  

And my screenfetch


                          ./+o+-       sergio@sergio-pos
                  yyyyy- -yyyyyy+      OS: Ubuntu 18.04 bionic
               ://+//////-yyyyyyo      Kernel: x86_64 Linux 4.15.0-34-generic
           .++ .:/++++++/-.+sss/`      Uptime: 10m
         .:++o:  /++++++++/:--:/-      Packages: 3111
        o:+o+:++.`..```.-/oo+++++/     Shell: bash
       .:+o:+o/.          `+sssoo+/    Resolution: 3040x900
  .++/+:+oo+o:`             /sssooo.   DE: Budgie
 /+++//+:`oo+o               /::--:.   WM: BudgieWM
 \+/+o+++`o++o               ++////.   WM Theme: Pocillo
  .++.o+++oo+:`             /dddhhh.   GTK Theme: Default [GTK2/3]
       .+.o+oo:.          `oddhhhh+    Icon Theme: LoginIcons
        \+.++o+o``-````.:ohdhhhhh+     Font: Ubuntu 11
         `:o+++ `ohhhhhhhhyo++os:      CPU: Intel Core i5-4440 @ 4x 3.3GHz [27.8°C]
           .o:`.syhhhhhhh/.oo++o`      GPU: Mesa DRI Intel(R) Haswell Desktop
               /osyyyyyyo++ooo+++/     RAM: 4287MiB / 7849MiB
                   ````` +oo+++o\:
                          `oo++.

Thanks!

@ibarraespinosa
Copy link
Author

I solved in a non-elegant way

osm <- osmdata_sf(
  add_osm_feature(
    opq(bbox = st_bbox(gCO)),
    key = 'highway'))$osm_lines[, c("highway")]
format(object.size(osm), units = "Mb")
[1] "3.6 Mb"

@mpadge
Copy link
Member

mpadge commented Oct 4, 2018

Thanks for using the package. As you discovered, using add_osm_feature(key = "highway") is the best way to restrict to highways alone. The package is intentionally designed not to allow restricting to osm_lines alone, rather to return all OSM data associated with a given query. In your example, highways are made of points, so those are returned as osm_points, often with additional data, and highways may also form defined polygons, or higher-level multi-way entities ($osm_multiline).

You can also easily pipe queries to make them possibly more elegant, so the above could be written

opq(bbox = st_bbox(gCO)) %>%
  add_osm_feature(key = "highway") %>%
  osmdata_sf() %>%
  magrittr::extract2("osm_lines") %>%
  magrittr::extract("highway")

That should do the job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants