Utils.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 terralib/edit/Utils.h
22 
23 \brief Utility functions for TerraLib Edit module.
24 */
25 
26 #ifndef __TERRALIB_EDIT_INTERNAL_UTILS_H
27 #define __TERRALIB_EDIT_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "../maptools/AbstractLayer.h"
31 #include "Config.h"
32 
33 // STL
34 #include <string>
35 #include <vector>
36 
37 namespace te
38 {
39  // Forward declarations
40  namespace da
41  {
42  class ObjectId;
43  }
44 
45  namespace gm
46  {
47  struct Coord2D;
48  class Envelope;
49  class Geometry;
50  class GeometryCollection;
51  class LineString;
52  class Polygon;
53  }
54 
55  namespace edit
56  {
57  // Forward declaration
58  class Feature;
59 
60  struct VertexIndex
61  {
62  void setIndex(const std::size_t& line, const std::size_t& pos)
63  {
64  m_line = line;
65  m_pos = pos;
66  }
67 
68  void makeInvalid()
69  {
70  m_line = std::string::npos;
71  m_pos = std::string::npos;
72  }
73 
74  bool isValid() const
75  {
76  return m_line != std::string::npos && m_pos != std::string::npos;
77  }
78 
79  std::size_t m_line;
80  std::size_t m_pos;
81  };
82 
83  /*!
84  \enum OperationsType
85 
86  \brief Defines the operations (CUD - Create, Update ad Remove) to this tool.
87  */
89  {
90  GEOMETRY_CREATE, /*!< New Features */
91  GEOMETRY_UPDATE, /*!< Features to update. */
92  GEOMETRY_DELETE, /*!< Features to delete. */
93  GEOMETRY_UPDATE_ATTRIBUTES, /*!< Features to update attributes. */
94  NumberOfOperationTypes /*!< Size of Enum */
95  };
96 
97  TEEDITEXPORT Feature* PickFeature(const te::map::AbstractLayerPtr& layer, const te::gm::Envelope& env, int srid, OperationType operation);
98 
99  TEEDITEXPORT Feature* PickFeature(const te::map::AbstractLayer* layer, const te::gm::Envelope& env, int srid, OperationType operation);
100 
101  TEEDITEXPORT void GetLines(te::gm::Geometry* geom, std::vector<te::gm::LineString*>& lines);
102 
103  TEEDITEXPORT void GetLines(te::gm::GeometryCollection* gc, std::vector<te::gm::LineString*>& lines);
104 
105  TEEDITEXPORT void GetLines(te::gm::Polygon* p, std::vector<te::gm::LineString*>& lines);
106 
107  TEEDITEXPORT void GetLines(te::gm::LineString* l, std::vector<te::gm::LineString*>& lines);
108 
109  TEEDITEXPORT void MoveVertex(std::vector<te::gm::LineString*>& lines, const VertexIndex& index, const double& x, const double& y);
110 
111  TEEDITEXPORT void RemoveVertex(std::vector<te::gm::LineString*>& lines, const VertexIndex& index);
112 
113  TEEDITEXPORT void AddVertex(std::vector<te::gm::LineString*>& lines, const double& x, const double& y, const te::gm::Envelope& env, int srid);
114 
115  TEEDITEXPORT VertexIndex FindSegment(std::vector<te::gm::LineString*>& lines, const te::gm::Envelope& env, int srid);
116 
117  TEEDITEXPORT void MoveGeometry(te::gm::Geometry* geom, const double& deltax, const double& deltay);
118 
119  TEEDITEXPORT bool IsSpecialRingVertex(te::gm::LineString* l, const VertexIndex& index);
120 
121  TEEDITEXPORT double GetDistance(const te::gm::Coord2D& c1, const te::gm::Coord2D& c2);
122 
123  TEEDITEXPORT void GetCoordinates(te::gm::Geometry* geom, std::vector<te::gm::Coord2D>& coords);
124 
125  TEEDITEXPORT void TrySnap(te::gm::Coord2D& coord, int srid);
126 
128 
129  } // end namespace edit
130 } // end namespace te
131 
132 #endif // __TERRALIB_EDIT_INTERNAL_UTILS_H
TEEDITEXPORT void AddVertex(std::vector< te::gm::LineString * > &lines, const double &x, const double &y, const te::gm::Envelope &env, int srid)
This is the base class for layers.
Definition: AbstractLayer.h:76
#define TEEDITEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:64
TEEDITEXPORT Feature * PickFeature(const te::map::AbstractLayerPtr &layer, const te::gm::Envelope &env, int srid, OperationType operation)
TEEDITEXPORT te::da::ObjectId * GenerateId()
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
TEEDITEXPORT void RemoveVertex(std::vector< te::gm::LineString * > &lines, const VertexIndex &index)
TEEDITEXPORT void GetLines(te::gm::Geometry *geom, std::vector< te::gm::LineString * > &lines)
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void setIndex(const std::size_t &line, const std::size_t &pos)
Definition: Utils.h:62
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
URI C++ Library.
TEEDITEXPORT void MoveVertex(std::vector< te::gm::LineString * > &lines, const VertexIndex &index, const double &x, const double &y)
Configuration flags for the TerraLib Edit module.
TEEDITEXPORT VertexIndex FindSegment(std::vector< te::gm::LineString * > &lines, const te::gm::Envelope &env, int srid)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
OperationType
Definition: Utils.h:88
TEEDITEXPORT void GetCoordinates(te::gm::Geometry *geom, std::vector< te::gm::Coord2D > &coords)
std::size_t m_pos
Definition: Utils.h:80
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
std::size_t m_line
Definition: Utils.h:79
bool isValid() const
Definition: Utils.h:74
TEEDITEXPORT void TrySnap(te::gm::Coord2D &coord, int srid)
TEEDITEXPORT void MoveGeometry(te::gm::Geometry *geom, const double &deltax, const double &deltay)
void makeInvalid()
Definition: Utils.h:68
It is a collection of other geometric objects.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEEDITEXPORT bool IsSpecialRingVertex(te::gm::LineString *l, const VertexIndex &index)
TEEDITEXPORT double GetDistance(const te::gm::Coord2D &c1, const te::gm::Coord2D &c2)