pysal / momepy

Urban Morphology Measuring Toolkit
https://docs.momepy.org
BSD 3-Clause "New" or "Revised" License
496 stars 59 forks source link

DOC: note on a precision issue in enclosed_tessellation #598

Closed martinfleis closed 5 months ago

martinfleis commented 5 months ago

We have noticed a nasty issue with the contiguity of enclosed tessellation caused by floating point imprecision within GEOS. Spent some time trying to fix it but I don't think it is possible with the current version of GEOS / shapely. For our use case, there is a solution, so making a note in the docstring.

Repr of the issue:

import geopandas as gpd
import momepy

streets = gpd.read_file(momepy.datasets.get_path("bubenec"), layer="streets")
buildings = gpd.read_file(momepy.datasets.get_path("bubenec"), layer="buildings")

enclosures = momepy.enclosures(streets, limit=momepy.buffered_limit(buildings, buffer=50))

tess = momepy.enclosed_tessellation(buildings, enclosures)

tess.union_all()
Screenshot 2024-06-13 at 22 00 25

The lines shown in the interior are actual gaps in contiguity when building the graph:

from libpysal.graph import Graph

m = tess_new.explore()
g = Graph.build_contiguity(tess_new, rook=False, strict=True)
g.explore(tess_new, m=m)
m
Screenshot 2024-06-13 at 22 02 06

It's been in the enclosed tessellation since the first implementation 4 years ago.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.0%. Comparing base (4037c70) to head (373455a). Report is 84 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/momepy/pull/598/graphs/tree.svg?width=650&height=150&src=pr&token=VNn0WR5JWT&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/momepy/pull/598?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #598 +/- ## ======================================= + Coverage 97.4% 98.0% +0.6% ======================================= Files 26 37 +11 Lines 4328 6026 +1698 ======================================= + Hits 4214 5904 +1690 - Misses 114 122 +8 ``` | [Files with missing lines](https://app.codecov.io/gh/pysal/momepy/pull/598?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [momepy/functional/\_elements.py](https://app.codecov.io/gh/pysal/momepy/pull/598?src=pr&el=tree&filepath=momepy%2Ffunctional%2F_elements.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvX2VsZW1lbnRzLnB5) | `99.0% <ø> (ø)` | |
martinfleis commented 5 months ago

Just for a reference, this is how it should ideally look like.

Screenshot 2024-06-13 at 22 13 34
jGaboardi commented 5 months ago

Is this something we are going to report upstream to shapely?

martinfleis commented 5 months ago

Is this something we are going to report upstream to shapely?

It is on my to-do list but I've been a bit demoralised by this finding so haven't managed to find a strength to come up with a minimal repr.

martinfleis commented 5 months ago

It's apparently expected... https://github.com/libgeos/geos/issues/1109