U
    mÇf™  ã                   @   s¦   d dl mZmZmZmZ d dlmZmZ d dlm	Z	 dddddg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   úK/tmp/pip-unpacked-wheel-siwebuq3/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   sj   | j sZ| j d¡pt| ddƒ}|  ¡ }| |  ¡ t|ƒf•¡ d}|j||fd|i|—ŽS | j||f|Ž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(   0   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                   @   s   e Zd Zd ZeZdS )r	   N)r/   r0   r1   r   r   r   r   r   r   r   r	   <   s   c                       s,   e Zd Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r
   Z2Dc                    s   t ƒ j|fdtƒ i|—Ž d S ©Nr   ©r   Ú__init__r   ©r   Ú
expressionr!   r   r   r   r5   E   s    zExtent.__init__c                 C   s   |j  |¡S ©N)r   Zconvert_extent©r   Úvaluer7   r   r   r   r   Úconvert_valueH   s    zExtent.convert_value©r/   r0   r1   r   r    r5   r;   r2   r   r   r   r   r
   A   s   c                       s,   e Zd Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r   Z3Dc                    s   t ƒ j|fdtƒ i|—Ž d S r3   r4   r6   r   r   r   r5   P   s    zExtent3D.__init__c                 C   s   |j  |¡S r8   )r   Zconvert_extent3dr9   r   r   r   r;   S   s    zExtent3D.convert_valuer<   r   r   r   r   r   L   s   c                   @   s   e Zd Zd ZeZdS )r   N)r/   r0   r1   r   r   r   r   r   r   r   r   W   s   c                   @   s   e Zd Zd ZeZdS )r   N)r/   r0   r1   r   r   r   r   r   r   r   r   \   s   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   /