3
©ôÁg  ã               @   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 | jd jjƒS )Nr   )Úoutput_field_classZsource_expressionsÚoutput_fieldZsrid)Úself© r   úe/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/contrib/gis/db/models/aggregates.pyr      s    zGeoAggregate.output_fieldc                s4   |j j| ƒ tƒ j||fd|p*|j 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jdƒpt| ddƒ}| jƒ }|j| jƒ 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 ƒ j|||||ƒ}x$|jƒ D ]}t|jdƒstdƒ‚qW |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Ú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/   r0   r   r   r   r   r   r   r   r	   1   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   r2   :   s    zExtent.__init__c             C   s   |j j|ƒS )N)r   Zconvert_extent)r   Úvaluer3   r   r   r   r   Úconvert_value=   s    zExtent.convert_value)r.   r/   r0   r   r   r2   r5   r1   r   r   )r   r   r
   6   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   r2   r   )r   r3   r    )r   r   r   r2   E   s    zExtent3D.__init__c             C   s   |j j|ƒS )N)r   Zconvert_extent3d)r   r4   r3   r   r   r   r   r5   H   s    zExtent3D.convert_value)r.   r/   r0   r   r   r2   r5   r1   r   r   )r   r   r   A   s   c               @   s   e Zd Zd ZeZdS )r   N)r.   r/   r0   r   r   r   r   r   r   r   r   L   s   c               @   s   e Zd Zd ZeZdS )r   N)r.   r/   r0   r   r   r   r   r   r   r   r   Q   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   '