|
1 """ |
|
2 The GeometryColumns and SpatialRefSys models for the PostGIS backend. |
|
3 """ |
|
4 from django.db import models |
|
5 |
|
6 class GeometryColumns(models.Model): |
|
7 """ |
|
8 The 'geometry_columns' table from the PostGIS. See the PostGIS |
|
9 documentation at Ch. 4.2.2. |
|
10 """ |
|
11 f_table_catalog = models.CharField(max_length=256) |
|
12 f_table_schema = models.CharField(max_length=256) |
|
13 f_table_name = models.CharField(max_length=256) |
|
14 f_geometry_column = models.CharField(max_length=256) |
|
15 coord_dimension = models.IntegerField() |
|
16 srid = models.IntegerField(primary_key=True) |
|
17 type = models.CharField(max_length=30) |
|
18 |
|
19 class Meta: |
|
20 app_label = 'gis' |
|
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): |
|
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 abstract = True |
|
58 db_table = 'spatial_ref_sys' |
|
59 managed = False |
|
60 |
|
61 @property |
|
62 def wkt(self): |
|
63 return self.srtext |
|
64 |
|
65 @classmethod |
|
66 def wkt_col(cls): |
|
67 return 'srtext' |