-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkmlWriter.cpp
More file actions
133 lines (119 loc) · 5.17 KB
/
kmlWriter.cpp
File metadata and controls
133 lines (119 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "kmlWriter.h"
kmlWriter::kmlWriter(){
}
void kmlWriter::open(string filename){
_filename = filename;
_stream.open(_filename.c_str());
if(isGood()){
writeHeader();
}
}
bool kmlWriter::isGood(){
return _stream.good();
}
kmlWriter::~kmlWriter(){
if(_stream.is_open()){
writeFooter();
_stream.close();
}
}
void kmlWriter::writePlacemark(string name, string description, double lat, double lon, double height){
_stream << " <Placemark>" << endl;
_stream << " <name>" << name << "</name>" << endl;
_stream << " <description>" << description << "</description>" <<endl;
_stream << " <styleUrl>#msn_ylw-pushpin</styleUrl>" << endl;
_stream << " <Point>" << endl;
_stream << " <coordinates>"<< setprecision(15) << lon << "," << lat << "," << height << "</coordinates>" << endl;
_stream << " </Point>" << endl;
_stream << " </Placemark>" << endl;
}
void kmlWriter::writePath(string name, string description, vector< vector<double> >& coordinates, int extrude, int tessellate, string altitude){
_stream << " <Placemark>" << endl;
_stream << " <name>" << name << "</name>" << endl;
_stream << " <description>" << description << "</description>" << endl;
_stream << " <LineString>" << endl;
_stream << " <extrude>" << extrude << "</extrude>" << endl;
_stream << " <tessellate>" << tessellate << "</tessellate>" << endl;
_stream << " <altitudeMode>" << altitude << "</altitudeMode>" << endl;
_stream << " <coordinates>" << endl;
for(int i = 0; i< coordinates.size(); i++){
if(coordinates[i].size() == 3){
_stream << " " << setprecision(15)<< coordinates[i][0] << "," << coordinates[i][1] << "," <<coordinates[i][2] << endl;
}else{
cout << "kmlWriter::writePath coordinates must be size Nx3" << endl;
}
}
_stream << " </coordinates>" << endl;
_stream << " </LineString>" << endl;
_stream << " </Placemark>" << endl;
}
void kmlWriter::writePolygon(string name, string description, ossimGeoPolygon& coordinates, int extrude, int tessellate, string altitude){
_stream << " <Placemark>" << endl;
_stream << " <name>" << name << "</name>" << endl;
_stream << " <description>" << description << "</description>" << endl;
_stream << " <Polygon>" << endl;
_stream << " <extrude>" << extrude << "</extrude>" << endl;
_stream << " <tessellate>" << tessellate << "</tessellate>" << endl;
_stream << " <altitudeMode>" << altitude << "</altitudeMode>" << endl;
_stream << " <outerBoundaryIs>" << endl;
_stream << " <LinearRing>" << endl;
_stream << " <coordinates>" << endl;
//cout << "NEED TO ADD A FOR LOOP TO WRITE EACH COORDINATE IN THE writePolygon FUNCTION OF KMLWRITER" << endl;
//hints: use setprecision(15)
//the coordinates need to be lon, lat, 0
for(int i = 0; i< coordinates.size(); i++){
_stream << " "<< setprecision(15)
<< coordinates[i].lon << "," <<
coordinates[i].lat << ",0" << endl;
}
_stream << " </coordinates>" << endl;
_stream << " </LinearRing>" << endl;
_stream << " </outerBoundaryIs>" << endl;
/*
_stream << " <innerBoundaryIs>" << endl;
_stream << " <LinearRing>" << endl;
_stream << " <coordinates>" << endl;
_stream << " </coordinates>" << endl;
_stream << " </LinearRing>" << endl;
_stream << " </innerBoundaryIs>" << endl;
*/
_stream << " </Polygon>" << endl;
_stream << " </Placemark>" << endl;
}
void kmlWriter::writeHeader(){
_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
_stream << "<kml xmlns=\"http://www.opengis.net/kml/2.2\">" << endl;
_stream << "<Document>" << endl;
_stream << "<Style id=\"sn_ylw-pushpin\">" << endl;
_stream << " <IconStyle>" << endl;
_stream << " <scale>1.1</scale>" << endl;
_stream << " <Icon>" << endl;
_stream << " <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>" << endl;
_stream << " </Icon>" << endl;
_stream << " <hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/>" << endl;
_stream << " </IconStyle>" << endl;
_stream << "</Style>" << endl;
_stream << "<Style id=\"sh_ylw-pushpin\">" << endl;
_stream << " <IconStyle>" << endl;
_stream << " <scale>1.3</scale>" << endl;
_stream << " <Icon>" << endl;
_stream << " <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>" << endl;
_stream << " </Icon>" << endl;
_stream << " <hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/>" << endl;
_stream << " </IconStyle>" << endl;
_stream << "</Style>" << endl;
_stream << "<StyleMap id=\"msn_ylw-pushpin\">" << endl;
_stream << " <Pair>" << endl;
_stream << " <key>normal</key>" << endl;
_stream << " <styleUrl>#sn_ylw-pushpin</styleUrl>" << endl;
_stream << " </Pair>" << endl;
_stream << " <Pair>" << endl;
_stream << " <key>highlight</key>" << endl;
_stream << " <styleUrl>#sh_ylw-pushpin</styleUrl>" << endl;
_stream << " </Pair>" << endl;
_stream << "</StyleMap>" << endl;
}
void kmlWriter::writeFooter(){
_stream << "</Document>" << endl;
_stream << "</kml>" << endl;
}