@@ -123,17 +123,17 @@ int main(int argc, char* argv[]) {
123
123
124
124
uint baseZoom, startZoom, endZoom;
125
125
string projectName, projectVersion, projectDesc;
126
- bool includeID = false ;
126
+ bool includeID = false , compress = true ;
127
+ rapidjson::Document jsonConfig;
127
128
try {
128
129
FILE* fp = fopen (jsonFile.c_str (), " r" );
129
130
char readBuffer[65536 ];
130
131
rapidjson::FileReadStream is (fp, readBuffer, sizeof (readBuffer));
131
- rapidjson::Document document;
132
- document.ParseStream (is);
133
- if (document.HasParseError ()) { cerr << " Invalid JSON file." << endl; return -1 ; }
132
+ jsonConfig.ParseStream (is);
133
+ if (jsonConfig.HasParseError ()) { cerr << " Invalid JSON file." << endl; return -1 ; }
134
134
fclose (fp);
135
135
136
- rapidjson::Value& layerHash = document [" layers" ];
136
+ rapidjson::Value& layerHash = jsonConfig [" layers" ];
137
137
for (rapidjson::Value::MemberIterator it = layerHash.MemberBegin (); it != layerHash.MemberEnd (); ++it) {
138
138
// work with (*itr)["status"], etc.
139
139
string layerName = it->name .GetString ();
@@ -143,13 +143,14 @@ int main(int argc, char* argv[]) {
143
143
cout << " Layer " << layerName << " (z" << minZoom << " -" << maxZoom << " )" << endl;
144
144
}
145
145
146
- baseZoom = document[" settings" ][" basezoom" ].GetUint ();
147
- startZoom = document[" settings" ][" minzoom" ].GetUint ();
148
- endZoom = document[" settings" ][" maxzoom" ].GetUint ();
149
- includeID = document[" settings" ][" include_ids" ].GetBool ();
150
- projectName = document[" settings" ][" name" ].GetString ();
151
- projectVersion = document[" settings" ][" version" ].GetString ();
152
- projectDesc = document[" settings" ][" description" ].GetString ();
146
+ baseZoom = jsonConfig[" settings" ][" basezoom" ].GetUint ();
147
+ startZoom = jsonConfig[" settings" ][" minzoom" ].GetUint ();
148
+ endZoom = jsonConfig[" settings" ][" maxzoom" ].GetUint ();
149
+ includeID = jsonConfig[" settings" ][" include_ids" ].GetBool ();
150
+ compress = jsonConfig[" settings" ][" compress" ].GetBool ();
151
+ projectName = jsonConfig[" settings" ][" name" ].GetString ();
152
+ projectVersion = jsonConfig[" settings" ][" version" ].GetString ();
153
+ projectDesc = jsonConfig[" settings" ][" description" ].GetString ();
153
154
if (endZoom > baseZoom) { cerr << " maxzoom must be the same or smaller than basezoom." << endl; return -1 ; }
154
155
} catch (...) {
155
156
cerr << " Couldn't find expected details in JSON file." << endl;
@@ -177,6 +178,19 @@ int main(int argc, char* argv[]) {
177
178
mbtiles.writeMetadata (" version" ,projectVersion);
178
179
mbtiles.writeMetadata (" description" ,projectDesc);
179
180
mbtiles.writeMetadata (" format" ," pbf" );
181
+ if (jsonConfig[" settings" ].HasMember (" metadata" )) {
182
+ const rapidjson::Value &md = jsonConfig[" settings" ][" metadata" ];
183
+ for (rapidjson::Value::ConstMemberIterator it=md.MemberBegin (); it != md.MemberEnd (); ++it) {
184
+ if (it->value .IsString ()) {
185
+ mbtiles.writeMetadata (it->name .GetString (), it->value .GetString ());
186
+ } else {
187
+ rapidjson::StringBuffer strbuf;
188
+ rapidjson::Writer<rapidjson::StringBuffer> writer (strbuf);
189
+ it->value .Accept (writer);
190
+ mbtiles.writeMetadata (it->name .GetString (), strbuf.GetString ());
191
+ }
192
+ }
193
+ }
180
194
}
181
195
182
196
// ---- Read all PBFs
@@ -472,11 +486,12 @@ int main(int argc, char* argv[]) {
472
486
473
487
// Write to file or sqlite
474
488
489
+ string data, compressed;
475
490
if (sqlite) {
476
491
// Write to sqlite
477
- string data;
478
492
tile.SerializeToString (&data);
479
- mbtiles.saveTile (zoom, bbox.tilex , bbox.tiley , &data);
493
+ if (compress) { compressed = compress_string (data); }
494
+ mbtiles.saveTile (zoom, bbox.tilex , bbox.tiley , compress ? &compressed : &data);
480
495
481
496
} else {
482
497
// Write to file
@@ -485,13 +500,14 @@ int main(int argc, char* argv[]) {
485
500
filename << outputFile << " /" << zoom << " /" << bbox.tilex << " /" << bbox.tiley << " .pbf" ;
486
501
boost::filesystem::create_directories (dirname.str ());
487
502
fstream outfile (filename.str (), ios::out | ios::trunc | ios::binary);
488
- if (!tile.SerializeToOstream (&outfile)) {
489
- cerr << " Couldn't write to " << filename.str () << endl;
490
- return -1 ;
503
+ if (compress) {
504
+ tile.SerializeToString (&data);
505
+ outfile << compress_string (data);
506
+ } else {
507
+ if (!tile.SerializeToOstream (&outfile)) { cerr << " Couldn't write to " << filename.str () << endl; return -1 ; }
491
508
}
492
509
outfile.close ();
493
510
}
494
-
495
511
}
496
512
}
497
513
0 commit comments