|
@@ -41,9 +41,9 @@ class GeoQuerySet(QuerySet):
|
|
|
# Peforming setup here rather than in `_spatial_attribute` so that
|
|
|
# we can get the units for `AreaField`.
|
|
|
procedure_args, geo_field = self._spatial_setup('area', field_name=kwargs.get('field_name', None))
|
|
|
- s = {'procedure_args' : procedure_args,
|
|
|
- 'geo_field' : geo_field,
|
|
|
- 'setup' : False,
|
|
|
+ s = {'procedure_args': procedure_args,
|
|
|
+ 'geo_field': geo_field,
|
|
|
+ 'setup': False,
|
|
|
}
|
|
|
connection = connections[self.db]
|
|
|
backend = connection.ops
|
|
@@ -170,9 +170,9 @@ class GeoQuerySet(QuerySet):
|
|
|
options = 1
|
|
|
elif bbox:
|
|
|
options = 2
|
|
|
- s = {'desc' : 'GeoJSON',
|
|
|
- 'procedure_args' : {'precision' : precision, 'options' : options},
|
|
|
- 'procedure_fmt' : '%(geo_col)s,%(precision)s,%(options)s',
|
|
|
+ s = {'desc': 'GeoJSON',
|
|
|
+ 'procedure_args': {'precision': precision, 'options': options},
|
|
|
+ 'procedure_fmt': '%(geo_col)s,%(precision)s,%(options)s',
|
|
|
}
|
|
|
return self._spatial_attribute('geojson', s, **kwargs)
|
|
|
|
|
@@ -184,7 +184,7 @@ class GeoQuerySet(QuerySet):
|
|
|
The `precision` keyword may be used to custom the number of
|
|
|
_characters_ used in the output GeoHash, the default is 20.
|
|
|
"""
|
|
|
- s = {'desc' : 'GeoHash',
|
|
|
+ s = {'desc': 'GeoHash',
|
|
|
'procedure_args': {'precision': precision},
|
|
|
'procedure_fmt': '%(geo_col)s,%(precision)s',
|
|
|
}
|
|
@@ -196,7 +196,7 @@ class GeoQuerySet(QuerySet):
|
|
|
on each element of the GeoQuerySet.
|
|
|
"""
|
|
|
backend = connections[self.db].ops
|
|
|
- s = {'desc' : 'GML', 'procedure_args' : {'precision' : precision}}
|
|
|
+ s = {'desc': 'GML', 'procedure_args': {'precision': precision}}
|
|
|
if backend.postgis:
|
|
|
# PostGIS AsGML() aggregate function parameter order depends on the
|
|
|
# version -- uggh.
|
|
@@ -204,7 +204,7 @@ class GeoQuerySet(QuerySet):
|
|
|
s['procedure_fmt'] = '%(version)s,%(geo_col)s,%(precision)s'
|
|
|
else:
|
|
|
s['procedure_fmt'] = '%(geo_col)s,%(precision)s,%(version)s'
|
|
|
- s['procedure_args'] = {'precision' : precision, 'version' : version}
|
|
|
+ s['procedure_args'] = {'precision': precision, 'version': version}
|
|
|
|
|
|
return self._spatial_attribute('gml', s, **kwargs)
|
|
|
|
|
@@ -221,9 +221,9 @@ class GeoQuerySet(QuerySet):
|
|
|
Returns KML representation of the geometry field in a `kml`
|
|
|
attribute on each element of this GeoQuerySet.
|
|
|
"""
|
|
|
- s = {'desc' : 'KML',
|
|
|
- 'procedure_fmt' : '%(geo_col)s,%(precision)s',
|
|
|
- 'procedure_args' : {'precision' : kwargs.pop('precision', 8)},
|
|
|
+ s = {'desc': 'KML',
|
|
|
+ 'procedure_fmt': '%(geo_col)s,%(precision)s',
|
|
|
+ 'procedure_args': {'precision': kwargs.pop('precision', 8)},
|
|
|
}
|
|
|
return self._spatial_attribute('kml', s, **kwargs)
|
|
|
|
|
@@ -300,14 +300,14 @@ class GeoQuerySet(QuerySet):
|
|
|
if connections[self.db].ops.spatialite:
|
|
|
if z != 0.0:
|
|
|
raise NotImplementedError('SpatiaLite does not support 3D scaling.')
|
|
|
- s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s',
|
|
|
- 'procedure_args' : {'x' : x, 'y' : y},
|
|
|
- 'select_field' : GeomField(),
|
|
|
+ s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
|
|
|
+ 'procedure_args': {'x': x, 'y': y},
|
|
|
+ 'select_field': GeomField(),
|
|
|
}
|
|
|
else:
|
|
|
- s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
|
|
- 'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
|
|
|
- 'select_field' : GeomField(),
|
|
|
+ s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
|
|
+ 'procedure_args': {'x': x, 'y': y, 'z': z},
|
|
|
+ 'select_field': GeomField(),
|
|
|
}
|
|
|
return self._spatial_attribute('scale', s, **kwargs)
|
|
|
|
|
@@ -327,22 +327,22 @@ class GeoQuerySet(QuerySet):
|
|
|
if nargs == 1:
|
|
|
size = args[0]
|
|
|
procedure_fmt = '%(geo_col)s,%(size)s'
|
|
|
- procedure_args = {'size' : size}
|
|
|
+ procedure_args = {'size': size}
|
|
|
elif nargs == 2:
|
|
|
xsize, ysize = args
|
|
|
procedure_fmt = '%(geo_col)s,%(xsize)s,%(ysize)s'
|
|
|
- procedure_args = {'xsize' : xsize, 'ysize' : ysize}
|
|
|
+ procedure_args = {'xsize': xsize, 'ysize': ysize}
|
|
|
elif nargs == 4:
|
|
|
xsize, ysize, xorigin, yorigin = args
|
|
|
procedure_fmt = '%(geo_col)s,%(xorigin)s,%(yorigin)s,%(xsize)s,%(ysize)s'
|
|
|
- procedure_args = {'xsize' : xsize, 'ysize' : ysize,
|
|
|
- 'xorigin' : xorigin, 'yorigin' : yorigin}
|
|
|
+ procedure_args = {'xsize': xsize, 'ysize': ysize,
|
|
|
+ 'xorigin': xorigin, 'yorigin': yorigin}
|
|
|
else:
|
|
|
raise ValueError('Must provide 1, 2, or 4 arguments to `snap_to_grid`.')
|
|
|
|
|
|
- s = {'procedure_fmt' : procedure_fmt,
|
|
|
- 'procedure_args' : procedure_args,
|
|
|
- 'select_field' : GeomField(),
|
|
|
+ s = {'procedure_fmt': procedure_fmt,
|
|
|
+ 'procedure_args': procedure_args,
|
|
|
+ 'select_field': GeomField(),
|
|
|
}
|
|
|
|
|
|
return self._spatial_attribute('snap_to_grid', s, **kwargs)
|
|
@@ -362,10 +362,10 @@ class GeoQuerySet(QuerySet):
|
|
|
relative = int(bool(relative))
|
|
|
if not isinstance(precision, six.integer_types):
|
|
|
raise TypeError('SVG precision keyword argument must be an integer.')
|
|
|
- s = {'desc' : 'SVG',
|
|
|
- 'procedure_fmt' : '%(geo_col)s,%(rel)s,%(precision)s',
|
|
|
- 'procedure_args' : {'rel' : relative,
|
|
|
- 'precision' : precision,
|
|
|
+ s = {'desc': 'SVG',
|
|
|
+ 'procedure_fmt': '%(geo_col)s,%(rel)s,%(precision)s',
|
|
|
+ 'procedure_args': {'rel': relative,
|
|
|
+ 'precision': precision,
|
|
|
}
|
|
|
}
|
|
|
return self._spatial_attribute('svg', s, **kwargs)
|
|
@@ -385,14 +385,14 @@ class GeoQuerySet(QuerySet):
|
|
|
if connections[self.db].ops.spatialite:
|
|
|
if z != 0.0:
|
|
|
raise NotImplementedError('SpatiaLite does not support 3D translation.')
|
|
|
- s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s',
|
|
|
- 'procedure_args' : {'x' : x, 'y' : y},
|
|
|
- 'select_field' : GeomField(),
|
|
|
+ s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
|
|
|
+ 'procedure_args': {'x': x, 'y': y},
|
|
|
+ 'select_field': GeomField(),
|
|
|
}
|
|
|
else:
|
|
|
- s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
|
|
- 'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
|
|
|
- 'select_field' : GeomField(),
|
|
|
+ s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
|
|
+ 'procedure_args': {'x': x, 'y': y, 'z': z},
|
|
|
+ 'select_field': GeomField(),
|
|
|
}
|
|
|
return self._spatial_attribute('translate', s, **kwargs)
|
|
|
|
|
@@ -455,7 +455,7 @@ class GeoQuerySet(QuerySet):
|
|
|
(desc, connection.ops.name))
|
|
|
|
|
|
# Initializing the procedure arguments.
|
|
|
- procedure_args = {'function' : func}
|
|
|
+ procedure_args = {'function': func}
|
|
|
|
|
|
# Is there a geographic field in the model to perform this
|
|
|
# operation on?
|
|
@@ -580,7 +580,7 @@ class GeoQuerySet(QuerySet):
|
|
|
# Finally, setting the extra selection attribute with
|
|
|
# the format string expanded with the stored procedure
|
|
|
# arguments.
|
|
|
- return self.extra(select={model_att : fmt % settings['procedure_args']},
|
|
|
+ return self.extra(select={model_att: fmt % settings['procedure_args']},
|
|
|
select_params=settings['select_params'])
|
|
|
|
|
|
def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, **kwargs):
|
|
@@ -695,29 +695,29 @@ class GeoQuerySet(QuerySet):
|
|
|
if spheroid:
|
|
|
# Call to distance_spheroid() requires spheroid param as well.
|
|
|
procedure_fmt += ",'%(spheroid)s'"
|
|
|
- procedure_args.update({'function' : backend.distance_spheroid, 'spheroid' : params[1]})
|
|
|
+ procedure_args.update({'function': backend.distance_spheroid, 'spheroid': params[1]})
|
|
|
else:
|
|
|
- procedure_args.update({'function' : backend.distance_sphere})
|
|
|
+ procedure_args.update({'function': backend.distance_sphere})
|
|
|
elif length or perimeter:
|
|
|
procedure_fmt = '%(geo_col)s'
|
|
|
if not geography and geodetic and length:
|
|
|
# There's no `length_sphere`, and `length_spheroid` also
|
|
|
# works on 3D geometries.
|
|
|
procedure_fmt += ",'%(spheroid)s'"
|
|
|
- procedure_args.update({'function' : backend.length_spheroid, 'spheroid' : params[1]})
|
|
|
+ procedure_args.update({'function': backend.length_spheroid, 'spheroid': params[1]})
|
|
|
elif geom_3d and backend.postgis:
|
|
|
# Use 3D variants of perimeter and length routines on PostGIS.
|
|
|
if perimeter:
|
|
|
- procedure_args.update({'function' : backend.perimeter3d})
|
|
|
+ procedure_args.update({'function': backend.perimeter3d})
|
|
|
elif length:
|
|
|
- procedure_args.update({'function' : backend.length3d})
|
|
|
+ procedure_args.update({'function': backend.length3d})
|
|
|
|
|
|
# Setting up the settings for `_spatial_attribute`.
|
|
|
- s = {'select_field' : DistanceField(dist_att),
|
|
|
- 'setup' : False,
|
|
|
- 'geo_field' : geo_field,
|
|
|
- 'procedure_args' : procedure_args,
|
|
|
- 'procedure_fmt' : procedure_fmt,
|
|
|
+ s = {'select_field': DistanceField(dist_att),
|
|
|
+ 'setup': False,
|
|
|
+ 'geo_field': geo_field,
|
|
|
+ 'procedure_args': procedure_args,
|
|
|
+ 'procedure_fmt': procedure_fmt,
|
|
|
}
|
|
|
if geom_args:
|
|
|
s['geom_args'] = ('geom',)
|
|
@@ -736,7 +736,7 @@ class GeoQuerySet(QuerySet):
|
|
|
s = {'select_field': GeomField()}
|
|
|
if connections[self.db].ops.oracle:
|
|
|
s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s'
|
|
|
- s['procedure_args'] = {'tolerance' : tolerance}
|
|
|
+ s['procedure_args'] = {'tolerance': tolerance}
|
|
|
return self._spatial_attribute(func, s, **kwargs)
|
|
|
|
|
|
def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
|
|
@@ -746,10 +746,10 @@ class GeoQuerySet(QuerySet):
|
|
|
for geometry set-like operations (e.g., intersection, difference,
|
|
|
union, sym_difference).
|
|
|
"""
|
|
|
- s = {'geom_args' : ('geom',),
|
|
|
- 'select_field' : GeomField(),
|
|
|
- 'procedure_fmt' : '%(geo_col)s,%(geom)s',
|
|
|
- 'procedure_args' : {'geom' : geom},
|
|
|
+ s = {'geom_args': ('geom',),
|
|
|
+ 'select_field': GeomField(),
|
|
|
+ 'procedure_fmt': '%(geo_col)s,%(geom)s',
|
|
|
+ 'procedure_args': {'geom': geom},
|
|
|
}
|
|
|
if connections[self.db].ops.oracle:
|
|
|
s['procedure_fmt'] += ',%(tolerance)s'
|