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

DStability - Shapely accuracy leads to invalid new layers #172

Open
breinbaas opened this issue Jan 5, 2024 · 1 comment
Open

DStability - Shapely accuracy leads to invalid new layers #172

breinbaas opened this issue Jan 5, 2024 · 1 comment
Assignees
Labels
bug Something isn't working d-stability

Comments

@breinbaas
Copy link
Collaborator

In the current version of geolib adding new layers to a DStability geometry can lead to errors in the geometry. This seems to be related to the accuracy of the coordinates. Here is an example of a layer that has been added programmatically;

01

As you can see the rightmost point of the new layer is not connected to the geometry which leads to an error if you want to calculate this using DStability.

@breinbaas breinbaas self-assigned this Jan 5, 2024
@breinbaas breinbaas added bug Something isn't working d-stability labels Jan 5, 2024
@breinbaas
Copy link
Collaborator Author

breinbaas commented Jan 5, 2024

The solution is easy and implemented in #171

Since it was a very small code change I have added it to the other PR but if you want to keep this seperate the code to be changed is;

def connect_layers(self, layer1: PersistableLayer, layer2: PersistableLayer):
        """Connects two polygons by adding a the missing points on the polygon edges. Returns the two new polygons."""
        linestring1 = self.to_shapely_linestring(layer1.Points)
        linestring2 = self.to_shapely_linestring(layer2.Points)

        # Create a union of the two polygons and polygonize it creating two connected polygons
        union = linestring1.union(linestring2, grid_size=1e-3) # ADDED GRIDSIZE PARAMETER
        result = [geom for geom in polygonize(union)]

        # If the result has two polygons, we return them, otherwise we return the original polygons
        if len(result) == 2:
            return result[0].exterior, result[1].exterior
        else:
            return linestring1, linestring2

Now everything looks fine;

02

@breinbaas breinbaas linked a pull request Jan 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working d-stability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant