source: issm/trunk/src/c/kml/KML_LinearRing.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.6 KB
Line 
1/*!\file KML_LinearRing.cpp
2 * \brief: implementation of the kml_linearring 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_LinearRing.h"
14#include "./KMLFileReadUtils.h"
15#include "../shared/shared.h"
16/*}}}*/
17
18/*Constructors/destructor/copy*/
19/*FUNCTION KML_LinearRing::KML_LinearRing(){{{*/
20KML_LinearRing::KML_LinearRing(){
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_LinearRing::~KML_LinearRing(){{{*/
32KML_LinearRing::~KML_LinearRing(){
33
34 if (coords) xDelete<double>(coords);
35
36 coords =NULL;
37 ncoord =0;
38
39}
40/*}}}*/
41
42/*Other*/
43/*FUNCTION KML_LinearRing::Echo {{{*/
44void KML_LinearRing::Echo(){
45
46 bool flag=true;
47
48 if(flag) _printf0_("KML_LinearRing:\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_LinearRing::DeepEcho {{{*/
60void KML_LinearRing::DeepEcho(){
61
62 char indent[81]="";
63
64 KML_LinearRing::DeepEcho(indent);
65
66 return;
67}
68/*}}}*/
69/*FUNCTION KML_LinearRing::DeepEcho {{{*/
70void KML_LinearRing::DeepEcho(const char* indent){
71
72 int i;
73 bool flag=true;
74
75 if(flag) _printf0_(indent << "KML_LinearRing:\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)_printf_(indent << " (" <<coords[3*i+0] << "," <<coords[3*i+1] << "," <<coords[3*i+2] << ")\n\n");
84
85 return;
86}
87/*}}}*/
88/*FUNCTION KML_LinearRing::Write {{{*/
89void KML_LinearRing::Write(FILE* filout,const char* indent){
90
91 int i;
92
93 fprintf(filout,"%s<LinearRing",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 linearring */
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</LinearRing>\n",indent);
112
113 return;
114}
115/*}}}*/
116/*FUNCTION KML_LinearRing::Read {{{*/
117void KML_LinearRing::Read(FILE* fid,char* kstr){
118
119 char *kstri = NULL;
120 int ncom = 0;
121 char **pcom = NULL;
122
123/* get object attributes and check for solo tag */
124
125 if (KMLFileTagAttrib(this,kstr)) return;
126
127/* loop over and process fields within opening and closing tags */
128
129 while (kstri=KMLFileToken(fid,&ncom,&pcom)){
130 if (!strncmp(kstri,"</LinearRing",12)){
131 xDelete<char>(kstri);
132 break;
133 }
134 else if (!strncmp(kstri,"</",2))
135 {_error_("KML_LinearRing::Read -- Unexpected closing tag " << kstri << ".\n");}
136 else if (strncmp(kstri,"<",1))
137 {_error_("KML_LinearRing::Read -- Unexpected field \"" << kstri << "\".\n");}
138
139 else if (!strcmp(kstri,"<extrude>"))
140 KMLFileTokenParse(&extrude,kstri,fid);
141 else if (!strcmp(kstri,"<tessellate>"))
142 KMLFileTokenParse(&tessellate,kstri,fid);
143 else if (!strcmp(kstri,"<altitudeMode>"))
144 KMLFileTokenParse(altmode,NULL,KML_LINEARRING_ALTMODE_LENGTH,kstri,fid);
145 else if (!strcmp(kstri,"<coordinates>"))
146 KMLFileTokenParse(&coords,&ncoord,3,0,kstri,fid);
147 else if (!strncmp(kstri,"<",1))
148 KML_Geometry::Read(fid,kstri);
149
150 xDelete<char>(kstri);
151 }
152
153 this->AddCommnt(ncom,pcom);
154
155 for(ncom; ncom>0; ncom--)
156 xDelete<char>(pcom[ncom-1]);
157 xDelete<char*>(pcom);
158
159 return;
160}
161/*}}}*/
162/*FUNCTION KML_LinearRing::WriteExp {{{*/
163void KML_LinearRing::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
164
165 int i;
166 double *lat,*lon,*x,*y;
167 char nstr2[81];
168
169/* extract latitude and longitude into vectors */
170
171 lat=xNew<IssmPDouble>(ncoord);
172 lon=xNew<IssmPDouble>(ncoord);
173 for (i=0; i<ncoord; i++) {
174 lon[i]=coords[3*i+0];
175 lat[i]=coords[3*i+1];
176 }
177
178/* convert latitude and longitude to x and y */
179
180 x =xNew<IssmPDouble>(ncoord);
181 y =xNew<IssmPDouble>(ncoord);
182 if (sgn) {
183 Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp);
184 }
185 else {
186 memcpy(x,lon,ncoord*sizeof(IssmDouble));
187 memcpy(y,lat,ncoord*sizeof(IssmDouble));
188 }
189
190/* write header */
191
192 memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
193
194 for (i=0; i<strlen(nstr2); i++)
195 if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
196 nstr2[i]='_';
197 fprintf(fid,"## Name:%s\n",nstr2);
198 fprintf(fid,"## Icon:0\n");
199 fprintf(fid,"# Points Count Value\n");
200 if ((lat[ncoord-1] != lat[0]) || (lon[ncoord-1] != lon[0]))
201 fprintf(fid,"%u %s\n",ncoord+1,"1.");
202 else
203 fprintf(fid,"%u %s\n",ncoord ,"1.");
204 fprintf(fid,"# X pos Y pos\n");
205
206/* write vertices, making sure ring is closed */
207
208 for (i=0; i<ncoord; i++)
209 fprintf(fid,"%lf\t%lf\n",x[i],y[i]);
210 if ((lat[ncoord-1] != lat[0]) || (lon[ncoord-1] != lon[0]))
211 fprintf(fid,"%lf\t%lf\n",x[0],y[0]);
212
213/* write blank line */
214
215 fprintf(fid,"\n");
216
217 xDelete<double>(y);
218 xDelete<double>(x);
219 xDelete<double>(lon);
220 xDelete<double>(lat);
221
222 return;
223}
224/*}}}*/
Note: See TracBrowser for help on using the repository browser.