web/lib/django/contrib/gis/db/backends/postgis/models.py
changeset 29 cc9b7e14412b
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
       
     1 """
       
     2  The GeometryColumns and SpatialRefSys models for the PostGIS backend.
       
     3 """
       
     4 from django.db import models
       
     5 from django.contrib.gis.db.backends.base import SpatialRefSysMixin
       
     6 
       
     7 class GeometryColumns(models.Model):
       
     8     """
       
     9     The 'geometry_columns' table from the PostGIS. See the PostGIS
       
    10     documentation at Ch. 4.2.2.
       
    11     """
       
    12     f_table_catalog = models.CharField(max_length=256)
       
    13     f_table_schema = models.CharField(max_length=256)
       
    14     f_table_name = models.CharField(max_length=256)
       
    15     f_geometry_column = models.CharField(max_length=256)
       
    16     coord_dimension = models.IntegerField()
       
    17     srid = models.IntegerField(primary_key=True)
       
    18     type = models.CharField(max_length=30)
       
    19 
       
    20     class Meta:
       
    21         db_table = 'geometry_columns'
       
    22         managed = False
       
    23 
       
    24     @classmethod
       
    25     def table_name_col(cls):
       
    26         """
       
    27         Returns the name of the metadata column used to store the
       
    28         the feature table name.
       
    29         """
       
    30         return 'f_table_name'
       
    31 
       
    32     @classmethod
       
    33     def geom_col_name(cls):
       
    34         """
       
    35         Returns the name of the metadata column used to store the
       
    36         the feature geometry column.
       
    37         """
       
    38         return 'f_geometry_column'
       
    39 
       
    40     def __unicode__(self):
       
    41         return "%s.%s - %dD %s field (SRID: %d)" % \
       
    42                (self.f_table_name, self.f_geometry_column,
       
    43                 self.coord_dimension, self.type, self.srid)
       
    44 
       
    45 class SpatialRefSys(models.Model, SpatialRefSysMixin):
       
    46     """
       
    47     The 'spatial_ref_sys' table from PostGIS. See the PostGIS
       
    48     documentaiton at Ch. 4.2.1.
       
    49     """
       
    50     srid = models.IntegerField(primary_key=True)
       
    51     auth_name = models.CharField(max_length=256)
       
    52     auth_srid = models.IntegerField()
       
    53     srtext = models.CharField(max_length=2048)
       
    54     proj4text = models.CharField(max_length=2048)
       
    55 
       
    56     class Meta:
       
    57         db_table = 'spatial_ref_sys'
       
    58         managed = False
       
    59 
       
    60     @property
       
    61     def wkt(self):
       
    62         return self.srtext
       
    63 
       
    64     @classmethod
       
    65     def wkt_col(cls):
       
    66         return 'srtext'