@@ -211,6 +211,63 @@ def test_st_centroid(eng, geom, expected):
211211 eng .assert_query_result (f"SELECT ST_Centroid({ geom_or_null (geom )} )" , expected )
212212
213213
214+ @pytest .mark .parametrize ("eng" , [SedonaDB , PostGIS ])
215+ @pytest .mark .parametrize (
216+ ("geom" , "expected" ),
217+ [
218+ (None , None ),
219+ ("POINT (0 0)" , True ),
220+ ("POINT EMPTY" , True ),
221+ ("LINESTRING (0 0, 1 1)" , True ),
222+ ("LINESTRING (0 0, 1 1, 1 0, 0 1)" , True ),
223+ (
224+ "MULTILINESTRING ((0 0, 1 1), (0 0, 1 1, 1 0, 0 1))" ,
225+ True ,
226+ ),
227+ ("LINESTRING EMPTY" , True ),
228+ # Invalid LineStrings
229+ ("LINESTRING (0 0, 0 0)" , False ), # Degenerate - both points identical
230+ ("LINESTRING (0 0, 0 0, 0 0)" , False ), # All points identical
231+ # Invalid MultiLineStrings
232+ ("MULTILINESTRING ((0 0, 0 0), (1 1, 2 2))" , False ), # Degenerate component
233+ (
234+ "MULTILINESTRING ((0 0, 0 0), (1 1, 1 1))" ,
235+ False ,
236+ ), # Multiple degenerate components
237+ ("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))" , True ),
238+ ("POLYGON EMPTY" , True ),
239+ ("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1))" , True ),
240+ # Invalid Polygons
241+ # Self-intersecting polygon (bowtie)
242+ ("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))" , False ),
243+ # Inner ring shares an edge with the outer ring
244+ ("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (0 0, 0 1, 1 1, 1 0, 0 0))" , False ),
245+ # Self-intersecting polygon (figure-8)
246+ ("Polygon((0 0, 2 0, 1 1, 2 2, 0 2, 1 1, 0 0))" , False ),
247+ # Inner ring touches the outer ring at a point
248+ (
249+ "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 10, 1 9, 2 9, 2 10, 1 10))" ,
250+ False ,
251+ ),
252+ # Overlapping polygons in a multipolygon
253+ (
254+ "MULTIPOLYGON (((0 0, 2 0, 2 2, 0 2, 0 0)), ((1 1, 3 1, 3 3, 1 3, 1 1)))" ,
255+ False ,
256+ ),
257+ (
258+ "MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((2 2, 3 2, 3 3, 2 3, 2 2)))" ,
259+ True ,
260+ ),
261+ # Geometry collection with an invalid polygon
262+ ("GEOMETRYCOLLECTION (POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0)))" , False ),
263+ ("GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0)))" , True ),
264+ ],
265+ )
266+ def test_st_isvalid (eng , geom , expected ):
267+ eng = eng .create_or_skip ()
268+ eng .assert_query_result (f"SELECT ST_IsValid({ geom_or_null (geom )} )" , expected )
269+
270+
214271@pytest .mark .parametrize ("eng" , [SedonaDB , PostGIS ])
215272@pytest .mark .parametrize (
216273 ("geom" , "expected" ),
0 commit comments