operations.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. class BaseSpatialOperations(object):
  2. """
  3. This module holds the base `BaseSpatialBackend` object, which is
  4. instantiated by each spatial database backend with the features
  5. it has.
  6. """
  7. truncate_params = {}
  8. # Quick booleans for the type of this spatial backend, and
  9. # an attribute for the spatial database version tuple (if applicable)
  10. postgis = False
  11. spatialite = False
  12. mysql = False
  13. oracle = False
  14. spatial_version = None
  15. # How the geometry column should be selected.
  16. select = None
  17. # Does the spatial database have a geometry or geography type?
  18. geography = False
  19. geometry = False
  20. area = False
  21. centroid = False
  22. difference = False
  23. distance = False
  24. distance_sphere = False
  25. distance_spheroid = False
  26. envelope = False
  27. force_rhr = False
  28. mem_size = False
  29. bounding_circle = False
  30. num_geom = False
  31. num_points = False
  32. perimeter = False
  33. perimeter3d = False
  34. point_on_surface = False
  35. polygonize = False
  36. reverse = False
  37. scale = False
  38. snap_to_grid = False
  39. sym_difference = False
  40. transform = False
  41. translate = False
  42. union = False
  43. # Aggregates
  44. collect = False
  45. extent = False
  46. extent3d = False
  47. make_line = False
  48. unionagg = False
  49. # Serialization
  50. geohash = False
  51. geojson = False
  52. gml = False
  53. kml = False
  54. svg = False
  55. # Constructors
  56. from_text = False
  57. from_wkb = False
  58. # Default conversion functions for aggregates; will be overridden if implemented
  59. # for the spatial backend.
  60. def convert_extent(self, box, srid):
  61. raise NotImplementedError('Aggregate extent not implemented for this spatial backend.')
  62. def convert_extent3d(self, box, srid):
  63. raise NotImplementedError('Aggregate 3D extent not implemented for this spatial backend.')
  64. def convert_geom(self, geom_val, geom_field):
  65. raise NotImplementedError('Aggregate method not implemented for this spatial backend.')
  66. # For quoting column values, rather than columns.
  67. def geo_quote_name(self, name):
  68. return "'%s'" % name
  69. # GeometryField operations
  70. def geo_db_type(self, f):
  71. """
  72. Returns the database column type for the geometry field on
  73. the spatial backend.
  74. """
  75. raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_type() method')
  76. def get_distance(self, f, value, lookup_type):
  77. """
  78. Returns the distance parameters for the given geometry field,
  79. lookup value, and lookup type.
  80. """
  81. raise NotImplementedError('Distance operations not available on this spatial backend.')
  82. def get_geom_placeholder(self, f, value, compiler):
  83. """
  84. Returns the placeholder for the given geometry field with the given
  85. value. Depending on the spatial backend, the placeholder may contain a
  86. stored procedure call to the transformation function of the spatial
  87. backend.
  88. """
  89. raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_placeholder() method')
  90. # Spatial SQL Construction
  91. def spatial_aggregate_sql(self, agg):
  92. raise NotImplementedError('Aggregate support not implemented for this spatial backend.')
  93. # Routines for getting the OGC-compliant models.
  94. def geometry_columns(self):
  95. raise NotImplementedError('subclasses of BaseSpatialOperations must a provide geometry_columns() method')
  96. def spatial_ref_sys(self):
  97. raise NotImplementedError('subclasses of BaseSpatialOperations must a provide spatial_ref_sys() method')