
    hH!                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr   " S S\5      r " S S\\5      rg)z\
SQL functions reference lists:
https://www.gaia-gis.it/gaia-sins/spatialite-sql-4.3.0.html
    )models)BaseSpatialOperations)SpatiaLiteAdapter)SpatialOperator)GEOSGeometryGEOSGeometryBase)wkb_r)Distance)ImproperlyConfigured)DatabaseOperations)cached_property)get_version_tuplec                   (   ^  \ rS rSrU 4S jrSrU =r$ )SpatialiteNullCheckOperator   c                 6   > [         TU ]  XX45      u  pVSU-  U4$ )Nz%s > 0)superas_sql)self
connectionlookuptemplate_params
sql_paramssqlparams	__class__s          f/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/db/backends/spatialite/operations.pyr   "SpatialiteNullCheckOperator.as_sql   s$    gnZU#~v%%     )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r      s    & &r   r   c                      \ rS rSrSrSr\rSrSr	Sr
SrSr0 S	\" S
S9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S\" SS9_S \" S!S9_S"\" S#S9_S$\" S%S9_S&\" S
S9_S'\" S
S9_S(\" S)S9_r\R"                  4rS*rS+S,S-S.S/S0S1S2S3S4S5S6S7.r\S8 5       r\S9 5       rS: rS; rS< rS= rS> rS? rS@ rSA rSB r SC r!SD r"SE r#SF r$SG r%SH r&SIr'gJ)KSpatiaLiteOperations   
spatialiteTCollectExtentMakeLineGUnionGeomFromTextequalsEquals)funcdisjointDisjointtouchesTouchescrossesCrosseswithinWithinoverlapsOverlapscontainsContains
intersects
IntersectsrelateRelate	coveredby	CoveredBycoversCovers	contained	MbrWithin
bbcontainsMbrContains
bboverlapsMbrOverlapssame_asexactdwithinPtDistWithinzCAST (AsEWKB(%s) AS BLOB)St_AsBinaryGEOSMinimumBoundingCircleST_ForceLHRST_GeomFromWKBST_GeomFromText	ST_LengthST_Line_Locate_Point
ST_NPoints
ST_ReverseScaleCoordsST_TranslateST_Union)AsWKBBoundingCircleForcePolygonCWFromWKBFromWKTLengthLineLocatePoint	NumPointsReverseScale	TranslateUnionc                 r    1 SknU R                  5       (       d  U1 Sk-  nU R                  S:  a  US1-  nU$ )N>   IsEmptyMemSizeGeometryDistance>   AzimuthGeoHash	MakeValid)      r^   )geom_lib_versionspatial_version)r   unsupporteds     r   unsupported_functions*SpatiaLiteOperations.unsupported_functionsS   sC    @$$&&>>K&(,--Kr   c                      U R                  5       SS nUS:  a  [        S5      eU$ ! [         a-  n[        SU R                  R                  S   < S35      UeSnAff = f)z0Determine the version of the SpatiaLite library.rq   Nz1Cannot determine the SpatiaLite version for the "NAMEzJ" database. Was the SpatiaLite initialization SQL loaded on this database?)      r   z.GeoDjango supports SpatiaLite 4.3.0 and above.)spatialite_version_tuple	Exceptionr   r   settings_dict)r   versionexcs      r   rs   $SpatiaLiteOperations.spatial_version\   st    	335ab9G Y&'WXX  	& ??008; 		s   ( 
A(AAc                 d    Uc  g[        U5      R                  nUS   SS u  p4US   SS u  pVX4XV4$ )zF
Convert the polygon data received from SpatiaLite to min/max values.
Nr      )r   shell)r   boxr   xminyminxmaxymaxs          r   convert_extent#SpatiaLiteOperations.convert_extentk   sI     ;S!''1Xbq\
1Xbq\
D''r   c                     g)zl
Return None because geometry columns are added via the
`AddGeometryColumn` stored procedure on SpatiaLite.
Nr    )r   fs     r   geo_db_type SpatiaLiteOperations.geo_db_typev   s    
 r   c                 L   U(       d  / $ US   n[        U[        5      (       a}  UR                  U R                  5      (       a   US:X  a  [	        S5      eUR
                  nU/$ [        U[        R                  " UR                  U R                  5      5      5      n U/$ UnU/$ )z]
Return the distance parameters for the given geometry field,
lookup value, and lookup type.
r   rO   zNOnly numeric values of degree units are allowed on geographic DWithin queries.)	
isinstancer
   geodeticr   
ValueErrormgetattrunit_attname
units_name)r   r   valuelookup_type
dist_params        r   get_distance!SpatiaLiteOperations.get_distance}   s    
 IaeX&&zz$//**)+$6  #WW
 | %800doo1NO

 | J|r   c                     U R                   R                  5       n UR                  SU-  5        UR                  5       nUR	                  5         US   $ ! UR	                  5         f = f)z
Helper routine for calling SpatiaLite functions and returning
their result.
Any error occurring in this method should be handled by the caller.
z	SELECT %sr   )r   _cursorexecutefetchoneclose)r   r2   cursorrows       r   _get_spatialite_func)SpatiaLiteOperations._get_spatialite_func   sW     ((*	NN;-.//#CLLN1v LLNs   $A A'c                 $    U R                  S5      $ )z:Return the version of GEOS used by SpatiaLite as a string.zgeos_version()r   r   s    r   geos_version!SpatiaLiteOperations.geos_version   s    (()9::r   c                 $    U R                  S5      $ )z:Return the version of the PROJ library used by SpatiaLite.zproj4_version()r   r   s    r   proj_version!SpatiaLiteOperations.proj_version   s    (():;;r   c                 $    U R                  S5      $ )z8Return the version of LWGEOM library used by SpatiaLite.zlwgeom_version()r   r   s    r   lwgeom_version#SpatiaLiteOperations.lwgeom_version       (();<<r   c                 $    U R                  S5      $ )z8Return the version of RTTOPO library used by SpatiaLite.zrttopo_version()r   r   s    r   rttopo_version#SpatiaLiteOperations.rttopo_version   r   r   c                 b    U R                   S:  a  U R                  5       $ U R                  5       $ )zN
Return the version of the version-dependant geom library used by
SpatiaLite.
)rp   )rs   r   r   r   s    r   rr   %SpatiaLiteOperations.geom_lib_version   s0    
 4'&&((&&((r   c                 $    U R                  S5      $ )z2Return the SpatiaLite library version as a string.zspatialite_version()r   r   s    r   spatialite_version'SpatiaLiteOperations.spatialite_version   s    (()?@@r   c                 @    U R                  5       nU4[        U5      -   $ )zT
Return the SpatiaLite version as a tuple (version string, major,
minor, subminor).
)r   r   )r   r~   s     r   r{   -SpatiaLiteOperations.spatialite_version_tuple   s%    
 ))+z-g666r   c                 d    UR                  5       S:X  a  SOUR                  5       n[        X5      $ )zZ
