Skip to main content

GeoAggregate

This class provides a base for geospatial aggregate functions, ensuring that operations are performed exclusively on geometry fields. It handles the resolution of spatial output fields based on SRID and manages the translation of aggregate expressions into database-specific SQL, including specialized support for Oracle spatial types.

Attributes

AttributeTypeDescription
functionstringThe SQL aggregate function name to be used for the geospatial operation.
is_extentboolean = falseBoolean flag indicating if the aggregate operation represents a bounding box extent, which bypasses specific Oracle spatial type wrapping.

Methods


output_field()

@classmethod
def output_field() - > [Field](../../../../../forms/fields/field.md?sid=django_forms_fields_field)

Determines the appropriate geometry field type for the aggregate result based on the SRID of the source expression.

Returns

TypeDescription
[Field](../../../../../forms/fields/field.md?sid=django_forms_fields_field)An instance of the output field class initialized with the spatial reference identifier (SRID) of the input data.

as_sql()

@classmethod
def as_sql(
compiler: [SQLCompiler](../../../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler),
connection: [DatabaseWrapper](../../../../../db/backends/sqlite3/base/databasewrapper.md?sid=django_db_backends_sqlite3_base_databasewrapper),
function: string = null
) - > tuple

Generates the SQL fragment for the geospatial aggregate, ensuring the backend supports the expression and using the spatial-specific aggregate name.

Parameters

NameTypeDescription
compiler[SQLCompiler](../../../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler)The query compiler instance responsible for generating the final SQL string.
connection[DatabaseWrapper](../../../../../db/backends/sqlite3/base/databasewrapper.md?sid=django_db_backends_sqlite3_base_databasewrapper)The current database connection object used to check spatial support and retrieve backend-specific aggregate names.
functionstring = nullAn optional override for the SQL aggregate function name; defaults to the backend's spatial aggregate name.

Returns

TypeDescription
tupleA tuple containing the SQL string and the list of parameters to be bound to the query.

as_oracle()

@classmethod
def as_oracle(
compiler: [SQLCompiler](../../../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler),
connection: [DatabaseWrapper](../../../../../db/backends/sqlite3/base/databasewrapper.md?sid=django_db_backends_sqlite3_base_databasewrapper)
) - > tuple

Provides Oracle-specific SQL generation, wrapping non-extent aggregates in SDOAGGRTYPE with a defined tolerance level.

Parameters

NameTypeDescription
compiler[SQLCompiler](../../../../../db/models/sql/compiler/sqlcompiler.md?sid=django_db_models_sql_compiler_sqlcompiler)The query compiler instance used to compile the modified Oracle expression.
connection[DatabaseWrapper](../../../../../db/backends/sqlite3/base/databasewrapper.md?sid=django_db_backends_sqlite3_base_databasewrapper)The Oracle database connection object.

Returns

TypeDescription
tupleThe SQL fragment and parameters formatted specifically for Oracle's spatial engine.

resolve_expression()

@classmethod
def resolve_expression(
query: [Query](../../../../../db/models/sql/query/query.md?sid=django_db_models_sql_query_query) = null,
allow_joins: boolean = true,
reuse: set = null,
summarize: boolean = false,
for_save: boolean = false
) - > [Expression](../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression)

Validates that the aggregate is being applied to geometry fields and prepares the expression for use in a query.

Parameters

NameTypeDescription
query[Query](../../../../../db/models/sql/query/query.md?sid=django_db_models_sql_query_query) = nullThe current query object being constructed.
allow_joinsboolean = trueWhether the expression resolution is permitted to introduce joins into the query.
reuseset = nullA set of reusable joins to optimize query performance.
summarizeboolean = falseIndicates if the expression is part of an aggregate or summary clause.
for_saveboolean = falseIndicates if the expression is being resolved for a database save operation.

Returns

TypeDescription
[Expression](../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression)The resolved expression object ready for SQL compilation.