o
    åË·ez  ã                   @   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   úe/var/www/ideatree/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Ú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_extentJ   ó   ÿz$BaseSpatialOperations.convert_extentc                 C   r-   )Nz=Aggregate 3D extent not implemented for this spatial backend.r.   r0   r   r   r   Úconvert_extent3dO   r4   z&BaseSpatialOperations.convert_extent3dc                 C   s   d| S )Nz'%s'r   )r   Únamer   r   r   Úgeo_quote_nameU   s   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_typeY   ó   ÿ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_distanceb   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_values   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_placeholderk   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   Š   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_name’   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   —   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]   ³   r4   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ÚmariadbÚmysqlÚoracleÚspatial_versionr
   r   r   rK   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.dbr   Údjango.utils.functionalr   r   r   r   r   r   Ú<module>   s    