This is an automated email from the ASF dual-hosted git repository.

jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git


The following commit(s) were added to refs/heads/master by this push:
     new d2dee1387 [SEDONA-610] Add ST_IsValidTrajectory (Python code) (#1489)
d2dee1387 is described below

commit d2dee1387a80222b4f13bcea302f1f7603b2bf37
Author: Furqaan Khan <[email protected]>
AuthorDate: Fri Jun 21 12:57:28 2024 -0400

    [SEDONA-610] Add ST_IsValidTrajectory (Python code) (#1489)
    
    * feat: add ST_IsValidTrajectory
    
    * remove print statements and add example
    
    * feat: add python code and tests
---
 python/sedona/sql/st_functions.py      | 13 +++++++++++++
 python/tests/sql/test_dataframe_api.py |  2 ++
 python/tests/sql/test_function.py      |  8 ++++++++
 3 files changed, 23 insertions(+)

diff --git a/python/sedona/sql/st_functions.py 
b/python/sedona/sql/st_functions.py
index 305ab8681..630d6e224 100644
--- a/python/sedona/sql/st_functions.py
+++ b/python/sedona/sql/st_functions.py
@@ -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:
     """
diff --git a/python/tests/sql/test_dataframe_api.py 
b/python/tests/sql/test_dataframe_api.py
index 70d491595..ced18e5d7 100644
--- a/python/tests/sql/test_dataframe_api.py
+++ b/python/tests/sql/test_dataframe_api.py
@@ -149,6 +149,7 @@ test_configurations = [
     (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),
@@ -356,6 +357,7 @@ wrong_type_configurations = [
     (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,)),
diff --git a/python/tests/sql/test_function.py 
b/python/tests/sql/test_function.py
index fe32bb950..05a8f7e08 100644
--- a/python/tests/sql/test_function.py
+++ b/python/tests/sql/test_function.py
@@ -322,6 +322,14 @@ class TestPredicateJoin(TestBase):
         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, " +

Reply via email to