GeometryFile.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 terralib/geometry/GeometryFile.h
22 
23  \brief A class for read a wkb encoded geometry file.
24 */
25 
26 #ifndef __TERRALIB_PLUGINEDIT_INTERNAL_GEOMETRYFILE_H
27 #define __TERRALIB_PLUGINEDIT_INTERNAL_GEOMETRYFILE_H
28 
29 // TerraLib
30 #include "../../../common/Exception.h"
31 
32 // STL
33 #include <fstream>
34 #include <map>
35 #include <memory>
36 #include <vector>
37 
38 namespace te
39 {
40  // Forward declarations
41  namespace gm
42  {
43  class Geometry;
44  }
45 }
46 
47 /*!
48  * \class GeometryFile
49  *
50  * \brief A class that can parses a file with wkb encoded geometries.
51  *
52  * \ingroup geometry
53  */
55 {
56 public:
57 
58  /*!
59  * \name Initializer methods.
60  * Methods for initializing and destructing object.
61  */
62  //@{
63 
64  /*!
65  * \brief Constructor.
66  */
67  GeometryFile();
68 
69  /*!
70  * \brief Destructor.
71  */
72  ~GeometryFile();
73  //@}
74 
75  /*!
76  * \brief Opens the file \a fileName.
77  *
78  * \param fileName The name of geometry file. (File extension is .geom)
79  *
80  * \exception If the file could not be opened an te::common::Exception will be raised.
81  *
82  * \note There's no check about the file contents, just for its existence. It means that if an unknown type of file was passed,
83  * it will try to open it. The behavior of the class then is unknown.
84  */
85  void openFile(const char* fileName) throw (te::common::Exception);
86 
87  /*!
88  * \brief Returns the next geometry.
89  *
90  * If the setGeometries was used, then the geometries to be returned are the geometries identified by ids given to the function,
91  * otherwise it will traverse the entire file.
92  *
93  * \return The next geometry on the file or NULL if there's no more geometries to get.
94  *
95  * \note The ownership of the returned geometries are given to the caller.
96  */
97  te::gm::Geometry* next();
98 
99  /*!
100  * \brief Sets the desired geometries to get from file.
101  *
102  * This is a filter of the traversing file. If this is used before next was called, only geometries indentified by \a gids
103  * will be returned by \a next function. If not defined the file will be entirely traversed.
104  *
105  * \param gids Ids of the geometries to be filtered. These values comes from 'FID' column.
106  */
107  void setGeometries(const std::vector<unsigned int>& gids);
108 
109  static void writeGeometries(const char* fileName, const std::map<int, te::gm::Geometry*>& geoms);
110 
111  static void writeGeometries(const char* fileName, const std::vector<te::gm::Geometry*>& geoms);
112 
113 protected:
114 
115  std::unique_ptr<std::ifstream> m_file; //!< Pointer to the geometry file.
116  std::unique_ptr<std::ifstream> m_posFile; //!< Pointer to the geometry pos file.
117  std::vector<unsigned int> m_gids; //!< Selected ids to use on traverse operation.
118  unsigned int m_i; //!< Current position on traversing.
119 };
120 
121 
122 #endif // __TERRALIB_PLUGINEDIT_INTERNAL_GEOMETRYFILE_H
123 
124 
125 
void openFile(const std::string &filename, const std::string dstype)
URI C++ Library.
Definition: Attributes.h:37
std::unique_ptr< std::ifstream > m_posFile
Pointer to the geometry pos file.
Definition: GeometryFile.h:116
unsigned int m_i
Current position on traversing.
Definition: GeometryFile.h:118
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::vector< unsigned int > m_gids
Selected ids to use on traverse operation.
Definition: GeometryFile.h:117
std::unique_ptr< std::ifstream > m_file
Pointer to the geometry file.
Definition: GeometryFile.h:115
A class that can parses a file with wkb encoded geometries.
Definition: GeometryFile.h:54