o
    i                     @   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   n/var/www/html/formularioweb/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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    