Return the spatial aggregate SQL template and function for the
given Aggregate instance.
unionunionagg)lowerr   )r   agg_names     r   spatial_aggregate_name+SpatiaLiteOperations.spatial_aggregate_name   s+    
 "*!1W!<:(..BRt&&r   c                     SSK Jn  U$ )Nr   )SpatialiteGeometryColumns)0django.contrib.gis.db.backends.spatialite.modelsr   )r   r   s     r   geometry_columns%SpatiaLiteOperations.geometry_columns   s    	
 )(r   c                     SSK Jn  U$ )Nr   )SpatialiteSpatialRefSys)r   r   )r   r   s     r   spatial_ref_sys$SpatiaLiteOperations.spatial_ref_sys   s    	
 '&r   c                 l   ^^ UR                   R                  m[        5       R                  mUU4S jnU$ )Nc                 2   > U c  S $ [        T" U 5      T5      $ )N)r   )r   
expressionr   
geom_classreads      r   	converter>SpatiaLiteOperations.get_geometry_converter.<locals>.converter   s     =4W.>tE{J.WWr   )output_fieldr   r	   r   )r   r   r   r   r   s      @@r   get_geometry_converter+SpatiaLiteOperations.get_geometry_converter   s-    ,,77
w||	X r   r    N)(r!   r"   r#   r$   namer*   r   Adaptercollectextentmakeliner   	from_textr   r   gis_operatorsr   Extent3Ddisallowed_aggregatesselectfunction_namesr   ru   rs   r   r   r   r   r   r   r   r   rr   r   r{   r   r   r   r   r%   r    r   r   r(   r(      s   DJGGFHHI-8< 	/Z@ 	.I>	
 	.I> 	-8< 	/Z@ 	/Z@ 	1|D 	-8< 	0kB 	-8< 	_+6  	o=9!$ 	o=9%( 	.H=)* 	,(;+. 	?7/M4 $__.(F 5'#$1!#N    	(0;<==)A7')'r   r(   N)__doc__django.contrib.gis.dbr   .django.contrib.gis.db.backends.base.operationsr   1django.contrib.gis.db.backends.spatialite.adapterr   $django.contrib.gis.db.backends.utilsr    django.contrib.gis.geos.geometryr   r   %django.contrib.gis.geos.prototypes.ior	   django.contrib.gis.measurer
   django.core.exceptionsr   %django.db.backends.sqlite3.operationsr   django.utils.functionalr   django.utils.versionr   r   r(   r    r   r   <module>r      sK   
 ) P O @ K 7 / 7 D 3 2&/ &N02D Nr   