-
Notifications
You must be signed in to change notification settings - Fork 293
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
Make st_voronoi() retain the point order #1371
Comments
|
This is a "feature" of the implementation of Voronoi polygons in JTS/GEOS. You should simplify your notation, neither ggplot2 nor data.table are needed. Do everything step by step. My approach (not putting the two |
|
@rsbivand I'm sorry for the use of I did the same as you to reorder the polygon according to the point order, but it is time consuming since I work with A LOT of points. I still feel there is no good reason to reorder the polygons when outputting from The only reason I see is, what if more than one points are exactly at the same coordinates. In that case, these points would share the same Voronoi polygon. In that particular case, there would not be the same number of polygons than points, thus it would not be possible to match the order perfectly. The two solutions I see would be to throw a warning (about duplicate points) and remove the duplicated points before performing tessellation OR to only match the order of points and polygons when the length of both is the same. |
|
Not a big problem that you use complicating extra packages, it just makes it a lot harder to debug problems. Wrt. identical points - you'll find that many problems in computational geometry get much harder for such duplicated observations. The excellent deldir package drops them silently: This should really be done prior to running the function. A method of |
|
So, my dream of having an optional |
|
Personally, I do not trust JTS/GEOS and trust deldir more on this. A lot more work would be needed to eliminate duplicates, then re-order, and possibly copy geometries out to the duplicated points in any case. You have not described a use case - that in deldir is point pattern, so silently dropping duplicates makes sense (or throwing an error, as in other analytical functions). You could contribute the code to set aside duplicates, noting which retained point is their equal, run |
|
Yes, all of this can be done in R easily. Since it won't be integrated in the |
|
Thanks @jplecavalier, I agree things should be aligned! As @rsbivand mentioned, it is GEOS that returns the set unordered. Apparently, we're not alone: https://trac.osgeo.org/postgis/ticket/4392 Note that you could use If your data is very large, maybe it might be worth using a database. Since this solution is not very well documented, and little used, here's an example using a docker container (and only ten points). Note that the SQL code is not prettier than the R code here. # setup
system2("docker run --rm -p 25432:5432 -d -t kartoza/postgis")
Sys.sleep(10)
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = "localhost",
port = 25432,
dbname = "gis",
user = "docker",
password= "docker"
)st_write(data, con, layer = "data")
st_write(border, con, layer = "border")
q <- "
SELECT point as geom, voronoi
FROM
(SELECT (st_dump(ST_VoronoiPolygons(g.geom, 0.001, b.geom))).geom as voronoi
FROM
(SELECT st_collect(point) as geom FROM data) as g, border as b) as v,
data
WHERE st_intersects(point, voronoi)"
x <- st_read(con, query = q)
x %>%
mutate(
row = row_number()
) %>%
ggplot() +
geom_sf(aes(geometry = voronoi)) +
geom_sf(aes(geometry = geom)) +
facet_wrap(~row) |
|
I think GEOS should retain the order when returning the polygons. The only reason I can think of for not doing so is ambiguity in the case of duplicates. But I like @jplecavalier 's suggestion:
I don't see that this functionality has ever been requested/ticketed in GEOS, so I opened one at https://trac.osgeo.org/geos/ticket/1030#ticket |
|
See discussion in geos-devel thread: https://lists.osgeo.org/pipermail/geos-devel/2020-May/009508.html |
|
Thanks! Follow-ups on the referenced GEOS tickets. |
|
Presumably, this has been dealt with in GEOS. Is it possible for you to add this to |
|
Please install GEOS head, re-build GDAL, then install sf HEAD with the new libraries and test that the flag works with a reprex. This reached the development version of GEOS: NEWS.md for 3.12.0 has:
so only from source builds from the github repo head. Once a release candidate becomes available, PRs are welcome. |
|
I don't know how to do any of that?
But it sounds like it is too early to do that.
…On Fri, 20 Jan 2023, 23.23 Roger Bivand, ***@***.***> wrote:
Please install GEOS head, re-build GDAL, then install sf HEAD with the new
libraries and test that the flag works with a reprex. This reached the
development version of GEOS: NEWS.md for 3.12.0 has:
Voronoi: Add option to create diagram in order consistent with inputs (
GH-781 <#781>, Dan Baston)
so only from source builds from the github repo head. Once a release
candidate becomes available, PRs are welcome.
—
Reply to this email directly, view it on GitHub
<#1371 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIDVSFRRSLAFOKIZ6337KLWTMF7FANCNFSM4MJBPLRQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|

I have a very simple example in which I simulate 100 points, then create the Voronoi polygons associated with this partition and assigne it to another column. My problem is that the order of the polygons created by
st_voronoiwon't have the same order than the points used in argument.As one could see with the image above, the point and the polygon are not associated correctly and this is due to the
st_voronoifunction which do not preserve the order of the points.Is it possible to improve this on your side or my only solution is to wrap
st_voronoiinto a personal function that will reorder the polygon to follow the point pattern correctly?The text was updated successfully, but these errors were encountered: