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