B
    ¥0H[±  ã               @   sF   d dl mZ d dlmZ d dlmZmZ d dlm	Z	 G dd„ dƒZ
dS )é    )ÚGeometryField)ÚDistance)ÚArear   )Úcached_propertyc                   s  e Zd ZdZdZdZdZdZdZe	dd„ ƒZ
dZdZd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d0d1„ Z‡ fd2d3„Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ ZeeƒZ‡ fd<d=„Z d>d?„ Z!d@dA„ Z"dBdC„ Z#‡  Z$S )DÚBaseSpatialOperationsFNz%sc             C   s   | j S )N)Úselect)Úself© r	   úrC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\gis\db\backends\base\operations.pyÚselect_extent   s    z#BaseSpatialOperations.select_extentr	   Ú r   Z	AsGeoJSONZAsGMLZAsKMLZAsSVGZAzimuthZBoundingCircleZCentroidZ
Differencer   ZEnvelopeZForceRHRZGeoHashZ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_extent5   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_extent3d8   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_distanceG   s    z"BaseSpatialOperations.get_distancec             C   s„   dd„ }t |dƒr6||j|ƒr2d|  d¡|jf S dS |||ƒr\d|  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_valueU   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_placeholderN   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
   r'   j   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_nameq   s    z,BaseSpatialOperations.spatial_aggregate_namec             C   s*   || j k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
   r   t   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_columnsz   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 ƒ  |¡}t|jtƒr(| |  |¡¡ |S )N)r&   Úget_db_convertersr$   r   r   ÚappendÚget_geometry_converter)r   r(   Ú
converters)r)   r	   r
   r2   ‚   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
   r4   ˆ   s    z,BaseSpatialOperations.get_geometry_converterc             C   sB   |  | j¡r$| jjjrdS tdƒ‚n| | j¡}|r>t |¡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   r7   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}n| | j¡}|r:t |¡}|S )NÚm)r6   r    r!   Zsupports_distance_geodeticr7   ÚDistanceMeasurer9   )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mysqlZoracleZspatial_versionr   r   r   Z	geographyZgeometryr%   r.   r,   r+   r   r   r   r   r   r   r#   r'   r*   r   r0   r1   Ústaticmethodr   Zdistance_expr_for_lookupr2   r4   r:   r=   Ú__classcell__r	   r	   )r)   r
   r   	   sF   



r   N)Zdjango.contrib.gis.db.modelsr   Z&django.contrib.gis.db.models.functionsr   Zdjango.contrib.gis.measurer   r8   r<   Zdjango.utils.functionalr   r   r	   r	   r	   r
   Ú<module>   s   