Testing automatic transform for lookups and inserts.
(self)
| 122 | |
| 123 | @skipUnlessDBFeature("supports_transform") |
| 124 | def test_lookup_insert_transform(self): |
| 125 | "Testing automatic transform for lookups and inserts." |
| 126 | # San Antonio in 'WGS84' (SRID 4326) |
| 127 | sa_4326 = "POINT (-98.493183 29.424170)" |
| 128 | wgs_pnt = fromstr(sa_4326, srid=4326) # Our reference point in WGS84 |
| 129 | # San Antonio in 'WGS 84 / Pseudo-Mercator' (SRID 3857) |
| 130 | other_srid_pnt = wgs_pnt.transform(3857, clone=True) |
| 131 | # Constructing & querying with a point from a different SRID. Oracle |
| 132 | # `SDO_OVERLAPBDYINTERSECT` operates differently from |
| 133 | # `ST_Intersects`, so contains is used instead. |
| 134 | if connection.ops.oracle: |
| 135 | tx = Country.objects.get(mpoly__contains=other_srid_pnt) |
| 136 | else: |
| 137 | tx = Country.objects.get(mpoly__intersects=other_srid_pnt) |
| 138 | self.assertEqual("Texas", tx.name) |
| 139 | |
| 140 | # Creating San Antonio. Remember the Alamo. |
| 141 | sa = City.objects.create(name="San Antonio", point=other_srid_pnt) |
| 142 | |
| 143 | # Now verifying that San Antonio was transformed correctly |
| 144 | sa = City.objects.get(name="San Antonio") |
| 145 | self.assertAlmostEqual(wgs_pnt.x, sa.point.x, 6) |
| 146 | self.assertAlmostEqual(wgs_pnt.y, sa.point.y, 6) |
| 147 | |
| 148 | # If the GeometryField SRID is -1, then we shouldn't perform any |
| 149 | # transformation if the SRID of the input geometry is different. |
| 150 | m1 = MinusOneSRID(geom=Point(17, 23, srid=4326)) |
| 151 | m1.save() |
| 152 | self.assertEqual(-1, m1.geom.srid) |
| 153 | |
| 154 | def test_createnull(self): |
| 155 | "Testing creating a model instance and the geometry being None" |