petern48 commented on code in PR #2493:
URL: https://github.com/apache/sedona/pull/2493#discussion_r2518903506


##########
python/tests/geopandas/test_match_geopandas_series.py:
##########
@@ -833,7 +833,26 @@ def test_transform(self):
         pass
 
     def test_force_2d(self):
-        pass
+        # force_2d was added from geopandas 1.0.0
+        if parse_version(gpd.__version__) < parse_version("1.0.0"):
+            pytest.skip("geopandas force_2d requires version 1.0.0 or higher")
+        # 1) No-op on existing 2D fixtures
+        for geom in self.geoms:
+            sgpd_result = GeoSeries(geom).force_2d()
+            gpd_result = gpd.GeoSeries(geom).force_2d()
+            self.check_sgpd_equals_gpd(sgpd_result, gpd_result)
+
+        # 2) Minimal 3D sample to verify Z is actually stripped
+        data = [
+            Point(0, -1, 2.5),
+            LineString([(0, 0, 1), (1, 1, 2)]),
+            Polygon([(0, 0, 1), (1, 0, 2), (1, 1, 3), (0, 0, 1)]),
+            Point(5, 5),  # already 2D
+            Polygon(),  # empty geometry

Review Comment:
   ```suggestion
               Polygon(),  # empty geometry
               shapely.wkt.loads("POINT M (1 2 3)"),
               shapely.wkt.loads("LINESTRING ZM (1 2 3 4, 5 6 7 8)"),
   ```



##########
python/sedona/spark/geopandas/base.py:
##########
@@ -861,8 +861,37 @@ def segmentize(self, max_segment_length):
     # def transform(self, transformation, include_z=False):
     #     raise NotImplementedError("This method is not implemented yet.")
 
-    # def force_2d(self):
-    #     raise NotImplementedError("This method is not implemented yet.")
+    def force_2d(self):
+        """
+        Forces the dimensionality of each geometry to 2D.
+        Removes the Z coordinate (if present) from each geometry and returns a

Review Comment:
   ```suggestion
           Removes the Z and M coordinates (if present) from each geometry and 
returns a
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1409,7 +1409,34 @@ def test_transform(self):
         pass
 
     def test_force_2d(self):
-        pass
+        s = sgpd.GeoSeries(
+            [
+                Point(0, -1, 2.5),  # 3D point
+                LineString([(0, 0, 1), (1, 1, 2)]),  # 3D line
+                Polygon([(0, 0, 1), (1, 0, 2), (1, 1, 3), (0, 0, 1)]),  # 3D 
polygon
+                Point(5, 5),  # already 2D
+                Polygon(),  # empty geometry
+                None,  # None preserved

Review Comment:
   ```suggestion
                   None,  # None preserved
                   shapely.wkt.loads("POINT M (1 2 3)"),
                   shapely.wkt.loads("LINESTRING ZM (1 2 3 4, 5 6 7 8)"),
   ```



##########
python/tests/geopandas/test_geoseries.py:
##########
@@ -1409,7 +1409,34 @@ def test_transform(self):
         pass
 
     def test_force_2d(self):
-        pass
+        s = sgpd.GeoSeries(
+            [
+                Point(0, -1, 2.5),  # 3D point
+                LineString([(0, 0, 1), (1, 1, 2)]),  # 3D line
+                Polygon([(0, 0, 1), (1, 0, 2), (1, 1, 3), (0, 0, 1)]),  # 3D 
polygon
+                Point(5, 5),  # already 2D
+                Polygon(),  # empty geometry
+                None,  # None preserved
+            ]
+        )
+
+        result = s.force_2d()
+
+        expected = gpd.GeoSeries(
+            [
+                Point(0, -1),
+                LineString([(0, 0), (1, 1)]),
+                Polygon([(0, 0), (1, 0), (1, 1), (0, 0)]),
+                Point(5, 5),
+                Polygon(),
+                None,

Review Comment:
   ```suggestion
                   None,
                   shapely.wkt.loads("POINT (1 2)"),
                   shapely.wkt.loads("LINESTRING (1 2, 5 6)"),
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to