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