o
    úÑÐb  ã                   @   s    d dl mZmZmZmZ d dl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ÚValue)Úcached_property)ÚCollectÚExtentÚExtent3DÚMakeLineÚUnionc                       sH   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_classZsource_expressionsÚoutput_fieldZsrid)Úself© r   úf/var/www/secure340b-portal/env/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)ÚopsZcheck_expression_supportÚsuperÚas_sqlZspatial_aggregate_nameÚname)r   ÚcompilerÚ
connectionr   Úextra_context©Ú	__class__r   r   r      s   þýüzGeoAggregate.as_sqlc                 K   sp   | j s.| j d¡pt| ddƒ}|  ¡ }| g |  ¡ ¢t|ƒ‘¡ d}|j||fd|i|¤ŽS | j||fi |¤ŽS )NÚ	tolerancegš™™™™™©?z*%(function)s(SDOAGGRTYPE(%(expressions)s))Útemplate)	Ú	is_extentÚextraÚgetÚgetattrÚcopyZset_source_expressionsÚget_source_expressionsr   r   )r   r   r   r   r   Úcloner   r   r   r   Ú	as_oracle   s   ÿþzGeoAggregate.as_oracleTc                    s:   t ƒ  |||||¡}| ¡ D ]}t|jdƒstdƒ‚q|S )NZ	geom_typez6Geospatial aggregates only allowed on geometry fields.)r   Úresolve_expressionr%   ÚhasattrÚfieldÚ
ValueError)r   ÚqueryZallow_joinsZreuseZ	summarizeZfor_saveÚcÚexprr   r   r   r(   )   s   ÿzGeoAggregate.resolve_expression©N)NTNFF)Ú__name__Ú
__module__Ú__qualname__r   r    r   r   r   r'   r(   Ú__classcell__r   r   r   r   r   
   s    
r   c                   @   ó   e Zd Zd ZeZdS )r	   N)r0   r1   r2   r   r   r   r   r   r   r   r	   1   ó    r	   c                       ó,   e Zd Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r
   Z2Dc                    ó   t ƒ j|fdtƒ i|¤Ž d S ©Nr   ©r   Ú__init__r   ©r   Ú
expressionr!   r   r   r   r:   :   ó   zExtent.__init__c                 C   ó   |j  |¡S r/   )r   Zconvert_extent©r   Úvaluer<   r   r   r   r   Úconvert_value=   ó   zExtent.convert_value©r0   r1   r2   r   r    r:   rA   r3   r   r   r   r   r
   6   ó
    r
   c                       r6   )r   Z3Dc                    r7   r8   r9   r;   r   r   r   r:   E   r=   zExtent3D.__init__c                 C   r>   r/   )r   Zconvert_extent3dr?   r   r   r   rA   H   rB   zExtent3D.convert_valuerC   r   r   r   r   r   A   rD   r   c                   @   r4   )r   N)r0   r1   r2   r   r   r   r   r   r   r   r   L   r5   r   c                   @   r4   )r   N)r0   r1   r2   r   r   r   r   r   r   r   r   Q   r5   r   N)Z#django.contrib.gis.db.models.fieldsr   r   r   r   Zdjango.db.modelsr   r   Zdjango.utils.functionalr   Ú__all__r   r	   r
   r   r   r   r   r   r   r   Ú<module>   s    '