RTreeExamples.cpp
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 RTreeExamples.cpp
22 
23  \brief This file contains several examples on how to use the R-tree spatial access method.
24  */
25 
26 // TerraLib
27 #include <terralib_buildconfig.h>
28 
29 #include <terralib/common.h>
30 #include <terralib/geometry.h>
31 #include <terralib/sam.h>
32 #include "SAMExamples.h"
33 
34 // STL
35 #include <vector>
36 
38 {
39  std::vector<te::gm::Point*> pointVec;
41 
42  pointVec.reserve(100);
43 
44  for(int i = 0; i < 100; ++i)
45  {
46  te::gm::Point* pt = new te::gm::Point(static_cast<double>(i), static_cast<double>(i), 4326);
47  pointVec.push_back(pt);
48  rtree.insert(*(pt->getMBR()), i);
49  }
50 
51  for(int i = 0; i < 100; ++i)
52  {
53  std::vector<std::size_t> report;
54  const te::gm::Envelope* mbr = pointVec[i]->getMBR();
55 
56  assert(rtree.search(*mbr, report) == 1);
57  assert(report[0] == static_cast<std::size_t>(i));
58  }
59 
60  te::common::FreeContents(pointVec);
61 }
62 
This file contains include headers for TerraLib Spatial Access Methods module.
Several examples on how to use Spatial Access Methods in TerraLib.
A point with x and y coordinate values.
Definition: Point.h:50
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
An Envelope defines a 2D rectangular region.
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
void IndexPointUsingRTree()
This example shows how to index a set of points using the R-tree spatial access method.
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
This file contains include headers for the TerraLib Common Runtime module.
This file contains include headers for the Vector Geometry model of TerraLib.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55