U
    Hax  ã                   @   sR   d dl mZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ G dd„ dƒZdS )	é    )ÚGeometryField)ÚDistance)ÚArear   )Ú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%hZdZd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Z‡ fd2d3„Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ ZeeƒZ‡ fd<d=„Zd>d?„ Z d@dA„ Z!dBdC„ Z"‡  Z#S )DÚBaseSpatialOperationsFNú%sc                 C   s   | j S ©N)Úselect©Úself© r   úR/tmp/pip-unpacked-wheel-3jxiddxt/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GeoHashZGeometryDistanceZIntersectionZ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_extent3   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_extent3d6   s    z&BaseSpatialOperations.convert_extent3dc                 C   s   d| S )Nz'%s'r   )r   Únamer   r   r   Úgeo_quote_name:   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_valueS   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_placeholderL   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,   h   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_nameo   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#   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_columnsx   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   
   sx   
                        ú

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
   