B
    ¥0H[
  ã               @   s¢   d dl mZmZmZmZ d dl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)Ú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   úkC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\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   Zextra_context)Ú	__class__r   r   r      s    zGeoAggregate.as_sqlc             C   s8   | j  d¡pt| ddƒ}| jr"d nd}| j||||d�S )NÚ	tolerancegš™™™™™©?z8%(function)s(SDOAGGRTYPE(%(expressions)s,%(tolerance)s)))Útemplater   )ÚextraÚgetÚgetattrÚ	is_extentr   )r   r   r   r   r   r   r   r   Ú	as_oracle   s    zGeoAggregate.as_oracleTc                s>   t ƒ  |||||¡}x$| ¡ D ]}t|jdƒstdƒ‚qW |S )NZ	geom_typez6Geospatial aggregates only allowed on geometry fields.)r   Úresolve_expressionZget_source_expressionsÚhasattrÚfieldÚ
ValueError)r   ÚqueryZallow_joinsZreuseZ	summarizeZfor_saveÚcÚexpr)r   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               @   s   e Zd Zd ZeZdS )r   N)r)   r*   r+   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   r-   3   s    zExtent.__init__c             C   s   |j  |¡S )N)r   Zconvert_extent)r   Úvaluer.   r   r   r   r   Úconvert_value6   s    zExtent.convert_value)r)   r*   r+   r   r    r-   r0   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3Dc                s   t ƒ j|fdtƒ i|—Ž d S )Nr   )r   r-   r   )r   r.   r   )r   r   r   r-   >   s    zExtent3D.__init__c             C   s   |j  |¡S )N)r   Zconvert_extent3d)r   r/   r.   r   r   r   r   r0   A   s    zExtent3D.convert_value)r)   r*   r+   r   r    r-   r0   r,   r   r   )r   r   r
   :   s   c               @   s   e Zd Zd ZeZdS )r   N)r)   r*   r+   r   r   r   r   r   r   r   r   E   s   c               @   s   e Zd Zd ZeZdS )r   N)r)   r*   r+   r   r   r   r   r   r   r   r   J   s   N)Z#django.contrib.gis.db.models.fieldsr   r   r   r   Zdjango.db.models.aggregatesr   Zdjango.utils.functionalr   Ú__all__r   r   r	   r
   r   r   r   r   r   r   Ú<module>   s    