Ticket #14060: 14060.1.diff

File 14060.1.diff, 3.3 KB (added by jbronn, 14 years ago)
  • django/contrib/gis/db/models/fields.py

     
    9494        # Is this a geography rather than a geometry column?
    9595        self.geography = geography
    9696
    97         # Oracle-specific private attributes for creating the entrie in
     97        # Oracle-specific private attributes for creating the entry in
    9898        # `USER_SDO_GEOM_METADATA`
    9999        self._extent = kwargs.pop('extent', (-180.0, -90.0, 180.0, 90.0))
    100100        self._tolerance = kwargs.pop('tolerance', 0.05)
     
    237237            elif isinstance(value, SQLEvaluator):
    238238                params = []
    239239            else:
    240                 params = [connection.ops.Adapter(value)]
     240                params = [connection.ops.Adapter(value, geography=self.geography)]
    241241
    242242            return params
    243243        else:
  • django/contrib/gis/db/backends/adapter.py

     
    33    This provides an adaptor for Geometries sent to the
    44    MySQL and Oracle database backends.
    55    """
    6     def __init__(self, geom):
     6    def __init__(self, geom, **kwargs):
    77        self.wkt = geom.wkt
    88        self.srid = geom.srid
    99
  • django/contrib/gis/db/backends/postgis/adapter.py

     
    66from psycopg2.extensions import ISQLQuote
    77
    88class PostGISAdapter(object):
    9     def __init__(self, geom):
     9    def __init__(self, geom, geography=False, **kwargs):
    1010        "Initializes on the geometry."
    1111        # Getting the WKB (in string form, to allow easy pickling of
    1212        # the adaptor) and the SRID from the geometry.
    1313        self.ewkb = str(geom.ewkb)
    1414        self.srid = geom.srid
     15        self.geography = geography
    1516
    1617    def __conform__(self, proto):
    1718        # Does the given protocol conform to what Psycopg2 expects?
     
    2930    def getquoted(self):
    3031        "Returns a properly quoted string for use in PostgreSQL/PostGIS."
    3132        # Want to use WKB, so wrap with psycopg2 Binary() to quote properly.
    32         return 'ST_GeomFromEWKB(E%s)' % Binary(self.ewkb)
     33        if self.geography:
     34            return 'ST_GeogFromWKB(E%s)' % Binary(self.ewkb)
     35        else:
     36            return 'ST_GeomFromEWKB(E%s)' % Binary(self.ewkb)
    3337
    3438    def prepare_database_save(self, unused):
    3539        return self
  • django/contrib/gis/tests/geogapp/tests.py

     
    7272            self.assertEqual(num_poly, len(c.mpoly))
    7373            self.assertEqual(name, c.name)
    7474            self.assertEqual(state, c.state)
     75
     76    def test06_geography_adapter(self):
     77        # Try to get Victoria by equivalence comparison.
     78        c = City.objects.get(point="POINT (-123.305196 48.462611)")
Back to Top