3
3
Tutorial
4
4
------------------------------------------------------------------------------
5
5
6
- This tutorial demonstrates how to take advantage of :ref:`Rtree <home>` for
7
- querying data that have a spatial component that can be modeled as bounding
6
+ This tutorial demonstrates how to take advantage of :ref:`Rtree <home>` for
7
+ querying data that have a spatial component that can be modeled as bounding
8
8
boxes.
9
9
10
10
11
11
Creating an index
12
12
..............................................................................
13
13
14
- The following section describes the basic instantiation and usage of
14
+ The following section describes the basic instantiation and usage of
15
15
:ref:`Rtree <home>`.
16
16
17
17
Import
18
18
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
19
20
- After :ref:`installing <installation>` :ref:`Rtree <home>`, you should be able to
20
+ After :ref:`installing <installation>` :ref:`Rtree <home>`, you should be able to
21
21
open up a Python prompt and issue the following::
22
22
23
23
>>> from rtree import index
@@ -30,21 +30,21 @@ with the index.
30
30
Construct an instance
31
31
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32
32
33
- After importing the index module, construct an index with the default
33
+ After importing the index module, construct an index with the default
34
34
construction::
35
35
36
36
>>> idx = index.Index()
37
37
38
38
.. note::
39
39
40
- While the default construction is useful in many cases, if you want to
41
- manipulate how the index is constructed you will need pass in a
42
- :py:class:`rtree.index.Property` instance when creating the index.
40
+ While the default construction is useful in many cases, if you want to
41
+ manipulate how the index is constructed you will need pass in a
42
+ :py:class:`rtree.index.Property` instance when creating the index.
43
43
44
44
Create a bounding box
45
45
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46
46
47
- After instantiating the index, create a bounding box that we can
47
+ After instantiating the index, create a bounding box that we can
48
48
insert into the index::
49
49
50
50
>>> left, bottom, right, top = (0.0, 0.0, 1.0, 1.0)
@@ -67,16 +67,16 @@ Insert an entry into the index::
67
67
68
68
.. note::
69
69
70
- Entries that are inserted into the index are not unique in either the
71
- sense of the `id` or of the bounding box that is inserted with index
72
- entries. If you need to maintain uniqueness, you need to manage that before
70
+ Entries that are inserted into the index are not unique in either the
71
+ sense of the `id` or of the bounding box that is inserted with index
72
+ entries. If you need to maintain uniqueness, you need to manage that before
73
73
inserting entries into the Rtree.
74
74
75
75
.. note::
76
76
77
77
Inserting a point, i.e. where left == right && top == bottom, will
78
78
essentially insert a single point entry into the index instead of copying
79
- extra coordinates and inserting them. There is no shortcut to explicitly
79
+ extra coordinates and inserting them. There is no shortcut to explicitly
80
80
insert a single point, however.
81
81
82
82
Query the index
@@ -95,7 +95,7 @@ Given a query window, return ids that are contained within the window::
95
95
>>> list(idx.intersection((1.0, 1.0, 2.0, 2.0)))
96
96
[0]
97
97
98
- Given a query window that is beyond the bounds of data we have in the
98
+ Given a query window that is beyond the bounds of data we have in the
99
99
index::
100
100
101
101
>>> list(idx.intersection((1.0000001, 1.0000001, 2.0, 2.0)))
@@ -106,7 +106,7 @@ Nearest Neighbors
106
106
107
107
The following finds the 1 nearest item to the given bounds. If multiple items
108
108
are of equal distance to the bounds, both are returned::
109
-
109
+
110
110
>>> idx.insert(1, (left, bottom, right, top))
111
111
>>> list(idx.nearest((1.0000001, 1.0000001, 2.0, 2.0), 1))
112
112
[0, 1]
@@ -138,10 +138,10 @@ to intersection::
138
138
Serializing your index to a file
139
139
..............................................................................
140
140
141
- One of :ref:`Rtree <home>`'s most useful properties is the ability to
142
- serialize Rtree indexes to disk. These include the clustered indexes
141
+ One of :ref:`Rtree <home>`'s most useful properties is the ability to
142
+ serialize Rtree indexes to disk. These include the clustered indexes
143
143
described :ref:`here <clustered>`::
144
-
144
+
145
145
>>> file_idx = index.Rtree('rtree')
146
146
>>> file_idx.insert(1, (left, bottom, right, top))
147
147
>>> file_idx.insert(2, (left - 1.0, bottom - 1.0, right + 1.0, top + 1.0))
@@ -191,7 +191,7 @@ stored on disk as the files ``3d_index.data`` and ``3d_index.index``::
191
191
>>> p = index.Property()
192
192
>>> p.dimension = 3
193
193
>>> p.dat_extension = 'data'
194
- >>> p.idx_extension = 'index'
194
+ >>> p.idx_extension = 'index'
195
195
>>> idx3d = index.Index('3d_index',properties=p)
196
196
>>> idx3d.insert(1, (0, 60, 23.0, 0, 60, 42.0))
197
197
>>> idx3d.intersection( (-1, 62, 22, -1, 62, 43))
@@ -200,9 +200,9 @@ stored on disk as the files ``3d_index.data`` and ``3d_index.index``::
200
200
ZODB and Custom Storages
201
201
..............................................................................
202
202
203
- https://mail.zope.org/pipermail/zodb-dev/2010-June/013491.html contains a custom
203
+ https://mail.zope.org/pipermail/zodb-dev/2010-June/013491.html contains a custom
204
204
storage backend for `ZODB`_
205
205
206
206
.. _ZODB: http://www.zodb.org/
207
207
208
- .. _`libspatialindex`: https://libspatialindex.org/
208
+ .. _`libspatialindex`: https://libspatialindex.org/
0 commit comments