ropensci / osmdata

R package for downloading OpenStreetMap data
https://docs.ropensci.org/osmdata
314 stars 45 forks source link

Fix queries with multiple features and more than one osm_types #318

Closed jmaspons closed 1 year ago

jmaspons commented 1 year ago

Example of the error for osm_types and features with non-multiple lengths

q <- opq("Catalunya") |> 
    add_osm_features(features = c("\"amenity\"=\"school\"",
                                  "\"amenity\"=\"kindergarten\"",
                                  "\"amenity\"=\"music_school\"",
                                  "\"amenity\"=\"language_school\"",
                                  "\"amenity\"=\"dancing_school\""))
opq_string(q)
#> Error in sprintf("  %s %s (%s);\n", opq$osm_types, features, opq$bbox) :
#>  arguments cannot be recycled to the same length

For osm_types and features with multiple lengths, every feature gets only one osm_type instead of all osm_types

q <- opq("Catalunya") |> 
    add_osm_features(features = c("\"amenity\"=\"school\"",
                              "\"amenity\"=\"kindergarten\"",
                              "\"amenity\"=\"music_school\""))
cat(opq_string(q))
#> [out:xml][timeout:25];
#> (
#>   node ["amenity"="school"] (40.5229822,0.1594133,42.8615226,3.3222508);
#>   way ["amenity"="kindergarten"] (40.5229822,0.1594133,42.8615226,3.3222508);
#>   relation ["amenity"="music_school"] (40.5229822,0.1594133,42.8615226,3.3222508);
#> );
#> (._;>;);
#> out body;
jmaspons commented 1 year ago

Tests added and NEWS updated

mpadge commented 1 year ago

Great, thanks!