MCPcopy
hub / github.com/django/django / as_postgresql

Method as_postgresql

django/contrib/gis/db/models/functions.py:322–351  ·  view source on GitHub ↗
(self, compiler, connection, **extra_context)

Source from the content-addressed store, hash-verified

320 super().__init__(*expressions, **extra)
321
322 def as_postgresql(self, compiler, connection, **extra_context):
323 clone = self.copy()
324 function = None
325 expr2 = clone.source_expressions[1]
326 geography = self.source_is_geography()
327 if expr2.output_field.geography != geography:
328 if isinstance(expr2, Value):
329 expr2.output_field.geography = geography
330 else:
331 clone.source_expressions[1] = Cast(
332 expr2,
333 GeometryField(srid=expr2.output_field.srid, geography=geography),
334 )
335
336 if not geography and self.geo_field.geodetic(connection):
337 # Geometry fields with geodetic (lon/lat) coordinates need special
338 # distance functions.
339 if self.spheroid:
340 # DistanceSpheroid is more accurate and resource intensive than
341 # DistanceSphere.
342 function = connection.ops.spatial_function_name("DistanceSpheroid")
343 # Replace boolean param by the real spheroid of the base field
344 clone.source_expressions.append(
345 Value(self.geo_field.spheroid(connection))
346 )
347 else:
348 function = connection.ops.spatial_function_name("DistanceSphere")
349 return super(Distance, clone).as_sql(
350 compiler, connection, function=function, **extra_context
351 )
352
353 def as_sqlite(self, compiler, connection, **extra_context):
354 if self.geo_field.geodetic(connection):

Callers

nothing calls this directly

Calls 10

CastClass · 0.90
GeometryFieldClass · 0.90
ValueClass · 0.90
source_is_geographyMethod · 0.80
geodeticMethod · 0.80
spatial_function_nameMethod · 0.80
copyMethod · 0.45
appendMethod · 0.45
spheroidMethod · 0.45
as_sqlMethod · 0.45

Tested by

no test coverage detected