Skip to content

Instantly share code, notes, and snippets.

@claudep
Last active August 29, 2015 14:09
Show Gist options
  • Save claudep/c234e546eab00ff9fdbf to your computer and use it in GitHub Desktop.
Save claudep/c234e546eab00ff9fdbf to your computer and use it in GitHub Desktop.
Register as_<vendor>
diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py
index 690194f..2a7e1f6 100644
--- a/django/contrib/gis/db/backends/postgis/operations.py
+++ b/django/contrib/gis/db/backends/postgis/operations.py
@@ -4,6 +4,7 @@ from django.conf import settings
from django.contrib.gis.db.backends.base import BaseSpatialOperations
from django.contrib.gis.db.backends.postgis.adapter import PostGISAdapter
from django.contrib.gis.db.backends.utils import SpatialOperator
+from django.contrib.gis.db.models.sql import aggregates # .sql should disappear with 14030
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.measure import Distance
from django.core.exceptions import ImproperlyConfigured
@@ -43,6 +44,12 @@ class PostGISDistanceOperator(PostGISOperator):
return super(PostGISDistanceOperator, self).as_sql(connection, lookup, template_params, sql_params)
+class PostGISMakeLine(object):
+ def as_postgresql(self, qn, connection):
+ # Here custom behaviour
+ return super(PostGISMakeLine, self).as_sql(qn, connection)
+
+
class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = 'django.contrib.gis.db.models.sql.compiler'
name = 'postgis'
@@ -87,9 +94,17 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
'distance_lt': PostGISDistanceOperator(func='ST_Distance', op='<', geography=True),
'distance_lte': PostGISDistanceOperator(func='ST_Distance', op='<=', geography=True),
}
+ gis_aggregates = {
+ 'MakeLine': PostGISMakeLine,
+ }
def __init__(self, connection):
super(PostGISOperations, self).__init__(connection)
+ # register aggregates Mixins (will have to be moved to Base)
+ for klass_name, mixin in self.gis_aggregates.items():
+ base = getattr(aggregates, klass_name)
+ if mixin not in base.__bases__:
+ base.__bases__ = (mixin,) + base.__bases__
prefix = self.geom_func_prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment