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

[SEDONA-610] Add ST_IsValidTrajectory (Python code) #1489

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/sedona/sql/st_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,19 @@ def ST_IsValidDetail(geometry: ColumnOrName, flag: Optional[Union[ColumnOrName,
args = (geometry,) if flag is None else (geometry, flag)
return _call_st_function("ST_IsValidDetail", args)

@validate_argument_types
def ST_IsValidTrajectory(geometry: ColumnOrName) -> Column:
"""
Tests if a geometry encodes a valid trajectory. A valid trajectory is represented as a LINESTRING with measures
(M values). The measure values must increase from each vertex to the next.

:param geometry: Geometry column to validate.
:type geometry: ColumnOrName
:return: True if the geometry is valid trajectory and False otherwise as a boolean column.
:rtype: Column
"""
return _call_st_function("ST_IsValidTrajectory", (geometry))

@validate_argument_types
def ST_IsValidReason(geometry: ColumnOrName, flag: Optional[Union[ColumnOrName, int]] = None) -> Column:
"""
Expand Down
2 changes: 2 additions & 0 deletions python/tests/sql/test_dataframe_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
(stf.ST_IsPolygonCCW, ("geom",), "geom_with_hole", "", True),
(stf.ST_IsRing, ("line",), "linestring_geom", "", False),
(stf.ST_IsSimple, ("geom",), "triangle_geom", "", True),
(stf.ST_IsValidTrajectory, ("line",), "4D_line", "", False),
(stf.ST_IsValid, ("geom",), "triangle_geom", "", True),
(stf.ST_IsValid, ("geom", 1), "triangle_geom", "", True),
(stf.ST_IsValid, ("geom", 0), "triangle_geom", "", True),
Expand Down Expand Up @@ -356,6 +357,7 @@
(stf.ST_IsPolygonCCW, (None,)),
(stf.ST_IsRing, (None,)),
(stf.ST_IsSimple, (None,)),
(stf.ST_IsValidTrajectory, (None,)),
(stf.ST_IsValidDetail, (None,)),
(stf.ST_IsValid, (None,)),
(stf.ST_IsValidReason, (None,)),
Expand Down
8 changes: 8 additions & 0 deletions python/tests/sql/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ def test_st_is_valid_detail(self):
self.spark.sql("SELECT ST_GeomFromText('POINT (1 1)')").first()[0])
assert expected == actual

def test_st_is_valid_trajectory(self):
baseDf = self.spark.sql("SELECT ST_GeomFromText('LINESTRING M (0 0 1, 0 1 2)') as geom1, ST_GeomFromText('LINESTRING M (0 0 1, 0 1 1)') as geom2")
actual = baseDf.selectExpr("ST_IsValidTrajectory(geom1)").first()[0]
assert actual

actual = baseDf.selectExpr("ST_IsValidTrajectory(geom2)").first()[0]
assert not actual

def test_st_is_valid(self):
test_table = self.spark.sql(
"SELECT ST_IsValid(ST_GeomFromWKT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (15 15, 15 20, 20 20, 20 15, 15 15))')) AS a, " +
Expand Down
Loading