/*!\file KML_LineString.cpp * \brief: implementation of the kml_linestring object */ /*Headers:*/ /*{{{*/ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif #include "./KML_LineString.h" #include "./KMLFileReadUtils.h" #include "../shared/shared.h" /*}}}*/ /*Constructors/destructor/copy*/ /*FUNCTION KML_LineString::KML_LineString(){{{*/ KML_LineString::KML_LineString(){ extrude =false; tessellate=false; memcpy(altmode,"clampToGround",(strlen("clampToGround")+1)*sizeof(char)); ncoord =0; coords =NULL; } /*}}}*/ /*FUNCTION KML_LineString::~KML_LineString(){{{*/ KML_LineString::~KML_LineString(){ if (coords) xDelete(coords); coords =NULL; ncoord =0; } /*}}}*/ /*Other*/ /*FUNCTION KML_LineString::Echo {{{*/ void KML_LineString::Echo(){ bool flag=true; if(flag) _printf0_("KML_LineString:\n"); KML_Geometry::Echo(); if(flag) _printf0_(" extrude: " << (extrude ? "true" : "false") << "\n"); if(flag) _printf0_(" tessellate: " << (tessellate ? "true" : "false") << "\n"); if(flag) _printf0_(" altmode: \"" << altmode << "\"\n"); if(flag) _printf0_(" coords: (ncoord=" << ncoord << ")\n"); return; } /*}}}*/ /*FUNCTION KML_LineString::DeepEcho {{{*/ void KML_LineString::DeepEcho(){ char indent[81]=""; KML_LineString::DeepEcho(indent); return; } /*}}}*/ /*FUNCTION KML_LineString::DeepEcho {{{*/ void KML_LineString::DeepEcho(const char* indent){ int i; bool flag=true; if(flag) _printf0_(indent << "KML_LineString:\n"); KML_Geometry::DeepEcho(indent); if(flag) _printf0_(indent << " extrude: " << (extrude ? "true" : "false") << "\n"); if(flag) _printf0_(indent << " tessellate: " << (tessellate ? "true" : "false") << "\n"); if(flag) _printf0_(indent << " altmode: \"" << altmode << "\"\n"); if(flag) _printf0_(indent << " coords: (ncoord=" << ncoord << ")\n"); for (i=0; i\n"); WriteCommnt(filout,indent); KML_Geometry::Write(filout,indent); fprintf(filout,"%s %d\n",indent,(extrude ? 1 : 0)); fprintf(filout,"%s %d\n",indent,(tessellate ? 1 : 0)); fprintf(filout,"%s %s\n",indent,altmode); fprintf(filout,"%s \n",indent); /* loop over the coordinates for the linestring */ for (i=0; i\n",indent); fprintf(filout,"%s\n",indent); return; } /*}}}*/ /*FUNCTION KML_LineString::Read {{{*/ void KML_LineString::Read(FILE* fid,char* kstr){ char* kstri; int ncom=0; char** pcom=NULL; /* get object attributes and check for solo tag */ if (KMLFileTagAttrib(this, kstr)) return; /* loop over and process fields within opening and closing tags */ while (kstri=KMLFileToken(fid, &ncom,&pcom)) { if (!strncmp(kstri,"(kstri); break; } else if (!strncmp(kstri,"")) KMLFileTokenParse(&extrude , kstri, fid); else if (!strcmp(kstri,"")) KMLFileTokenParse(&tessellate, kstri, fid); else if (!strcmp(kstri,"")) KMLFileTokenParse( altmode ,NULL,KML_LINESTRING_ALTMODE_LENGTH, kstri, fid); else if (!strcmp(kstri,"")) KMLFileTokenParse(&coords ,&ncoord ,0, kstri, fid); else if (!strncmp(kstri,"<",1)) KML_Geometry::Read(fid,kstri); xDelete(kstri); } this->AddCommnt(ncom,pcom); for (ncom; ncom>0; ncom--) xDelete(pcom[ncom-1]); xDelete(pcom); return; } /*}}}*/ /*FUNCTION KML_LineString::WriteExp {{{*/ void KML_LineString::WriteExp(FILE* fid,const char* nstr,int sgn,double cm,double sp){ int i; double *lat,*lon,*x,*y; char nstr2[81]; /* extract latitude and longitude into vectors */ lat=xNew(ncoord); lon=xNew(ncoord); for (i=0; i(ncoord); y =xNew(ncoord); if (sgn) { Ll2xyx(x,y,lat,lon,ncoord,sgn,cm,sp); } else { memcpy(x,lon,ncoord*sizeof(IssmDouble)); memcpy(y,lat,ncoord*sizeof(IssmDouble)); } /* write header */ memcpy(nstr2,nstr,(strlen(nstr)+1)*sizeof(char)); for (i=0; i(y); xDelete(x); xDelete(lon); xDelete(lat); return; } /*}}}*/