1 /**********************************************************
2 * Version $Id$
3 *********************************************************/
4
5 ///////////////////////////////////////////////////////////
6 // //
7 // SAGA //
8 // //
9 // System for Automated Geoscientific Analyses //
10 // //
11 // Tool Library //
12 // Shapes_Polygon //
13 // //
14 //-------------------------------------------------------//
15 // //
16 // Polygon_To_Points.cpp //
17 // //
18 // Copyright (C) 2008 by //
19 // Olaf Conrad //
20 // //
21 //-------------------------------------------------------//
22 // //
23 // This file is part of 'SAGA - System for Automated //
24 // Geoscientific Analyses'. SAGA is free software; you //
25 // can redistribute it and/or modify it under the terms //
26 // of the GNU General Public License as published by the //
27 // Free Software Foundation, either version 2 of the //
28 // License, or (at your option) any later version. //
29 // //
30 // SAGA is distributed in the hope that it will be //
31 // useful, but WITHOUT ANY WARRANTY; without even the //
32 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
33 // PARTICULAR PURPOSE. See the GNU General Public //
34 // License for more details. //
35 // //
36 // You should have received a copy of the GNU General //
37 // Public License along with this program; if not, see //
38 // <http://www.gnu.org/licenses/>. //
39 // //
40 //-------------------------------------------------------//
41 // //
42 // e-mail: oconrad@saga-gis.org //
43 // //
44 // contact: Olaf Conrad //
45 // Institute of Geography //
46 // University of Goettingen //
47 // Goldschmidtstr. 5 //
48 // 37077 Goettingen //
49 // Germany //
50 // //
51 ///////////////////////////////////////////////////////////
52
53 //---------------------------------------------------------
54
55
56 ///////////////////////////////////////////////////////////
57 // //
58 // //
59 // //
60 ///////////////////////////////////////////////////////////
61
62 //---------------------------------------------------------
63 #include "polygon_to_points.h"
64
65
66 ///////////////////////////////////////////////////////////
67 // //
68 // //
69 // //
70 ///////////////////////////////////////////////////////////
71
72 //---------------------------------------------------------
CPolygon_To_Points(void)73 CPolygon_To_Points::CPolygon_To_Points(void)
74 {
75 //-----------------------------------------------------
76 Set_Name (_TL("Convert Polygon/Line Vertices to Points"));
77
78 Set_Author (SG_T("O. Conrad (c) 2008"));
79
80 Set_Description (_TW(
81 ""
82 ));
83
84 //-----------------------------------------------------
85 Parameters.Add_Shapes(
86 NULL , "SHAPES" , _TL("Shapes"),
87 _TL(""),
88 PARAMETER_INPUT
89 );
90
91 Parameters.Add_Shapes(
92 NULL , "POINTS" , _TL("Points"),
93 _TL(""),
94 PARAMETER_OUTPUT, SHAPE_TYPE_Point
95 );
96 }
97
98
99 ///////////////////////////////////////////////////////////
100 // //
101 // //
102 // //
103 ///////////////////////////////////////////////////////////
104
105 //---------------------------------------------------------
On_Execute(void)106 bool CPolygon_To_Points::On_Execute(void)
107 {
108 CSG_Shapes *pShapes, *pPoints;
109
110 pShapes = Parameters("SHAPES") ->asShapes();
111 pPoints = Parameters("POINTS") ->asShapes();
112
113 //-----------------------------------------------------
114 if( pShapes->is_Valid() )
115 {
116 pPoints->Create(SHAPE_TYPE_Point, pShapes->Get_Name());
117 pPoints->Add_Field(SG_T("ID") , SG_DATATYPE_String);
118 pPoints->Add_Field(SG_T("ID_SHAPE") , SG_DATATYPE_Int);
119 pPoints->Add_Field(SG_T("ID_PART") , SG_DATATYPE_Int);
120 pPoints->Add_Field(SG_T("ID_POINT") , SG_DATATYPE_Int);
121
122 if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
123 {
124 pPoints->Add_Field(SG_T("CLOCKWISE"), SG_DATATYPE_String);
125 pPoints->Add_Field(SG_T("LAKE") , SG_DATATYPE_String);
126 }
127
128 switch( pShapes->Get_Vertex_Type() )
129 {
130 case SG_VERTEX_TYPE_XY:
131 break;
132
133 case SG_VERTEX_TYPE_XYZ:
134 pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Double);
135 break;
136
137 case SG_VERTEX_TYPE_XYZM:
138 pPoints->Add_Field(SG_T("Z"), SG_DATATYPE_Double);
139 pPoints->Add_Field(SG_T("M"), SG_DATATYPE_Double);
140 break;
141 }
142
143 for(int iShape=0; iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
144 {
145 CSG_Shape *pShape = pShapes->Get_Shape(iShape);
146
147 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
148 {
149 for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
150 {
151 CSG_Shape *pPoint = pPoints->Add_Shape();
152
153 pPoint->Add_Point(pShape->Get_Point(iPoint, iPart));
154
155 int n = 0;
156
157 pPoint->Set_Value(n++, CSG_String::Format(SG_T("%d/%d/%d"), iShape, iPart, iPoint));
158 pPoint->Set_Value(n++, iShape);
159 pPoint->Set_Value(n++, iPart);
160 pPoint->Set_Value(n++, iPoint);
161
162 if( pShapes->Get_Type() == SHAPE_TYPE_Polygon )
163 {
164 pPoint->Set_Value(n++, ((CSG_Shape_Polygon *)pShape)->is_Clockwise(iPart) ? SG_T("Y") : SG_T("N"));
165 pPoint->Set_Value(n++, ((CSG_Shape_Polygon *)pShape)->is_Lake (iPart) ? SG_T("Y") : SG_T("N"));
166 }
167
168 switch( pShapes->Get_Vertex_Type() )
169 {
170 case SG_VERTEX_TYPE_XY:
171 break;
172
173 case SG_VERTEX_TYPE_XYZ:
174 pPoint->Set_Value(n++, pShape->Get_Z(iPoint, iPart));
175 break;
176
177 case SG_VERTEX_TYPE_XYZM:
178 pPoint->Set_Value(n++, pShape->Get_Z(iPoint, iPart));
179 pPoint->Set_Value(n++, pShape->Get_M(iPoint, iPart));
180 break;
181 }
182 }
183 }
184 }
185
186 return( pPoints->is_Valid() );
187 }
188
189 //-----------------------------------------------------
190 return( false );
191 }
192
193
194 ///////////////////////////////////////////////////////////
195 // //
196 // //
197 // //
198 ///////////////////////////////////////////////////////////
199
200 //---------------------------------------------------------
201