~canonical-django/canonical-django/project-template

« back to all changes in this revision

Viewing changes to trunk/python-packages/django/contrib/gis/db/backend/postgis/models.py

  • Committer: Matthew Nuzum
  • Date: 2008-11-13 05:46:03 UTC
  • Revision ID: matthew.nuzum@canonical.com-20081113054603-v0kvr6z6xyexvqt3
adding to version control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
 The GeometryColumns and SpatialRefSys models for the PostGIS backend.
 
3
"""
 
4
from django.db import models
 
5
from django.contrib.gis.models import SpatialRefSysMixin
 
6
 
 
7
# Checking for the presence of GDAL (needed for the SpatialReference object)
 
8
from django.contrib.gis.gdal import HAS_GDAL
 
9
if HAS_GDAL:
 
10
    from django.contrib.gis.gdal import SpatialReference
 
11
 
 
12
class GeometryColumns(models.Model):
 
13
    """
 
14
    The 'geometry_columns' table from the PostGIS. See the PostGIS
 
15
    documentation at Ch. 4.2.2.
 
16
    """
 
17
    f_table_catalog = models.CharField(max_length=256)
 
18
    f_table_schema = models.CharField(max_length=256)
 
19
    f_table_name = models.CharField(max_length=256)
 
20
    f_geometry_column = models.CharField(max_length=256)
 
21
    coord_dimension = models.IntegerField()
 
22
    srid = models.IntegerField(primary_key=True)
 
23
    type = models.CharField(max_length=30)
 
24
 
 
25
    class Meta:
 
26
        db_table = 'geometry_columns'
 
27
 
 
28
    @classmethod
 
29
    def table_name_col(cls):
 
30
        "Class method for returning the table name column for this model."
 
31
        return 'f_table_name'
 
32
 
 
33
    def __unicode__(self):
 
34
        return "%s.%s - %dD %s field (SRID: %d)" % \
 
35
               (self.f_table_name, self.f_geometry_column,
 
36
                self.coord_dimension, self.type, self.srid)
 
37
 
 
38
class SpatialRefSys(models.Model, SpatialRefSysMixin):
 
39
    """
 
40
    The 'spatial_ref_sys' table from PostGIS. See the PostGIS
 
41
    documentaiton at Ch. 4.2.1.
 
42
    """
 
43
    srid = models.IntegerField(primary_key=True)
 
44
    auth_name = models.CharField(max_length=256)
 
45
    auth_srid = models.IntegerField()
 
46
    srtext = models.CharField(max_length=2048)
 
47
    proj4text = models.CharField(max_length=2048)
 
48
 
 
49
    class Meta:
 
50
        db_table = 'spatial_ref_sys'
 
51
 
 
52
    @property
 
53
    def wkt(self):
 
54
        return self.srtext
 
55
 
 
56
    @classmethod
 
57
    def wkt_col(cls):
 
58
        return 'srtext'