U
    f                     @   sZ   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ G dd dZdS )	    )GeometryField)Distance)Area)NotSupportedError)cached_propertyc                !       s  e Zd ZdZdZdZdZdZdZdZ	e
dd ZdZdZi Zdd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(h!ZdZd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Z fd5d6Zd7d8 Zd9d: Zd;d< Zd=d> ZeeZ fd?d@ZdAdB Z dCdD Z!dEdF Z"  Z#S )GBaseSpatialOperationsFN%sc                 C   s   | j S N)selectself r   R/tmp/pip-unpacked-wheel-_jot26k8/django/contrib/gis/db/backends/base/operations.pyselect_extent   s    z#BaseSpatialOperations.select_extentr    r   Z	AsGeoJSONZAsGMLZAsKMLZAsSVGZAzimuthZBoundingCircleZCentroidZ
Differencer   ZEnvelopeZFromWKBZFromWKTZGeoHashZGeometryDistanceZIntersectionZIsEmptyZIsValidZLengthZLineLocatePointZ	MakeValidZMemSizeZNumGeometriesZ	NumPointsZ	PerimeterZPointOnSurfaceZReverseZScaleZ
SnapToGridZSymDifference	TransformZ	TranslateUnionc                 C   s   t dd S )Nz:Aggregate extent not implemented for this spatial backend.NotImplementedErrorr   Zboxsridr   r   r   convert_extentM   s    z$BaseSpatialOperations.convert_extentc                 C   s   t dd S )Nz=Aggregate 3D extent not implemented for this spatial backend.r   r   r   r   r   convert_extent3dR   s    z&BaseSpatialOperations.convert_extent3dc                 C   s   d| S )Nz'%s'r   )r   namer   r   r   geo_quote_nameX   s    z$BaseSpatialOperations.geo_quote_namec                 C   s   t ddS )zh
        Return the database column type for the geometry field on
        the spatial backend.
        zGsubclasses of BaseSpatialOperations must provide a geo_db_type() methodNr   )r   fr   r   r   geo_db_type\   s    z!BaseSpatialOperations.geo_db_typec                 C   s   t ddS )zu
        Return the distance parameters for the given geometry field,
        lookup value, and lookup type.
        z:Distance operations not available on this spatial backend.Nr   )r   r   valueZlookup_typer   r   r   get_distancee   s    z"BaseSpatialOperations.get_distancec                 C   s   dd }t |dr6||j|r2d| d|jf S dS |||r\d| d| j|j|jf S | jjjrvd| j|jf S d	| j S d
S )a  
        Return the placeholder for the given geometry field with the given
        value.  Depending on the spatial backend, the placeholder may contain a
        stored procedure call to the transformation function of the spatial
        backend.
        c                 S   s   | d k	o| j |j kS r	   )r   )r   fieldr   r   r   transform_valuev   s    zCBaseSpatialOperations.get_geom_placeholder.<locals>.transform_valueZas_sqlz%s(%%s, %s)r   r   z%s(%s(%%s,%s), %s)z
%s(%%s,%s)z%s(%%s)N)hasattroutput_fieldspatial_function_namer   	from_text
connectionfeaturesZhas_spatialrefsys_table)r   r   r   compilerr    r   r   r   get_geom_placeholdern   s     



z*BaseSpatialOperations.get_geom_placeholderc                    s*   t || jrtd|j t | d S )NzA%s spatial aggregation is not supported by this database backend.)
isinstancedisallowed_aggregatesr   r   supercheck_expression_supportr   
expression	__class__r   r   r,      s    z.BaseSpatialOperations.check_expression_supportc                 C   s   t dd S )Nz;Aggregate support not implemented for this spatial backend.r   )r   Zagg_namer   r   r   spatial_aggregate_name   s    z,BaseSpatialOperations.spatial_aggregate_namec                 C   s*   || j krtd| | j|| j| S )Nz-This backend doesn't support the %s function.)unsupported_functionsr   function_namesgetgeom_func_prefix)r   	func_namer   r   r   r#      s
    
z+BaseSpatialOperations.spatial_function_namec                 C   s   t dd S )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.r   r   r   r   r   geometry_columns   s    z&BaseSpatialOperations.geometry_columnsc                 C   s   t dd S )NzKsubclasses of BaseSpatialOperations must a provide spatial_ref_sys() methodr   r   r   r   r   spatial_ref_sys   s    z%BaseSpatialOperations.spatial_ref_sysc                    s,   t  |}t|jtr(|| | |S r	   )r+   get_db_convertersr)   r"   r   appendget_geometry_converter)r   r.   
convertersr/   r   r   r9      s    z'BaseSpatialOperations.get_db_convertersc                 C   s   t dd S )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.r   r-   r   r   r   r;      s    z,BaseSpatialOperations.get_geometry_converterc                 C   sB   | | jr$| jjjrdS tdn|| j}|r>t|S d S )NZsq_mz2Area on geodetic coordinate systems not supported.)geodeticr%   r&   Zsupports_area_geodeticr   
units_nameAreaMeasureunit_attname)r   r   r>   r   r   r   get_area_att_for_field   s    
z,BaseSpatialOperations.get_area_att_for_fieldc                 C   s>   d }| | jr | jjjr:d}n|| j}|r:t|}|S )Nm)r=   r%   r&   Zsupports_distance_geodeticr>   DistanceMeasurer@   )r   r   Zdist_attZunitsr   r   r   get_distance_att_for_field   s    

z0BaseSpatialOperations.get_distance_att_for_field)$__name__
__module____qualname__ZpostgisZ
spatialiteZmariadbZmysqloracleZspatial_versionr
   r   r   r*   r5   r3   r2   r$   r   r   r   r   r   r(   r,   r1   r#   r7   r8   staticmethodr   Zdistance_expr_for_lookupr9   r;   rA   rD   __classcell__r   r   r/   r   r   	   s~   
%		r   N)Zdjango.contrib.gis.db.modelsr   Z&django.contrib.gis.db.models.functionsr   Zdjango.contrib.gis.measurer   r?   rC   Z	django.dbr   Zdjango.utils.functionalr   r   r   r   r   r   <module>   s   