Open mpadge opened 7 years ago
Hello Mark,
I attended yout talk in the useR2017 conference, it was great. I wanted to give your package a try and I encountered an error I can't seem to solve.
I tried to plot natural parks on a map with add_osm_objects and it gave an error. Natural parks are multipolygons, is this the same thing as this issue ?
My code is below
tignes_box <- get_bbox (c(6.88, 45.45, 6.92, 45.48))
tignes_parks <- extract_osm_objects(key = 'boundary',
value = 'national_park',
bbox = tignes_box)
tignes_map <- osm_basemap(bbox = tignes_box, bg = 'gray80')
tignes_map <- add_osm_objects(obj = tignes_parks, col = 'forestgreen')
The error is Error in geom_to_xy(obj, obj_type) : object 'xy' not found
.
Anyway thank you for this great package.
Mathieu
thanks a lot @MathieuMarauri! What you want should now be implemented:
tignes_box <- get_bbox (c(6.6, 45.1, 7.0, 45.6))
tignes_parks <- extract_osm_objects(key = 'boundary', value = 'national_park',
bbox = tignes_box)
tignes_map <- osm_basemap(bbox = tignes_box, bg = 'gray80')
tignes_map <- add_osm_objects(tignes_map, obj = tignes_parks, col = 'forestgreen')
print_osm_map (tignes_map)
(Note that I adjusted your bounding box a little - this map actually contains two adjacent multipolygons.)
Note also that these are only "multipolygons" because that's an OSM rule for boundaries, but they're not really geometrical multipolygons because they have no "inner" and "outer" objects. A more complex example is islands within rivers (in this case one called Chiswick Eyot):
bb <- get_bbox (c(-0.25, 51.48, -0.235, 51.49))
obj <- extract_osm_objects(bbox = bb, key = 'name', value = 'River Thames',
return_type = "multipolygon")
map <- osm_basemap(bbox = bb, bg = 'gray80') %>%
add_osm_objects (obj = obj, col = "skyblue")
print_osm_map (map)
Now just have to do same for multiline objects ...
Hello Mark,
Thanks a lot for your quick answer. It works perfectly.
Have a nice day,
Mathieu
I had a similar problem
trial <- get_bbox(c(-75.1, 39.9, -75.2, 40))
dat_H <- extract_osm_objects(key = 'highway', bbox = trial)
dat_W <- extract_osm_objects(key = 'waterway', bbox = trial)
dat_W <- extract_osm_objects(key = 'waterway', bbox = trial)
osm_basemap(trial, bg = 'gray80') %>%
add_osm_objects(dat_H) %>%
add_osm_objects(dat_W,
'blue') %>%
print_osm_map()
the extract_osm_objects()
was returning multipolygons
, I ended up forcing them into normal polygons by typing:
dat_W <- extract_osm_objects(key = 'waterway', bbox = trial, return_type = 'polygon')
I don't actually understand the problem. I just guessed and it ended up working. Why are multipolygons/multilines
giving osmplotr
a hard time? What can I do to help?
That example actually works as intended at the moment - most NYC Philly waterways are simply polygons only with no multipolygons, which is why the force is needed. I guess I could or should implement more informative messages, so rather than just No valid data returned
it would say something like, defaulting to multipolygons ... no valid data; maybe try return_type = "polygons"
? The place to implement that would be somewhere in these lines - feel free to PR!
(This issue is open because multilines are still awaiting proper implementation.)
This doesn't actually work at all!