o
    ó<âgK  ã                   @   s¤   d dl mZmZmZmZ d dlmZmZmZ d dl	m
Z
 g d¢ZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )ÚExtentFieldÚGeometryCollectionFieldÚGeometryFieldÚLineStringField)Ú	AggregateÚFuncÚValue)Úcached_property)ÚCollectÚExtentÚExtent3DÚMakeLineÚUnionc                       sJ   e Zd ZdZdZedd„ ƒZd‡ fdd„	Zdd„ Z	d‡ fd
d„	Z	‡  Z
S )ÚGeoAggregateNFc                 C   s   |   | jd jj¡S )Nr   )Úoutput_field_classÚsource_expressionsÚoutput_fieldÚsrid)Úself© r   úZ/var/www/html/venv/lib/python3.10/site-packages/django/contrib/gis/db/models/aggregates.pyr      s   zGeoAggregate.output_fieldc                    s4   |j  | ¡ tƒ j||fd|p|j  | j¡i|¤ŽS )NÚfunction)ÚopsÚcheck_expression_supportÚsuperÚas_sqlÚspatial_aggregate_nameÚname)r   ÚcompilerÚ
connectionr   Úextra_context©Ú	__class__r   r   r      s   þýüzGeoAggregate.as_sqlc                 K   s’   | j s?| j d¡pt| ddƒ}|  ¡ }|  ¡ }| ¡  tg |¢t|ƒ‘R d| j	dœŽ}|| j
g}| |¡ |j||fi |¤ŽS | j||fi |¤ŽS )NÚ	tolerancegš™™™™™©?ÚSDOAGGRTYPE)r   r   )Ú	is_extentÚextraÚgetÚgetattrÚcopyÚget_source_expressionsÚpopr   r   r   ÚfilterÚset_source_expressionsr   )r   r   r   r    r#   Úcloner   Úspatial_type_exprr   r   r   Ú	as_oracle    s"   ÿþü

zGeoAggregate.as_oracleTc                    s8   t ƒ  |||||¡}| ¡ D ]}t|dƒstdƒ‚q|S )NÚ	geom_typez6Geospatial aggregates only allowed on geometry fields.)r   Úresolve_expressionÚget_source_fieldsÚhasattrÚ
ValueError)r   ÚqueryÚallow_joinsÚreuseÚ	summarizeÚfor_saveÚcÚfieldr!   r   r   r2   1   s   
ÿÿzGeoAggregate.resolve_expression©N)NTNFF)Ú__name__Ú
__module__Ú__qualname__r   r%   r	   r   r   r0   r2   Ú__classcell__r   r   r!   r   r      s    
ÿr   c                   @   ó   e Zd Zd ZeZdS )r
   N)r>   r?   r@   r   r   r   r   r   r   r   r
   =   ó    r
   c                       ó,   e Zd Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r   Ú2Dc                    ó   t ƒ j|fdtƒ i|¤Ž d S ©Nr   ©r   Ú__init__r   ©r   Ú
expressionr&   r!   r   r   rI   F   ó   zExtent.__init__c                 C   ó   |j  |¡S r=   )r   Úconvert_extent©r   ÚvaluerK   r   r   r   r   Úconvert_valueI   ó   zExtent.convert_value©r>   r?   r@   r   r%   rI   rQ   rA   r   r   r!   r   r   B   ó
    r   c                       rD   )r   Ú3Dc                    rF   rG   rH   rJ   r!   r   r   rI   Q   rL   zExtent3D.__init__c                 C   rM   r=   )r   Úconvert_extent3drO   r   r   r   rQ   T   rR   zExtent3D.convert_valuerS   r   r   r!   r   r   M   rT   r   c                   @   rB   )r   N)r>   r?   r@   r   r   r   r   r   r   r   r   X   rC   r   c                   @   rB   )r   N)r>   r?   r@   r   r   r   r   r   r   r   r   ]   rC   r   N)Ú#django.contrib.gis.db.models.fieldsr   r   r   r   Údjango.db.modelsr   r   r   Údjango.utils.functionalr	   Ú__all__r   r
   r   r   r   r   r   r   r   r   Ú<module>   s    0