a
    Kcò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h d£ZdZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡ fdd„Zdd„ Zdd„ Zdd„ Zdd„ ZeeƒZ‡ fdd „Zd!d"„ Z d#d$„ Z!d%d&„ Z"‡  Z#S )'ÚBaseSpatialOperationsFNú%sc                 C   s   | j S ©N)Úselect©Úself© r   úk/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/contrib/gis/db/backends/base/operations.pyÚselect_extent   s    z#BaseSpatialOperations.select_extentr   Ú >!   ZSymDifferenceZ
DifferenceZAsGMLZFromWKTZ	AsGeoJSONZAsSVGZCentroidZFromWKBr   r   Z	PerimeterZBoundingCircleZGeoHashZGeometryDistanceZ	TranslateZScaleZAzimuthÚ	TransformZPointOnSurfaceZIsEmptyZ	NumPointsZLineLocatePointZ
SnapToGridZNumGeometriesZAsKMLZ	MakeValidZReverseÚUnionZEnvelopeZLengthZMemSizeZIntersectionZIsValidc                 C   s   t dƒ‚d S )Nz:Aggregate extent not implemented for this spatial backend.©ÚNotImplementedError©r   Ú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 u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 v 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/   Ú
convertersr0   r   r   r:   °   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?   ÚDistanceMeasurerA   )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mariadbÚmysqlÚoracleZspatial_versionr
   r   r   r+   r6   r4   r3   r%   r   r   r   r   r   r)   r-   r2   r$   r8   r9   Ústaticmethodr   Zdistance_expr_for_lookupr:   r<   rB   rE   Ú__classcell__r   r   r0   r   r   	   s<   
%		r   N)Zdjango.contrib.gis.db.modelsr   Z&django.contrib.gis.db.models.functionsr   Zdjango.contrib.gis.measurer   r@   rD   Z	django.dbr   Zdjango.utils.functionalr   r   r   r   r   r   Ú<module>   s   