kml_path_creator.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #include <iostream>
33 #include <kml/dom.h>
34 
35 #include <string>
36 #include <stdio.h>
37 #include <string.h>
38 #include <math.h>
39 
40 using namespace std;
41 
42 // libkml types are in the kmldom namespace
43 using kmldom::CoordinatesPtr;
44 using kmldom::KmlPtr;
45 using kmldom::KmlFactory;
46 using kmldom::PlacemarkPtr;
47 using kmldom::PointPtr;
48 using kmldom::DocumentPtr;
49 using kmldom::LineStringPtr;
50 
51 int main(int argc,char**argv)
52 {
53 
54  if(argc>2)
55  {
56  if(strcmp(argv[2],"conv")==0)
57  {
58  double ox=atof(argv[3]);
59  double oy=atof(argv[4]);
60  double theta=atof(argv[5]);
61 
62  FILE*fp=fopen(argv[1],"r");
63  if(!fp)
64  {
65  perror("Unable to open file");
66  return 1;
67  }
68 
69  char s[1024];
70  double x,y;
71  double nx,ny;
72 
73  while(fgets(s,1024,fp))
74  {
75  sscanf(s,"%lf %lf",&x,&y);
76 
77  nx=x*cos(theta)-y*sin(theta);
78  ny=x*sin(theta)+y*cos(theta);
79 
80  nx+=ox;
81  ny+=oy;
82 
83  printf("%f\t%f\n",nx,ny);
84  }
85  return 0;
86  }
87  }
88 
89  if(argc==2)
90  {
91  //Create kml from file with lat, lon
92 
93  // Get the factory singleton to create KML elements.
94  KmlFactory* factory = KmlFactory::GetFactory();
95  DocumentPtr document = factory->CreateDocument();
96 
97  // Line
98  PlacemarkPtr linePlacemark = factory->CreatePlacemark();
99  linePlacemark->set_name("Line");
100 
101  CoordinatesPtr lineCoordinates = factory->CreateCoordinates();
102 
103  FILE*fp=fopen(argv[1],"r");
104  if(!fp)
105  {
106  perror("Unable to open file");
107  return 0;
108  }
109 
110  char s[1024];
111  double lat,lon;
112  while(fgets(s,1024,fp))
113  {
114  sscanf(s,"%lf %lf",&lat,&lon);
115  lineCoordinates->add_latlng(lat,lon);
116  }
117 
118  LineStringPtr lineString = factory->CreateLineString();
119  lineString->set_coordinates(lineCoordinates);
120  lineString->set_extrude(false);
121  lineString->set_altitudemode(kmldom::ALTITUDEMODE_RELATIVETOGROUND);
122  lineString->set_tessellate(false);
123 
124  linePlacemark->set_geometry(lineString);
125  document->add_feature(linePlacemark);
126 
127  // Create <kml> and give it <Placemark>.
128  KmlPtr kml = factory->CreateKml();
129 
130  kml->set_feature(document);
131 
132  // Serialize to XML
133  std::string xml = kmldom::SerializePretty(kml);
134 
135  // Print to stdout
136  std::cout << xml;
137 
138  return 0;
139  }
140 
141  cout<<"Malformed command"<<endl;
142  return 0;
143 }
int main(int argc, char **argv)


kml_path_creator
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:32:05