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
| Attribute | Type | Description |
|---|---|---|
| function | string | The SQL aggregate function name to be used for the geospatial operation. |
| is_extent | boolean = false | Boolean 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
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| 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. |
| function | string = null | An optional override for the SQL aggregate function name; defaults to the backend's spatial aggregate name. |
Returns
| Type | Description |
|---|---|
tuple | A 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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
tuple | The 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
| Name | Type | Description |
|---|---|---|
| query | [Query](../../../../../db/models/sql/query/query.md?sid=django_db_models_sql_query_query) = null | The current query object being constructed. |
| allow_joins | boolean = true | Whether the expression resolution is permitted to introduce joins into the query. |
| reuse | set = null | A set of reusable joins to optimize query performance. |
| summarize | boolean = false | Indicates if the expression is part of an aggregate or summary clause. |
| for_save | boolean = false | Indicates if the expression is being resolved for a database save operation. |
Returns
| Type | Description |
|---|---|
[Expression](../../../../../db/models/expressions/expression.md?sid=django_db_models_expressions_expression) | The resolved expression object ready for SQL compilation. |