You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

features.py 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import re
  2. from django.contrib.gis.db.models import aggregates
  3. class BaseSpatialFeatures:
  4. gis_enabled = True
  5. # Does the database contain a SpatialRefSys model to store SRID information?
  6. has_spatialrefsys_table = True
  7. # Does the backend support the django.contrib.gis.utils.add_srs_entry() utility?
  8. supports_add_srs_entry = True
  9. # Does the backend introspect GeometryField to its subtypes?
  10. supports_geometry_field_introspection = True
  11. # Does the backend support storing 3D geometries?
  12. supports_3d_storage = False
  13. # Reference implementation of 3D functions is:
  14. # https://postgis.net/docs/PostGIS_Special_Functions_Index.html#PostGIS_3D_Functions
  15. supports_3d_functions = False
  16. # Does the database support SRID transform operations?
  17. supports_transform = True
  18. # Do geometric relationship operations operate on real shapes (or only on bounding boxes)?
  19. supports_real_shape_operations = True
  20. # Can geometry fields be null?
  21. supports_null_geometries = True
  22. # Are empty geometries supported?
  23. supports_empty_geometries = False
  24. # Can the function be applied on geodetic coordinate systems?
  25. supports_distance_geodetic = True
  26. supports_length_geodetic = True
  27. supports_perimeter_geodetic = False
  28. supports_area_geodetic = True
  29. # Is the database able to count vertices on polygons (with `num_points`)?
  30. supports_num_points_poly = True
  31. # The following properties indicate if the database backend support
  32. # certain lookups (dwithin, left and right, relate, ...)
  33. supports_left_right_lookups = False
  34. # Does the database have raster support?
  35. supports_raster = False
  36. # Does the database support a unique index on geometry fields?
  37. supports_geometry_field_unique_index = True
  38. @property
  39. def supports_bbcontains_lookup(self):
  40. return 'bbcontains' in self.connection.ops.gis_operators
  41. @property
  42. def supports_contained_lookup(self):
  43. return 'contained' in self.connection.ops.gis_operators
  44. @property
  45. def supports_crosses_lookup(self):
  46. return 'crosses' in self.connection.ops.gis_operators
  47. @property
  48. def supports_distances_lookups(self):
  49. return self.has_Distance_function
  50. @property
  51. def supports_dwithin_lookup(self):
  52. return 'dwithin' in self.connection.ops.gis_operators
  53. @property
  54. def supports_relate_lookup(self):
  55. return 'relate' in self.connection.ops.gis_operators
  56. @property
  57. def supports_isvalid_lookup(self):
  58. return self.has_IsValid_function
  59. # Is the aggregate supported by the database?
  60. @property
  61. def supports_collect_aggr(self):
  62. return aggregates.Collect not in self.connection.ops.disallowed_aggregates
  63. @property
  64. def supports_extent_aggr(self):
  65. return aggregates.Extent not in self.connection.ops.disallowed_aggregates
  66. @property
  67. def supports_make_line_aggr(self):
  68. return aggregates.MakeLine not in self.connection.ops.disallowed_aggregates
  69. @property
  70. def supports_union_aggr(self):
  71. return aggregates.Union not in self.connection.ops.disallowed_aggregates
  72. def __getattr__(self, name):
  73. m = re.match(r'has_(\w*)_function$', name)
  74. if m:
  75. func_name = m.group(1)
  76. return func_name not in self.connection.ops.unsupported_functions
  77. raise AttributeError