Comments (2)
No, you've introduced new vertices where the voronoi edges hit the boundary edges, so the old and new boundaries won't be the same. New vertices have to fit into the precision grid of the underlying numeric format (IEEE doubles in this case), they do not fall into the precise "rational number line" location you are thinking of.
from geos.
As I started typing this already yesterday, I can as well post it as an elaboration on the answer by @pramsey.
During the clip operation, new points will need to be calculated at the crossings between the voronoi boundaries and the original geom, as marked with red circles in the image below. Due to non-infinite precision, in many cases this point will not be "exactly" on the crossing... so if you overlay with the original polygon in this case you'll get gaps/slivers. In my experience these slivers are always narrower than 1e-8, and this is also the case in this example.
2 options:
- if you run
set_precision
on the result of the overlay those slivers will be cleaned up. This is what I always do in practice. - make the data topologically sound, so make sure that such calculated points are also added to neighbouring polygons. If the points are introduced in the neighbours, the edges fit perfectly and there will no gaps or slivers. Hopefully GEOSCoverageMakeValid is on the way to support this ;-)...
![image](https://private-user-images.githubusercontent.com/1565789/339639779-bf9249ff-1ebf-4afb-95e2-3e5976f44ad6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MjIwMDUsIm5iZiI6MTcyNDQyMTcwNSwicGF0aCI6Ii8xNTY1Nzg5LzMzOTYzOTc3OS1iZjkyNDlmZi0xZWJmLTRhZmItOTVlMi0zZTU5NzZmNDRhZDYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjNUMTQwMTQ1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YWQ3ZmU2MzNkZGVmYWNhZWViYmFjMmY0YTM0NTM3NzgwMzk2N2M1NDQ5NTkzNzM3OWI5MDM2YThhNDBjNWVjNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Mt9dugxxXRPG0sXd76_HrVKGobOAXvjpDZMHF0IDxgQ)
Script used
from matplotlib import pyplot as plt
import shapely
import shapely.plotting as plot
geom = shapely.from_wkt(
"POLYGON ((1603268.502117987 6464060.781328565, 1603296.8217964454 6464047.851641227, 1603349.1085612718 6464035.338499875, 1603363.557831175 6464031.88480676, 1603361.0308787343 6464021.107210826, 1603317.7832565615 6463836.796863219, 1603217.2506244255 6463859.844110653, 1603202.3783404578 6463872.287568242, 1603157.794884393 6463914.581579376, 1603146.6963311615 6463924.630126579, 1603157.0490438067 6463936.205929175, 1603258.3275165292 6464049.413615812, 1603268.502117987 6464060.781328565))"
)
points = shapely.from_wkt(
[
"POINT (1603284.828798125 6464019.5353853395)",
"POINT (1603323.0633351507 6464000.228348275)",
"POINT (1603278.2522754562 6464030.13553264)",
"POINT (1603304.896049631 6463958.075765142)",
"POINT (1603264.5876622554 6463903.927670779)",
]
)
voronoi = shapely.get_parts(shapely.voronoi_polygons(shapely.union_all(points)))
clipped = shapely.intersection(voronoi, geom)
symmdiff = shapely.union_all(clipped).symmetric_difference(geom)
print(f"{symmdiff=}")
# output: symmdiff=<MULTIPOLYGON (...)>
print(f"{shapely.set_precision(symmdiff, 1e-8)=}")
# output: shapely.set_precision(symmdiff, 1e-8)=<MULTIPOLYGON EMPTY>
figure, ax = plt.subplots()
for voronoi_geom in voronoi:
plot.plot_polygon(voronoi_geom, ax=ax, color="blue")
plot.plot_polygon(geom, ax=ax, color="green")
plt.show()
from geos.
Related Issues (20)
- Dynamic library is not fully setup by `make install` ( missing ldconfig ) HOT 3
- `include/geos/constants.h` - relies on transitive inclusion of `std::size_t` which breaks build in C++23 language mode
- Build fails in C++23 language mode due to one forward declaration HOT 3
- `voronoi_polygons` results in "IllegalArgumentException: point array must contain 0 or >1 elements" HOT 2
- could not find libgeos_c HOT 1
- Polygon buffer removes its hole when quadSegs = 0
- Doubts about the goes C interface HOT 1
- `simplify` with `preserve_topology=True` difference for MultiLineString between 3.12.1 and 3.12.2
- MSVC 32-bit test failure with LargestEmptyCircle HOT 1
- Is it possible to export to dxf format HOT 1
- Refactor MCIndexSegmentSetMutualIntersector to match JTS
- MakeValid method HOT 3
- How to split a polygon with a line? HOT 1
- OverlayNG should return Point for intersection between area and zero-length LineString
- Remove prebuilt capi_indexed_predicate binary
- RelateNG DE9IM regression HOT 4
- RelateNG Equals regression HOT 4
- RelateNG boundaryNode DE9IM regression HOT 11
- Dimension handling with setPrecision / reducePrecision HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geos.