Django

Code

Changeset 5657

Show
Ignore:
Timestamp:
07/12/07 01:47:40 (1 year ago)
Author:
jbronn
Message:

gis: lazy-geometry support has landed -- thanks Robert Coup!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/db/models/fields/__init__.py

    r5448 r5657  
    11# The Django base Field class. 
    22from django.db.models.fields import Field 
     3from django.contrib.gis.db.models.proxy import GeometryProxy 
    34from django.contrib.gis.db.models.postgis import POSTGIS_TERMS, quotename 
    45from django.contrib.gis.oldforms import WKTField 
     
    8788            return post_sql 
    8889 
     90    def _post_delete_sql(self, style, db_table): 
     91        "Drops the geometry column." 
     92        sql = style.SQL_KEYWORD('SELECT ') + \ 
     93            style.SQL_KEYWORD('DropGeometryColumn') + '(' + \ 
     94            style.SQL_TABLE(quotename(db_table)) + ', ' + \ 
     95            style.SQL_FIELD(quotename(self.column)) +  ');' 
     96        return sql 
     97 
    8998    def contribute_to_class(self, cls, name): 
    9099        super(GeometryField, self).contribute_to_class(cls, name) 
     100 
     101        # setup for lazy-instantiated GEOSGeometry objects 
     102        setattr(cls, self.attname, GeometryProxy(self)) 
    91103 
    92104        # Adding needed accessor functions 
  • django/branches/gis/django/contrib/gis/db/models/__init__.py

    r5008 r5657  
    1515 
    1616# The geographic mixin class. 
    17 from GeoMixin import GeoMixin 
     17from mixin import GeoMixin 
  • django/branches/gis/django/contrib/gis/db/models/mixin.py

    r5448 r5657  
    11# GEOS Routines 
     2from warnings import warn 
    23from django.contrib.gis.geos import GEOSGeometry, hex_to_wkt, centroid, area 
    34from django.contrib.gis.gdal import OGRGeometry, SpatialReference 
     
    1213    def _get_GEOM_geos(self, field): 
    1314        "Returns a GEOS Python object for the geometry." 
    14         return GEOSGeometry(getattr(self, field.attname), 'hex') 
     15        warn("use model.%s" % field.attname, DeprecationWarning)  
     16        return getattr(self, field.attname) 
    1517 
    1618    def _get_GEOM_ogr(self, field, srid): 
     
    2123    def _get_GEOM_srid(self, srid): 
    2224        "Returns the spatial reference identifier (SRID) of the geometry." 
     25        warn("use model.geometry_field.srid", DeprecationWarning) 
    2326        return srid 
    2427 
     
    2932    def _get_GEOM_wkt(self, field): 
    3033        "Returns the WKT of the geometry." 
    31         hex = getattr(self, field.attname) 
    32         return hex_to_wkt(hex) 
     34        warn("use model.%s.centroid.wkt" % field.attname, DeprecationWarning)  
     35        return getattr(self, field.attname).wkt 
    3336 
    3437    def _get_GEOM_centroid(self, field): 
    3538        "Returns the centroid of the geometry, in WKT." 
    36         hex = getattr(self, field.attname) 
    37         return centroid(hex) 
     39        warn("use model.%s.centroid.wkt" % field.attname, DeprecationWarning)  
     40        return getattr(self, field.attname).centroid.wkt 
    3841     
    3942    def _get_GEOM_area(self, field): 
    4043        "Returns the area of the geometry, in projected units." 
    41         hex = getattr(self, field.attname
    42         return area(hex) 
     44        warn("use model.%s.area" % field.attname, DeprecationWarning
     45        return getattr(self, field.attname).area 
    4346 
    4447 
  • django/branches/gis/django/contrib/gis/db/models/postgis.py

    r5397 r5657  
    3939# PostGIS Geometry Functions -- most of these use GEOS. 
    4040POSTGIS_GEOMETRY_FUNCTIONS = { 
    41     'distance' : 'Distance', 
     41    #'distance' : 'Distance', -- doesn't work right now. 
    4242    'equals' : 'Equals', 
    4343    'disjoint' : 'Disjoint',