3
©ôÁgx  ã               @   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f ZdZi Zddd	d
dddddddddddddddddddddd d!d"d#d$hZdZd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z‡ fd1d2„Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ ZeeƒZ‡ fd;d<„Zd=d>„ Z d?d@„ Z!dAdB„ Z"‡  Z#S )CÚBaseSpatialOperationsFNz%sc             C   s   | j S )N)Úselect)Úself© r
   úl/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/contrib/gis/db/backends/base/operations.pyÚselect_extent   s    z#BaseSpatialOperations.select_extentÚ r   Z	AsGeoJSONZAsGMLZAsKMLZAsSVGZAzimuthZBoundingCircleZCentroidZ
Differencer   ZEnvelopeZGeoHashZGeometryDistanceZIntersectionZIsValidZLengthZLineLocatePointZ	MakeValidZMemSizeZNumGeometriesZ	NumPointsZ	PerimeterZPointOnSurfaceZReverseZScaleZ
SnapToGridZSymDifferenceÚ	TransformZ	TranslateÚUnionc             C   s   t dƒ‚d S )Nz:Aggregate extent not implemented for this spatial backend.)ÚNotImplementedError)r	   ÚboxÚsridr
   r
   r   Úconvert_extent3   s    z$BaseSpatialOperations.convert_extentc             C   s   t dƒ‚d S )Nz=Aggregate 3D extent not implemented for this spatial backend.)r   )r	   r   r   r
   r
   r   Úconvert_extent3d6   s    z&BaseSpatialOperations.convert_extent3dc             C   s   d| S )Nz'%s'r
   )r	   Únamer
   r
   r   Úgeo_quote_name:   s    z$BaseSpatialOperations.geo_quote_namec             C   s   t dƒ‚dS )zh
        Return the database column type for the geometry field on
        the spatial backend.
        zGsubclasses of BaseSpatialOperations must provide a geo_db_type() methodN)r   )r	   Úfr
   r
   r   Úgeo_db_type>   s    z!BaseSpatialOperations.geo_db_typec             C   s   t dƒ‚dS )zu
        Return the distance parameters for the given geometry field,
        lookup value, and lookup type.
        z:Distance operations not available on this spatial backend.N)r   )r	   r   ÚvalueZlookup_typer
   r
   r   Úget_distanceE   s    z"BaseSpatialOperations.get_distancec             C   s„   dd„ }t |dƒr6||j|ƒr2d| jdƒ|jf S dS |||ƒr\d| jdƒ| j|j|jf S | jjjrvd| j|jf S d	| j S d
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 k	o| j |j kS )N)r   )r   Úfieldr
   r
   r   Útransform_valueS   s    zCBaseSpatialOperations.get_geom_placeholder.<locals>.transform_valueZas_sqlz%s(%%s, %s)r   z%sz%s(%s(%%s,%s), %s)z
%s(%%s,%s)z%s(%%s)N)ÚhasattrÚoutput_fieldÚspatial_function_namer   Ú	from_textÚ
connectionÚfeaturesZhas_spatialrefsys_table)r	   r   r   Úcompilerr   r
   r
   r   Úget_geom_placeholderL   s    
 

z*BaseSpatialOperations.get_geom_placeholderc                s*   t || jƒrtd|j ƒ‚tƒ j|ƒ 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   r(   h   s    z.BaseSpatialOperations.check_expression_supportc             C   s   t dƒ‚d S )Nz;Aggregate support not implemented for this spatial backend.)r   )r	   Zagg_namer
   r
   r   Úspatial_aggregate_nameo   s    z,BaseSpatialOperations.spatial_aggregate_namec             C   s*   || j krtd| ƒ‚| j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   r   r   s    
z+BaseSpatialOperations.spatial_function_namec             C   s   t dƒ‚d S )NzMSubclasses of BaseSpatialOperations must provide a geometry_columns() method.)r   )r	   r
   r
   r   Úgeometry_columnsx   s    z&BaseSpatialOperations.geometry_columnsc             C   s   t dƒ‚d S )NzKsubclasses of BaseSpatialOperations must a provide spatial_ref_sys() method)r   )r	   r
   r
   r   Úspatial_ref_sys{   s    z%BaseSpatialOperations.spatial_ref_sysc                s,   t ƒ j|ƒ}t|jtƒr(|j| j|ƒƒ |S )N)r'   Úget_db_convertersr%   r   r   ÚappendÚget_geometry_converter)r	   r)   Ú
converters)r*   r
   r   r3   €   s    z'BaseSpatialOperations.get_db_convertersc             C   s   t dƒ‚d S )NzSSubclasses of BaseSpatialOperations must provide a get_geometry_converter() method.)r   )r	   r)   r
   r
   r   r5   †   s    z,BaseSpatialOperations.get_geometry_converterc             C   sB   |j | jƒr$| jjjrdS tdƒ‚n|j| jƒ}|r>tj|ƒS d S )NZsq_mz2Area on geodetic coordinate systems not supported.)Úgeodeticr!   r"   Zsupports_area_geodeticr   Ú
units_nameÚAreaMeasureÚunit_attname)r	   r   r8   r
   r
   r   Úget_area_att_for_fieldŒ   s    

z,BaseSpatialOperations.get_area_att_for_fieldc             C   s>   d }|j | jƒr | jjjr:d}n|j| jƒ}|r:tj|ƒ}|S )NÚm)r7   r!   r"   Zsupports_distance_geodeticr8   Ú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mariadbZmysqlÚoracleZspatial_versionr   r   r   r&   r/   r-   r,   r    r   r   r   r   r   r$   r(   r+   r   r1   r2   Ústaticmethodr   Zdistance_expr_for_lookupr3   r5   r;   r>   Ú__classcell__r
   r
   )r*   r   r   
   sD   



r   N)Zdjango.contrib.gis.db.modelsr   Z&django.contrib.gis.db.models.functionsr   Zdjango.contrib.gis.measurer   r9   r=   Z	django.dbr   Zdjango.utils.functionalr   r   r
   r
   r
   r   Ú<module>   s
   