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

encode shapes #2

Merged
merged 1 commit into from
Jan 21, 2021
Merged

encode shapes #2

merged 1 commit into from
Jan 21, 2021

Conversation

vincentsarago
Copy link
Member

ref #1

@vincentsarago
Copy link
Member Author

FYI, I tried to use Mapbox's wagyu to create valid geometry but it didn't really change the results

from wagyu import enums as wEnums
from wagyu.linear_ring import LinearRing as wLinearRing
from wagyu.point import Point as wPoint
from wagyu.polygon import Polygon as wPolygon
from wagyu.wagyu import Wagyu

        w = Wagyu()
        wext = wPolygon(
            [
                wLinearRing(
                    [wPoint(x, y) for x, y in exterior.coords]
                )
            ]
        )
        w.add_polygon(wext, wEnums.PolygonKind.SUBJECT)
        for interior in list(interiors):
            wint = wPolygon(
                [
                    wLinearRing(
                        [wPoint(x, y) for x, y in interior.coords]
                    )
                ]
            )
            w.add_polygon(wint, wEnums.PolygonKind.SUBJECT)

        result = w.execute(
            wEnums.OperationKind.UNION,
            wEnums.FillKind.EVEN_ODD,
            wEnums.FillKind.EVEN_ODD
        )
        for p in result.polygons:
            for l in p.linear_rings:
                feature.add_ring(len(l))
                for p in l.points:
                    feature.set_point(int(p.x), int(p.y))

feature.set_id(v)

polygon = geometry.shape(p)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we use shapely to split the geometry between interior/exterior

if not polygon.is_valid:
# If the polygon is not valid we use a little trick
polygon = polygon.buffer(0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that applying a 0 buffer creates a valid geometry (for GEOS)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read that the other day too, when I had a large polygonize output

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is still WIP. (see #1)

I've deployed a tiler using https://github.com/developmentseed/titiler-mvt but I'm getting a lot of warnings because the geometry are still invalid.

I may try to use pygeos instead of shapely (and maybe try wagyu again)

@vincentsarago vincentsarago merged commit 0b8d171 into master Jan 21, 2021
@vincentsarago vincentsarago deleted the shapesEncoder branch August 8, 2022 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants