Ice Sheet System Model  4.18
Code documentation
KML_LineString.cpp
Go to the documentation of this file.
1 
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*/
20 
21  extrude =false;
22  tessellate=false;
23  memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char));
24 
25  ncoord =0;
26  coords =NULL;
27 
28 }
29 /*}}}*/
31 
32  if (coords) xDelete<double>(coords);
33 
34  coords =NULL;
35  ncoord =0;
36 
37 }
38 /*}}}*/
39 
40 /*Other*/
41 void KML_LineString::Echo(){/*{{{*/
42 
43  bool flag=true;
44 
45  if(flag) _printf0_("KML_LineString:\n");
47 
48  if(flag) _printf0_(" extrude: " << (extrude ? "true" : "false") << "\n");
49  if(flag) _printf0_(" tessellate: " << (tessellate ? "true" : "false") << "\n");
50  if(flag) _printf0_(" altmode: \"" << altmode << "\"\n");
51  if(flag) _printf0_(" coords: (ncoord=" << ncoord << ")\n");
52 
53  return;
54 }
55 /*}}}*/
57 
58  char indent[81]="";
59 
61 
62  return;
63 }
64 /*}}}*/
65 void KML_LineString::DeepEcho(const char* indent){/*{{{*/
66 
67  int i;
68  bool flag=true;
69 
70  if(flag) _printf0_(indent << "KML_LineString:\n");
71  KML_Geometry::DeepEcho(indent);
72 
73  if(flag) _printf0_(indent << " extrude: " << (extrude ? "true" : "false") << "\n");
74  if(flag) _printf0_(indent << " tessellate: " << (tessellate ? "true" : "false") << "\n");
75  if(flag) _printf0_(indent << " altmode: \"" << altmode << "\"\n");
76  if(flag) _printf0_(indent << " coords: (ncoord=" << ncoord << ")\n");
77  for (i=0; i<ncoord; i++)
78  if(flag) _printf0_(indent << " (" << coords[3*i+0] << "," << coords[3*i+1] << "," << coords[3*i+2] << ")\n");
79 
80  return;
81 }
82 /*}}}*/
83 void KML_LineString::Write(FILE* filout,const char* indent){/*{{{*/
84 
85  int i;
86 
87  fprintf(filout,"%s<LineString",indent);
88  WriteAttrib(filout," ");
89  fprintf(filout,">\n");
90  WriteCommnt(filout,indent);
91 
92  KML_Geometry::Write(filout,indent);
93 
94  fprintf(filout,"%s <extrude>%d</extrude>\n",indent,(extrude ? 1 : 0));
95  fprintf(filout,"%s <tessellate>%d</tessellate>\n",indent,(tessellate ? 1 : 0));
96  fprintf(filout,"%s <altitudeMode>%s</altitudeMode>\n",indent,altmode);
97  fprintf(filout,"%s <coordinates>\n",indent);
98 
99 /* loop over the coordinates for the linestring */
100 
101  for (i=0; i<ncoord; i++)
102  fprintf(filout,"%s %0.16g,%0.16g,%0.16g\n",indent, coords[3*i+0],coords[3*i+1],coords[3*i+2]);
103 
104  fprintf(filout,"%s </coordinates>\n",indent);
105  fprintf(filout,"%s</LineString>\n",indent);
106 
107  return;
108 }
109 /*}}}*/
110 void KML_LineString::Read(FILE* fid,char* kstr){/*{{{*/
111 
112  char* kstri;
113  int ncom=0;
114  char** pcom=NULL;
115 
116 /* get object attributes and check for solo tag */
117 
118  if (KMLFileTagAttrib(this,
119  kstr))
120  return;
121 
122 /* loop over and process fields within opening and closing tags */
123 
124  while((kstri=KMLFileToken(fid, &ncom,&pcom))){
125  if (!strncmp(kstri,"</LineString",12)) {
126  xDelete<char>(kstri);
127  break;
128  }
129  else if (!strncmp(kstri,"</",2))
130  {_error_("KML_LineString::Read -- Unexpected closing tag " << kstri << ".\n");}
131  else if (strncmp(kstri,"<",1))
132  {_error_("KML_LineString::Read -- Unexpected field \"" << kstri << "\".\n");}
133 
134  else if (!strcmp(kstri,"<extrude>"))
136  kstri,
137  fid);
138  else if (!strcmp(kstri,"<tessellate>"))
140  kstri,
141  fid);
142  else if (!strcmp(kstri,"<altitudeMode>"))
144  kstri,
145  fid);
146  else if (!strcmp(kstri,"<coordinates>"))
148  kstri,
149  fid);
150 
151  else if (!strncmp(kstri,"<",1))
152  KML_Geometry::Read(fid,kstri);
153 
154  xDelete<char>(kstri);
155  }
156 
157  this->AddCommnt(ncom,pcom);
158 
159  for (ncom=ncom; ncom>0; ncom--)
160  xDelete<char>(pcom[ncom-1]);
161  xDelete<char*>(pcom);
162 
163  return;
164 }
165 /*}}}*/
166 void KML_LineString::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){/*{{{*/
167 
168  int i;
169  double *lat,*lon,*x,*y;
170  char nstr2[81];
171 
172 /* extract latitude and longitude into vectors */
173 
174  lat=xNew<IssmPDouble>(ncoord);
175  lon=xNew<IssmPDouble>(ncoord);
176  for (i=0; i<ncoord; i++) {
177  lon[i]=coords[3*i+0];
178  lat[i]=coords[3*i+1];
179  }
180 
181 /* convert latitude and longitude to x and y */
182 
183  x =xNew<IssmPDouble>(ncoord);
184  y =xNew<IssmPDouble>(ncoord);
185  if (sgn) {
186  Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp);
187  }
188  else {
189  memcpy(x,lon,ncoord*sizeof(IssmDouble));
190  memcpy(y,lat,ncoord*sizeof(IssmDouble));
191  }
192 
193 /* write header */
194 
195  memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
196 
197  for (i=0; i<strlen(nstr2); i++)
198  if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
199  nstr2[i]='_';
200  fprintf(fid,"## Name:%s\n",nstr2);
201  fprintf(fid,"## Icon:0\n");
202  fprintf(fid,"# Points Count Value\n");
203  fprintf(fid,"%u %s\n",ncoord ,"1.");
204  fprintf(fid,"# X pos Y pos\n");
205 
206 /* write vertices */
207 
208  for (i=0; i<ncoord; i++)
209  fprintf(fid,"%lf\t%lf\n",x[i],y[i]);
210 
211 /* write blank line */
212 
213  fprintf(fid,"\n");
214 
215  xDelete<IssmPDouble>(y);
216  xDelete<IssmPDouble>(x);
217  xDelete<IssmPDouble>(lon);
218  xDelete<IssmPDouble>(lat);
219 
220  return;
221 }
222 /*}}}*/
Ll2xyx
int Ll2xyx(double *x, double *y, double *lat, double *lon, int ncoord, int sgn)
Definition: Ll2xyx.cpp:8
KML_LineString::tessellate
bool tessellate
Definition: KML_LineString.h:21
IssmDouble
double IssmDouble
Definition: types.h:37
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
KML_Object::WriteAttrib
virtual void WriteAttrib(FILE *fid, const char *indent)
Definition: KML_Object.cpp:288
KML_LineString::coords
double * coords
Definition: KML_LineString.h:24
KML_Geometry::Write
void Write(FILE *fid, const char *indent)
Definition: KML_Geometry.cpp:56
KML_LineString::WriteExp
void WriteExp(FILE *fid, const char *nstr, int sgn, double cm, double sp)
Definition: KML_LineString.cpp:166
KMLFileReadUtils.h
: header file for kml file reading utilities.
KMLFileTagAttrib
int KMLFileTagAttrib(KML_Object *kobj, char *ktag)
Definition: KMLFileReadUtils.cpp:287
KML_LineString.h
: header file for kml_linestring object
KML_LINESTRING_ALTMODE_LENGTH
#define KML_LINESTRING_ALTMODE_LENGTH
Definition: KML_LineString.h:8
KML_LineString::altmode
char altmode[KML_LINESTRING_ALTMODE_LENGTH+1]
Definition: KML_LineString.h:22
KMLFileToken
char * KMLFileToken(FILE *fid, int *pncom=NULL, char ***ppcom=NULL)
Definition: KMLFileReadUtils.cpp:18
KML_LineString::Write
void Write(FILE *fid, const char *indent)
Definition: KML_LineString.cpp:83
KML_Geometry::DeepEcho
void DeepEcho()
Definition: KML_Geometry.cpp:40
KML_LineString::Echo
void Echo()
Definition: KML_LineString.cpp:41
KML_LineString::KML_LineString
KML_LineString()
Definition: KML_LineString.cpp:19
KMLFileTokenParse
int KMLFileTokenParse(int *pival, char *ktag, FILE *fid)
Definition: KMLFileReadUtils.cpp:335
KML_LineString::~KML_LineString
~KML_LineString()
Definition: KML_LineString.cpp:30
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
KML_LineString::Read
void Read(FILE *fid, char *kstr)
Definition: KML_LineString.cpp:110
KML_LineString::DeepEcho
void DeepEcho()
Definition: KML_LineString.cpp:56
KML_LineString::extrude
bool extrude
Definition: KML_LineString.h:20
KML_LineString::ncoord
int ncoord
Definition: KML_LineString.h:23
KML_Object::AddCommnt
virtual void AddCommnt(int ncom, char **pcom)
Definition: KML_Object.cpp:301
KML_Object::WriteCommnt
virtual void WriteCommnt(FILE *fid, const char *indent)
Definition: KML_Object.cpp:326
KML_Geometry::Echo
void Echo()
Definition: KML_Geometry.cpp:33
KML_Geometry::Read
void Read(FILE *fid, char *kstr)
Definition: KML_Geometry.cpp:63