initial upload
This commit is contained in:
117
archive/xyz2gpx/func.h
Normal file
117
archive/xyz2gpx/func.h
Normal file
@@ -0,0 +1,117 @@
|
||||
#ifndef _FUNC_H
|
||||
#define _FUNC_H
|
||||
#include "iostream"
|
||||
#include "fstream"
|
||||
#include "sstream"
|
||||
#include "iomanip"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "list"
|
||||
#define OUTFILE "-o"
|
||||
#define RESET "\033[0m" /* reset */
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
using namespace std;
|
||||
|
||||
struct loc
|
||||
{
|
||||
double geox,geoy,altitude;
|
||||
string tag;
|
||||
};
|
||||
typedef list<loc> LocList;
|
||||
|
||||
class XyzGpx
|
||||
{
|
||||
public:
|
||||
XyzGpx();
|
||||
~XyzGpx();
|
||||
int readxyz(char*);
|
||||
int outgpx(char*);
|
||||
private:
|
||||
LocList list_loc;
|
||||
LocList::iterator il;
|
||||
loc temp_loc;
|
||||
|
||||
double outbox[4];
|
||||
};
|
||||
|
||||
XyzGpx::XyzGpx()
|
||||
{
|
||||
outbox[0] = outbox[2] = 1e+30;
|
||||
outbox[1] = outbox[3] = -1e+30;
|
||||
}
|
||||
|
||||
XyzGpx::~XyzGpx()
|
||||
{
|
||||
if(!list_loc.empty()) list_loc.clear();
|
||||
}
|
||||
|
||||
int XyzGpx::readxyz(char* filename)
|
||||
{
|
||||
stringstream stemp;
|
||||
string strtemp;
|
||||
ifstream xyzin(filename);
|
||||
if (!xyzin)
|
||||
{
|
||||
cout<<filename<<" not found!"<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(getline(xyzin,strtemp))
|
||||
{
|
||||
if (strtemp!="")
|
||||
{
|
||||
stemp.clear();
|
||||
stemp.str(strtemp);
|
||||
stemp>>temp_loc.tag>>temp_loc.geox>>temp_loc.geoy>>temp_loc.altitude;
|
||||
list_loc.push_back(temp_loc);
|
||||
if(temp_loc.geox<outbox[0]) outbox[0] = temp_loc.geox;
|
||||
if(temp_loc.geox>outbox[1]) outbox[1] = temp_loc.geox;
|
||||
if(temp_loc.geoy<outbox[2]) outbox[2] = temp_loc.geoy;
|
||||
if(temp_loc.geoy>outbox[3]) outbox[3] = temp_loc.geoy;
|
||||
}
|
||||
}
|
||||
xyzin.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int XyzGpx::outgpx(char* filename)
|
||||
{
|
||||
ofstream gpxout(filename);
|
||||
if (!gpxout)
|
||||
{
|
||||
cout<<"can not create "<<filename<<endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gpxout<<"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"<<endl
|
||||
<<"<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"MapSource 6.15.6\" version=\"1.1\" "<<endl
|
||||
<<"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1"<<endl
|
||||
<<"http://www.topografix.com/GPX/1/1/gpx.xsd\">"<<endl
|
||||
<<" <metadata>"<<endl
|
||||
<<" <link href=\"http://www.garmin.com\">"<<endl
|
||||
<<" <text>Garmin International</text>"<<endl
|
||||
<<" </link>"<<endl
|
||||
<<" <time>2014-07-06T00:40:40Z</time>"<<endl
|
||||
<<" <bounds \"maxlat\"="<<setprecision(8)<<outbox[3]<<" \"maxlon\"="<<outbox[1]<<" \"minlat\"="<<outbox[2]<<" \"minlon\"="<<outbox[0]<<"\"/>"<<endl
|
||||
<<" </metadata>"<<endl;
|
||||
for (il=list_loc.begin();il!=list_loc.end();il++)
|
||||
{
|
||||
temp_loc = *il;
|
||||
gpxout<<setprecision(8)
|
||||
<<" <wpt lat=\""<<temp_loc.geox<<"\" lon=\""<<temp_loc.geoy<<"\">"<<endl
|
||||
<<" <ele>"<<temp_loc.altitude<<"</ele>"<<endl
|
||||
<<" <name>"<<temp_loc.tag<<"</name>"<<endl
|
||||
<<" <sym>Dot, White</sym>"<<endl
|
||||
<<" <extensions>"<<endl
|
||||
<<" </extensions>"<<endl
|
||||
<<" </wpt>"<<endl;
|
||||
}
|
||||
gpxout<<"</gpx>";
|
||||
gpxout.close();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
62
archive/xyz2gpx/main.cpp
Normal file
62
archive/xyz2gpx/main.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "func.h"
|
||||
|
||||
void disp_help()
|
||||
{
|
||||
cout<<"xyz2gpx 1.0 - convet a xyz table file into .gpx file for portable GPX device"<<endl<<endl
|
||||
<<"syntax: xyz2gpx <xyz_file> [-o<outfile>]"<<endl
|
||||
<<" -o specify output file's name, the input name will be used if -o is absent"<<endl;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
XyzGpx XG;
|
||||
char command_type[1024] = {0};
|
||||
char inname[1024] = {0};
|
||||
char nametype[1024] = {0};
|
||||
char outname[1024] = {0};
|
||||
if (argc==1)
|
||||
{
|
||||
disp_help();
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(argv[1],"%s",inname);//按格式读入文件名与扩展名
|
||||
if(!strcmp(inname,""))//检查文件名是否为空
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[1]<<endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc>2)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i)
|
||||
{
|
||||
sscanf(argv[i],"%2s",command_type);
|
||||
if(!strcmp(command_type,OUTFILE))//命令为文件名设置符
|
||||
{
|
||||
sscanf(argv[i],"%*2s%s",outname);//按格式读入文件名与扩展名
|
||||
if(!strcmp(outname,""))//检查文件名是否为空
|
||||
{
|
||||
cout<<BOLDRED<<"==> "<<RESET<<"bad syntax: "<<argv[i]<<endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(outname,""))
|
||||
{
|
||||
char temp[1024] = {0};
|
||||
char temp2[1024] = {0};
|
||||
sscanf(inname,"%[^.]%s",temp,temp2);
|
||||
strcpy(outname,temp);
|
||||
strcat(outname,".gpx");
|
||||
}
|
||||
|
||||
if (!XG.readxyz(inname))
|
||||
{
|
||||
XG.outgpx(outname);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user