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

implement plotting for multiline/polygon objects #23

Open
mpadge opened this issue Jul 12, 2017 · 5 comments
Open

implement plotting for multiline/polygon objects #23

mpadge opened this issue Jul 12, 2017 · 5 comments
Labels

Comments

@mpadge
Copy link
Member

mpadge commented Jul 12, 2017

This doesn't actually work at all!

@mpadge mpadge added the must do label Jul 12, 2017
@MathieuMarauri
Copy link

MathieuMarauri commented Jul 19, 2017

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

@mpadge
Copy link
Member Author

mpadge commented Jul 19, 2017

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)

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)

map


Now just have to do same for multiline objects ...

@MathieuMarauri
Copy link

Hello Mark,

Thanks a lot for your quick answer. It works perfectly.

Have a nice day,

Mathieu

@beemyfriend
Copy link
Contributor

beemyfriend commented Jul 31, 2017

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?

@mpadge
Copy link
Member Author

mpadge commented Jul 31, 2017

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.)

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

No branches or pull requests

3 participants