You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sedona.apache.org by "Martin Andersson (Jira)" <ji...@apache.org> on 2022/03/30 09:01:00 UTC
[jira] [Commented] (SEDONA-96) ST_MakeValid returning multiple geometries for polygons with holes
[ https://issues.apache.org/jira/browse/SEDONA-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17514551#comment-17514551 ]
Martin Andersson commented on SEDONA-96:
----------------------------------------
The current ST_MakeValid implementation in Sedona is based on JTS.makeValid in geotools. It only works for polygons and multipolygons.
Would GeometryFixer available in jts 1.18.2 be a better option? See: [http://lin-ear-th-inking.blogspot.com/2021/05/fixing-invalid-geometry-with-jts.html]
It works for all geometry types and jts doesn't have a the same license issues wrt apache.
GeometryFixer:
{{jshell> var geometry = new WKTReader().read("POLYGON((3 3, 3 -3, -3 -3, -3 3, 3 3), (1 1, 1 -1, -1 -1, -1 1, 1 1))");}}
{{jshell> GeometryFixer.fix(geometry).toText();}}
{{$12 ==> "POLYGON ((3 -3, -3 -3, -3 3, 3 3, 3 -3), (-1 1, -1 -1, 1 -1, 1 1, -1 1))"}}
> ST_MakeValid returning multiple geometries for polygons with holes
> ------------------------------------------------------------------
>
> Key: SEDONA-96
> URL: https://issues.apache.org/jira/browse/SEDONA-96
> Project: Apache Sedona
> Issue Type: Bug
> Reporter: Russell W
> Priority: Major
> Attachments: Screen Shot 2022-03-29 at 2.17.43 PM.png, Screen Shot 2022-03-29 at 2.19.37 PM.png
>
>
> When pass a polygon with holes, ST_MakeValid is returning new rows for each hole. This can lead to significant incorrectness when using ST_MakeValid prior to a spatial join.
> Example:
> {code:java}
> polygon = spark.createDataFrame([['{"type": "Polygon", "coordinates": [[[3, 3], [3, -3], [-3, -3], [-3, 3], [3, 3]], [[1, 1], [1, -1], [-1, -1], [-1, 1], [1, 1]]]}']], ['geometry'])
> polygon = polygon.withColumn('geometry', F.expr('ST_MakeValid(ST_GeomFromGeoJSON(geometry), false)'))
> polygon = polygon.withColumn('geometry', F.expr('ST_AsGeoJSON(geometry)'))
> polygon
> geometry
> --------------------------------------------------------------------------------------------------------------------------------------------------
> {"type":"Polygon","coordinates":[[[3.0,3.0],[3.0,-3.0],[-3.0,-3.0],[-3.0,3.0],[3.0,3.0]],[[1.0,1.0],[-1.0,1.0],[-1.0,-1.0],[1.0,-1.0],[1.0,1.0]]]}
> {"type":"Polygon","coordinates":[[[-1.0,1.0],[1.0,1.0],[1.0,-1.0],[-1.0,-1.0],[-1.0,1.0]]]}{code}
> Input:
> !Screen Shot 2022-03-29 at 2.17.43 PM.png|width=458,height=379!
> Output:
> !Screen Shot 2022-03-29 at 2.19.37 PM.png|width=457,height=378!
--
This message was sent by Atlassian Jira
(v8.20.1#820001)