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   úa/var/www/html/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ÚClosestPointÚ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_extentN   ó   ÿz$BaseSpatialOperations.convert_extentc                 C   r1   )Nz=Aggregate 3D extent not implemented for this spatial backend.r2   r4   r   r   r   Úconvert_extent3dS   r8   z&BaseSpatialOperations.convert_extent3dc                 C   s   d| S )Nz'%s'r   )r   Únamer   r   r   Úgeo_quote_nameY   s   z$BaseSpatialOperations.geo_quote_namec                 C   r1   )zh
        Return the database column type for the geometry field on
        the spatial backend.
        zGsubclasses of BaseSpatialOperations must provide a geo_db_type() methodr2   )r   Úfr   r   r   Úgeo_db_type]   ó   ÿz!BaseSpatialOperations.geo_db_typec                 C   r1   )zu
        Return the distance parameters for the given geometry field,
        lookup value, and lookup type.
        z:Distance operations not available on this spatial backend.r2   )r   r<   ÚvalueÚlookup_typer   r   r   Úget_distancef   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	   )r6   )r?   Úfieldr   r   r   Útransform_valuew   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_namer6   Ú	from_textÚ
connectionÚfeaturesÚhas_spatialrefsys_table)r   r<   r?   ÚcompilerrC   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   r:   ÚsuperÚcheck_expression_support©r   Ú
expression©Ú	__class__r   r   rQ   Ž   s   ÿÿz.BaseSpatialOperations.check_expression_supportc                 C   r1   )Nz;Aggregate support not implemented for this spatial backend.r2   )r   Úagg_namer   r   r   Úspatial_aggregate_name–   r8   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   rG   ›   s
   
ÿz+BaseSpatialOperations.spatial_function_namec                 C   r1   )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.r2   r   r   r   r   Úgeometry_columns£   r8   z&BaseSpatialOperations.geometry_columnsc                 C   r1   )NzKsubclasses of BaseSpatialOperations must a provide spatial_ref_sys() methodr2   r   r   r   r   Úspatial_ref_sys©   r8   z%BaseSpatialOperations.spatial_ref_sysc                    s,   t ƒ  |¡}t|jtƒr| |  |¡¡ |S r	   )rP   Úget_db_convertersrN   rF   r   ÚappendÚget_geometry_converter)r   rS   Ú
convertersrT   r   r   r_   ±   s   z'BaseSpatialOperations.get_db_convertersc                 C   r1   )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.r2   rR   r   r   r   ra   ·   r8   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.)ÚgeodeticrI   rJ   Úsupports_area_geodeticr3   Ú
units_nameÚAreaMeasureÚunit_attname)r   rB   rf   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)rd   rI   rJ   Úsupports_distance_geodeticrf   ÚDistanceMeasurerh   )r   rB   Ú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   rO   r[   rY   rX   rH   r7   r9   r;   r=   rA   rM   rQ   rW   rG   r]   r^   Ústaticmethodr   Údistance_expr_for_lookupr_   ra   ri   ro   Ú__classcell__r   r   rT   r   r   	   s>    
&		r   N)Údjango.contrib.gis.db.modelsr   Ú&django.contrib.gis.db.models.functionsr   Údjango.contrib.gis.measurer   rg   rl   Ú	django.dbr   Údjango.utils.functionalr   r   r   r   r   r   Ú<module>   s    