source: issm/trunk-jpl/src/c/kml/KML_Point.cpp@ 15068

Last change on this file since 15068 was 15068, checked in by Eric.Larour, 12 years ago

CHG: finished moving the kml objects from the classes directory to the kml directory.

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