GAP.h
Go to the documentation of this file.
1 #include <terralib/common.h>
2 #include <terralib/dataaccess.h>
5 
11 
12 #include <terralib/memory/dataset.h>
13 #include <terralib/memory/datasetitem.h>
14 
15 #include <terralib/sam.h>
16 
17 
18 
19 #include <geos/geom/Coordinate.h>
20 #include <geos/geom/CoordinateSequence.h>
21 #include <geos/operation/distance/DistanceOp.h>
22 
23 
24 #include <string>
25 #include <vector>
26 
29 
30 enum Pol_OUT
31 {
36 };
37 
38 class GAP_inter
39 {
40 public:
42  : m_polid(-1), m_ptid(-1), m_x(0), m_y(0), m_xint(0), m_yint(0), m_xnew(0), m_ynew(0),
43  m_distance(0), m_distance0(0), m_tipo("") {}
44 
45  GAP_inter(int32_t polid, int32_t id, double x, double y, double xint, double yint, double xn, double yn,
46  double distance, double distance0, std::string t, bool inside)
47  : m_polid(polid), m_ptid(id), m_x(x), m_y(y), m_xint(xint), m_yint(yint), m_xnew(xn), m_ynew(yn),
48  m_distance(distance), m_distance0(distance0), m_tipo(t), m_inside(inside) {}
49 
50  bool operator < (const GAP_inter&);
51  bool operator == (const GAP_inter&);
52 
53  int32_t m_polid; //polygon id
54  int32_t m_ptid; //point order
55  double m_x; //X coordinate
56  double m_y; //y coordinate
57  double m_xint; //X coordinate intersection calculated point in segment
58  double m_yint; //Y coordinate intersection calculated point in segment
59  double m_xnew; //X new positon
60  double m_ynew; //X new positon
61  double m_distance; //Distance point to segment
62  double m_distance0; //Distance point to first point segment
63  std::string m_tipo;
64  bool m_inside;
65 };
66 
68 {
69 public:
71  : m_seg(te::gm::LineStringType), m_polid(-1), m_centroid(), m_mindist(0) {}
72  GAP_segment(te::gm::Line &seg, int32_t polid, te::gm::Coord2D &cent, double min)
73  : m_seg(seg), m_polid(polid), m_centroid(cent), m_mindist(min) {}
74 
75  bool isInside(te::gm::Coord2D &pt);
76  void insert_inter(GAP_inter *inter);
77 
78  te::gm::Line m_seg; //Segment - line with 2 points
79  int32_t m_polid; //ID polygon which contains segment
80  te::gm::Coord2D m_centroid; //Polygon centroid
81  double m_mindist; //Tolerancy to find closest points
82  std::vector<GAP_inter *> m_inter; //Points close this segment
83 
84 };
85 
87 {
88 public:
90 
91  GAP_pt_extern(te::gm::Coord2D pint, int32_t id, double dist)
92  : m_ptint(pint), m_seg_id(id), m_dist(dist) {}
93 
95  int32_t m_seg_id;
96  double m_dist;
97 };
98 
99 class GAP
100 {
101 public:
102 
103  GAP();
104  ~GAP()
105  {
106  delete m_nodetree;
107  delete m_nodetree_step2;
108  }
109 
110  bool run();
111 
112  bool step00(std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
113  bool step0(std::vector< std::pair< size_t, te::gm::Polygon* > > &pols, std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
114  bool step1(std::vector< std::pair< size_t, te::gm::Polygon* > > &pols, std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
115  bool step2(std::vector< std::pair< size_t, te::gm::Polygon* > > &pols, std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
116  bool step3(std::vector< std::pair< size_t, te::gm::Polygon* > > &pols, std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
117  bool step4(std::vector< std::pair< size_t, te::gm::Polygon* > > &pols, std::vector< std::pair< size_t, te::gm::Polygon* > > &polsout);
118 
119  bool LoadPolygons(std::string &filename, std::string &inDsetName, Pol_OUT out);
120 
121  bool Polygon2Points(te::gm::Polygon* pol, int32_t id);
122  bool Polygon2RTree(te::gm::Polygon* pol, te::sam::rtree::Index<te::gm::Line*> &rtree);
123  bool Polygon2Lines(te::gm::Polygon* pol);
124 
125  void Save(te::da::DataSource* source, te::da::DataSet* result, te::da::DataSetType* outDsType);
126  bool SavePol(std::vector< std::pair< size_t, te::gm::Polygon* > >& pols, std::string step);
127 
128  void verify_polygon(std::vector<te::gm::Coord2D> &pt_out);
129  bool verifyIntersections(te::gm::Coord2D &pt0, te::gm::Coord2D &pc, te::sam::rtree::Index<te::gm::Line*> &rtree_pol);
130  int pointLocate(te::gm::Coord2D &pt, te::gm::Polygon *pol);
131 
132 
133 protected:
134  double m_dist_min;
135  std::string m_filename1; //agregado
136  std::string m_inDS1;
137  std::string m_filename2;
138  std::string m_inDS2;
139  std::string m_filenameout;
140  std::string m_inDSout;
141 
142  int m_srid;
143 
144  std::map<size_t, te::gm::Polygon*> m_pol; //poligonos do desflorestamento
145  std::vector<te::gm::Line*> m_line;
147 
148  KD_TREE *m_nodetree; //pontos do agregado
149  KD_TREE *m_nodetree_step2; // pontos dos poligonos gerados no step2
150 
151  //std::vector< std::pair< size_t, te::gm::Polygon* > > m_pols_1; //poligonos gerados no step1
152  //std::vector< std::pair< size_t, te::gm::Polygon* > > m_pols_2; //poligonos gerados mo step2
153  // std::vector< std::pair< size_t, te::gm::Polygon* > > m_pols_3; //poligonos gerados mo step3
154  //std::vector< std::pair< size_t, te::gm::Polygon* > > m_pols_final; //poligonos gerados mo step3 - segunda passada
155  std::map<int32_t, double> m_original_area;
156 
157  std::vector<GAP_inter> m_pol_points;
158 
159  double m_tol = 0.1e-7;
160 
161 };
This file contains include headers for TerraLib Spatial Access Methods module.
double m_dist_min
Definition: GAP.h:134
std::map< size_t, te::gm::Polygon * > m_pol
Definition: GAP.h:144
TEXSDEXPORT void Save(All *all, te::xml::AbstractWriter &writer)
std::string m_inDS1
Definition: GAP.h:136
KD_TREE * m_nodetree_step2
Definition: GAP.h:149
A Line is LineString with 2 points.
Definition: Line.h:50
A Line is LineString with 2 points.
std::string m_filename2
Definition: GAP.h:137
std::vector< te::gm::Line * > m_line
Definition: GAP.h:145
double m_xint
Definition: GAP.h:57
A class that models the description of a dataset.
Definition: DataSetType.h:72
int32_t m_ptid
Definition: GAP.h:54
std::vector< GAP_inter > m_pol_points
Definition: GAP.h:157
std::string m_tipo
Definition: GAP.h:63
int32_t m_polid
Definition: GAP.h:53
~GAP()
Definition: GAP.h:104
double m_distance
Definition: GAP.h:61
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
te::gm::Coord2D m_ptint
Definition: GAP.h:94
bool m_inside
Definition: GAP.h:64
GAP_inter(int32_t polid, int32_t id, double x, double y, double xint, double yint, double xn, double yn, double distance, double distance0, std::string t, bool inside)
Definition: GAP.h:45
GAP_pt_extern(te::gm::Coord2D pint, int32_t id, double dist)
Definition: GAP.h:91
int32_t m_polid
Definition: GAP.h:79
te::sam::rtree::Index< te::gm::Line * > m_rtree
Definition: GAP.h:146
GAP_segment(te::gm::Line &seg, int32_t polid, te::gm::Coord2D &cent, double min)
Definition: GAP.h:72
GAP_inter()
Definition: GAP.h:41
Definition: GAP.h:99
bool operator==(const GAP_inter &)
Definition: GAP.cpp:301
Pol_OUT
Definition: GAP.h:30
double m_ynew
Definition: GAP.h:60
Definition: GAP.h:34
double m_yint
Definition: GAP.h:58
URI C++ Library.
Definition: Attributes.h:37
te::gm::Coord2D m_centroid
Definition: GAP.h:80
std::string m_filename1
Definition: GAP.h:135
A factory for data sources.
Geometric property.
double m_dist
Definition: GAP.h:96
MultiPolygon is a MultiSurface whose elements are Polygons.
double m_distance0
Definition: GAP.h:62
A class that represents a two dimensional K-d Tree (2-d Tree).
std::string m_inDS2
Definition: GAP.h:138
double m_y
Definition: GAP.h:56
double m_x
Definition: GAP.h:55
double m_mindist
Definition: GAP.h:81
bool isInside(te::gm::Coord2D &first, te::gm::Coord2D &last, te::gm::Coord2D &c, te::gm::Coord2D &cent)
Definition: GAP.cpp:94
A class that converts a GEOS geometry to a TerraLib geometry.
KD_TREE * m_nodetree
Definition: GAP.h:148
A class that converts a TerraLib geometry to a GEOS geometry.
std::map< int32_t, double > m_original_area
Definition: GAP.h:155
int m_srid
Definition: GAP.h:142
A dataset is the unit of information manipulated by the data access module of TerraLib.
std::string m_inDSout
Definition: GAP.h:140
int32_t m_seg_id
Definition: GAP.h:95
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
Definition: GAP.h:35
GAP_pt_extern()
Definition: GAP.h:89
te::sam::kdtree::Index< KD_NODE > KD_TREE
Definition: GAP.h:28
Definition: GAP.h:33
A class that represents an Kd-tree node.
Definition: kdtree/Node.h:61
te::sam::kdtree::Node< te::gm::Coord2D, std::pair< int32_t, int32_t >, std::pair< int32_t, int32_t > > KD_NODE
Definition: GAP.h:27
GAP_segment()
Definition: GAP.h:70
An atomic property like an integer or double.
std::vector< GAP_inter * > m_inter
Definition: GAP.h:82
This file contains include headers for the TerraLib Common Runtime module.
bool operator<(const GAP_inter &)
Definition: GAP.cpp:288
Definition: GAP.h:38
double m_xnew
Definition: GAP.h:59
std::string m_filenameout
Definition: GAP.h:139
This file contains include headers for the Data Access module of TerraLib.
te::gm::Line m_seg
Definition: GAP.h:78