o
    :Zc                     @   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e	dd Z
dZ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   d/var/www/chikooza/env/lib/python3.10/site-packages/django/contrib/gis/db/backends/base/operations.pyselect_extent   s   z#BaseSpatialOperations.select_extentr    >   r   AsGMLAsKMLAsSVGScaleUnionLengthAzimuthGeoHashIsValidMemSizeReverseCentroidr   Envelope	AsGeoJSON	MakeValid	NumPoints	Perimeter	Transform	Translate
Difference
SnapToGridIntersectionNumGeometriesSymDifferenceBoundingCirclePointOnSurfaceLineLocatePointGeometryDistancec                 C      t d)Nz:Aggregate extent not implemented for this spatial backend.NotImplementedErrorr   boxsridr   r   r   convert_extent6      z$BaseSpatialOperations.convert_extentc                 C   r-   )Nz=Aggregate 3D extent not implemented for this spatial backend.r.   r0   r   r   r   convert_extent3d9   r4   z&BaseSpatialOperations.convert_extent3dc                 C   s   d| S )Nz'%s'r   )r   namer   r   r   geo_quote_name=   r4   z$BaseSpatialOperations.geo_quote_namec                 C   r-   )zh
        Return the database column type for the geometry field on
        the spatial backend.
        zGsubclasses of BaseSpatialOperations must provide a geo_db_type() methodr.   )r   fr   r   r   geo_db_typeA      z!BaseSpatialOperations.geo_db_typec                 C   r-   )zu
        Return the distance parameters for the given geometry field,
        lookup value, and lookup type.
        z:Distance operations not available on this spatial backend.r.   )r   r8   valuelookup_typer   r   r   get_distanceH   r:   z"BaseSpatialOperations.get_distancec                 C   s   dd }t |dr||j|rd| d|jf S dS |||r.d| d| j|j|jf S | jjjr;d| j|jf S d	| j 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	   )r2   )r;   fieldr   r   r   transform_valueV   s   zCBaseSpatialOperations.get_geom_placeholder.<locals>.transform_valueas_sqlz%s(%%s, %s)r"   r   z%s(%s(%%s,%s), %s)z
%s(%%s,%s)z%s(%%s))hasattroutput_fieldspatial_function_namer2   	from_text
connectionfeatureshas_spatialrefsys_table)r   r8   r;   compilerr?   r   r   r   get_geom_placeholderO   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   r6   supercheck_expression_supportr   
expression	__class__r   r   rM   k   s
   z.BaseSpatialOperations.check_expression_supportc                 C   r-   )Nz;Aggregate support not implemented for this spatial backend.r.   )r   agg_namer   r   r   spatial_aggregate_namer   r4   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   rC   u   s   
z+BaseSpatialOperations.spatial_function_namec                 C   r-   )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.r.   r   r   r   r   geometry_columns{   r4   z&BaseSpatialOperations.geometry_columnsc                 C   r-   )NzKsubclasses of BaseSpatialOperations must a provide spatial_ref_sys() methodr.   r   r   r   r   spatial_ref_sys~   r4   z%BaseSpatialOperations.spatial_ref_sysc                    s,   t  |}t|jtr|| | |S r	   )rL   get_db_convertersrJ   rB   r   appendget_geometry_converter)r   rO   
convertersrP   r   r   r[      s   z'BaseSpatialOperations.get_db_convertersc                 C   r-   )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.r.   rN   r   r   r   r]      s   z,BaseSpatialOperations.get_geometry_converterc                 C   s@   | | jr| jjjrdS td|| j}|rt|S d S )Nsq_mz2Area on geodetic coordinate systems not supported.)geodeticrE   rF   supports_area_geodeticr/   
units_nameAreaMeasureunit_attname)r   r>   rb   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}|S || j}|rt|}|S )Nm)r`   rE   rF   supports_distance_geodeticrb   DistanceMeasurerd   )r   r>   dist_attunitsr   r   r   get_distance_att_for_field   s   

z0BaseSpatialOperations.get_distance_att_for_field)%__name__
__module____qualname__postgis
spatialitemysqloraclespatial_versionr
   r   r   	geographygeometryrK   rW   rU   rT   rD   r3   r5   r7   r9   r=   rI   rM   rS   rC   rY   rZ   staticmethodr   distance_expr_for_lookupr[   r]   re   rk   __classcell__r   r   rP   r   r   
   s@    


r   N)django.contrib.gis.db.modelsr   &django.contrib.gis.db.models.functionsr   django.contrib.gis.measurer   rc   rh   django.db.utilsr   django.utils.functionalr   r   r   r   r   r   <module>   s    