Ticket #17736: 17736_gis_precision.diff

File 17736_gis_precision.diff, 1.6 KB (added by David Eklund, 12 years ago)

Uses Polygon if the input is numerical. Test added.

  • django/contrib/gis/geos/tests/test_geos.py

     
    381381        p = Polygon.from_bbox( bbox )
    382382        self.assertEqual(bbox, p.extent)
    383383
     384        # Testing numerical precision when using `from_bbox`
     385        x = 3.14159265358979323
     386        B = (0, 0, 1, x)
     387        p = Polygon.from_bbox(B)
     388        y = p.extent[-1]
     389        self.assertEqual(format(x, '.13f'), format(y, '.13f'))
     390
    384391        prev = fromstr('POINT(0 0)')
    385392        for p in self.geometries.polygons:
    386393            # Creating the Polygon, testing its properties.
  • django/contrib/gis/geos/polygon.py

     
    5555    def from_bbox(cls, bbox):
    5656        "Constructs a Polygon from a bounding box (4-tuple)."
    5757        x0, y0, x1, y1 = bbox
    58         return GEOSGeometry( 'POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' %  (
    59                 x0, y0, x0, y1, x1, y1, x1, y0, x0, y0) )
     58        for z in bbox:
     59            if not isinstance(z, (int, long, float)):
     60                return GEOSGeometry('POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))' %
     61                                    (x0, y0, x0, y1, x1, y1, x1, y0, x0, y0))
     62        return Polygon(((x0, y0), (x0, y1), (x1, y1), (x1, y0), (x0, y0)))
    6063
    6164    ### These routines are needed for list-like operation w/ListMixin ###
    6265    def _create_polygon(self, length, items):
Back to Top