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
RevLine 
[10256]1/*!\file KML_Point.cpp
2 * \brief: implementation of the kml_point object
3 */
4
5/*Headers:*/
[12365]6/*{{{*/
[10256]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
[15068]13#include "./KML_Point.h"
14#include "./KMLFileReadUtils.h"
15#include "../shared/shared.h"
16#include "../modules/Ll2xyx/Ll2xyx.h"
[10256]17/*}}}*/
18
19/*Constructors/destructor/copy*/
[12365]20/*FUNCTION KML_Point::KML_Point(){{{*/
[10256]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/*}}}*/
[12365]32/*FUNCTION KML_Point::~KML_Point(){{{*/
[10256]33KML_Point::~KML_Point(){
34
35 ;
36
37}
38/*}}}*/
39
40/*Other*/
[12365]41/*FUNCTION KML_Point::Echo {{{*/
[10256]42void KML_Point::Echo(){
43
44 bool flag=true;
45
[12515]46 if(flag) _pprintLine_("KML_Point:");
[10256]47 KML_Geometry::Echo();
48
[12515]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] << ")");
[10256]52
53 return;
54}
55/*}}}*/
[12365]56/*FUNCTION KML_Point::DeepEcho {{{*/
[10256]57void KML_Point::DeepEcho(){
58
59 char indent[81]="";
60
61 KML_Point::DeepEcho(indent);
62
63 return;
64}
65/*}}}*/
[12365]66/*FUNCTION KML_Point::DeepEcho {{{*/
[11201]67void KML_Point::DeepEcho(const char* indent){
[10256]68
69 bool flag=true;
70
[12520]71 if(flag) _pprintLine_(indent << "KML_Point:");
[10256]72 KML_Geometry::DeepEcho(indent);
73
[12520]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] << ")");
[10256]77
78 return;
79}
80/*}}}*/
[12365]81/*FUNCTION KML_Point::Write {{{*/
[11202]82void KML_Point::Write(FILE* filout,const char* indent){
[10256]83
84 fprintf(filout,"%s<Point",indent);
85 WriteAttrib(filout," ");
86 fprintf(filout,">\n");
[10840]87 WriteCommnt(filout,indent);
[10256]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/*}}}*/
[12365]101/*FUNCTION KML_Point::Read {{{*/
[10256]102void KML_Point::Read(FILE* fid,char* kstr){
103
[10274]104 double* pcoords=&coords[0];
[10256]105 char* kstri;
[10840]106 int ncom=0;
107 char** pcom=NULL;
[10256]108
[10629]109/* get object attributes and check for solo tag */
[10256]110
[10629]111 if (KMLFileTagAttrib(this,
112 kstr))
113 return;
[10256]114
115/* loop over and process fields within opening and closing tags */
116
[10840]117 while (kstri=KMLFileToken(fid,
118 &ncom,&pcom)) {
[10256]119 if (!strncmp(kstri,"</Point", 7)) {
[12915]120 xDelete<char>(kstri);
[10256]121 break;
122 }
123 else if (!strncmp(kstri,"</",2))
[13056]124 {_error_("KML_Point::Read -- Unexpected closing tag " << kstri << ".\n");}
[10256]125 else if (strncmp(kstri,"<",1))
[13056]126 {_error_("KML_Point::Read -- Unexpected field \"" << kstri << "\".\n");}
[10256]127
128 else if (!strcmp(kstri,"<extrude>"))
[12493]129 KMLFileTokenParse(&extrude , kstri, fid);
[10256]130 else if (!strcmp(kstri,"<altitudeMode>"))
[12493]131 KMLFileTokenParse( altmode ,NULL,KML_POINT_ALTMODE_LENGTH, kstri, fid);
[10256]132 else if (!strcmp(kstri,"<coordinates>"))
[12493]133 KMLFileTokenParse(&pcoords ,NULL,3, kstri, fid);
[10256]134
135 else if (!strncmp(kstri,"<",1))
136 KML_Geometry::Read(fid,kstri);
137
[12915]138 xDelete<char>(kstri);
[10256]139 }
140
[10840]141 this->AddCommnt(ncom,pcom);
142
143 for (ncom; ncom>0; ncom--)
[12915]144 xDelete<char>(pcom[ncom-1]);
145 xDelete<char*>(pcom);
[10840]146
[10256]147 return;
148}
149/*}}}*/
[12365]150/*FUNCTION KML_Point::WriteExp {{{*/
[11200]151void KML_Point::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
[10256]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
[14282]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 }
[10256]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.