source: issm/trunk/src/c/kml/KML_LineString.cpp@ 16137

Last change on this file since 16137 was 16137, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 16135

File size: 5.5 KB
Line 
1/*!\file KML_LineString.cpp
2 * \brief: implementation of the kml_linestring object
3 */
4
5/*Headers:*/
6/*{{{*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include "./KML_LineString.h"
14#include "./KMLFileReadUtils.h"
15#include "../shared/shared.h"
16/*}}}*/
17
18/*Constructors/destructor/copy*/
19/*FUNCTION KML_LineString::KML_LineString(){{{*/
20KML_LineString::KML_LineString(){
21
22 extrude =false;
23 tessellate=false;
24 memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char));
25
26 ncoord =0;
27 coords =NULL;
28
29}
30/*}}}*/
31/*FUNCTION KML_LineString::~KML_LineString(){{{*/
32KML_LineString::~KML_LineString(){
33
34 if (coords) xDelete<double>(coords);
35
36 coords =NULL;
37 ncoord =0;
38
39}
40/*}}}*/
41
42/*Other*/
43/*FUNCTION KML_LineString::Echo {{{*/
44void KML_LineString::Echo(){
45
46 bool flag=true;
47
48 if(flag) _printf0_("KML_LineString:\n");
49 KML_Geometry::Echo();
50
51 if(flag) _printf0_(" extrude: " << (extrude ? "true" : "false") << "\n");
52 if(flag) _printf0_(" tessellate: " << (tessellate ? "true" : "false") << "\n");
53 if(flag) _printf0_(" altmode: \"" << altmode << "\"\n");
54 if(flag) _printf0_(" coords: (ncoord=" << ncoord << ")\n");
55
56 return;
57}
58/*}}}*/
59/*FUNCTION KML_LineString::DeepEcho {{{*/
60void KML_LineString::DeepEcho(){
61
62 char indent[81]="";
63
64 KML_LineString::DeepEcho(indent);
65
66 return;
67}
68/*}}}*/
69/*FUNCTION KML_LineString::DeepEcho {{{*/
70void KML_LineString::DeepEcho(const char* indent){
71
72 int i;
73 bool flag=true;
74
75 if(flag) _printf0_(indent << "KML_LineString:\n");
76 KML_Geometry::DeepEcho(indent);
77
78 if(flag) _printf0_(indent << " extrude: " << (extrude ? "true" : "false") << "\n");
79 if(flag) _printf0_(indent << " tessellate: " << (tessellate ? "true" : "false") << "\n");
80 if(flag) _printf0_(indent << " altmode: \"" << altmode << "\"\n");
81 if(flag) _printf0_(indent << " coords: (ncoord=" << ncoord << ")\n");
82 for (i=0; i<ncoord; i++)
83 if(flag) _printf0_(indent << " (" << coords[3*i+0] << "," << coords[3*i+1] << "," << coords[3*i+2] << ")\n");
84
85 return;
86}
87/*}}}*/
88/*FUNCTION KML_LineString::Write {{{*/
89void KML_LineString::Write(FILE* filout,const char* indent){
90
91 int i;
92
93 fprintf(filout,"%s<LineString",indent);
94 WriteAttrib(filout," ");
95 fprintf(filout,">\n");
96 WriteCommnt(filout,indent);
97
98 KML_Geometry::Write(filout,indent);
99
100 fprintf(filout,"%s <extrude>%d</extrude>\n",indent,(extrude ? 1 : 0));
101 fprintf(filout,"%s <tessellate>%d</tessellate>\n",indent,(tessellate ? 1 : 0));
102 fprintf(filout,"%s <altitudeMode>%s</altitudeMode>\n",indent,altmode);
103 fprintf(filout,"%s <coordinates>\n",indent);
104
105/* loop over the coordinates for the linestring */
106
107 for (i=0; i<ncoord; i++)
108 fprintf(filout,"%s %0.16g,%0.16g,%0.16g\n",indent, coords[3*i+0],coords[3*i+1],coords[3*i+2]);
109
110 fprintf(filout,"%s </coordinates>\n",indent);
111 fprintf(filout,"%s</LineString>\n",indent);
112
113 return;
114}
115/*}}}*/
116/*FUNCTION KML_LineString::Read {{{*/
117void KML_LineString::Read(FILE* fid,char* kstr){
118
119 char* kstri;
120 int ncom=0;
121 char** pcom=NULL;
122
123/* get object attributes and check for solo tag */
124
125 if (KMLFileTagAttrib(this,
126 kstr))
127 return;
128
129/* loop over and process fields within opening and closing tags */
130
131 while (kstri=KMLFileToken(fid,
132 &ncom,&pcom)) {
133 if (!strncmp(kstri,"</LineString",12)) {
134 xDelete<char>(kstri);
135 break;
136 }
137 else if (!strncmp(kstri,"</",2))
138 {_error_("KML_LineString::Read -- Unexpected closing tag " << kstri << ".\n");}
139 else if (strncmp(kstri,"<",1))
140 {_error_("KML_LineString::Read -- Unexpected field \"" << kstri << "\".\n");}
141
142 else if (!strcmp(kstri,"<extrude>"))
143 KMLFileTokenParse(&extrude ,
144 kstri,
145 fid);
146 else if (!strcmp(kstri,"<tessellate>"))
147 KMLFileTokenParse(&tessellate,
148 kstri,
149 fid);
150 else if (!strcmp(kstri,"<altitudeMode>"))
151 KMLFileTokenParse( altmode ,NULL,KML_LINESTRING_ALTMODE_LENGTH,
152 kstri,
153 fid);
154 else if (!strcmp(kstri,"<coordinates>"))
155 KMLFileTokenParse(&coords ,&ncoord ,0,
156 kstri,
157 fid);
158
159 else if (!strncmp(kstri,"<",1))
160 KML_Geometry::Read(fid,kstri);
161
162 xDelete<char>(kstri);
163 }
164
165 this->AddCommnt(ncom,pcom);
166
167 for (ncom; ncom>0; ncom--)
168 xDelete<char>(pcom[ncom-1]);
169 xDelete<char*>(pcom);
170
171 return;
172}
173/*}}}*/
174/*FUNCTION KML_LineString::WriteExp {{{*/
175void KML_LineString::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
176
177 int i;
178 double *lat,*lon,*x,*y;
179 char nstr2[81];
180
181/* extract latitude and longitude into vectors */
182
183 lat=xNew<IssmPDouble>(ncoord);
184 lon=xNew<IssmPDouble>(ncoord);
185 for (i=0; i<ncoord; i++) {
186 lon[i]=coords[3*i+0];
187 lat[i]=coords[3*i+1];
188 }
189
190/* convert latitude and longitude to x and y */
191
192 x =xNew<IssmPDouble>(ncoord);
193 y =xNew<IssmPDouble>(ncoord);
194 if (sgn) {
195 Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp);
196 }
197 else {
198 memcpy(x,lon,ncoord*sizeof(IssmDouble));
199 memcpy(y,lat,ncoord*sizeof(IssmDouble));
200 }
201
202/* write header */
203
204 memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
205
206 for (i=0; i<strlen(nstr2); i++)
207 if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
208 nstr2[i]='_';
209 fprintf(fid,"## Name:%s\n",nstr2);
210 fprintf(fid,"## Icon:0\n");
211 fprintf(fid,"# Points Count Value\n");
212 fprintf(fid,"%u %s\n",ncoord ,"1.");
213 fprintf(fid,"# X pos Y pos\n");
214
215/* write vertices */
216
217 for (i=0; i<ncoord; i++)
218 fprintf(fid,"%lf\t%lf\n",x[i],y[i]);
219
220/* write blank line */
221
222 fprintf(fid,"\n");
223
224 xDelete<IssmPDouble>(y);
225 xDelete<IssmPDouble>(x);
226 xDelete<IssmPDouble>(lon);
227 xDelete<IssmPDouble>(lat);
228
229 return;
230}
231/*}}}*/
Note: See TracBrowser for help on using the repository browser.