PageRenderTime 30ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/django/contrib/gis/db/backends/spatialite/models.py

https://code.google.com/p/mango-py/
Python | 60 lines | 55 code | 1 blank | 4 comment | 0 complexity | 7db741a1f5a9a9c7d16088091717cf25 MD5 | raw file
 1"""
 2 The GeometryColumns and SpatialRefSys models for the SpatiaLite backend.
 3"""
 4from django.db import models
 5from django.contrib.gis.db.backends.base import SpatialRefSysMixin
 6
 7class GeometryColumns(models.Model):
 8    """
 9    The 'geometry_columns' table from SpatiaLite.
10    """
11    f_table_name = models.CharField(max_length=256)
12    f_geometry_column = models.CharField(max_length=256)
13    type = models.CharField(max_length=30)
14    coord_dimension = models.IntegerField()
15    srid = models.IntegerField(primary_key=True)
16    spatial_index_enabled = models.IntegerField()
17
18    class Meta:
19        db_table = 'geometry_columns'
20        managed = False
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 'f_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 'f_geometry_column'
37
38    def __unicode__(self):
39        return "%s.%s - %dD %s field (SRID: %d)" % \
40               (self.f_table_name, self.f_geometry_column,
41                self.coord_dimension, self.type, self.srid)
42
43class SpatialRefSys(models.Model, SpatialRefSysMixin):
44    """
45    The 'spatial_ref_sys' table from SpatiaLite.
46    """
47    srid = models.IntegerField(primary_key=True)
48    auth_name = models.CharField(max_length=256)
49    auth_srid = models.IntegerField()
50    ref_sys_name = models.CharField(max_length=256)
51    proj4text = models.CharField(max_length=2048)
52
53    @property
54    def wkt(self):
55        from django.contrib.gis.gdal import SpatialReference
56        return SpatialReference(self.proj4text).wkt
57
58    class Meta:
59        db_table = 'spatial_ref_sys'
60        managed = False