o a,@sddlmZddlmZddlmZddlmZmZm Z ddl m Z ddl m Z Gddde ZGd d d eZejGd d d eZejGd ddeZejGdddeZejGdddeZejGdddeZejGdddeZejGdddeZejGdddeZejGdddeZeedejGdddeZejGd d!d!eZejGd"d#d#eZejGd$d%d%eZejGd&d'd'eZejGd(d)d)eZejGd*d+d+eZ ejGd,d-d-eZ!ejGd.d/d/eZ"ejGd0d1d1eZ#ejGd2d3d3eZ$ejGd4d5d5eZ%ejGd6d7d7eZ&ejGd8d9d9eZ'ejGd:d;d;eZ(Gdd?d?e)Z*Gd@dAdAe)Z+ejGdBdCdCe+Z,ejGdDdEdEe+Z-ejGdFdGdGe+Z.ejGdHdIdIe+Z/dJS)K)BaseSpatialField)Distance)NotSupportedError) ExpressionLookup Transform)Query)_lazy_re_compilec@eZdZddZdS)RasterBandTransformcCs ||jSN)compilelhs)selfcompiler connectionrF/usr/lib/python3/dist-packages/django/contrib/gis/db/models/lookups.pyas_sql s zRasterBandTransform.as_sqlN__name__ __module__ __qualname__rrrrrr  r csfeZdZdZdZdZdZdZfddZddZ dddZ d d Z fd d Z d dZ ddZZS) GISLookupNFcs>t|ttfr |n|g^}|_t||i|_|dSr ) isinstancelisttuple rhs_paramssuper__init__template_paramsprocess_rhs_params)rrrhs __class__rrr s zGISLookup.__init__cCsn|jr't|j|jdkrdndkr|dSt|jdkr%td|jdSt|jtr5|jdddSdS)NrelatezTuple too long for lookup %s.T)only_lhs)rlen lookup_nameprocess_band_indices ValueErrorrrr rrrrr"s  zGISLookup.process_rhs_paramscCsP|rd|_|jjd|_dSt|jtr|jjd|_nd|_|j^|_|_dS)z Extract the lhs band index from the band transform class and the rhs band index from the input tuple. r(N)band_rhsr band_indexband_lhsrr r)rr)rrrr,%s zGISLookup.process_band_indicescCsd|j|gfS)N%s)opsAdapter)rvaluerrrrget_db_prep_lookup8szGISLookup.get_db_prep_lookupcsjt|jtr t||St|jtr|j|j|_t||\}}|j |j j |j|}|||fSr ) rr#rr process_rhsrresolve_expressionqueryr3get_geom_placeholderr output_field)rrrr#r placeholderr$rrr7<s   zGISLookup.process_rhscCs|jj|jSr )r3 gis_operatorsr+)rrr#rrr get_rhs_opFszGISLookup.get_rhs_opc Cs\|||\}}|||\}}g||R}||dd|j}|||} | ||||S)Nr2)rr#r5) process_lhsr7r!r>r) rrrlhs_sql lhs_paramsrhs_sqlr sql_paramsr!rhs_oprrrrLs  zGISLookup.as_sql)F)rrr sql_templatetransform_funcdistancer/r1r r"r,r6r7r>r __classcell__rrr$rrs    rc@eZdZdZdZdS)OverlapsLeftLookupzy The overlaps_left operator returns true if A's bounding box overlaps or is to the left of B's bounding box. overlaps_leftNrrr__doc__r+rrrrrJZrJc@rI)OverlapsRightLookupz} The 'overlaps_right' operator returns true if A's bounding box overlaps or is to the right of B's bounding box. overlaps_rightNrLrrrrrOcrNrOc@rI)OverlapsBelowLookupzs The 'overlaps_below' operator returns true if A's bounding box overlaps or is below B's bounding box. overlaps_belowNrLrrrrrQlrNrQc@rI)OverlapsAboveLookupzs The 'overlaps_above' operator returns true if A's bounding box overlaps or is above B's bounding box. overlaps_aboveNrLrrrrrSurNrSc@rI) LeftLookupzo The 'left' operator returns true if A's bounding box is strictly to the left of B's bounding box. leftNrLrrrrrU~rNrUc@rI) RightLookupzq The 'right' operator returns true if A's bounding box is strictly to the right of B's bounding box. rightNrLrrrrrWrNrWc@rI)StrictlyBelowLookupzp The 'strictly_below' operator returns true if A's bounding box is strictly below B's bounding box. strictly_belowNrLrrrrrYrNrYc@rI)StrictlyAboveLookupzp The 'strictly_above' operator returns true if A's bounding box is strictly above B's bounding box. strictly_aboveNrLrrrrr[rNr[c@rI) SameAsLookupz The "~=" operator is the "same as" operator. It tests actual geometric equality of two features. So if A and B are the same feature, vertex-by-vertex, the operator returns true. same_asNrLrrrrr]sr]exactc@rI)BBContainsLookupzq The 'bbcontains' operator returns true if A's bounding box completely contains by B's bounding box. bbcontainsNrLrrrrr`rNr`c@rI)BBOverlapsLookupz_ The 'bboverlaps' operator returns true if A's bounding box overlaps B's bounding box. bboverlapsNrLrrrrrbsrbc@rI)ContainedLookupzt The 'contained' operator returns true if A's bounding box is completely contained by B's bounding box. containedNrLrrrrrdrNrdc@eZdZdZdS)ContainsLookupcontainsNrrrr+rrrrrgrgc@rf)ContainsProperlyLookupcontains_properlyNrirrrrrkrjrkc@rf)CoveredByLookup coveredbyNrirrrrrmrjrmc@rf) CoversLookupcoversNrirrrrrorjroc@rf) CrossesLookupcrossesNrirrrrrqrjrqc@rf)DisjointLookupdisjointNrirrrrrsrjrsc@rf) EqualsLookupequalsNrirrrrrurjruc@rf)IntersectsLookup intersectsNrirrrrrwrjrwc@rf)OverlapsLookupoverlapsNrirrrrryrjrycs,eZdZdZdZedZfddZZS) RelateLookupr&z%(func)s(%(lhs)s, %(rhs)s, %%s)z^[012TF\*]{9}$csp|jd}|jj|j}t|dr||nt|tr"|j |s(t d|t ||\}}|||gfS)Nrcheck_relate_argumentz)Invalid intersection matrix pattern "%s".) rr3r=r+hasattrr|rstr pattern_regexmatchr-rr7)rrrpattern backend_opsqlparamsr$rrr7s    zRelateLookup.process_rhs) rrrr+rEr rr7rHrrr$rr{s r{c@rf) TouchesLookuptouchesNrirrrrr rjrc@rf) WithinLookupwithinNrirrrrrrjrc@s$eZdZdZdZddZddZdS)DistanceLookupBaseTz+%(func)s(%(lhs)s, %(rhs)s) %(op)s %(value)scCs~dt|jkr dksntd|jt|jdkr'|jddkr'tdt|jdkr;|jddkr=|dSdSdS)Nr(z22, 3, or 4-element tuple required for '%s' lookup.r'spheroidzHFor 4-element tuples the last argument must be the 'spheroid' directive.)r*rr-r+r,r.rrrr"s z%DistanceLookupBase.process_rhs_paramscCsB|jd}t|dr|||jSd|j|jj|j|j fS)Nrr8r2) rr}r r8r9r3 get_distancerr;r+rrr dist_paramrrrprocess_distance$s z#DistanceLookupBase.process_distanceN)rrrrGrEr"rrrrrrs  rcs0eZdZdZdZfddZfddZZS) DWithinLookupdwithinz%%(func)s(%(lhs)s, %(rhs)s, %(value)s)cs<|jd}|jjst|drt|tstdt||S)Nrr8zXThis backend does not support expressions for specifying distance in the dwithin lookup.) rfeaturessupports_dwithin_distance_exprr}rrrrrrr$rrr2s zDWithinLookup.process_distancecs8|||\}}||jd<t||\}}|||fS)Nr5)rr!rr7)rrrdist_sql dist_paramsrBrr$rrr7?s  zDWithinLookup.process_rhs)rrrr+rErr7rHrrr$rr-s   rc@r )DistanceLookupFromFunctionc Csvt|jdkr|jddkpd}|jj|j|j|d}|||j\}}| ||\}}d||j |d||fS)Nr'r)rz%(func)s %(op)s %(dist)s)funcopdist) r*rr3distance_expr_for_lookuprr#r r8r9rr) rrrr distance_exprrrrrrrrrGs z!DistanceLookupFromFunction.as_sqlNrrrrrrFrrc@rI)DistanceGTLookup distance_gt>Nrrrr+rrrrrrRrc@rI)DistanceGTELookup distance_gtez>=NrrrrrrXrrc@rI)DistanceLTLookup distance_lts    L