
v^7                 @   s   d  d l  m Z m Z m Z m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d d d d d	 g Z Gd
 d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z Gd d	   d	 e  Z d S)    )ExtentFieldGeometryCollectionFieldGeometryFieldLineStringField)Value)	Aggregate)cached_propertyCollectExtentExtent3DMakeLineUnionc                   sp   e  Z d  Z d Z d Z e d d    Z d   f d d  Z d d   Z d d	 d d d   f d
 d  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-8lau8j11/django/django/contrib/gis/db/models/aggregates.pyr      s    zGeoAggregate.output_fieldc                sA   | j  j |   t   j | | d | p: | j  j |  j  | 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  sz |  j j d  p* t |  d d  } |  j   } | j |  j   t |  f   d } | j | | d | | S|  j | | |  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                sW   t    j | | | | |  } x2 | 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)
__name__
__module____qualname__r   r   r   r   r   r&   r'   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	   2   s   c                   s:   e  Z d  Z d  Z d Z   f d d   Z d d   Z   S)r
   Z2Dc                s    t    j | d t   | d  S)Nr   )r   __init__r   )r   
expressionr    )r   r   r   r1   ;   s    zExtent.__init__c             C   s   | j  j |  S)N)r   Zconvert_extent)r   valuer2   r   r   r   r   convert_value>   s    zExtent.convert_value)r.   r/   r0   r   r   r1   r4   r   r   )r   r   r
   7   s   c                   s:   e  Z d  Z d  Z d Z   f d d   Z d d   Z   S)r   Z3Dc                s    t    j | d t   | d  S)Nr   )r   r1   r   )r   r2   r    )r   r   r   r1   F   s    zExtent3D.__init__c             C   s   | j  j |  S)N)r   Zconvert_extent3d)r   r3   r2   r   r   r   r   r4   I   s    zExtent3D.convert_value)r.   r/   r0   r   r   r1   r4   r   r   )r   r   r   B   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   M   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   R   s   N)Z#django.contrib.gis.db.models.fieldsr   r   r   r   Zdjango.db.modelsr   Zdjango.db.models.aggregatesr   Zdjango.utils.functionalr   __all__r   r	   r
   r   r   r   r   r   r   r   <module>   s   "'