|
16 | 16 | from odc.geo.geom import ( |
17 | 17 | chop_along_antimeridian, |
18 | 18 | clip_lon180, |
| 19 | + count_coordinates, |
19 | 20 | densify, |
20 | 21 | force_2d, |
21 | 22 | multigeom, |
@@ -1055,3 +1056,49 @@ def test_explore_geom(geom_json) -> None: |
1055 | 1056 | geometry.explore(map=m_external) |
1056 | 1057 | assert isinstance(m_external, Map) |
1057 | 1058 | assert any(isinstance(child, GeoJson) for child in m_external._children.values()) |
| 1059 | + |
| 1060 | + |
| 1061 | +def test_count_coordinates() -> None: |
| 1062 | + """Test count_coordinates function with various input types.""" |
| 1063 | + crs = epsg4326 |
| 1064 | + |
| 1065 | + # Test with Geometry (Point) |
| 1066 | + point = geom.point(10, 20, crs) |
| 1067 | + assert count_coordinates(point) == 1 |
| 1068 | + |
| 1069 | + # Test with Geometry (LineString) |
| 1070 | + line = geom.line([(0, 0), (1, 1), (2, 2)], crs) |
| 1071 | + assert count_coordinates(line) == 3 |
| 1072 | + |
| 1073 | + # Test with Geometry (Polygon) |
| 1074 | + polygon = geom.polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)], crs) |
| 1075 | + assert count_coordinates(polygon) == 5 |
| 1076 | + |
| 1077 | + # Test with Geometry (MultiPoint) |
| 1078 | + multi_point = geom.multipoint([(0, 0), (1, 1), (2, 2)], crs) |
| 1079 | + assert count_coordinates(multi_point) == 3 |
| 1080 | + |
| 1081 | + # Test with BoundingBox |
| 1082 | + bbox = geom.BoundingBox(0, 0, 10, 10, crs) |
| 1083 | + assert count_coordinates(bbox) == 4 |
| 1084 | + |
| 1085 | + # Test with Iterable[Geometry] |
| 1086 | + geometries = [point, line, polygon] |
| 1087 | + assert count_coordinates(geometries) == 9 # 1 + 3 + 5 |
| 1088 | + |
| 1089 | + # Test with empty list |
| 1090 | + assert count_coordinates([]) == 0 |
| 1091 | + |
| 1092 | + # Test with single geometry in list |
| 1093 | + assert count_coordinates([point]) == 1 |
| 1094 | + |
| 1095 | + # Test with complex geometry (MultiPolygon) |
| 1096 | + multi_polygon = geom.multipolygon( |
| 1097 | + [ |
| 1098 | + [[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]], |
| 1099 | + [[(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]], |
| 1100 | + ], |
| 1101 | + crs, |
| 1102 | + ) |
| 1103 | + # MultiPolygon with 2 polygons, each with 5 coordinates |
| 1104 | + assert count_coordinates(multi_polygon) == 10 |
0 commit comments