Loading...
Searching...
No Matches
RTreeIndex.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file RTreeIndex.h
22
23 \brief This class makes easier and more generic the use of the te::sam::rtree::Index
24
25 \ingroup vp
26 */
27
28#ifndef __TERRALIB_VP_INTERNAL_RTREEINDEX_H
29#define __TERRALIB_VP_INTERNAL_RTREEINDEX_H
30
31// Terralib
32#include "Config.h"
33
34#include "../common/STLUtils.h"
35#include "../sam/rtree/Index.h"
37
38//STL
39#include <memory>
40#include <vector>
41
42namespace te
43{
44 namespace vp
45 {
46 /*!
47 \class RTreeIndex
48
49 \brief This class makes easier and more generic the use of the te::sam::rtree::Index
50
51 \ingroup vp
52 */
53 template<class T>
55 {
56 public:
57
58 //!< Constructor
59 RTreeIndex();
60
61 //!< Destructor
63
64 //!< Clears the index
65 void clear();
66
67 //!< Inserts the given data considering the given envelope as key
68 void insert(const te::gm::Envelope& envelope, const T& data);
69
70 //!< Removes the given data considering the given envelope as key
71 void remove(const te::gm::Envelope& envelope, std::size_t dataIndex);
72
73 //!< Gets all data from the RTreeIndex
74 std::unique_ptr<te::vp::IndexReport<T>> getData() const;
75
76 //!< Searches from all data consdering the given mbr
77 std::unique_ptr<te::vp::IndexReport<T>> search(const te::gm::Envelope& mbr) const;
78
79 private:
80 te::sam::rtree::Index<std::size_t> m_index; //!< The internal rtree to store the data indexes
81 IndexContainer<T> m_indexContainer; //!< The indexed data container
82 };
83 }
84}
85
86//Implementation
87template<class T>
89{
90
91}
92template<class T>
94{
95 clear();
96}
97
98template<class T>
100{
101 m_index.clear();
102 m_indexContainer.clear();
103}
104
105
106template<class T>
107void te::vp::RTreeIndex<T>::insert(const te::gm::Envelope& envelope, const T& data)
108{
109 std::size_t newDataIndex = m_indexContainer.insert(data);
110 m_index.insert(envelope, newDataIndex);
111}
112
113template<class T>
114void te::vp::RTreeIndex<T>::remove(const te::gm::Envelope& envelope, std::size_t dataIndex)
115{
116 m_index.remove(envelope, dataIndex);
117 m_indexContainer.remove(dataIndex);
118}
119
120template<class T>
121std::unique_ptr<te::vp::IndexReport<T>> te::vp::RTreeIndex<T>::getData() const
122{
123 std::vector<std::size_t> vecValidIndexes = m_indexContainer.getValidIndexes();
124
125 std::unique_ptr<te::vp::IndexReport<T>> indexReport(new te::vp::IndexReport<T>(&m_indexContainer, vecValidIndexes));
126 return indexReport;
127}
128
129template<class T>
130std::unique_ptr<te::vp::IndexReport<T>> te::vp::RTreeIndex<T>::search(const te::gm::Envelope& mbr) const
131{
132 std::vector<std::size_t> vecIndexesReport;
133 m_index.search(mbr, vecIndexesReport);
134
135 std::unique_ptr<te::vp::IndexReport<T>> indexReport(new te::vp::IndexReport<T>(&m_indexContainer, vecIndexesReport));
136 return indexReport;
137}
138
139#endif // __TERRALIB_VP_INTERNAL_RTREEINDEX_H
mydialect insert("=", new te::da::BinaryOpEncoder("="))
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
A class that represents an R-tree.
Definition: Index.h:57
This class makes easier and more generic the use of the te::sam::rtree::Index.
Definition: RTreeIndex.h:55
void insert(const te::gm::Envelope &envelope, const T &data)
Removes the given data considering the given envelope as key.
Definition: RTreeIndex.h:107
IndexContainer< T > m_indexContainer
The indexed data container.
Definition: RTreeIndex.h:81
std::unique_ptr< te::vp::IndexReport< T > > getData() const
Searches from all data consdering the given mbr.
Definition: RTreeIndex.h:121
std::unique_ptr< te::vp::IndexReport< T > > search(const te::gm::Envelope &mbr) const
Definition: RTreeIndex.h:130
~RTreeIndex()
Clears the index.
Definition: RTreeIndex.h:93
void remove(const te::gm::Envelope &envelope, std::size_t dataIndex)
Gets all data from the RTreeIndex.
Definition: RTreeIndex.h:114
RTreeIndex()
< Constructor
Definition: RTreeIndex.h:88
te::sam::rtree::Index< std::size_t > m_index
The internal rtree to store the data indexes.
Definition: RTreeIndex.h:80
void clear()
Inserts the given data considering the given envelope as key.
Definition: RTreeIndex.h:99
TerraLib.
Proxy configuration file for TerraView (see terraview_config.h).
Utility classes, structures and definitions for Vector Processing.