|
14 | 14 | # KIND, either express or implied. See the License for the |
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | | -import pytest |
18 | 17 | import pyproj |
19 | | -from sedonadb.testing import geom_or_null, PostGIS, SedonaDB, val_or_null |
| 18 | +import pytest |
| 19 | +from sedonadb.testing import PostGIS, SedonaDB, geom_or_null, val_or_null |
20 | 20 |
|
21 | 21 |
|
22 | 22 | @pytest.mark.parametrize("eng", [SedonaDB, PostGIS]) |
@@ -93,3 +93,56 @@ def test_st_crs_sedonadb(eng): |
93 | 93 | "SELECT ST_CRS(ST_SetCrs(ST_GeomFromText('POINT (1 1)'), NULL))", |
94 | 94 | None, |
95 | 95 | ) |
| 96 | + |
| 97 | + |
| 98 | +@pytest.mark.parametrize("eng", [SedonaDB, PostGIS]) |
| 99 | +@pytest.mark.parametrize( |
| 100 | + ("geom", "dx", "dy", "expected"), |
| 101 | + [ |
| 102 | + # Nulls |
| 103 | + (None, None, None, None), |
| 104 | + (None, 1.0, 2.0, None), |
| 105 | + ("POINT (0 1)", None, 2.0, None), |
| 106 | + ("POINT (0 1)", 1.0, None, None), |
| 107 | + ("POINT (0 1)", 1.0, 2.0, "POINT (1 3)"), # Positives |
| 108 | + ("POINT (0 1)", -1.0, -2.0, "POINT (-1 -1)"), # Negatives |
| 109 | + ("POINT (0 1)", 0.0, 0.0, "POINT (0 1)"), # Zeroes |
| 110 | + ("POINT (0 1)", 1, 2, "POINT (1 3)"), # Integers |
| 111 | + ("POINT Z (0 1 2)", 1.0, 2.0, "POINT Z (1 3 2)"), # Z |
| 112 | + ("POINT M (0 1 2)", 1.0, 2.0, "POINT M (1 3 2)"), # M |
| 113 | + ("POINT ZM (0 1 2 3)", 1.0, 2.0, "POINT ZM (1 3 2 3)"), # ZM |
| 114 | + # Not points |
| 115 | + ("LINESTRING (0 1, 2 3)", 1.0, 2.0, "LINESTRING (1 3, 3 5)"), |
| 116 | + ("POLYGON ((0 0, 1 0, 0 1, 0 0))", 1.0, 2.0, "POLYGON ((1 2, 2 2, 1 3, 1 2))"), |
| 117 | + ("MULTIPOINT (0 1, 2 3)", 1.0, 2.0, "MULTIPOINT (1 3, 3 5)"), |
| 118 | + ("MULTILINESTRING ((0 1, 2 3))", 1.0, 2.0, "MULTILINESTRING ((1 3, 3 5))"), |
| 119 | + ( |
| 120 | + "MULTIPOLYGON (((0 0, 1 0, 0 1, 0 0)))", |
| 121 | + 1.0, |
| 122 | + 2.0, |
| 123 | + "MULTIPOLYGON (((1 2, 2 2, 1 3, 1 2)))", |
| 124 | + ), |
| 125 | + ( |
| 126 | + "GEOMETRYCOLLECTION (POINT (0 1))", |
| 127 | + 1.0, |
| 128 | + 2.0, |
| 129 | + "GEOMETRYCOLLECTION (POINT (1 3))", |
| 130 | + ), |
| 131 | + # WKT output of geoarrow-c is causing this (both correctly output |
| 132 | + # empties) |
| 133 | + ("POINT EMPTY", 1.0, 2.0, "POINT (nan nan)"), |
| 134 | + ("POINT Z EMPTY", 1.0, 2.0, "POINT Z (nan nan nan)"), |
| 135 | + ("LINESTRING EMPTY", 1.0, 2.0, "LINESTRING EMPTY"), |
| 136 | + ("POLYGON EMPTY", 1.0, 2.0, "POLYGON EMPTY"), |
| 137 | + ("MULTIPOINT EMPTY", 1.0, 2.0, "MULTIPOINT EMPTY"), |
| 138 | + ("MULTILINESTRING EMPTY", 1.0, 2.0, "MULTILINESTRING EMPTY"), |
| 139 | + ("MULTIPOLYGON EMPTY", 1.0, 2.0, "MULTIPOLYGON EMPTY"), |
| 140 | + ("GEOMETRYCOLLECTION EMPTY", 1.0, 2.0, "GEOMETRYCOLLECTION EMPTY"), |
| 141 | + ], |
| 142 | +) |
| 143 | +def test_st_translate(eng, geom, dx, dy, expected): |
| 144 | + eng = eng.create_or_skip() |
| 145 | + eng.assert_query_result( |
| 146 | + f"SELECT ST_Translate({geom_or_null(geom)}, {val_or_null(dx)}, {val_or_null(dy)})", |
| 147 | + expected, |
| 148 | + ) |
0 commit comments