models.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. """
  2. The GeometryColumns and SpatialRefSys models for the PostGIS backend.
  3. """
  4. from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
  5. from django.db import models
  6. from django.utils.encoding import python_2_unicode_compatible
  7. @python_2_unicode_compatible
  8. class PostGISGeometryColumns(models.Model):
  9. """
  10. The 'geometry_columns' table from the PostGIS. See the PostGIS
  11. documentation at Ch. 4.3.2.
  12. On PostGIS 2, this is a view.
  13. """
  14. f_table_catalog = models.CharField(max_length=256)
  15. f_table_schema = models.CharField(max_length=256)
  16. f_table_name = models.CharField(max_length=256)
  17. f_geometry_column = models.CharField(max_length=256)
  18. coord_dimension = models.IntegerField()
  19. srid = models.IntegerField(primary_key=True)
  20. type = models.CharField(max_length=30)
  21. class Meta:
  22. app_label = 'gis'
  23. db_table = 'geometry_columns'
  24. managed = False
  25. @classmethod
  26. def table_name_col(cls):
  27. """
  28. Returns the name of the metadata column used to store the feature table
  29. name.
  30. """
  31. return 'f_table_name'
  32. @classmethod
  33. def geom_col_name(cls):
  34. """
  35. Returns the name of the metadata column used to store the feature
  36. geometry column.
  37. """
  38. return 'f_geometry_column'
  39. def __str__(self):
  40. return "%s.%s - %dD %s field (SRID: %d)" % \
  41. (self.f_table_name, self.f_geometry_column,
  42. self.coord_dimension, self.type, self.srid)
  43. class PostGISSpatialRefSys(models.Model, SpatialRefSysMixin):
  44. """
  45. The 'spatial_ref_sys' table from PostGIS. See the PostGIS
  46. documentation at Ch. 4.2.1.
  47. """
  48. srid = models.IntegerField(primary_key=True)
  49. auth_name = models.CharField(max_length=256)
  50. auth_srid = models.IntegerField()
  51. srtext = models.CharField(max_length=2048)
  52. proj4text = models.CharField(max_length=2048)
  53. class Meta:
  54. app_label = 'gis'
  55. db_table = 'spatial_ref_sys'
  56. managed = False
  57. @property
  58. def wkt(self):
  59. return self.srtext
  60. @classmethod
  61. def wkt_col(cls):
  62. return 'srtext'