o
    úÑÐbx  ã                   @   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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   úm/var/www/secure340b-portal/env/lib/python3.10/site-packages/django/contrib/gis/db/backends/base/operations.pyÚselect_extent   s   z#BaseSpatialOperations.select_extentr   Ú >   ÚAsGMLÚAsKMLÚAsSVGÚScaleÚLengthÚAzimuthÚGeoHashÚIsValidÚMemSizeÚReverseÚCentroidÚEnvelopeÚ	AsGeoJSONÚ	MakeValidÚ	NumPointsÚ	PerimeterÚ	TranslateÚ
DifferenceÚ
SnapToGridÚIntersectionÚNumGeometriesÚSymDifferenceÚBoundingCircleÚPointOnSurfaceÚLineLocatePointÚGeometryDistancer   ÚUnionr   Ú	Transformc                 C   ó   t dƒ‚)Nz:Aggregate extent not implemented for this spatial backend.©ÚNotImplementedError©r   ÚboxÚsridr   r   r   Úconvert_extent3   ó   z$BaseSpatialOperations.convert_extentc                 C   r-   )Nz=Aggregate 3D extent not implemented for this spatial backend.r.   r0   r   r   r   Úconvert_extent3d6   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_type>   ó   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   ÚvalueZ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	   )r2   )r;   Úfieldr   r   r   Útransform_valueS   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))ÚhasattrÚoutput_fieldÚspatial_function_namer2   Ú	from_textÚ
connectionÚfeaturesZhas_spatialrefsys_table)r   r8   r;   Úcompilerr>   r   r   r   Úget_geom_placeholderL   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   rJ   h   s
   ÿz.BaseSpatialOperations.check_expression_supportc                 C   r-   )Nz;Aggregate support not implemented for this spatial backend.r.   )r   Zagg_namer   r   r   Úspatial_aggregate_nameo   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   rA   r   s   
z+BaseSpatialOperations.spatial_function_namec                 C   r-   )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.r.   r   r   r   r   Úgeometry_columnsx   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	   )rI   Úget_db_convertersrG   r@   r   ÚappendÚget_geometry_converter)r   rL   Ú
convertersrM   r   r   rW   €   s   z'BaseSpatialOperations.get_db_convertersc                 C   r-   )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.r.   rK   r   r   r   rY   †   s   ÿz,BaseSpatialOperations.get_geometry_converterc                 C   s@   |  | j¡r| jjjrdS tdƒ‚| | j¡}|rt |¡S d S )NZsq_mz2Area on geodetic coordinate systems not supported.)ÚgeodeticrC   rD   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}|S | | j¡}|rt |¡}|S )NÚm)r[   rC   rD   Zsupports_distance_geodeticr\   ÚDistanceMeasurer^   )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   rH   rS   rQ   rP   rB   r3   r5   r7   r9   r<   rF   rJ   rO   rA   rU   rV   Ústaticmethodr   Zdistance_expr_for_lookuprW   rY   r_   rb   Ú__classcell__r   r   rM   r   r   
   s>    


r   N)Zdjango.contrib.gis.db.modelsr   Z&django.contrib.gis.db.models.functionsr   Zdjango.contrib.gis.measurer   r]   ra   Z	django.dbr   Zdjango.utils.functionalr   r   r   r   r   r   Ú<module>   s    