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
st_intersection: found non-noded intersection between LINESTRING #1549
Comments
Please see #794 and the extensive discussion there. You are attempting n-ary intersection, which recurses, intersecting intersection products. The input geometries are valid, but some intersection product ceases to be valid. Using GEOS-devel with OverlayNG does not help, although different invalid intermediate outputs are found. Further, your input objects, while being valid polygons, are actually: |
Could you put it in a for loop somehow, or would that make it very slow? |
Not only very slow, but also using very much memory, apparently. N-ary intersection is not provided by JTS or GEOS; sf added it as a speculation, but because it grosses up imprecision as you reach greater depths of overlaps, it is not as such covered by the available computational geometry models. rgeos does not permit it. The depth seems to be up to 14 iterations, but I maxed out 16GB on the fifth with recusing binary |
This gives 215 distinct areas:
Since the grid cells are about 1m^2, the intersection output less than 1 could perhaps be discarded.This is with about 100000 points, 1 million might also be feasible, but I feel that this is as good as you'll get. |
This branch gives us library(sf)
# Linking to GEOS 3.8.1, GDAL 3.1.3, PROJ 7.1.1
bbx <- readRDS("invalid_polygons.rds")
bbx <- bbx %>% st_set_precision(1e5) %>% st_make_valid()
(i <- st_intersection(bbx))
# Simple feature collection with 212 features and 3 fields
# geometry type: GEOMETRY
# dimension: XY
# bbox: xmin: 495762 ymin: 6311742 xmax: 497599.9 ymax: 6314854
# projected CRS: ETRS89 / UTM zone 32N
# First 10 features:
# no_pnts n.overlaps origins geometry
# 1 82 1 1 POLYGON ((496433.2 6312980,...
# 2 82 1 2 MULTIPOLYGON (((497346 6314...
# 3 74 1 3 MULTIPOLYGON (((497260.1 63...
# 2.1 82 2 2, 4 POLYGON ((497297.5 6313184,...
# 4 85 1 4 MULTIPOLYGON (((497325.1 63...
# 2.2 82 3 2, 4, 5 POLYGON ((497295.3 6313180,...
# 4.1 85 2 4, 5 POLYGON ((497299.3 6313214,...
# 2.3 82 2 2, 5 MULTIPOLYGON (((497308 6313...
# 5 76 1 5 MULTIPOLYGON (((497281.9 63...
# 4.2 85 2 4, 6 MULTIPOLYGON (((497314.4 63... basically by switching off GEOS error reporting and ignoring geometries causing trouble. |
I'm still trying to count, and report, the amount of troubling geometries... |
The nary branch and the grid give very similar output, with some missing combinations both ways (6.512942 [m^2] in nary intersection of 109888.1 [m^2], 28.57107 [m^2] in gridded binary intersection of 93167.42 [m^2]). I needed to aggregate my binary intersection as well, to combine separated geometries. |
I merged the nary branch: better to return something than nothing with an error message. |
There seems to be an issue with st_intersection that I can not solve with the usual methods.
download polygons from here: https://github.com/jepol77/test/blob/main/invalid_polygons.rds
bbx <- readRDS(".../invalid_polygons.rds")
bbx <- bbx %>% st_set_precision(1e5) %>% st_make_valid()
i <- st_intersection(bbx)
I get this error: Fejl i CPL_nary_intersection(x) :
Evaluation error: TopologyException: found non-noded intersection between LINESTRING (497314 6.31343e+06, 497314 6.31343e+06) and LINESTRING (497314 6.31343e+06, 497314 6.31343e+06) at 497313.60609830072 6313426.1116788359.
I know there has been some recent work on this in PostGIS; any news when that is gonna trickle down to R?
The text was updated successfully, but these errors were encountered: