def test01_srid(self):
     "Testing GeometryField with a SRID set."
     # Input that doesn't specify the SRID is assumed to be in the SRID
     # of the input field.
     fld = forms.GeometryField(srid=4326)
     geom = fld.clean('POINT(5 23)')
     self.assertEqual(4326, geom.srid)
     # Making the field in a different SRID from that of the geometry, and
     # asserting it transforms.
     fld = forms.GeometryField(srid=32140)
     tol = 0.0000001
     xform_geom = GEOSGeometry('POINT (951640.547328465 4219369.26171664)', srid=32140)
     # The cleaned geometry should be transformed to 32140.
     cleaned_geom = fld.clean('SRID=4326;POINT (-95.363151 29.763374)')
     self.assertTrue(xform_geom.equals_exact(cleaned_geom, tol))
Beispiel #2
0
    def _has_changed(self, initial, data):
        """ Compare geographic value of data with its initial value. """

        # Ensure we are dealing with a geographic object
        if isinstance(initial, six.string_types):
            try:
                initial = GEOSGeometry(initial)
            except (GEOSException, ValueError):
                initial = None

        # Only do a geographic comparison if both values are available
        if initial and data:
            data = fromstr(data)
            data.transform(initial.srid)
            # If the initial value was not added by the browser, the geometry
            # provided may be slightly different, the first time it is saved.
            # The comparison is done with a very low tolerance.
            return not initial.equals_exact(data, tolerance=0.000001)
        else:
            # Check for change of state of existence
            return bool(initial) != bool(data)