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