Beispiel #1
0
 def test_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 is transformed to 32140 (the widget map_srid is 3857).
     cleaned_geom = fld.clean(
         'SRID=3857;POINT (-10615777.40976205 3473169.895707852)')
     self.assertEqual(cleaned_geom.srid, 32140)
     self.assertTrue(xform_geom.equals_exact(cleaned_geom, tol))
Beispiel #2
0
    def test_make_line(self):
        """
        Testing the `MakeLine` aggregate.
        """
        if not connection.features.supports_make_line_aggr:
            with self.assertRaises(NotSupportedError):
                City.objects.all().aggregate(MakeLine('point'))
            return

        # MakeLine on an inappropriate field returns simply None
        self.assertIsNone(
            State.objects.aggregate(MakeLine('poly'))['poly__makeline'])
        # Reference query:
        # SELECT AsText(ST_MakeLine(geoapp_city.point)) FROM geoapp_city;
        ref_line = GEOSGeometry(
            'LINESTRING(-95.363151 29.763374,-96.801611 32.782057,'
            '-97.521157 34.464642,174.783117 -41.315268,-104.609252 38.255001,'
            '-95.23506 38.971823,-87.650175 41.850385,-123.305196 48.462611)',
            srid=4326)
        # We check for equality with a tolerance of 10e-5 which is a lower bound
        # of the precisions of ref_line coordinates
        line = City.objects.aggregate(MakeLine('point'))['point__makeline']
        self.assertTrue(ref_line.equals_exact(line, tolerance=10e-5),
                        "%s != %s" % (ref_line, line))