app/django/contrib/gis/db/backend/oracle/models.py
changeset 323 ff1a9aa48cfd
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
       
     1 """
       
     2  The GeometryColumns and SpatialRefSys models for the Oracle spatial
       
     3  backend.
       
     4 
       
     5  It should be noted that Oracle Spatial does not have database tables
       
     6  named according to the OGC standard, so the closest analogs are used.
       
     7  For example, the `USER_SDO_GEOM_METADATA` is used for the GeometryColumns
       
     8  model and the `SDO_COORD_REF_SYS` is used for the SpatialRefSys model.
       
     9 """
       
    10 from django.db import models
       
    11 from django.contrib.gis.models import SpatialRefSysMixin
       
    12 
       
    13 class GeometryColumns(models.Model):
       
    14     "Maps to the Oracle USER_SDO_GEOM_METADATA table."
       
    15     table_name = models.CharField(max_length=32)
       
    16     column_name = models.CharField(max_length=1024)
       
    17     srid = models.IntegerField(primary_key=True)
       
    18     # TODO: Add support for `diminfo` column (type MDSYS.SDO_DIM_ARRAY).
       
    19     class Meta:
       
    20         db_table = 'USER_SDO_GEOM_METADATA'
       
    21 
       
    22     @classmethod
       
    23     def table_name_col(cls):
       
    24         """
       
    25         Returns the name of the metadata column used to store the 
       
    26         the feature table name.
       
    27         """
       
    28         return 'table_name'
       
    29 
       
    30     @classmethod
       
    31     def geom_col_name(cls):
       
    32         """
       
    33         Returns the name of the metadata column used to store the 
       
    34         the feature geometry column.
       
    35         """
       
    36         return 'column_name'
       
    37 
       
    38     def __unicode__(self):
       
    39         return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid)
       
    40 
       
    41 class SpatialRefSys(models.Model, SpatialRefSysMixin):
       
    42     "Maps to the Oracle MDSYS.CS_SRS table."
       
    43     cs_name = models.CharField(max_length=68)
       
    44     srid = models.IntegerField(primary_key=True)
       
    45     auth_srid = models.IntegerField()
       
    46     auth_name = models.CharField(max_length=256)
       
    47     wktext = models.CharField(max_length=2046)
       
    48     #cs_bounds = models.GeometryField()
       
    49 
       
    50     class Meta:
       
    51         # TODO: Figure out way to have this be MDSYS.CS_SRS without
       
    52         #  having django's quoting mess up the SQL.
       
    53         db_table = 'CS_SRS'
       
    54 
       
    55     @property
       
    56     def wkt(self):
       
    57         return self.wktext
       
    58 
       
    59     @classmethod
       
    60     def wkt_col(cls):
       
    61         return 'wktext'