[7653] | 1 | /*!\file KML_LineString.cpp
|
---|
| 2 | * \brief: implementation of the kml_linestring object
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | /*Headers:*/
|
---|
[12365] | 6 | /*{{{*/
|
---|
[7653] | 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[7653] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[15068] | 13 | #include "./KML_LineString.h"
|
---|
| 14 | #include "./KMLFileReadUtils.h"
|
---|
| 15 | #include "../shared/shared.h"
|
---|
[7653] | 16 | /*}}}*/
|
---|
| 17 |
|
---|
| 18 | /*Constructors/destructor/copy*/
|
---|
[12365] | 19 | /*FUNCTION KML_LineString::KML_LineString(){{{*/
|
---|
[7653] | 20 | KML_LineString::KML_LineString(){
|
---|
| 21 |
|
---|
| 22 | extrude =false;
|
---|
| 23 | tessellate=false;
|
---|
[10255] | 24 | memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char));
|
---|
[9336] | 25 |
|
---|
[7653] | 26 | ncoord =0;
|
---|
| 27 | coords =NULL;
|
---|
| 28 |
|
---|
| 29 | }
|
---|
| 30 | /*}}}*/
|
---|
[12365] | 31 | /*FUNCTION KML_LineString::~KML_LineString(){{{*/
|
---|
[7653] | 32 | KML_LineString::~KML_LineString(){
|
---|
| 33 |
|
---|
[12442] | 34 | if (coords) xDelete<double>(coords);
|
---|
[7653] | 35 |
|
---|
| 36 | coords =NULL;
|
---|
| 37 | ncoord =0;
|
---|
| 38 |
|
---|
| 39 | }
|
---|
| 40 | /*}}}*/
|
---|
| 41 |
|
---|
| 42 | /*Other*/
|
---|
[12365] | 43 | /*FUNCTION KML_LineString::Echo {{{*/
|
---|
[7653] | 44 | void KML_LineString::Echo(){
|
---|
| 45 |
|
---|
| 46 | bool flag=true;
|
---|
| 47 |
|
---|
[15104] | 48 | if(flag) _printf0_("KML_LineString:\n");
|
---|
[7653] | 49 | KML_Geometry::Echo();
|
---|
| 50 |
|
---|
[15100] | 51 | if(flag) _printf0_(" extrude: " << (extrude ? "true" : "false") << "\n");
|
---|
| 52 | if(flag) _printf0_(" tessellate: " << (tessellate ? "true" : "false") << "\n");
|
---|
[15104] | 53 | if(flag) _printf0_(" altmode: \"" << altmode << "\"\n");
|
---|
| 54 | if(flag) _printf0_(" coords: (ncoord=" << ncoord << ")\n");
|
---|
[7653] | 55 |
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 | /*}}}*/
|
---|
[12365] | 59 | /*FUNCTION KML_LineString::DeepEcho {{{*/
|
---|
[7653] | 60 | void KML_LineString::DeepEcho(){
|
---|
| 61 |
|
---|
| 62 | char indent[81]="";
|
---|
| 63 |
|
---|
| 64 | KML_LineString::DeepEcho(indent);
|
---|
| 65 |
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 | /*}}}*/
|
---|
[12365] | 69 | /*FUNCTION KML_LineString::DeepEcho {{{*/
|
---|
[11201] | 70 | void KML_LineString::DeepEcho(const char* indent){
|
---|
[7653] | 71 |
|
---|
| 72 | int i;
|
---|
| 73 | bool flag=true;
|
---|
| 74 |
|
---|
[15104] | 75 | if(flag) _printf0_(indent << "KML_LineString:\n");
|
---|
[7653] | 76 | KML_Geometry::DeepEcho(indent);
|
---|
| 77 |
|
---|
[15100] | 78 | if(flag) _printf0_(indent << " extrude: " << (extrude ? "true" : "false") << "\n");
|
---|
| 79 | if(flag) _printf0_(indent << " tessellate: " << (tessellate ? "true" : "false") << "\n");
|
---|
[15104] | 80 | if(flag) _printf0_(indent << " altmode: \"" << altmode << "\"\n");
|
---|
| 81 | if(flag) _printf0_(indent << " coords: (ncoord=" << ncoord << ")\n");
|
---|
[7653] | 82 | for (i=0; i<ncoord; i++)
|
---|
[15104] | 83 | if(flag) _printf0_(indent << " (" << coords[3*i+0] << "," << coords[3*i+1] << "," << coords[3*i+2] << ")\n");
|
---|
[7653] | 84 |
|
---|
| 85 | return;
|
---|
| 86 | }
|
---|
| 87 | /*}}}*/
|
---|
[12365] | 88 | /*FUNCTION KML_LineString::Write {{{*/
|
---|
[11202] | 89 | void KML_LineString::Write(FILE* filout,const char* indent){
|
---|
[7653] | 90 |
|
---|
| 91 | int i;
|
---|
| 92 |
|
---|
[8461] | 93 | fprintf(filout,"%s<LineString",indent);
|
---|
| 94 | WriteAttrib(filout," ");
|
---|
| 95 | fprintf(filout,">\n");
|
---|
[10840] | 96 | WriteCommnt(filout,indent);
|
---|
[7653] | 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 linestring */
|
---|
| 106 |
|
---|
| 107 | for (i=0; i<ncoord; i++)
|
---|
[12442] | 108 | fprintf(filout,"%s %0.16g,%0.16g,%0.16g\n",indent, coords[3*i+0],coords[3*i+1],coords[3*i+2]);
|
---|
[7653] | 109 |
|
---|
| 110 | fprintf(filout,"%s </coordinates>\n",indent);
|
---|
| 111 | fprintf(filout,"%s</LineString>\n",indent);
|
---|
| 112 |
|
---|
| 113 | return;
|
---|
| 114 | }
|
---|
| 115 | /*}}}*/
|
---|
[12365] | 116 | /*FUNCTION KML_LineString::Read {{{*/
|
---|
[8293] | 117 | void KML_LineString::Read(FILE* fid,char* kstr){
|
---|
[8207] | 118 |
|
---|
[8461] | 119 | char* kstri;
|
---|
[10840] | 120 | int ncom=0;
|
---|
| 121 | char** pcom=NULL;
|
---|
[8207] | 122 |
|
---|
[10629] | 123 | /* get object attributes and check for solo tag */
|
---|
[8461] | 124 |
|
---|
[10629] | 125 | if (KMLFileTagAttrib(this,
|
---|
| 126 | kstr))
|
---|
| 127 | return;
|
---|
[8461] | 128 |
|
---|
| 129 | /* loop over and process fields within opening and closing tags */
|
---|
| 130 |
|
---|
[16560] | 131 | while((kstri=KMLFileToken(fid, &ncom,&pcom))){
|
---|
[8461] | 132 | if (!strncmp(kstri,"</LineString",12)) {
|
---|
[12915] | 133 | xDelete<char>(kstri);
|
---|
[8461] | 134 | break;
|
---|
| 135 | }
|
---|
| 136 | else if (!strncmp(kstri,"</",2))
|
---|
[13036] | 137 | {_error_("KML_LineString::Read -- Unexpected closing tag " << kstri << ".\n");}
|
---|
[8461] | 138 | else if (strncmp(kstri,"<",1))
|
---|
[13036] | 139 | {_error_("KML_LineString::Read -- Unexpected field \"" << kstri << "\".\n");}
|
---|
[8461] | 140 |
|
---|
| 141 | else if (!strcmp(kstri,"<extrude>"))
|
---|
| 142 | KMLFileTokenParse(&extrude ,
|
---|
| 143 | kstri,
|
---|
| 144 | fid);
|
---|
| 145 | else if (!strcmp(kstri,"<tessellate>"))
|
---|
| 146 | KMLFileTokenParse(&tessellate,
|
---|
| 147 | kstri,
|
---|
| 148 | fid);
|
---|
| 149 | else if (!strcmp(kstri,"<altitudeMode>"))
|
---|
| 150 | KMLFileTokenParse( altmode ,NULL,KML_LINESTRING_ALTMODE_LENGTH,
|
---|
| 151 | kstri,
|
---|
| 152 | fid);
|
---|
| 153 | else if (!strcmp(kstri,"<coordinates>"))
|
---|
| 154 | KMLFileTokenParse(&coords ,&ncoord ,0,
|
---|
| 155 | kstri,
|
---|
| 156 | fid);
|
---|
| 157 |
|
---|
| 158 | else if (!strncmp(kstri,"<",1))
|
---|
| 159 | KML_Geometry::Read(fid,kstri);
|
---|
| 160 |
|
---|
[12915] | 161 | xDelete<char>(kstri);
|
---|
[8461] | 162 | }
|
---|
| 163 |
|
---|
[10840] | 164 | this->AddCommnt(ncom,pcom);
|
---|
| 165 |
|
---|
[16560] | 166 | for (ncom=ncom; ncom>0; ncom--)
|
---|
[12915] | 167 | xDelete<char>(pcom[ncom-1]);
|
---|
| 168 | xDelete<char*>(pcom);
|
---|
[10840] | 169 |
|
---|
[8208] | 170 | return;
|
---|
[8207] | 171 | }
|
---|
| 172 | /*}}}*/
|
---|
[12365] | 173 | /*FUNCTION KML_LineString::WriteExp {{{*/
|
---|
[11200] | 174 | void KML_LineString::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){
|
---|
[9201] | 175 |
|
---|
[9261] | 176 | int i;
|
---|
| 177 | double *lat,*lon,*x,*y;
|
---|
| 178 | char nstr2[81];
|
---|
[9201] | 179 |
|
---|
[9261] | 180 | /* extract latitude and longitude into vectors */
|
---|
| 181 |
|
---|
[16137] | 182 | lat=xNew<IssmPDouble>(ncoord);
|
---|
| 183 | lon=xNew<IssmPDouble>(ncoord);
|
---|
[9261] | 184 | for (i=0; i<ncoord; i++) {
|
---|
[12442] | 185 | lon[i]=coords[3*i+0];
|
---|
| 186 | lat[i]=coords[3*i+1];
|
---|
[9261] | 187 | }
|
---|
| 188 |
|
---|
| 189 | /* convert latitude and longitude to x and y */
|
---|
| 190 |
|
---|
[16137] | 191 | x =xNew<IssmPDouble>(ncoord);
|
---|
| 192 | y =xNew<IssmPDouble>(ncoord);
|
---|
[14282] | 193 | if (sgn) {
|
---|
| 194 | Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp);
|
---|
| 195 | }
|
---|
| 196 | else {
|
---|
| 197 | memcpy(x,lon,ncoord*sizeof(IssmDouble));
|
---|
| 198 | memcpy(y,lat,ncoord*sizeof(IssmDouble));
|
---|
| 199 | }
|
---|
[9261] | 200 |
|
---|
| 201 | /* write header */
|
---|
| 202 |
|
---|
[9336] | 203 | memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char));
|
---|
| 204 |
|
---|
[9261] | 205 | for (i=0; i<strlen(nstr2); i++)
|
---|
| 206 | if ((nstr2[i] == ' ') || (nstr2[i] == '\t'))
|
---|
| 207 | nstr2[i]='_';
|
---|
| 208 | fprintf(fid,"## Name:%s\n",nstr2);
|
---|
| 209 | fprintf(fid,"## Icon:0\n");
|
---|
| 210 | fprintf(fid,"# Points Count Value\n");
|
---|
| 211 | fprintf(fid,"%u %s\n",ncoord ,"1.");
|
---|
| 212 | fprintf(fid,"# X pos Y pos\n");
|
---|
| 213 |
|
---|
| 214 | /* write vertices */
|
---|
| 215 |
|
---|
| 216 | for (i=0; i<ncoord; i++)
|
---|
| 217 | fprintf(fid,"%lf\t%lf\n",x[i],y[i]);
|
---|
| 218 |
|
---|
| 219 | /* write blank line */
|
---|
| 220 |
|
---|
| 221 | fprintf(fid,"\n");
|
---|
| 222 |
|
---|
[16137] | 223 | xDelete<IssmPDouble>(y);
|
---|
| 224 | xDelete<IssmPDouble>(x);
|
---|
| 225 | xDelete<IssmPDouble>(lon);
|
---|
| 226 | xDelete<IssmPDouble>(lat);
|
---|
[9261] | 227 |
|
---|
[9201] | 228 | return;
|
---|
| 229 | }
|
---|
| 230 | /*}}}*/
|
---|