o
    g                     @   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/var/www/rescue_company/venv/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FromWKBFromWKTGeoHashIsEmpty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_extentM      z$BaseSpatialOperations.convert_extentc                 C   r0   )Nz=Aggregate 3D extent not implemented for this spatial backend.r1   r3   r   r   r   convert_extent3dR   r7   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   r0   )zh
        Return the database column type for the geometry field on
        the spatial backend.
        zGsubclasses of BaseSpatialOperations must provide a geo_db_type() methodr1   )r   fr   r   r   geo_db_type\      z!BaseSpatialOperations.geo_db_typec                 C   r0   )zu
        Return the distance parameters for the given geometry field,
        lookup value, and lookup type.
        z:Distance operations not available on this spatial backend.r1   )r   r;   valuelookup_typer   r   r   get_distancee   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	   )r5   )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_namer5   	from_text
connectionfeatureshas_spatialrefsys_table)r   r;   r>   compilerrB   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   r9   supercheck_expression_supportr   
expression	__class__r   r   rP      s   z.BaseSpatialOperations.check_expression_supportc                 C   r0   )Nz;Aggregate support not implemented for this spatial backend.r1   )r   agg_namer   r   r   spatial_aggregate_name   r7   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   rF      s
   
z+BaseSpatialOperations.spatial_function_namec                 C   r0   )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.r1   r   r   r   r   geometry_columns   r7   z&BaseSpatialOperations.geometry_columnsc                 C   r0   )NzKsubclasses of BaseSpatialOperations must a provide spatial_ref_sys() methodr1   r   r   r   r   spatial_ref_sys   r7   z%BaseSpatialOperations.spatial_ref_sysc                    s,   t  |}t|jtr|| | |S r	   )rO   get_db_convertersrM   rE   r   appendget_geometry_converter)r   rR   
convertersrS   r   r   r^      s   z'BaseSpatialOperations.get_db_convertersc                 C   r0   )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.r1   rQ   r   r   r   r`      r7   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.)geodeticrH   rI   supports_area_geodeticr2   
units_nameAreaMeasureunit_attname)r   rA   re   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)rc   rH   rI   supports_distance_geodeticre   DistanceMeasurerg   )r   rA   dist_attunitsr   r   r   get_distance_att_for_field   s   

z0BaseSpatialOperations.get_distance_att_for_field)$__name__
__module____qualname__postgis
spatialitemariadbmysqloraclespatial_versionr
   r   r   rN   rZ   rX   rW   rG   r6   r8   r:   r<   r@   rL   rP   rV   rF   r\   r]   staticmethodr   distance_expr_for_lookupr^   r`   rh   rn   __classcell__r   r   rS   r   r   	   s>    
%		r   N)django.contrib.gis.db.modelsr   &django.contrib.gis.db.models.functionsr   django.contrib.gis.measurer   rf   rk   	django.dbr   django.utils.functionalr   r   r   r   r   r   <module>   s    