|
7 | 7 | from rest_framework_gis import serializers as gis_serializers
|
8 | 8 |
|
9 | 9 | Point = {"type": "Point", "coordinates": [-105.0162, 39.5742]}
|
| 10 | +Point31287 = {"type": "Point", "coordinates": [625826.2376404074, 483198.2074507246]} |
10 | 11 |
|
11 | 12 | MultiPoint = {
|
12 | 13 | "type": "MultiPoint",
|
@@ -141,6 +142,102 @@ def normalize(self, data):
|
141 | 142 | return data
|
142 | 143 |
|
143 | 144 |
|
| 145 | +class TestTransform(BaseTestCase): |
| 146 | + def test_no_transform_4326_Point_no_srid(self): |
| 147 | + model = self.get_instance(Point) |
| 148 | + Serializer = self.create_serializer() |
| 149 | + data = Serializer(model).data |
| 150 | + |
| 151 | + expected_coords = (-105.0162, 39.5742) |
| 152 | + for lat, lon in zip( |
| 153 | + data["geometry"]["coordinates"], |
| 154 | + expected_coords, |
| 155 | + ): |
| 156 | + self.assertAlmostEqual(lat, lon, places=5) |
| 157 | + |
| 158 | + def test_no_transform_4326_Point_set_srid(self): |
| 159 | + model = self.get_instance(Point) |
| 160 | + model.geometry.srid = 4326 |
| 161 | + Serializer = self.create_serializer() |
| 162 | + data = Serializer(model).data |
| 163 | + |
| 164 | + expected_coords = (-105.0162, 39.5742) |
| 165 | + for lat, lon in zip( |
| 166 | + data["geometry"]["coordinates"], |
| 167 | + expected_coords, |
| 168 | + ): |
| 169 | + self.assertAlmostEqual(lat, lon, places=5) |
| 170 | + |
| 171 | + def test_transform_Point_no_transform(self): |
| 172 | + model = self.get_instance(Point31287) |
| 173 | + model.geometry.srid = 31287 |
| 174 | + Serializer = self.create_serializer(transform=None) |
| 175 | + data = Serializer(model).data |
| 176 | + |
| 177 | + expected_coords = (625826.2376404074, 483198.2074507246) |
| 178 | + for lat, lon in zip( |
| 179 | + data["geometry"]["coordinates"], |
| 180 | + expected_coords, |
| 181 | + ): |
| 182 | + self.assertAlmostEqual(lat, lon, places=5) |
| 183 | + |
| 184 | + def test_transform_Point_no_srid(self): |
| 185 | + model = self.get_instance(Point31287) |
| 186 | + Serializer = self.create_serializer() |
| 187 | + data = Serializer(model).data |
| 188 | + |
| 189 | + expected_coords = (625826.2376404074, 483198.2074507246) |
| 190 | + for lat, lon in zip( |
| 191 | + data["geometry"]["coordinates"], |
| 192 | + expected_coords, |
| 193 | + ): |
| 194 | + self.assertAlmostEqual(lat, lon, places=5) |
| 195 | + |
| 196 | + def test_transform_Point_to_4326(self): |
| 197 | + model = self.get_instance(Point31287) |
| 198 | + model.geometry.srid = 31287 |
| 199 | + Serializer = self.create_serializer() |
| 200 | + data = Serializer(model).data |
| 201 | + |
| 202 | + expected_coords = (16.372500007573713, 48.20833306345481) |
| 203 | + for lat, lon in zip( |
| 204 | + data["geometry"]["coordinates"], |
| 205 | + expected_coords, |
| 206 | + ): |
| 207 | + self.assertAlmostEqual(lat, lon, places=5) |
| 208 | + |
| 209 | + def test_transform_Point_to_3857(self): |
| 210 | + model = self.get_instance(Point31287) |
| 211 | + model.geometry.srid = 31287 |
| 212 | + Serializer = self.create_serializer(transform=3857) |
| 213 | + data = Serializer(model).data |
| 214 | + |
| 215 | + expected_coords = (1822578.363856016, 6141584.271938089) |
| 216 | + for lat, lon in zip( |
| 217 | + data["geometry"]["coordinates"], |
| 218 | + expected_coords, |
| 219 | + ): |
| 220 | + self.assertAlmostEqual(lat, lon, places=1) |
| 221 | + |
| 222 | + def test_transform_Point_bbox_to_4326(self): |
| 223 | + model = self.get_instance(Point31287) |
| 224 | + model.geometry.srid = 31287 |
| 225 | + Serializer = self.create_serializer(auto_bbox=True) |
| 226 | + data = Serializer(model).data |
| 227 | + |
| 228 | + expected_coords = ( |
| 229 | + 16.372500007573713, |
| 230 | + 48.20833306345481, |
| 231 | + 16.372500007573713, |
| 232 | + 48.20833306345481, |
| 233 | + ) |
| 234 | + for received, expected in zip( |
| 235 | + data["geometry"]["bbox"], |
| 236 | + expected_coords, |
| 237 | + ): |
| 238 | + self.assertAlmostEqual(received, expected, places=5) |
| 239 | + |
| 240 | + |
144 | 241 | class TestPrecision(BaseTestCase):
|
145 | 242 | def test_precision_Point(self):
|
146 | 243 | model = self.get_instance(Point)
|
|
0 commit comments