
    h}v                      S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
  S SKJrJrJr  SSKJr  SSKJr  S rSrSrS rSrSrS rSrSr\R8                  R;                  5       rS	 \R?                  S
5      RA                  S5       5       u  r!r"r#\!\"\#4S:  a  \$" S5      e/ SQr%S r&S r' " S S5      r(\(r) " S S5      r* " S S\$5      r+ " S S5      r, " S S\,5      r- " S S\-5      r.  " S S\-5      r/ " S S \,5      r1 " S! S"5      r2\Rf                  r4 " S# S$\Rj                  5      r6 " S% S&5      r7 " S' S(\75      r8 " S) S*\75      r9 " S+ S,\)5      r:g! \0 a     Njf = f)-    )annotationsN)IteratorSequence)AnyLiteraloverload   )core)
RTreeError   c              #  8   #    U  H  n[        U5      v   M     g 7fN)int).0ts     ^C:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\rtree/index.py	<genexpr>r      s      /@qCFF@s   utf-8.)r	         z/Rtree requires libspatialindex 1.8.5 or greater)RtreeIndexPropertyc                   [         R                  " [         R                  " 5       5      n[         R                  " [         R                  " 5       5      n[         R                  " S5      nU" U [         R                  " U5      [         R                  " U5      [         R                  " U5      5        UR
                  S:X  a  g [         R                  " U[         R                  " [         R                  UR
                  -  5      5      n[         R                  " U[         R                  " [         R                  UR
                  -  5      5      n[        UR
                  5       Vs/ s H  oR                  U   PM     n	nU	[        UR
                  5       Vs/ s H  oR                  U   PM     sn-  n	[         R                  " U[         R                  " [         R                  5      5      n
[         R                  " U[         R                  " [         R                  5      5      n[        R                  R                  [         R                  " U
[         R                  " [         R                  5      5      5        [        R                  R                  [         R                  " U[         R                  " [         R                  5      5      5        U(       a  U	$ [        R                  U	5      $ s  snf s  snf Nr   )ctypespointerc_doublec_uint32byrefvaluecastPOINTERrangecontentsr
   rt
Index_Freec_void_pr   deinterleave)handle	bounds_fninterleavedpp_minspp_maxs	dimensionminsmaxsiresultsp_minsp_maxss               r   _get_boundsr7   '   s   nnV__./GnnV__./G"IW%v||G'<fll9>U !;;wv/P QRD;;wv/P QRD).y)?@)?A}}Q)?G@%	*@A*@Qa *@AAG[[v~~foo>?F[[v~~foo>?FGGv{{66>>&//+JKLGGv{{66>>&//+JKLg&& AAs   $K/K4c                h   [         R                  " S5      n[         R                  " [         R                  " S5      5      n[        R
                  R                  U [         R                  " U5      [         R                  " U5      5        [         R                  " U[         R                  " [         R                  5      5      nUR                  S:X  a   [        R
                  R                  U5        g [         R                  " X!R                  5      n[        R
                  R                  U5        U$ r   )r   c_uint64r   c_uint8r
   r'   IndexItem_GetDatar!   r#   r$   r)   r"   r(   	string_at)r+   lengthdcss        r   	_get_datarA   A   s    __QFv~~a()AGGffll1ov||F7KLAv~~foo67A||q1LL)AGGqH    c                     \ rS rSrSrS;S jrS<S jrS<S jrS=S jrS>S jr	S?S jr
S@S	 jrSAS
 jrSBS jrSBS jr    SCS jr\S 5       rS rS rS r\" \\5      rS rS r\" \\5      rSDSES jjr\r SD           SFS jjrSGS jr        SHS jr\SIS j5       r \ SJ     SKS jj5       r \      SLS j5       r  SJ     SMS jjr SNS jr!SNS jr"\      SIS j5       r#\ SJ     SOS  jj5       r#\      SLS! j5       r# SJ     SPS" jjr#SJS# jr$S$ r%SQS% jr&S& r'S' r(S( r)\        SRS) j5       r*\ SJ       SSS* jj5       r*\        STS+ j5       r*  SU       SVS, jjr*S- r+    SWS. jr,SUS/ jr-SDS0 jr.\" \.5      r/SXS1 jr0          SYS2 jr1SZS3 jr2S4 r3\4S[S5 j5       r5\4S\S6 j5       r6S7 r7S8 r8S9 r9S:r:g)]r   N   z0An R-Tree, MVR-Tree, or TPR-Tree indexing objectc                .
   UR                  S[        5       5      U l        U R                  R                  [        :X  a*  [        [        R                  S5      (       d  [        S5      e[        UR                  SS5      5      U l
        SnSnSnSnU(       a  [        US   [        5      (       d  [        US   [        5      (       a8  US   n[        U5      S:  a#  [        US   [        5      (       a  US   nO[US   nOU[        US   [         5      (       a  US   n[        U5      S:  a  US   nO#[        US   [        5      (       a  US   nOUS   nU(       GaD  ["        U R                  l        XPR                  l        [        U5      S	-   U R                  R(                  -   n[*        R,                  R/                  U5      n[*        R,                  R1                  U5      (       a\  [        UR                  S
S5      5      U R                  l        U R                  R2                  (       d   U R                  R4                    [*        R,                  R9                  U5      n	[*        R:                  " U	[*        R<                  5      (       d  SU S3n
[?        U
5      eOU(       a  [@        U R                  l        URB                  (       am  [        UR                  S
S5      5      U R                  l        U R                  R2                  (       d   U R                  R4                    OURE                  5         X`l#        URI                  U R                  5        O[J        U R                  l        UR                  SS5      nU(       a  [M        U5      U R                  l'        U(       aY  U R                  R                  [P        :X  a;  SU l)        U RU                  U5      U l+        U RR                  (       a  U RR                  egU(       aX  U R                  R                  [P        :X  a:  SU l)         U RX                  " U6 U l+        U RR                  (       a  U RR                  eg[_        U R                  RV                  5      U l+        U(       a  U H  nU R`                  " U6   M     gU(       a  []        S5      eg! [6         a    SU R                  l         GNf = f! [6         a    SU R                  l         GNf = f! [Z         a    []        S5      ef = f)a  Creates a new index

:param filename:
    The first argument in the constructor is assumed to be a filename
    determining that a file-based storage for the index should be used.
    If the first argument is not of type basestring, it is then assumed
    to be an instance of ICustomStorage or derived class.
    If the first argument is neither of type basestring nor an instance
    of ICustomStorage, it is then assumed to be an input index item
    stream.

:param stream:
    If the first argument in the constructor is not of type basestring,
    it is assumed to be an iterable stream of data that will raise a
    StopIteration.  It must be in the form defined by the
    :attr:`interleaved` attribute of the index. The following example
    would assume :attr:`interleaved` is False::

        (id,
         (minx, maxx, miny, maxy, minz, maxz, ..., ..., mink, maxk),
         object)

    The object can be None, but you must put a place holder of
    ``None`` there.

    For a TPR-Tree, this would be in the form::

        (id,
         ((minx, maxx, miny, maxy, ..., ..., mink, maxk),
          (minvx, maxvx, minvy, maxvy, ..., ..., minvk, maxvk),
          time),
         object)

:param storage:
    If the first argument in the constructor is an instance of
    ICustomStorage then the given custom storage is used.

:param interleaved: True or False, defaults to True.
    This parameter determines the coordinate order for all methods that
    take in coordinates.

:param properties: An :class:`index.Property` object.
    This object sets both the creation and instantiation properties
    for the object and they are passed down into libspatialindex.
    A few properties are curried from instantiation parameters
    for you like ``pagesize`` and ``overwrite``
    to ensure compatibility with previous versions of the library.  All
    other properties must be set on the object.

.. warning::
    The coordinate ordering for all functions are sensitive the
    index's :attr:`interleaved` data member.  If :attr:`interleaved`
    is False, the coordinates must be in the form
    [xmin, xmax, ymin, ymax, ..., ..., kmin, kmax]. If
    :attr:`interleaved` is True, the coordinates must be in the form
    [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax]. This also applies
    to velocities when using a TPR-Tree.

A basic example
::

    >>> from rtree import index
    >>> p = index.Property()

    >>> idx = index.Index(properties=p)
    >>> idx  # doctest: +NORMALIZE_WHITESPACE
    rtree.index.Index(bounds=[1.7976931348623157e+308,
                            1.7976931348623157e+308,
                            -1.7976931348623157e+308,
                            -1.7976931348623157e+308],
                            size=0)

Insert an item into the index::

    >>> idx.insert(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...            obj=42)

Query::

    >>> hits = idx.intersection((0, 0, 60, 60), objects=True)
    >>> for i in hits:
    ...     if i.id == 4321:
    ...         i.object
    ...         i.bbox
    ... # doctest: +ELLIPSIS
    42
    [34.37768294..., 26.73758537..., 49.37768294..., 41.73758537...]


Using custom serializers::

    >>> class JSONIndex(index.Index):
    ...     def dumps(self, obj):
    ...         # This import is nested so that the doctest doesn't
    ...         # require simplejson.
    ...         import simplejson
    ...         return simplejson.dumps(obj).encode('ascii')
    ...
    ...     def loads(self, string):
    ...         import simplejson
    ...         return simplejson.loads(string.decode('ascii'))

    >>> stored_obj = {"nums": [23, 45], "letters": "abcd"}
    >>> json_idx = JSONIndex()
    >>> try:
    ...     json_idx.insert(1, (0, 1, 0, 1), stored_obj)
    ...     list(json_idx.nearest((0, 0), 1,
    ...                           objects="raw")) == [stored_obj]
    ... except ImportError:
    ...     True
    True


propertiesIndex_InsertTPDataz;TPR-Tree type not supported with version of libspatialindexr-   TNr   r	   r   	overwriteFzUnable to open file 'z' for index storagepagesizez-libspatialindex >= 2.1 needed for bulk insertz%Bulk insert only supported for RTrees)1getr   rF   type
RT_TPRTreehasattrr
   r'   RuntimeErrorboolr-   
isinstancestrbyteslentupleICustomStorageRT_Diskstoragefilenameidx_extensionospathabspathexistsrH   index_idr   dirnameaccessW_OKOSError	RT_CustomhasDataclearcustomstorageregisterCallbacks	RT_Memoryr   rI   RT_RTree
_exception_create_idx_from_streamr+   _create_idx_from_array	NameErrorNotImplementedErrorIndexHandleinsert)selfargskwargsstreamarraysbasenamerW   fpr>   messagepsitems                r   __init__Index.__init__Q   s   h !**\8:>??:-gGG)7
 7
 M 
  

=$ ?@$q'3'':d1gu+E+E7t9q=!$q'511!%a!%aDG^44q't9q=!!WFDGU++aa&-DOO#'/OO$ H#doo&C&CCA"A ww~~a  ,0K1O,P) 00500 "A99Q((1!4GHg&& ) &/DOO#,0K1O,P)00500 MMO!(%%doo6&/DOO#ZZ
D)'*2wDOO$doo**h6"DO66v>DKoo% ,,8"DO"996B oo%  &doo&<&<=DK"DKK& #)*QRR c & 53405 & 53405.  )C s0   /R: S 1S> :SSS;:S;>Tc                N    [         R                  " S[        5        [        U 5      $ )Nz6index.get_size() is deprecated, use len(index) instead)warningswarnDeprecationWarningrS   rq   s    r   get_sizeIndex.get_size/  s     DFX	
 4yrB   c                Z     U R                  U R                  5      $ ! [         a     gf = f)z@The number of entries in the index.

:return: number of entries
r   countboundsr   r   s    r   __len__Index.__len__5  s,    
	::dkk** 		    
**c                :    SU R                    S[        U 5       S3$ )Nzrtree.index.Index(bounds=z, size=))r   rS   r   s    r   __repr__Index.__repr__?  s    *4;;-ws4ykKKrB   c                @    U R                   R                  5       nUS	 U$ )Nr+   )__dict__copyrq   states     r   __getstate__Index.__getstate__B  s     ""$(OrB   c                    U R                   R                  U5        [        U R                  R                  5      U l        g r   )r   updatero   rF   r+   r   s     r   __setstate__Index.__setstate__G  s*    U#!$//"8"89rB   c                .    [         R                  " U5      $ r   )pickledumpsrq   objs     r   r   Index.dumpsK  s    ||C  rB   c                .    [         R                  " U5      $ r   )r   loads)rq   strings     r   r   Index.loadsN  s    ||F##rB   c                ~    U R                   (       a"  U R                   R                  5         SU l         g[        S5      e)zBForce a flush of the index to storage. Renders index
inaccessible.NzUnclosable index)r+   destroyrb   r   s    r   closeIndex.closeQ  s.     ;;KK!DK,--rB   c                \    U R                   (       a  U R                   R                  5         gg)z&Force a flush of the index to storage.N)r+   flushr   s    r   r   Index.flushZ  s    ;;KK rB   c                B   U R                   R                  n[        U5      n[        R                  U-  nU" 5       n[        U5      U:X  a	  XS S & UnXE4$ U" 5       nU R                  (       a
  US U nXS  nOUS S S2   nUSS S2   nXdS S & XuS S & Xg::  d  [        S5      eXE4$ )Nr   r	   z5Coordinates must not have minimums more than maximums)rF   r0   listr   r   rS   r-   r   )rq   coordinatesr0   arrr1   r2   rx   qs           r   get_coordinate_pointersIndex.get_coordinate_pointers_  s     OO--	;'oo	)u {y(!GD, z' 5D 
+
+  !$1%GG6 K  zrB   c                    U S   U S   :  a  [        S5      e[        R                  " U S   5      n[        R                  " U S   5      nX4$ )Nr   r	   z%Start time must be less than end time)r   r   r   )timest_startt_ends      r   _get_time_doublesIndex._get_time_doubles  sJ    8eAhDEE//%(+a)~rB   c                
   U R                  U5      n[        U5      n[        R                  " U5      n[        R                  " U5      nU[        R
                  " U[        R                  " [        R                  5      5      U4$ r   )r   rS   r   create_string_bufferr   r#   r$   r:   )rq   r   
serializedsizer>   rx   s         r   
_serializeIndex._serialize  s]    ZZ_
:''
3NN1 V[[FNN6>>$BCZOOrB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   Index_SetResultSetOffsetr+   rq   r"   s     r   set_result_limitIndex.set_result_limit      ww//UCCrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   Index_GetResultSetOffsetr+   r   s    r   get_result_limitIndex.get_result_limit      ww//<<rB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   Index_SetResultSetLimitr+   r   s     r   set_result_offsetIndex.set_result_offset  s    ww..t{{EBBrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   Index_GetResultSetLimitr+   r   s    r   get_result_offsetIndex.get_result_offset  s    ww..t{{;;rB   Nc           	     t   U R                   R                  [        :X  a  U R                  " U/UQ7SU06$ U R	                  U5      u  pE[
        R                  " S5      nSnSnUb  U R                  U5      u  pvn[        R                  R                  U R                  XXPR                   R                  Xg5        g)a  Inserts an item into the index with the given coordinates.

:param id: A long integer that is the identifier for this index entry.  IDs
    need not be unique to be inserted into the index, and it is up
    to the user to ensure they are unique if this is a requirement.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time value as a float.

:param obj: a pickleable object.  If not None, this object will be
    stored in the index with the :attr:`id`.

The following example inserts an entry into the index with id `4321`,
and the object it stores with that id is the number `42`.  The
coordinate ordering in this instance is the default (interleaved=True)
ordering::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.insert(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...            obj=42)

This example is inserting the same object for a TPR-Tree, additionally
including a set of velocities at time `3`::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.Index(properties=p)  # doctest: +SKIP
    >>> idx.insert(4321,
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...            3.0),
    ...            obj=42)  # doctest: +SKIP

r   r   N)rF   rK   rL   	_insertTPr   r   c_ubyter   r
   r'   Index_InsertDatar+   r0   )	rq   idr   r   r5   r6   datar   pyserializeds	            r   rp   Index.insert  s    V ??:->>"<{<<<55kB~~a ?'+s';$D  KKV__-F-F	
rB   c                j   U R                  U5      u  pgU R                  U5      u  pU R                  XDS-   45      u  p[        R                  " S5      nSnUb  U R	                  U5      u  pn[
        R                  R                  U R                  UUUUU	U
UU R                  R                  UU5        g )Nr	   r   )r   r   r   r   r   r
   r'   rG   r+   rF   r0   )rq   r   r   
velocitiestimer   r5   r6   pv_minspv_maxsr   r   r   r   _s                  r   r   Index._insertTP  s     55kB77
C//ax0@A~~a ? OOC0MD""KKOO%%	
rB   c           	     p   U R                   R                  [        :X  a  U R                  " U6 $ U R	                  U5      u  p#[
        R                  " S5      n[        R                  R                  U R                  UUU R                   R                  [
        R                  " U5      5        UR                  $ )a  Return number of objects that intersect the given coordinates.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    time range as a float.

The following example queries the index for any objects any objects
that were stored in the index intersect the bounds given in the
coordinates::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.insert(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...            obj=42)

    >>> print(idx.count((0, 0, 60, 60)))
    1

This example is similar for a TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.Index(properties=p)  # doctest: +SKIP
    >>> idx.insert(4321,
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...             3.0),
    ...            obj=42)  # doctest: +SKIP

    >>> print(idx.count(((0, 0, 60, 60), (0, 0, 0, 0), (3, 5))))
    ... # doctest: +SKIP
    1

r   )rF   rK   rL   _countTPr   r   r9   r
   r'   Index_Intersects_countr+   r0   r!   r"   )rq   r   r5   r6   p_num_resultss        r   r   Index.count  s    T ??:-==+..55kB*&&KKOO%%LL'	
 """rB   c                j   U R                  U5      u  pEU R                  U5      u  pgU R                  U5      u  p[        R                  " S5      n
[        R
                  R                  U R                  UUUUUU	U R                  R                  [        R                  " U
5      5	        U
R                  $ r   )r   r   r   r9   r
   r'   Index_TPIntersects_countr+   rF   r0   r!   r"   )rq   r   r   r   r5   r6   r   r   r   r   r   s              r   r   Index._countTP9  s     55kB77
C//6*((KKOO%%LL'
	
 """rB   c                    g r    rq   r   objectss      r   containsIndex.containsP  s    TWrB   c                    g r   r   r   s      r   r   r   S  s      #rB   c                    g r   r   r   s      r   r   r   X       rB   c           
     6   U(       a  U R                  X5      $ U R                  U5      u  p4[        R                  " S5      n[        R                  " [        R
                  " 5       5      n [        R                  R                    [        R                  R                  U R                  UUU R                  R                  [        R                  " U5      [        R                  " U5      5        U R                  XeR                  5      $ ! [         a     gf = f)a
  Return ids or objects in the index that contains within the given
coordinates.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.

:param objects: If True, the intersection method will return index objects that
    were pickled when they were stored with each index entry, as well
    as the id and bounds of the index entries. If 'raw', the objects
    will be returned without the :class:`rtree.index.Item` wrapper.

The following example queries the index for any objects any objects
that were stored in the index intersect the bounds given in the
coordinates::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.insert(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...            obj=42)

    >>> hits = list(idx.contains((0, 0, 60, 60), objects=True))
    ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +SKIP
    >>> [(item.object, item.bbox) for item in hits if item.id == 4321]
    ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +SKIP
    [(42, [34.37768294..., 26.73758537..., 49.37768294...,
           41.73758537...])]

If the :class:`rtree.index.Item` wrapper is not used, it is faster to
request the 'raw' objects::

    >>> list(idx.contains((0, 0, 60, 60), objects="raw"))
    ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS +SKIP
    [42]

r   N)_contains_objr   r   r9   r   c_int64r
   r'   Index_Contains_idAttributeErrorr+   rF   r0   r!   _get_idsr"   rq   r   r   r5   r6   r   its          r   r   r   ]  s    V %%k;;55kB*^^FNN,-	GG%% 	!!KKOO%%LLLL'	
 }}R!4!455  		s   ,D 
DDc           
        U R                   UR                   :X  d   eU R                  R                  UR                  R                  :X  d   eSn[        U R                   U R                  S9nU R	                  U R
                  SS9 GH   nU R                   (       Ga   UR	                  UR                  SS9 H  n/ n[        [        UR                  5      5       H  nU[        UR                  5      S-  :  a7  UR                  [        UR                  U   UR                  U   5      5        MV  UR                  [        UR                  U   UR                  U   5      5        M     UR                  X&UR                  UR                  45        US-  nM     GM  UR	                  UR
                  SS9 H  n/ n[        [        UR
                  5      5       Hx  nUS-  S:X  a7  UR                  [        UR
                  U   UR
                  U   5      5        MC  UR                  [        UR
                  U   UR
                  U   5      5        Mz     UR                  X(UR                  UR                  45        US-  nM     GM     U$ )zTake the intersection of two Index objects.

:param other: another index
:return: a new index
:raises AssertionError: if self and other have different interleave or dimension
r   r-   rF   Tr   r   r	   )r-   rF   r0   r   intersectionr   bboxr%   rS   appendmaxminrp   object)	rq   otherr3   new_idxitem1item2r   jr   s	            r   __and__Index.__and__  s    5#4#4444((E,<,<,F,FFFFD$4$4Q &&t{{D&AE"//

D/IED"3uzz?3s5::!33 KKEJJqM5::a=(IJ KKEJJqM5::a=(IJ	 4 NN1U\\5<<,HIFA J #//d/KEF"3u||#45q5A:"MM#ell1ou||A*OP"MM#ell1ou||A*OP	 6 NN1u||U\\.JKFA L# B: rB   c                   U R                   UR                   :X  d   eU R                  R                  UR                  R                  :X  d   e[        U R                   U R                  S9nX4 H  nUR	                  UR
                  SS9 Hx  nU R                   (       a3  UR                  UR                  UR                  UR                  5        MG  UR                  UR                  UR
                  UR                  5        Mz     M     U$ )zTake the union of two Index objects.

:param other: another index
:return: a new index
:raises AssertionError: if self and other have different interleave or dimension
r   Tr   )
r-   rF   r0   r   r   r   rp   r   r   r  )rq   r  r  old_idxr{   s        r   __or__Index.__or__  s     5#4#4444((E,<,<,F,FFFFD$4$4Q }G,,W^^T,J##NN477DIIt{{CNN477DKKE	 K % rB   c                    g r   r   r   s      r   r   Index.intersection       rB   c                    g r   r   r   s      r   r   r         rB   c                    g r   r   r   s      r   r   r    r   rB   c           
     @   U R                   R                  [        :X  a  U R                  " USU06$ U(       a  U R	                  X5      $ U R                  U5      u  p4[        R                  " S5      n[        R                  " [        R                  " 5       5      n[        R                  R                  U R                  UUU R                   R                  [        R                  " U5      [        R                  " U5      5        U R!                  XeR"                  5      $ )a-	  Return ids or objects in the index that intersect the given
coordinates.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    time range as a float.

:param objects: If True, the intersection method will return index objects that
    were pickled when they were stored with each index entry, as well
    as the id and bounds of the index entries. If 'raw', the objects
    will be returned without the :class:`rtree.index.Item` wrapper.

The following example queries the index for any objects any objects
that were stored in the index intersect the bounds given in the
coordinates::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.insert(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...            obj=42)

    >>> hits = list(idx.intersection((0, 0, 60, 60), objects=True))
    >>> [(item.object, item.bbox) for item in hits if item.id == 4321]
    ... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
    [(42, [34.37768294..., 26.73758537..., 49.37768294...,
           41.73758537...])]

If the :class:`rtree.index.Item` wrapper is not used, it is faster to
request the 'raw' objects::

    >>> list(idx.intersection((0, 0, 60, 60), objects="raw"))
    [42]

Similar for the TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.Index(properties=p)  # doctest: +SKIP
    >>> idx.insert(4321,
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...             3.0),
    ...            obj=42)  # doctest: +SKIP

    >>> hits = list(idx.intersection(
    ...     ((0, 0, 60, 60), (0, 0, 0, 0), (3, 5)), objects=True))
    ...  # doctest: +SKIP
    >>> [(item.object, item.bbox) for item in hits if item.id == 4321]
    ... # doctest: +SKIP
    [(42, [34.37768294..., 26.73758537..., 49.37768294...,
           41.73758537...])]

r   r   )rF   rK   rL   _intersectionTP_intersection_objr   r   r9   r   r   r
   r'   Index_Intersects_idr+   r0   r!   r   r"   r   s          r   r   r    s    ~ ??:-''&-  ))+??55kB*^^FNN,-##KKOO%%LLLL'	
 }}R!4!455rB   c                   U R                  U5      u  pVU R                  U5      u  pxU R                  U5      u  p[        R                  " S5      nU(       aD  [        R
                  R                  n[        R                  " [        R                  " 5       5      nOC[        R
                  R                  n[        R                  " [        R                  " 5       5      nU" U R                  UUUUU	U
U R                  R                  [        R                  " U5      [        R                  " U5      5
        U(       a  U R                  XR                   U5      $ U R#                  XR                   5      $ r   )r   r   r   r9   r
   r'   Index_TPIntersects_objr   r)   Index_TPIntersects_idr   r+   rF   r0   r!   _get_objectsr"   r   )rq   r   r   r   r   r5   r6   r   r   r   r   r   callr   s                 r   r  Index._intersectionTPJ  s   55kB77
C//6*7711D 12B7700D 01BKKOO%%LLLL'	
 $$R)<)<gFF==%8%899rB   c           
        U R                  U5      u  p4[        R                  " S5      n[        R                  " [        R                  " 5       5      n[
        R                  R                  U R                  UUU R                  R                  [        R                  " U5      [        R                  " U5      5        U R                  XeR                  U5      $ r   )r   r   r9   r   r)   r
   r'   Index_Intersects_objr+   rF   r0   r!   r  r"   r   s          r   r  Index._intersection_objj  s    55kB*^^FOO-.$$KKOO%%LLLL'	
   %8%8'BBrB   c           
        U R                  U5      u  p4[        R                  " S5      n[        R                  " [        R                  " 5       5      n [
        R                  R                    [
        R                  R                  U R                  UUU R                  R                  [        R                  " U5      [        R                  " U5      5        U R                  XeR                  U5      $ ! [         a     g f = fr   )r   r   r9   r   r)   r
   r'   Index_Contains_objr   r+   rF   r0   r!   r  r"   r   s          r   r   Index._contains_obj{  s    55kB*^^FOO-.	GG&& 	""KKOO%%LLLL'	
   %8%8'BB  		s   C4 4
D Dc           	   #    #    [         R                  " U[         R                  " [         R                  " [         R                  U-  5      5      5      n[         R                  " U[         R                  " [         R                  " [         R                  5      5      5      n US:w  a-  [	        U5       H  n[        U R                  XF   5      v   M     O;[	        U5       H,  n[        XF   5      nUc  Uv   M  U R                  U5      v   M.     [        R                  R                  XR5        g ! [        R                  R                  XR5        f = f7f)Nraw)r   r#   r$   r)   r%   Itemr   rA   r
   r'   Index_DestroyObjResults)rq   r   num_resultsr   itemsitsr3   r   s           r   r  Index._get_objects  s     v~~foo.KLM
 kk%v0O!PQ	>%{+Atzz5844 , {+A$UX.D|"
"jj.. , GG++C=DGG++C=s   BE!A.D/  E/!EEc              #    #    [         R                  " U[         R                  " [         R                  U-  5      5      n[         R                  " U[         R                  " [         R                  5      5      n [        U5       H  nUR                  U   v   M     [        R                  R                  U5        g ! [        R                  R                  U5        f = f7fr   )
r   r#   r$   r   r)   r%   r&   r
   r'   r(   )rq   r   r(  r)  r*  r3   s         r   r   Index._get_ids  s     Bv~~/K LMkk%!@A	$;'nnQ'' ( GGs#DGGs#s   A6C 9#B<  C <!CC c           	        U R                  U5      u  pE[        R                  " [        R                  " U5      5      n[        R                  " [        R                  " 5       5      n[
        R                  R                  U R                  UUU R                  R                  [        R                  " U5      U5        U R                  XvR                  R                  U5      $ r   )r   r   r   r9   r)   r
   r'   Index_NearestNeighbors_objr+   rF   r0   r!   r  r&   r"   rq   r   r(  r   r5   r6   r   r   s           r   _nearest_objIndex._nearest_obj  s    55kBv{'CD^^FOO-.**KKOO%%LL	
   %;%;%A%A7KKrB   c                    g r   r   rq   r   r(  r   s       r   nearestIndex.nearest  r  rB   c                    g r   r   r4  s       r   r5  r6    r  rB   c                    g r   r   r4  s       r   r5  r6    r   rB   c           	     V   U R                   R                  [        :X  a  U R                  " USU06$ U(       a  U R	                  XU5      $ U R                  U5      u  pE[        R                  " [        R                  " U5      5      n[        R                  " [        R                  " 5       5      n[        R                  R                  U R                  UUU R                   R                  [        R                  " U5      U5        U R!                  XvR"                  R$                  5      $ )ap  Returns the ``k``-nearest objects to the given coordinates.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    time range as a float.

:param num_results: The number of results to return nearest to the given
    coordinates. If two index entries are equidistant, *both* are returned.
    This property means that :attr:`num_results` may return more
    items than specified

:param objects: If True, the nearest method will return index objects that
    were pickled when they were stored with each index entry, as
    well as the id and bounds of the index entries.
    If 'raw', it will return the object as entered into the database
    without the :class:`rtree.index.Item` wrapper.

.. warning::
    This is currently not implemented for the TPR-Tree.

Example of finding the three items nearest to this one::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.insert(4321, (34.37, 26.73, 49.37, 41.73), obj=42)
    >>> hits = idx.nearest((0, 0, 10, 10), 3, objects=True)
r   )rF   rK   rL   
_nearestTPr1  r   r   r   r9   r   r
   r'   Index_NearestNeighbors_idr+   r0   r!   r   r&   r"   r0  s           r   r5  r6    s    L ??:-??KAAA$$[wGG55kB v{'CD^^FNN,-))KKOO%%LL	
 }}R!7!7!=!=>>rB   c                R   SSK nUR                  UR                  :X  d   eUR                  UR                  :X  d   eUR                  UR                  5      nUR                  UR                  5      nUR                  u  pEUR                  S   UR
                  -  nUR                  S   UR
                  -  nUR                  SU-  UR                  S9nUR                  XCR                  S9n	[        R                  " S5      n
Su  p [        R                  R                  U R                  XK-
  U[        U5      UUXS R                  R                   X+S R                  R                   XS R                  R                   XS R                  R                   [        R"                  " U
5      5        U
R$                  XK-
  :X  a  USU	R'                  5        U	4$ XXU
R$                  -    R'                  5       -  nXR$                  -  nUR)                  S[        U5      -  SS9nGM  )	a  Bulk intersection query for obtaining the ids of entries
which intersect with the provided bounding boxes.  The return
value is a tuple consisting of two 1D NumPy arrays: one of
intersecting ids and another containing the counts for each
bounding box.

:param mins: A NumPy array of shape `(n, d)` containing the
    minima to query.

:param maxs: A NumPy array of shape `(n, d)` containing the
    maxima to query.
r   Nr	   r   dtyper   r   Frefcheck)numpyshapestridesastypefloat64itemsizeemptyint64uint64r   r   r
   r'   Index_Intersects_id_vr+   rS   r   r!   r"   sumresize)rq   r1   r2   npnr>   d_i_strid_j_striidscountsnroffnoffis                r   intersection_vIndex.intersection_v  s    	zzTZZ'''||t||+++ {{2::&{{2::& zz <<?dmm3<<?dmm3hhq1uBHHh-!99-^^A
GG))CU""''U""''E
!!&&u$$))R  xx18#>VZZ\*F22 tRXXo6::<< jjSXj>/ rB   c                   SSK nUR                  UR                  :X  d   eUR                  UR                  :X  d   eUR                  UR                  5      nUR                  UR                  5      nUR                  u  pUR                  S   UR
                  -  n
UR                  S   UR
                  -  nUR                  X-  UR                  S9nUR                  XR                  S9n[        R                  " S5      nSu  nnUb;  [        U5      U:X  d   eUR                  UR                  5      R                  5       nOU(       a  UR                  U5      nOSn [        R                  R!                  U R"                  U(       d  UOU* X-
  U	[        U5      U
UXS R                  R$                  X/S R                  R$                  UUS R                  R$                  XS R                  R$                  Ub  UUS R                  R$                  OS[        R&                  " U5      5        UR(                  X-
  :X  a2  U(       a  USUR+                  5        UU4$ USUR+                  5        U4$ UXXR(                  -    R+                  5       -  nXR(                  -  nUR-                  S[        U5      -  SS9nGMe  )	a  Bulk ``k``-nearest query for the given bounding boxes.  The
return value is a tuple consisting of, by default, two 1D NumPy
arrays: one of intersecting ids and another containing the
counts for each bounding box.

:param mins: A NumPy array of shape `(n, d)` containing the
    minima to query.

:param maxs: A NumPy array of shape `(n, d)` containing the
    maxima to query.

:param num_results: The maximum number of neighbors to return
    for each bounding box.  If there are multiple equidistant
    furthest neighbors then, by default, they are *all*
    returned.  Hence, the actual number of results can be
    greater than requested.

:param max_dists: Optional; a NumPy array of shape `(n,)`
    containing the maximum distance to consider for each
    bounding box.

:param strict: If True then each point will never return more
    than `num_results` even in cases of equidistant furthest
    neighbors.

:param return_max_dists: If True, the distance of the furthest
    neighbor for each bounding box will also be returned.
r   Nr	   r=  r?  r   Fr@  )rB  rC  rD  rE  rF  rG  rH  rI  rJ  r   r   rS   r   zerosr
   r'   Index_NearestNeighbors_id_vr+   r   r!   r"   rL  rM  )rq   r1   r2   r(  	max_distsstrictreturn_max_distsrN  rO  r>   rP  rQ  rR  rS  rT  rU  rV  distss                     r   	nearest_vIndex.nearest_vT  sb   J 	zzTZZ'''||t||+++ {{2::&{{2::& zz <<?dmm3<<?dmm3hhqbhhh7!99-^^A
d y>Q&&&$$RZZ0557EHHQKEEGG//#)|CU""''U""''DE
!!&&u$$)),1,=de##((4R " xx18##~.==~.66 dXXo6::<< jjSXj>9 rB   c                   U R                  U5      u  pgU R                  U5      u  pU R                  U5      u  p[        R                  " [        R                  " U5      5      nU(       aD  [        R                  " [        R
                  " 5       5      n[        R                  R                  nOC[        R                  " [        R                  " 5       5      n[        R                  R                  nU" U R                  UUUU	U
UU R                  R                  [        R                  " U5      U5
        U(       a&  U R                  XR                   R"                  U5      $ U R%                  XR                   R"                  5      $ r   )r   r   r   r   r9   r)   r
   r'   Index_TPNearestNeighbors_objr   Index_TPNearestNeighbors_idr+   rF   r0   r!   r  r&   r"   r   )rq   r   r   r   r(  r   r5   r6   r   r   r   r   r   r   r  s                  r   r:  Index._nearestTP  s   55kB77
C//6v{'CD 12B7777D 01B7766DKKOO%%LL	
 $$R)?)?)E)EwOO==%;%;%A%ABBrB   c                ~    Uc  U R                   n[        U R                  [        R                  R
                  U5      $ )ac  Returns the bounds of the index

:param coordinate_interleaved: If True, the coordinates are turned
    in the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax],
    otherwise they are returned as
    [xmin, xmax, ymin, ymax, ..., ..., kmin, kmax].  If not specified,
    the :attr:`interleaved` member of the index is used, which
    defaults to True.
)r-   r7   r+   r
   r'   Index_GetBounds)rq   coordinate_interleaveds     r   
get_boundsIndex.get_bounds  s4     ")%)%5%5"4;;(?(?AWXXrB   c                
   U R                   R                  [        :X  a  U R                  " U/UQ76 $ U R	                  U5      u  p4[
        R                  R                  U R                  XX@R                   R                  5        g)a1  Deletes an item from the index with the given ``'id'`` and
   coordinates given by the ``coordinates`` sequence. As the index can
   contain multiple items with the same ID and coordinates, deletion
   is not guaranteed to delete all items in the index with the given ID
   and coordinates.

:param id: A long integer ID for the entry, which need not be unique. The
    index can contain multiple entries with identical IDs and
    coordinates. Uniqueness of items should be enforced at the
    application level by the user.

:param coordinates: Dimension * 2 coordinate pairs, representing the min
    and max coordinates in each dimension of the item to be
    deleted from the index. Their ordering will depend on the
    index's :attr:`interleaved` data member.
    These are not the coordinates of a space containing the
    item, but those of the item itself. Together with the
    id parameter, they determine which item will be deleted.
    This may be an object that satisfies the numpy array protocol.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    original time the object was inserted and the current time
    as a float.

Example::

    >>> from rtree import index
    >>> idx = index.Index()
    >>> idx.delete(4321,
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734))

For the TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.Index(properties=p)  # doctest: +SKIP
    >>> idx.delete(4321,
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...             (3.0, 5.0)))  # doctest: +SKIP

N)
rF   rK   rL   	_deleteTPr   r
   r'   Index_DeleteDatar+   r0   )rq   r   r   r5   r6   s        r   deleteIndex.delete  sd    Z ??:->>"3{3355kB  KKV__-F-F	
rB   c                    U R                  U5      u  pVU R                  U5      u  pxU R                  U5      u  p[        R                  R	                  U R
                  UUUUUU	U
U R                  R                  5	        g r   )r   r   r
   r'   Index_DeleteTPDatar+   rF   r0   )rq   r   r   r   r   r5   r6   r   r   r   r   s              r   rl  Index._deleteTP  sv     55kB77
C//6""KKOO%%
	
rB   c                f    [        [        R                  R                  U R                  5      5      $ r   )rO   r
   r'   Index_IsValidr+   r   s    r   validIndex.valid/  s     DGG))$++677rB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   Index_ClearBufferr+   r   s    r   clearBufferIndex.clearBuffer2  s    ww((55rB   c                    [        U5      S-  S:X  d   S5       e[        U5      S-  n/ n[        U5       H  nUR                  X   XU-      /5        M     U$ )z
[xmin, ymin, xmax, ymax] => [xmin, xmax, ymin, ymax]

>>> Index.deinterleave([0, 10, 1, 11])
[0, 1, 10, 11]

>>> Index.deinterleave([0, 1, 2, 10, 11, 12])
[0, 10, 1, 11, 2, 12]

r   r   must be a pairwise listrS   r%   extend)rq   r-   r0   dir3   s        r   r*   Index.deinterleave5  sd     ;!#q(C*CC($)	y!AII{~{y='ABC "	rB   c           	         [        U5      S-  S:X  d   S5       e/ n[        S5       H=  nUR                  [        S[        U5      S5       Vs/ s H	  oAX4-      PM     sn5        M?     U$ s  snf )a  
[xmin, xmax, ymin, ymax, zmin, zmax]
    => [xmin, ymin, zmin, xmax, ymax, zmax]

>>> Index.interleave([0, 1, 10, 11])
[0, 10, 1, 11]

>>> Index.interleave([0, 10, 1, 11, 2, 12])
[0, 1, 2, 10, 11, 12]

>>> Index.interleave((-1, 1, 58, 62, 22, 24))
[-1, 58, 22, 1, 62, 24]

r   r   r|  r}  )rq   deinterleavedr-   r3   r  s        r   
interleaveIndex.interleaveH  sx      =!A%*E,EE*qA/4QM8JA/NO/N!qu%/NO   Ps   A*
c                  ^ ^^^^^ [        U5      mT R                  R                  m[        R                  T-  nU" 5       mU" 5       m[        R
                  " [        R                  " [        R                  " S5      5      [        R                  " [        R                  5      5      mUUUUU U4S jn[        R                  " U5      n[        T R                  R                  U5      $ )zPThis function is used to instantiate the index given an
iterable stream of data.r   c                  >  [        T5      u  U S'   pgTR                  (       a  UST TSS& UTS TSS& OUSSS2   TSS& USSS2   TSS& TUS'   TUS'   TUS'   Uc  TUS'   SUS'   gTR                  U5      u  US'   p[        R                  " U	[        R                  " [        R                  5      5      US'   g! [         a     g[         a  nUTl         SnAgSnAff = f)zThis function must fill pointers to individual entries that will
be added to the index.  The C API will actually call this function
to fill out the pointers.  If this function returns anything other
than 0, it is assumed that the stream of data is done.r   Nr   r	   )
nextStopIteration	Exceptionrj   r-   r   r   r#   r$   r   )p_idr5   r6   p_dimensionp_datap_lengthr   r   excr   r   r0   r2   r1   no_datarq   stream_iters              r   py_next_item3Index._create_idx_from_stream.<locals>.py_next_itemn  s	   ,0,=)Q %jy1Q%ij1Q%cc*Q%add+QF1IF1I 'KN{#q	
  (,s';$T"KKfnnV^^.LMq	5 !  "%s   B= =
C#		C#CC#)iterrF   r0   r   r   r#   r   r   r$   r
   NEXTFUNCIndexStreamHandler+   )	rq   rt   darrayr  r0   r2   r1   r  r  s	   `   @@@@@r   rk   Index._create_idx_from_streama  s     6lOO--	9,xx++NN6>>!,-v~~fnn/M
"	 "	H |, !7!7@@rB   c                n   [        U5      [        U5      :X  d   e[        U5      [        U5      :X  d   eUR                  UR                  :X  d   eUR                  [        5      nUR                  [        5      nUR                  [        5      nUR
                  u  pEUR                  S   S-  nUR                  S   S-  nUR                  S   S-  n[        U R                  R                  UUUUUUR                  R                  UR                  R                  UR                  R                  5	      $ )Nr   r   r	   )rS   rD  rE  r   floatrC  IndexArrayHandlerF   r+   r   r   )	rq   ibufminbufmaxbufrO  r>   i_strirP  rQ  s	            r   rl   Index._create_idx_from_array  s   4yCK'''4yCK'''~~/// {{3u%u% || aA%>>!$)>>!$)OO""KKMMMM

 
	
rB   c                |   [         R                  " 5       n[         R                  " [         R                  " 5       5      n[         R                  " [         R                  " 5       5      n[         R                  " [         R                  " [         R                  " 5       5      5      n[         R                  " [         R                  " [         R                  " 5       5      5      n[         R                  " [         R                  " [         R                  " 5       5      5      n[         R                  " S5      n[
        R                  R                  U R                  [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " U5      [         R                  " U5      5        / nUR                  n	[         R                  " U[         R                  " [         R                  U	-  5      5      n
[         R                  " U[         R                  " [         R                  U	-  5      5      n[         R                  " U[         R                  " [         R                  " [         R                  5      U	-  5      5      n[         R                  " U[         R                  " [         R                  " [         R                  5      U	-  5      5      n[         R                  " U[         R                  " [         R                  " [         R                  5      U	-  5      5      n[        U	5       GH;  nUR                  U   nUR                  U   nU
R                  U   n[         R                  " U[         R                  " [         R                  U-  5      5      n/ n[        U5       H!  nUR                  UR                  U   5        M#     [
        R                  R!                  [         R                  " U[         R                  " [         R"                  5      5      5        UR                  U   nUR                  U   n[         R                  " U[         R                  " [         R                  UR                  -  5      5      n[         R                  " U[         R                  " [         R                  UR                  -  5      5      n/ n[        UR                  5       Vs/ s H  nUR                  U   PM     nnU[        UR                  5       Vs/ s H  nUR                  U   PM     sn-  n[         R                  " U[         R                  " [         R                  5      5      n[         R                  " U[         R                  " [         R                  5      5      n[
        R                  R!                  [         R                  " U[         R                  " [         R"                  5      5      5        [
        R                  R!                  [         R                  " U[         R                  " [         R"                  5      5      5        UR                  UUU45        GM>     U$ s  snf s  snf r   )r   r    r   r   r   r
   r'   Index_GetLeavesr+   r!   r"   r#   r$   r%   r&   r   r(   r)   )rq   leaf_node_countp_leafsizes	p_leafidspp_childidsr.   r/   r0   outputr   sizesrR  childr1   r2   r3   p_child_idsr   r   child_ids_array	child_idsr  r5   r6   r   s                            r   leavesIndex.leaves  s/    //+nnV__%67NN6>>#34	nnV^^FNN4D%EF..0A!BC..0A!BCOOA&	KKLL)LL%LL#LL%LL!LL!LL#		
 %%K%8O)PQkk)V^^FNNU4J%KLv~~(F(NO
 {{V^^FNN6??$Ce$KL
 {{V^^FNN6??$Ce$KL
 uA..+KaB>>!$D$kkV^^FNNT,ABO I4[  !9!9!!<= ! GGK)HI ]]1%F]]1%F[[v'HIF [[v'HIF F27	2HI2HQfooa(2HFI53IJ3Iavq)3IJJF [[)HIF[[)HIFGGv{{66>>&//3RSTGGv{{66>>&//3RSTMM2y&12M P  JJs   *Z4Z9)rj   rf   r+   r-   rF   rr   r   rs   r   returnNoner  r   r  rQ   r  dict[str, Any]r   r  r  r  )r   r  r  rR   )r   rR   r  r  r  r  )r   Sequence[float]r  ztuple[float, float]r   )r   r   r   r   r   r  r  r  )r   r   r   r  r   r  r   r  r   r  r  r  )r   r   r  r   )r   r  r   r  r   r  r  r   )r   r   r   Literal[True]r  Iterator[Item]F)r   r   r   Literal[False]r  zIterator[int] | None)r   r   r   Literal['raw']r  Iterator[object])r   r   r   bool | Literal['raw']r  z$Iterator[Item | int | object] | None)r  r   r  r   )r   r   r   r  r  Iterator[int])r   r   r   r  r  Iterator[Item | int | object])r   r   )r   r   r(  r   r   r  r  r  )r   r   r(  r   r   r  r  r  )r   r   r(  r   r   r  r  r  r	   F)r   r   r(  r   r   r  r  r  )r	   NFF)r   r   r   r   r  r  )
r   r   r   r  r   r  r   r  r  r  )r  rO   )r-   zSequence[object]r  zlist[object])r  r  r  list[float]);__name__
__module____qualname____firstlineno____doc__r|   r   r   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   propertyresult_limitr   r   result_offsetrp   addr   r   r   r   r   r  r  r   r  r  r   r  r   r1  r5  rW  r`  r:  ri  r   rn  rl  ru  ry  classmethodr*   r  rk   rl   r  __static_attributes__r   rB   r   r   r   N   s   :\S|L
:!$. 
"*"	"H  	PD= ,.>?LC< .0ABM7
r C 

 %
 $	

 
 
 

<8#t#*#8G#PU#	#. W W:?##)7#	# # )7	 
 BGA6A6)>A6	-A6F+Z. )6	  :?)7	  )7	 
 BGU6U6)>U6	&U6n:@C"C,>,
$L$ -0;H	  LQ-0;I	  -0;I	  ).	C?C? C? '	C?
 
'C?J9?~ _?BC@Y j!F2
h

 %
 $	

 
 

,86  $  02Ah
<KrB   r   c                  X    \ rS rSrSrSrSSS jjrSS jrSS jr\	SS j5       r
S rS	rg
)r&  i  zA container for index entries)r+   ownedr   r  r   c                (   U(       a  X l         X0l        [        R                  R	                  U R                   5      U l        SU l        U R                  U5      U l        [        U R                   [        R                  R                  S5      U l
        g)zThere should be no reason to instantiate these yourself. Items are
created automatically when you call
:meth:`rtree.index.Index.intersection` (or other index querying
methods) with objects=True given the parameters of the function.NF)r+   r  r
   r'   IndexItem_GetIDr   r  
get_objectr7   IndexItem_GetBoundsr   )rq   r   r+   r  s       r   r|   Item.__init__
  s`      K
''))$++6ooe,!$++tww/J/JERrB   c                4    U R                   UR                   :  $ r   r   rq   r  s     r   __lt__Item.__lt__      ww!!rB   c                4    U R                   UR                   :  $ r   r  r  s     r   __gt__Item.__gt__  r  rB   c                @    [         R                  U R                  5      $ )z+Returns the bounding box of the index entry)r   r  r   r   s    r   r   	Item.bbox!  s     ,,rB   c                v    U R                   b  U R                   $ [        U R                  5      nUc  g U" U5      $ r   )r  rA   r+   )rq   r   r   s      r   r  Item.get_object&  s6    ;;";;%<T{rB   )r   r+   r   r  r  Nr  r  )r  r&  r  rO   )r  r  )r  r  r  r  r  	__slots__r|   r  r  r  r   r  r  r   rB   r   r&  r&    s3    '=IS""" - -rB   r&  c                      \ rS rSrSrSrg)InvalidHandleExceptioni0  z3Handle has been destroyed and can no longer be usedr   N)r  r  r  r  r  r  r   rB   r   r  r  0  s    =rB   r  c                  R    \ rS rSrS
S jrSS jrS rSS jr\S 5       r	SS jr
Srg	)Handlei4  c                2    U R                   " U0 UD6U l        g r   )_create_ptrrq   rr   rs   s      r   r|   Handle.__init__5  s    LL$1&1	rB   c                    [         er   rn   r  s      r   r  Handle._create8      !!rB   c                    [         er   r  )rq   ptrs     r   _destroyHandle._destroy;  r  rB   c                     U R                   b#  U R                  U R                   5        S U l         g g ! [         a     g f = fr   )r  r  r   r   s    r   r   Handle.destroy>  sA    	yy$dii( 	 %  		s   /3 
A A c                @    U R                   c  [        eU R                   $ r   )r  r  r   s    r   _as_parameter_Handle._as_parameter_F  s    99((yyrB   c                F     U R                  5         g ! [         a     g f = fr   )r   rm   r   s    r   __del__Handle.__del__L  s$    	LLN 	
 	s    
  )r  Nr  )rr   r   rs   r   r  )r  r  r  r  r|   r  r  r   r  r  r  r  r   rB   r   r  r  4  s/    2""  
rB   r  c                  v    \ rS rSr\R
                  R                  r\R
                  R                  r	SS jr
Srg)ro   iW  c                     [         R                  R                    U R                  b*  [         R                  R                  U R                  5        g g ! [         a     g f = fr   )r
   r'   Index_Flushr  r   r   s    r   r   IndexHandle.flush[  sK    	GGyy$##DII. % 		s   AA 
A! A!r   Nr  )r  r  r  r  r
   r'   Index_Creater  Index_Destroyr  r   r  r   rB   r   ro   ro   W  s%    gg""Gww$$HrB   ro   c                  @    \ rS rSr\R
                  R                  rSrg)r  id  r   N)	r  r  r  r  r
   r'   Index_CreateWithStreamr  r  r   rB   r   r  r  d  s    gg,,GrB   r  c                  @    \ rS rSr\R
                  R                  rSrg)r  ij  r   N)	r  r  r  r  r
   r'   Index_CreateWithArrayr  r  r   rB   r   r  r  j  s    ''//rB   r  c                  l    \ rS rSr\R
                  R                  r\R
                  R                  r	Sr
g)PropertyHandleip  r   N)r  r  r  r  r
   r'   IndexProperty_Creater  IndexProperty_Destroyr  r  r   rB   r   r	  r	  p  s     gg**Gww,,HrB   r	  c                     \ rS rSrSrSrS?S@S jjrSAS jrSBS jrS r	SCS	 jr
SDS
 jrSDS jrSES jrSFS jr\" \\5      r SES jrSFS jr\" \\5      r SES jrSFS jr\" \\5      r SES jrSFS jr\" \\5      r SES jrSFS jr\" \\5      r SES jrSFS jr\" \\5      r SES jr SFS jr!\" \ \!5      r" SES jr#SFS jr$\" \#\$5      r% SES jr&SFS jr'\" \&\'5      r( SES jr)SFS jr*\" \)\*5      r+ SES  jr,SFS! jr-\" \,\-5      r. S" r/S# r0\" \/\05      r1 S$ r2S% r3\" \2\35      r4 SES& jr5SFS' jr6\" \5\65      r7 S( r8S) r9\" \8\95      r: SES* jr;SFS+ jr<\" \;\<5      r= SES, jr>SFS- jr?\" \>\?5      r@ S. rAS/ rB\" \A\B5      rC S0 rDS1 rE\" \D\E5      rF S2 rGS3 rH\" \G\H5      rI S4 rJS5 rK\" \J\K5      rL S6 rMS7 rN\" \M\N5      rO SES8 jrPSFS9 jrQ\" \P\Q5      rR S: rSS; rT\" \S\T5      rU S< rVS= rW\" \V\W5      rXS>rYg)Gr   iu  zAn index property object is a container that contains a number of
settable index properties.  Many of these properties must be set at
index creation times, while others can be used to adjust performance
or behavior.)buffering_capacitycustom_storage_callbackscustom_storage_callbacks_sizedat_extensionr0   rX   fill_factorrY   index_capacityr^   leaf_capacitynear_minimum_overlap_factorrH   rI   point_pool_capacityregion_pool_capacityreinsert_factorsplit_distribution_factorrW   	tight_mbrtpr_horizonrK   variantwritethroughNc                L    Uc
  [        5       nXl        U R                  U5        g r   r	  r+   initialize_from_dict)rq   r+   r  rs   s       r   r|   Property.__init__  s"    >#%F!!&)rB   c                    UR                  5        H  u  p#Uc  M
  [        XU5        M     SU;  a@  U R                  n[        U R                  U R
                  5      nXE:  a  US-  S-   U l        g g g )Nr     r	   )r)  setattrr  r  r  r  )rq   r   kvnmofilcs         r   r  Property.initialize_from_dict  so    KKMDA}# "
 )533Dd))4+=+=>C{36!8a<0  6rB   c                "    U R                  5       $ r   )as_dictr   s    r   r   Property.__getstate__  s    ||~rB   c                D    [        5       U l        U R                  U5        g r   r  r   s     r   r   Property.__setstate__  s    $&!!%(rB   c                t    0 nU R                    H  n [        X5      nX1U'   M     U$ ! [         a    S n Nf = fr   )pkeysgetattrr   )rq   r>   r$  r%  s       r   r*  Property.as_dict  sJ    AD$ aD    s   (77c                4    [        U R                  5       5      $ r   )reprr*  r   s    r   r   Property.__repr__  s    DLLN##rB   c                J    [         R                  " U R                  5       5      $ r   )pprintpformatr*  r   s    r   __str__Property.__str__  s    ~~dlln--rB   c                     U R                   $ ! [         a4    [        R                  R	                  U R
                  5      nXl         Us $ f = fr   )_typer   r
   r'   IndexProperty_GetIndexTyper+   )rq   rK   s     r   get_index_typeProperty.get_index_type  sB    	:: 	7755dkkBD"JK	    ;AAc                b    Xl         [        R                  R                  U R                  U5      $ r   )r;  r
   r'   IndexProperty_SetIndexTyper+   r   s     r   set_index_typeProperty.set_index_type  s"    
ww11$++uEErB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetIndexVariantr+   r   s    r   get_variantProperty.get_variant      ww44T[[AArB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetIndexVariantr+   r   s     r   set_variantProperty.set_variant      ww44T[[%HHrB   c                     U R                   $ ! [         a4    [        R                  R	                  U R
                  5      nXl         Us $ f = fr   )
_dimensionr   r
   r'   IndexProperty_GetDimensionr+   )rq   dims     r   get_dimensionProperty.get_dimension  sB    	??" 	''44T[[AC#&OJ	r?  c                    US::  a  [        S5      eXl        [        R                  R	                  U R
                  U5      $ )Nr   z1Negative or 0 dimensional indexes are not allowed)r   rO  r
   r'   IndexProperty_SetDimensionr+   r   s     r   set_dimensionProperty.set_dimension  s5    A:PQQww11$++uEErB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetIndexStorager+   r   s    r   get_storageProperty.get_storage  rH  rB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetIndexStorager+   r   s     r   set_storageProperty.set_storage  rM  rB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetPagesizer+   r   s    r   get_pagesizeProperty.get_pagesize  s    ww00==rB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zPagesize must be > 0)r   r
   r'   IndexProperty_SetPagesizer+   r   s     r   set_pagesizeProperty.set_pagesize  s0    A:344ww00eDDrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetIndexCapacityr+   r   s    r   get_index_capacityProperty.get_index_capacity  s    ww55dkkBBrB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zindex_capacity must be > 0)r   r
   r'   IndexProperty_SetIndexCapacityr+   r   s     r   set_index_capacityProperty.set_index_capacity  s0    A:9::ww55dkk5IIrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetLeafCapacityr+   r   s    r   get_leaf_capacityProperty.get_leaf_capacity  rH  rB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zleaf_capacity must be > 0)r   r
   r'   IndexProperty_SetLeafCapacityr+   r   s     r   set_leaf_capacityProperty.set_leaf_capacity  s0    A:899ww44T[[%HHrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   "IndexProperty_GetIndexPoolCapacityr+   r   s    r   get_index_pool_capacity Property.get_index_pool_capacity      ww99$++FFrB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zindex_pool_capacity must be > 0)r   r
   r'   "IndexProperty_SetIndexPoolCapacityr+   r   s     r   set_index_pool_capacity Property.set_index_pool_capacity!  0    A:>??ww99$++uMMrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   "IndexProperty_GetPointPoolCapacityr+   r   s    r   get_point_pool_capacity Property.get_point_pool_capacity)  r|  rB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zpoint_pool_capacity must be > 0)r   r
   r'   "IndexProperty_SetPointPoolCapacityr+   r   s     r   set_point_pool_capacity Property.set_point_pool_capacity,  r  rB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   #IndexProperty_GetRegionPoolCapacityr+   r   s    r   get_region_pool_capacity!Property.get_region_pool_capacity4  s    ww::4;;GGrB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   z region_pool_capacity must be > 0)r   r
   r'   #IndexProperty_SetRegionPoolCapacityr+   r   s     r   set_region_pool_capacity!Property.set_region_pool_capacity7  s0    A:?@@ww::4;;NNrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   "IndexProperty_GetBufferingCapacityr+   r   s    r   get_buffering_capacityProperty.get_buffering_capacity?  r|  rB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   zbuffering_capacity must be > 0)r   r
   r'   "IndexProperty_SetBufferingCapacityr+   r   s     r   set_buffering_capacityProperty.set_buffering_capacityB  s0    A:=>>ww99$++uMMrB   c                f    [        [        R                  R                  U R                  5      5      $ r   )rO   r
   r'    IndexProperty_GetEnsureTightMBRsr+   r   s    r   get_tight_mbrProperty.get_tight_mbrJ  s     DGG<<T[[IJJrB   c                ~    [        U5      n[        [        R                  R                  U R                  U5      5      $ r   )rO   r
   r'    IndexProperty_SetEnsureTightMBRsr+   r   s     r   set_tight_mbrProperty.set_tight_mbrM  s+    UDGG<<T[[%PQQrB   c                f    [        [        R                  R                  U R                  5      5      $ r   )rO   r
   r'   IndexProperty_GetOverwriter+   r   s    r   get_overwriteProperty.get_overwriteT  s     DGG66t{{CDDrB   c                ~    [        U5      n[        [        R                  R                  U R                  U5      5      $ r   )rO   r
   r'   IndexProperty_SetOverwriter+   r   s     r   set_overwriteProperty.set_overwriteW  s+    UDGG66t{{EJKKrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   )IndexProperty_GetNearMinimumOverlapFactorr+   r   s    r   get_near_minimum_overlap_factor(Property.get_near_minimum_overlap_factor^  s    ww@@MMrB   c                x    US::  a  [        S5      e[        R                  R                  U R                  U5      $ )Nr   z'near_minimum_overlap_factor must be > 0)r   r
   r'   )IndexProperty_SetNearMinimumOverlapFactorr+   r   s     r   set_near_minimum_overlap_factor(Property.set_near_minimum_overlap_factora  s0    A:FGGww@@eTTrB   c                f    [        [        R                  R                  U R                  5      5      $ r   )rO   r
   r'   IndexProperty_GetWriteThroughr+   r   s    r   get_writethroughProperty.get_writethroughk  s     DGG99$++FGGrB   c                ~    [        U5      n[        [        R                  R                  U R                  U5      5      $ r   )rO   r
   r'   IndexProperty_SetWriteThroughr+   r   s     r   set_writethroughProperty.set_writethroughn  s+    UDGG99$++uMNNrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetFillFactorr+   r   s    r   get_fill_factorProperty.get_fill_factoru      ww224;;??rB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetFillFactorr+   r   s     r   set_fill_factorProperty.set_fill_factorx      ww224;;FFrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   (IndexProperty_GetSplitDistributionFactorr+   r   s    r   get_split_distribution_factor&Property.get_split_distribution_factor~  s    ww??LLrB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   (IndexProperty_SetSplitDistributionFactorr+   r   s     r   set_split_distribution_factor&Property.set_split_distribution_factor  s    ww??USSrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetTPRHorizonr+   r   s    r   get_tpr_horizonProperty.get_tpr_horizon  r  rB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetTPRHorizonr+   r   s     r   set_tpr_horizonProperty.set_tpr_horizon  r  rB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetReinsertFactorr+   r   s    r   get_reinsert_factorProperty.get_reinsert_factor  s    ww66t{{CCrB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetReinsertFactorr+   r   s     r   set_reinsert_factorProperty.set_reinsert_factor  s    ww66t{{EJJrB   c                p    [         R                  R                  U R                  5      R	                  5       $ r   )r
   r'   IndexProperty_GetFileNamer+   decoder   s    r   get_filenameProperty.get_filename  s$    ww00=DDFFrB   c                    [        U[        5      (       a  UR                  S5      n[        R                  R                  U R                  U5      $ Nr   )rP   rQ   encoder
   r'   IndexProperty_SetFileNamer+   r   s     r   set_filenameProperty.set_filename  s8    eS!!LL)Eww00eDDrB   c                t    [         R                  R                  U R                  5      nUR	                  5       $ r   )r
   r'   %IndexProperty_GetFileNameExtensionDatr+   r  rq   exts     r   get_dat_extensionProperty.get_dat_extension  &    gg;;DKKHzz|rB   c                    [        U[        5      (       a  UR                  S5      n[        R                  R                  U R                  U5      $ r  )rP   rQ   r  r
   r'   %IndexProperty_SetFileNameExtensionDatr+   r   s     r   set_dat_extensionProperty.set_dat_extension  8    eS!!LL)Eww<<T[[%PPrB   c                t    [         R                  R                  U R                  5      nUR	                  5       $ r   )r
   r'   %IndexProperty_GetFileNameExtensionIdxr+   r  r  s     r   get_idx_extensionProperty.get_idx_extension  r  rB   c                    [        U[        5      (       a  UR                  S5      n[        R                  R                  U R                  U5      $ r  )rP   rQ   r  r
   r'   %IndexProperty_SetFileNameExtensionIdxr+   r   s     r   set_idx_extensionProperty.set_idx_extension  r  rB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   +IndexProperty_GetCustomStorageCallbacksSizer+   r   s    r   !get_custom_storage_callbacks_size*Property.get_custom_storage_callbacks_size  s    wwBB4;;OOrB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   +IndexProperty_SetCustomStorageCallbacksSizer+   r   s     r   !set_custom_storage_callbacks_size*Property.set_custom_storage_callbacks_size  s    wwBB4;;PUVVrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   'IndexProperty_GetCustomStorageCallbacksr+   r   s    r   get_custom_storage_callbacks%Property.get_custom_storage_callbacks  s    ww>>t{{KKrB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   'IndexProperty_SetCustomStorageCallbacksr+   r   s     r   set_custom_storage_callbacks%Property.set_custom_storage_callbacks  s    ww>>t{{ERRrB   c                T    [         R                  R                  U R                  5      $ r   )r
   r'   IndexProperty_GetIndexIDr+   r   s    r   get_index_idProperty.get_index_id  r   rB   c                V    [         R                  R                  U R                  U5      $ r   )r
   r'   IndexProperty_SetIndexIDr+   r   s     r   set_index_idProperty.set_index_id  r   rB   )rO  r;  r+   r  )NT)r  rO   rs   r   r  r  r  )r  zdict[Any, Any]r  r  r  )r"   r   r  r  )Zr  r  r  r  r  r/  r|   r  r   r   r*  r   r8  r=  rB  r  rK   rF  rK  r  rR  rV  r0   rZ  r^  rW   rb  rf  rI   rj  rn  r  rr  rv  r  rz  r  index_pool_capacityr  r  r  r  r  r  r  r  r  r  r  r  r  r  rH   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rX   r  r  r  r  r  rY   r  r  r  r  r	  r  r  r  r^   r  r   rB   r   r   r   u  sB   
E6*
@)$.F NN3DEBI {K0GDF 6I BI {K0G>E
 l3HDCJ
 02DENBI
 .0ABMGN
 ##:<STGN
 ##:<STHO
 $$<>VWGN
 ""8:PQKR 6I(EL 6I(NU
 #+')H# &HO ,.>?L@G ?O<K1MT !)%'D! $@G ?O<KDK 24GHOGE
 l3H)Q
 .0ABM!Q
 .0ABM!PW %-)+L%! /LS  ($&B  '=D l3HrB   r   c                     \ rS rSr\R
                  " S\R                  \R                  " \R                  5      5      r	\R
                  " S\R                  \R                  " \R                  5      5      r
\R
                  " S\R                  \R                  " \R                  5      5      r\R
                  " S\R                  \\R                  " \R                  5      \R                  " \R                  " \R                  5      5      \R                  " \R                  5      5      r\R
                  " S\R                  \R                  " \5      \R                  \R                  " \R                  5      \R                  " \R                  5      5      r\R
                  " S\R                  \\R                  " \R                  5      5      rS\R                  4S\	4S\
4S\4S\4S\4S	\4/r  SS
 jrSrg)CustomStorageCallbacksi  NcontextcreateCallbackdestroyCallbackflushCallbackloadCallbackstoreCallbackdeleteCallbackc                ,   [         R                  R                  U [         R                  " U5      U R	                  U5      U R                  U5      U R                  U5      U R                  U5      U R                  U5      U R                  U5      5        g r   )
r   	Structurer|   r)   createCallbackTypedestroyCallbackTypeflushCallbackTypeloadCallbackTypestoreCallbackTypedeleteCallbackType)rq   r  r  r  r  r  r  r  s           r   r|   CustomStorageCallbacks.__init__  s{     	!!OOG$##N3$$_5""=1!!,/""=1##N3		
rB   r   r  )r  r  r  r  r   	CFUNCTYPEr)   r$   c_intr  r   r!  id_typer    r:   r"  r#  r$  _fields_r|   r  r   rB   r   r  r    s   ))foov~~fll; !**foov~~fll; ((foov~~fll; ''v'v~~fnn56v||$ ((wv~~&v||$  ))foowv||(D
 
FOO$	-.	/0	+,	)*	+,	-.H
 

rB   r  c                  L    \ rS rSrSrSrSrSrSrS r	S r
S r\" S	 5      rS
rg)rU   i#  r   r	   r   r  c                @    [         R                  R                  U5      $ r   )r
   r'   SIDX_NewBuffer)rq   r=   s     r   allocateBufferICustomStorage.allocateBuffer-  s    ww%%f--rB   c                    [        5       er   r  )rq   rF   s     r   rg    ICustomStorage.registerCallbacks0      !##rB   c                    [        5       er   r  r   s    r   re   ICustomStorage.clear3  r1  rB   c                    g)NFr   r   s    r   <lambda>ICustomStorage.<lambda>6  s    ErB   r   N)r  r  r  r  NoErrorInvalidPageErrorIllegalStateError	EmptyPageNewPager-  rg   re   r  rd   r  r   rB   r   rU   rU   #  s>    G IG.$$ )*GArB   rU   c                  B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)CustomStorageBasei:  z[Derive from this class to create your own storage manager with access
to the raw C buffers.c           	        [        [        R                  " 5       U R                  U R                  U R
                  U R                  U R                  U R                  5      n[        R                  " U5      Ul
        X l        [        R                  " [        R                  " U5      [        R                  5      Ul        g r   )r  r   r)   creater   r   loadByteArraystoreByteArraydeleteByteArraysizeofr  	callbacksr#   r   r  rq   rF   rD  s      r   rg   #CustomStorageBase.registerCallbacks>  s    *OOKKLLJJ  
	 4:==3K
0".4kkNN9%v/

+rB   c                N    U R                   UR                  l        [        S5      e)NYou must override this method.r9  r&   r"   rn   rq   r  returnErrors      r   r?  CustomStorageBase.createO  s"    %)%;%;"!"BCCrB   c                N    U R                   UR                  l        [        S5      ezplease overriderH  rI  rJ  s      r   r   CustomStorageBase.destroyS  "    %)%;%;"!"BCCrB   c                N    U R                   UR                  l        [        S5      erN  rI  )rq   r  page	resultLen
resultDatarK  s         r   r@  CustomStorageBase.loadByteArrayX  rP  rB   c                N    U R                   UR                  l        [        S5      erN  rI  )rq   r  rR  rS   r   rK  s         r   rA   CustomStorageBase.storeByteArray]  rP  rB   c                N    U R                   UR                  l        [        S5      erN  rI  rq   r  rR  rK  s       r   rB  !CustomStorageBase.deleteByteArrayb  rP  rB   c                N    U R                   UR                  l        [        S5      erN  rI  rJ  s      r   r   CustomStorageBase.flushg  rP  rB   rD  N)r  r  r  r  r  rg   r?  r   r@  rA  rB  r   r  r   rB   r   r=  r=  :  s0    
"DD
D
D
D
DrB   r=  c                  f    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)CustomStorageim  zProvides a useful default custom storage implementation which marshals
the buffers on the C side from/to python strings.
Derive from this class and override the necessary methods to provide
your own custom storage manager.c           	     \   [        SU R                  U R                  U R                  U R                  U R
                  U R                  5      n[        R                  " U5      Ul	        X l
        [        R                  " [        R                  " U5      [        R                  5      Ul        g r   )r  r  r  _flush_loadByteArray_storeByteArray_deleteByteArrayr   rC  r  rD  r#   r   r)   r  rE  s      r   rg   CustomStorage.registerCallbackss  sz    *LLMMKK  !!
	 4:==3K
0".4kkNN9%v/

+rB   c                &    U R                  U5        g r   )r?  rJ  s      r   r  CustomStorage._create  s    K rB   c                &    U R                  U5        g r   )r   rJ  s      r   r  CustomStorage._destroy  s    [!rB   c                &    U R                  U5        g r   )r   rJ  s      r   ra  CustomStorage._flush  s    

;rB   c                   U R                  X%5      nUR                  R                  U R                  :w  a  g [	        U5      nXsR                  l        U R                  U5      n[        R                  " U[        R                  " U5      U5        [        R                  " U[        R                  " [        R                  5      5      US'   g r   )r@  r&   r"   r7  rS   r-  r   memmovec_char_pr#   r$   r:   )	rq   r  rR  rS  rT  rK  resultStringr   buffers	            r   rb  CustomStorage._loadByteArray  s    ))$<%%5 L!#( $$U+vv|<eDFFNN6>>,JK
1rB   c                    [         R                  " XC5      nU R                  UR                  R                  Xe5      nXrR                  l        g r   )r   r<   rA  r&   r"   )rq   r  rR  rS   r   rK  rQ   	newPageIds           r   rc  CustomStorage._storeByteArray  s8    t)''(;(;SN	'rB   c                &    U R                  X#5        g r   )rB  rY  s       r   rd  CustomStorage._deleteByteArray  s    T/rB   c                N    U R                   UR                  l        [        S5      ez$Must be overridden. No return value.rH  rI  rq   rK  s     r   r?  CustomStorage.create  rP  rB   c                N    U R                   UR                  l        [        S5      erx  rI  ry  s     r   r   CustomStorage.destroy  rP  rB   c                N    U R                   UR                  l        [        S5      erx  rI  ry  s     r   r   CustomStorage.flush  rP  rB   c                N    U R                   UR                  l        [        S5      e)z>Must be overridden. Must return a string with the loaded data.rH  rI  rq   rR  rK  s      r   r@  CustomStorage.loadByteArray  rP  rB   c                N    U R                   UR                  l        [        S5      e)zMust be overridden. Must return the new 64-bit page ID of the stored
data if a new page had to be created (i.e. page is not NewPage).rH  rI  )rq   rR  r   rK  s       r   rA  CustomStorage.storeByteArray  s$     &*%;%;"!"BCCrB   c                N    U R                   UR                  l        [        S5      erN  rI  r  s      r   rB  CustomStorage.deleteByteArray  rP  rB   r]  N)r  r  r  r  r  rg   r  r  ra  rb  rc  rd  r?  r   r   r@  rA  rB  r  r   rB   r   r_  r_  m  sM    (

$!" L (
0D
D
D
DrB   r_  c                  ^  ^  \ rS rSrSrSU 4S jjrSS jrSS jrSS jrSS jr	SS jr
SU 4S	 jjr\r\SS
 j5       r\ S     SS jj5       r S     SU 4S jjjr\ S       SS jj5       r\ S       S S jj5       r S       S!U 4S jjjrSU 4S jjrU 4S jrSrU =r$ )"RtreeContaineri  zEAn R-Tree, MVR-Tree, or TPR-Tree indexed container for python objectsc                   > U(       a`  [        US   [        5      (       d0  [        US   [        5      (       d  [        US   [        5      (       a  [	        U R
                   S35      e0 U l        [        TU ]   " U0 UD6$ )a	  Creates a new index

:param stream:
    If the first argument in the constructor is not of type basestring,
    it is assumed to be an iterable stream of data that will raise a
    StopIteration.  It must be in the form defined by the
    :attr:`interleaved` attribute of the index. The following example
    would assume :attr:`interleaved` is False::

        (obj,
         (minx, maxx, miny, maxy, minz, maxz, ..., ..., mink, maxk))

    For a TPR-Tree, this would be in the form::

        (id,
         ((minx, maxx, miny, maxy, ..., ..., mink, maxk),
          (minvx, maxvx, minvy, maxvy, ..., ..., minvk, maxvk),
          time),
         object)

:param interleaved: True or False, defaults to True.
    This parameter determines the coordinate order for all methods that
    take in coordinates.

:param properties: This object sets both the creation and instantiation
    properties for the object and they are passed down into libspatialindex.
    A few properties are curried from instantiation parameters
    for you like ``pagesize`` to ensure compatibility with previous
    versions of the library.  All other properties must be set on the
    object.

.. warning::
    The coordinate ordering for all functions are sensitive the
    index's :attr:`interleaved` data member.  If :attr:`interleaved`
    is False, the coordinates must be in the form
    [xmin, xmax, ymin, ymax, ..., ..., kmin, kmax]. If
    :attr:`interleaved` is True, the coordinates must be in the form
    [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax]. This also applies
    to velocities when using a TPR-Tree.

A basic example
::

    >>> from rtree import index
    >>> p = index.Property()

    >>> idx = index.RtreeContainer(properties=p)
    >>> idx  # doctest: +NORMALIZE_WHITESPACE
    rtree.index.RtreeContainer(bounds=[1.7976931348623157e+308,
                             1.7976931348623157e+308,
                             -1.7976931348623157e+308,
                             -1.7976931348623157e+308],
                             size=0)

Insert an item into the index::

    >>> idx.insert(object(),
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734))

Query::

    >>> hits = idx.intersection((0, 0, 60, 60), bbox=True)
    >>> for obj in hits:
    ...     obj.object
    ...     obj.bbox  # doctest: +ELLIPSIS
    <object object at 0x...>
    [34.37768294..., 26.73758537..., 49.37768294..., 41.73758537...]
r   z  supports only in-memory indexes)	rP   rQ   rR   rU   
ValueError	__class___objectssuperr|   )rq   rr   rs   r  s      r   r|   RtreeContainer.__init__  sp    L 47C((d1gu--d1g~66 DNN#33S!TUU79w000rB   c                Z     U R                  U R                  5      $ ! [         a     gf = fr   r   r   s    r   r   RtreeContainer.get_size	  s,    	::dkk** 		r   c                Z    SnUR                  U R                  U R                  5       5      $ )Nz.rtree.index.RtreeContainer(bounds={}, size={}))formatr   r   )rq   ms     r   r   RtreeContainer.__repr__"	  s"    <xxT]]_55rB   c                2    [        U5      U R                  ;   $ r   )r   r  r   s     r   __contains__RtreeContainer.__contains__&	  s    #w$--''rB   c                V    [        S U R                  R                  5        5       5      $ )Nc              3  *   #    U  H	  u  pUv   M     g 7fr   r   r   r   r   s      r   r   )RtreeContainer.__len__.<locals>.<genexpr>*	  s     B+AZU5+A   )rL  r  valuesr   s    r   r   RtreeContainer.__len__)	  s     B4==+?+?+ABBBrB   c                V    [        S U R                  R                  5        5       5      $ )Nc              3  *   #    U  H	  u  pUv   M     g 7fr   r   r  s      r   r   *RtreeContainer.__iter__.<locals>.<genexpr>-	  s     A*@JEC*@r  )r  r  r  r   s    r   __iter__RtreeContainer.__iter__,	  s     A$--*>*>*@AAArB   c                   >  U R                   [        U5         S   S-   nX14U R                   [        U5      '   [        TU ]  [        U5      US5      $ ! [         a    Sn NAf = f)a  Inserts an item into the index with the given coordinates.

:param obj: Any object.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time value as a float.

The following example inserts a simple object into the container.
The coordinate ordering in this instance is the default
(interleaved=True) ordering::

    >>> from rtree import index
    >>> idx = index.RtreeContainer()
    >>> idx.insert(object(),
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734))

Similar for TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.RtreeContainer(properties=p)  # doctest: +SKIP
    >>> idx.insert(object(),
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...            3.0))  # doctest: +SKIP

r   r	   N)r  r   KeyErrorr  rp   rq   r   r   r   r  s       r   rp   RtreeContainer.insert/	  sh    D	MM"S'*1-1E #(bgw~bg{D99  	E	s   A A#"A#c                    g r   r   rq   r   r   s      r   r   RtreeContainer.intersectionZ	  s    UXrB   c                    g r   r   r  s      r   r   r  ]	  r   rB   c              #    >#    USL a+  [         TU ]  X5       H  nU R                  U   S   v   M     gUSL aC  [         TU ]  X5       H/  nU R                  UR                     S   Ul        SUl        Uv   M1     g[        S5      e7f)a[  Return ids or objects in the index that intersect the given
coordinates.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    time range as a float.

:param bbox: If True, the intersection method will return the stored objects,
    as well as the bounds of the entry.

The following example queries the container for any stored objects that
intersect the bounds given in the coordinates::

    >>> from rtree import index
    >>> idx = index.RtreeContainer()
    >>> idx.insert(object(),
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734))

    >>> hits = list(idx.intersection((0, 0, 60, 60), bbox=True))
    >>> [(item.object, item.bbox) for item in hits]
    ... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    [(<object object at 0x...>, [34.3776829412, 26.7375853734,
    49.3776829412, 41.7375853734])]

If the :class:`rtree.index.Item` wrapper is not used, it is faster to
request only the stored objects::

    >>> list(idx.intersection((0, 0, 60, 60)))   # doctest: +ELLIPSIS
    [<object object at 0x...>]

Similar for the TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.RtreeContainer(properties=p)  # doctest: +SKIP
    >>> idx.insert(object(),
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...             3.0))  # doctest: +SKIP

    >>> hits = list(idx.intersection(
    ...     ((0, 0, 60, 60), (0, 0, 0, 0), (3, 5)), bbox=True))
    ... # doctest: +SKIP
    >>> [(item.object, item.bbox) for item in hits]
    ... # doctest: +SKIP
    [(<object object at 0x...>, [34.3776829412, 26.7375853734,
    49.3776829412, 41.7375853734])]

Fr	   TN5valid values for the bbox argument are True and False)r  r   r  r   r  r  )rq   r   r   r   r"   r  s        r   r   r  b	  s     t 5=g*;=mmB'** >T\-k@#}}UXX6q9 A
 TUUs   BBc                    g r   r   rq   r   r(  r   s       r   r5  RtreeContainer.nearest	  r  rB   c                    g r   r   r  s       r   r5  r  	  r   rB   c              #    >#    USL a,  [         TU ]  XU5       H  nU R                  U   S   v   M     gUSL aD  [         TU ]  XU5       H/  nU R                  UR                     S   Ul        SUl        Uv   M1     g[        S5      e7f)a  Returns the ``k``-nearest objects to the given coordinates
in increasing distance order.

:param coordinates: This may be an object that satisfies the numpy array
    protocol, providing the index's dimension * 2 coordinate
    pairs representing the `mink` and `maxk` coordinates in
    each dimension defining the bounds of the query window.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    time range as a float.

:param num_results: The number of results to return nearest to the given
    coordinates. If two entries are equidistant, *both* are returned.
    This property means that :attr:`num_results` may return more
    items than specified.

:param bbox: If True, the nearest method will return the stored objects, as
    well as the bounds of the entry.

.. warning::
    This is currently not implemented for the TPR-Tree.

Example of finding the three items nearest to this one::

    >>> from rtree import index
    >>> idx = index.RtreeContainer()
    >>> idx.insert(object(), (34.37, 26.73, 49.37, 41.73))
    >>> hits = idx.nearest((0, 0, 10, 10), 3, bbox=True)
Fr	   TNr  )r  r5  r  r   r  r  )rq   r   r(  r   r   r"   r  s         r   r5  r  	  s     B 5=gokEmmB'** FT\4H#}}UXX6q9 I
 TUUs   BB	c                  >  U R                   [        U5         S   S-
  nUS:X  a  U R                   [        U5      	 OX14U R                   [        U5      '   [        TU ]  [        U5      U5      $ ! [         a    [        S5      ef = f)aR  Deletes the item from the container within the specified
coordinates.

:param obj: Any object.

:param coordinates: Dimension * 2 coordinate pairs, representing the min
    and max coordinates in each dimension of the item to be
    deleted from the index. Their ordering will depend on the
    index's :attr:`interleaved` data member.
    These are not the coordinates of a space containing the
    item, but those of the item itself. Together with the
    id parameter, they determine which item will be deleted.
    This may be an object that satisfies the numpy array protocol.
    For a TPR-Tree, this must be a 3-element sequence including
    not only the positional coordinate pairs but also the
    velocity pairs `minvk` and `maxvk` and a time pair for the
    original time the object was inserted and the current time
    as a float.

Example::

    >>> from rtree import index
    >>> idx = index.RtreeContainer()
    >>> idx.delete(object(),
    ...            (34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734))
    Traceback (most recent call last):
     ...
    IndexError: object is not in the index

For the TPR-Tree::

    >>> p = index.Property(type=index.RT_TPRTree)  # doctest: +SKIP
    >>> idx = index.RtreeContainer(properties=p)  # doctest: +SKIP
    >>> idx.delete(object(),
    ...            ((34.3776829412, 26.7375853734, 49.3776829412,
    ...             41.7375853734),
    ...             (0.5, 2, 1.5, 2.5),
    ...             (3.0, 5.0)))  # doctest: +SKIP
    Traceback (most recent call last):
     ...
    IndexError: object is not in the index

r   r	   zobject is not in the index)r  r   r  
IndexErrorr  rn  r  s       r   rn  RtreeContainer.delete	  s    Z	;MM"S'*1-1E A:bg&&+\DMM"S'"w~bg{33  	;9::	;s   A0 0Bc                   > [         TU ]  5        VVVVs/ s H;  u  pnU R                  U   S   U Vs/ s H  o@R                  U   S   PM     snU4PM=     snnnn$ s  snf s  snnnnf )Nr	   )r  r  r  )rq   r   r  r   child_idr  s        r   r  RtreeContainer.leaves
  st     */)9
 *:%v	 b!!$<EFIx(+IF
 *:
 	
 G
s   A"
A	A"
A"
)r  r  r  r  )r   r  r  rO   )r  r  )r   r  r   r   r  r  )r   r   r   r  r  r  r  )r   r   r   r  r  r  )r   r   r   rO   r  Iterator[Item | object])r	   T)r   r   r(  r   r   r  r  r  r  )r   r   r(  r   r   r  r  r  )r   r   r(  r   r   rO   r  r  )r  r  r  r  r  r|   r   r   r  r   r  rp   r  r   r   r5  rn  r  r  __classcell__)r  s   @r   r  r    sX   ON1`6(CB':R CX X7<&4	 
 .3CVCV&*CV	 CV CVJ LP-0<I	  MR-0<J	 
 DI*V*V-0*V<@*V	 *V *VX54n
 
rB   r  );
__future__r   r   rZ   os.pathr   r6  r   collections.abcr   r   typingr   r   r    r
   
exceptionsr   rh   rV   rc   	RT_LinearRT_QuadraticRT_Starri   
RT_MVRTreerL   r'   SIDX_Version__c_api_version__r  splitmajor_versionminor_versionpatch_versionr  __all__r7   rA   r   r   r&  r  r  ro   r  r  r   r	  r   r   r(  r  r  rU   r=  r_  r  r   rB   r   <module>r     s   "  	     . ) )  "	
		


GG((* /%,,W5;;C@/ +}m =-09<
E
FF
('4
p ph- 	( (V>Y >   F
& 
- -	0; 0-V -
f fV ..=
V-- =
@B B.0D 0DfYDN YDxS
U S
{  		s   1E E'&E'