3
7^9
                 @   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 | jd jjS )Nr   )output_field_classZsource_expressionsoutput_fieldZsrid)self r   I/tmp/pip-build-8app2_gc/Django/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   s@   | j jdpt| dd}| jr"d nd}| j||f||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   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_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 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.   r1   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 j|S )N)r   Zconvert_extent3d)r   r0   r/   r   r   r   r   r1   A   s    zExtent3D.convert_value)r*   r+   r,   r   r!   r.   r1   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    