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

Is st_voronoi using the envelope argument? #474

Closed
zross opened this issue Aug 29, 2017 · 4 comments
Closed

Is st_voronoi using the envelope argument? #474

zross opened this issue Aug 29, 2017 · 4 comments

Comments

@zross
Copy link

zross commented Aug 29, 2017

Perhaps my expectations are wrong. I was assuming that including the envelope argument in st_voronoi() would limit the resulting voronoi polygons to those in the envelope. Essentially, I thought the voronoi polygons would be clipped by the envelope. But I'm finding that the results with and without an envelope argument are the same, is this a bug or am I wrong about what it should be doing?

Green is the convex hull and grey is the voronoi

set.seed(100)
df <- data.frame(ID = 1:10, X = sample(1:10, 10), Y = sample(1:10, 10))
d <- st_geometry(st_as_sf(df,coords = c("X", "Y")))
d <- st_union(d)
hull <- st_convex_hull(d)
plot(hull)
plot(d, add = TRUE)

# No envelope
v <- st_voronoi(d)
plot(v, col = "grey")
plot(hull, add = TRUE, col = rgb(0, 1, 0, 0.5))
plot(d, add = TRUE)

# Envelope
v <- st_voronoi(d, envelope = hull)
plot(v, col = "grey")
plot(hull, add = TRUE, col = rgb(0, 1, 0, 0.5))
plot(d, add = TRUE)

@edzer
Copy link
Member

edzer commented Aug 29, 2017

It does, but only if it is larger than the default envelope:

pol = st_polygon(list(rbind(c(-10,-10), c(30,-10), c(30,30), c(-10,30), c(-10,-10))))
 v <- st_voronoi(d, env)
plot(v, col = "grey", axes = TRUE)

x

See lines 702-703 of geos_c.h. I will add this to the docs.

@edzer edzer closed this as completed in 080e460 Aug 29, 2017
@zross
Copy link
Author

zross commented Aug 30, 2017

OK. Is there a reason why it doesn't work for a smaller envelope? The default envelope seems to be bigger than necessary in many instances and I would have thought that including a smaller envelope should work the same as a larger envelope no?

@edzer
Copy link
Member

edzer commented Aug 30, 2017

I guess because the algorithm tesselates infinite space, and GEOS nor simple features can represent that. If you need a smaller section, cut it out:

plot(st_intersection(st_cast(v), hull), col = 'grey')

x

@zross
Copy link
Author

zross commented Aug 30, 2017

Will do, much appreciated!

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