00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #include <iostream>
00033 #include <kml/dom.h>
00034
00035 #include <string>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <math.h>
00039
00040 using namespace std;
00041
00042
00043 using kmldom::CoordinatesPtr;
00044 using kmldom::KmlPtr;
00045 using kmldom::KmlFactory;
00046 using kmldom::PlacemarkPtr;
00047 using kmldom::PointPtr;
00048 using kmldom::DocumentPtr;
00049 using kmldom::LineStringPtr;
00050
00051 int main(int argc,char**argv)
00052 {
00053
00054 if(argc>2)
00055 {
00056 if(strcmp(argv[2],"conv")==0)
00057 {
00058 double ox=atof(argv[3]);
00059 double oy=atof(argv[4]);
00060 double theta=atof(argv[5]);
00061
00062 FILE*fp=fopen(argv[1],"r");
00063 if(!fp)
00064 {
00065 perror("Unable to open file");
00066 return 1;
00067 }
00068
00069 char s[1024];
00070 double x,y;
00071 double nx,ny;
00072
00073 while(fgets(s,1024,fp))
00074 {
00075 sscanf(s,"%lf %lf",&x,&y);
00076
00077 nx=x*cos(theta)-y*sin(theta);
00078 ny=x*sin(theta)+y*cos(theta);
00079
00080 nx+=ox;
00081 ny+=oy;
00082
00083 printf("%f\t%f\n",nx,ny);
00084 }
00085 return 0;
00086 }
00087 }
00088
00089 if(argc==2)
00090 {
00091
00092
00093
00094 KmlFactory* factory = KmlFactory::GetFactory();
00095 DocumentPtr document = factory->CreateDocument();
00096
00097
00098 PlacemarkPtr linePlacemark = factory->CreatePlacemark();
00099 linePlacemark->set_name("Line");
00100
00101 CoordinatesPtr lineCoordinates = factory->CreateCoordinates();
00102
00103 FILE*fp=fopen(argv[1],"r");
00104 if(!fp)
00105 {
00106 perror("Unable to open file");
00107 return 0;
00108 }
00109
00110 char s[1024];
00111 double lat,lon;
00112 while(fgets(s,1024,fp))
00113 {
00114 sscanf(s,"%lf %lf",&lat,&lon);
00115 lineCoordinates->add_latlng(lat,lon);
00116 }
00117
00118 LineStringPtr lineString = factory->CreateLineString();
00119 lineString->set_coordinates(lineCoordinates);
00120 lineString->set_extrude(false);
00121 lineString->set_altitudemode(kmldom::ALTITUDEMODE_RELATIVETOGROUND);
00122 lineString->set_tessellate(false);
00123
00124 linePlacemark->set_geometry(lineString);
00125 document->add_feature(linePlacemark);
00126
00127
00128 KmlPtr kml = factory->CreateKml();
00129
00130 kml->set_feature(document);
00131
00132
00133 std::string xml = kmldom::SerializePretty(kml);
00134
00135
00136 std::cout << xml;
00137
00138 return 0;
00139 }
00140
00141 cout<<"Malformed command"<<endl;
00142 return 0;
00143 }