|
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 """ |
|
31 Returns the name of the metadata column used to store the |
|
32 the feature table name. |
|
33 """ |
|
34 return 'f_table_name' |
|
35 |
|
36 @classmethod |
|
37 def geom_col_name(cls): |
|
38 """ |
|
39 Returns the name of the metadata column used to store the |
|
40 the feature geometry column. |
|
41 """ |
|
42 return 'f_geometry_column' |
|
43 |
|
44 def __unicode__(self): |
|
45 return "%s.%s - %dD %s field (SRID: %d)" % \ |
|
46 (self.f_table_name, self.f_geometry_column, |
|
47 self.coord_dimension, self.type, self.srid) |
|
48 |
|
49 class SpatialRefSys(models.Model, SpatialRefSysMixin): |
|
50 """ |
|
51 The 'spatial_ref_sys' table from PostGIS. See the PostGIS |
|
52 documentaiton at Ch. 4.2.1. |
|
53 """ |
|
54 srid = models.IntegerField(primary_key=True) |
|
55 auth_name = models.CharField(max_length=256) |
|
56 auth_srid = models.IntegerField() |
|
57 srtext = models.CharField(max_length=2048) |
|
58 proj4text = models.CharField(max_length=2048) |
|
59 |
|
60 class Meta: |
|
61 db_table = 'spatial_ref_sys' |
|
62 |
|
63 @property |
|
64 def wkt(self): |
|
65 return self.srtext |
|
66 |
|
67 @classmethod |
|
68 def wkt_col(cls): |
|
69 return 'srtext' |