geojson文件示例,
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
},
"properties": {
"name": "Example Point"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0],
[103.0, 1.0],
[104.0, 0.0],
[105.0, 1.0]
]
},
"properties": {
"name": "Example Line"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
},
"properties": {
"name": "Example Polygon"
}
}
]
}
生成geojson文件的C++代码示例,
void GlobalMappingImpl::generate_geojson_gnss() const {
Json::Value root;
root.clear();
root["type"] = "FeatureCollection";
root["name"] = "SingleTrajectoryGlobalRes";
auto& root_features = root["features"];
auto _it_meas = _map_gnss._meas_map.begin();
while (_map_gnss._meas_map.size() >= 1 && _it_meas != _map_gnss._meas_map.end()) {
Json::Value json;
json["type"] = "Feature";
auto& json_properties = json["properties"];
json_properties["name"] = "GNSS";
json_properties["head_veh"].append(_it_meas->second->head_veh());
json_properties["fix_type"].append(_it_meas->second->fix_type());
auto& json_geometry = json["geometry"];
json_geometry["type"] = "Point";
json_geometry["coordinates"].append(_it_meas->second->lon());
json_geometry["coordinates"].append(_it_meas->second->lat());
root_features.append(json);
_it_meas++;
}
static Json::FastWriter fast_write;
auto* file = new std::ofstream("./debug_optimized_gnss.geojson", std::ios::trunc);
if (file->is_open()) {
*file << fast_write.write(root);
file->flush();
file->close();
}
delete file;
}