|
1 """ |
|
2 The GeometryColumns and SpatialRefSys models for the Oracle spatial |
|
3 backend. |
|
4 |
|
5 It should be noted that Oracle Spatial does not have database tables |
|
6 named according to the OGC standard, so the closest analogs are used. |
|
7 For example, the `USER_SDO_GEOM_METADATA` is used for the GeometryColumns |
|
8 model and the `SDO_COORD_REF_SYS` is used for the SpatialRefSys model. |
|
9 """ |
|
10 from django.contrib.gis.db import models |
|
11 from django.contrib.gis.db.models.fields import GeometryField |
|
12 from django.contrib.gis.db.backends.base import SpatialRefSysMixin |
|
13 |
|
14 class GeometryColumns(models.Model): |
|
15 "Maps to the Oracle USER_SDO_GEOM_METADATA table." |
|
16 table_name = models.CharField(max_length=32) |
|
17 column_name = models.CharField(max_length=1024) |
|
18 srid = models.IntegerField(primary_key=True) |
|
19 # TODO: Add support for `diminfo` column (type MDSYS.SDO_DIM_ARRAY). |
|
20 class Meta: |
|
21 db_table = 'USER_SDO_GEOM_METADATA' |
|
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 '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 'column_name' |
|
39 |
|
40 def __unicode__(self): |
|
41 return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid) |
|
42 |
|
43 class SpatialRefSys(models.Model, SpatialRefSysMixin): |
|
44 "Maps to the Oracle MDSYS.CS_SRS table." |
|
45 cs_name = models.CharField(max_length=68) |
|
46 srid = models.IntegerField(primary_key=True) |
|
47 auth_srid = models.IntegerField() |
|
48 auth_name = models.CharField(max_length=256) |
|
49 wktext = models.CharField(max_length=2046) |
|
50 # Optional geometry representing the bounds of this coordinate |
|
51 # system. By default, all are NULL in the table. |
|
52 cs_bounds = models.PolygonField(null=True) |
|
53 objects = models.GeoManager() |
|
54 |
|
55 class Meta: |
|
56 db_table = 'CS_SRS' |
|
57 managed = False |
|
58 |
|
59 @property |
|
60 def wkt(self): |
|
61 return self.wktext |
|
62 |
|
63 @classmethod |
|
64 def wkt_col(cls): |
|
65 return 'wktext' |