Skip to content

Commit f8a297b

Browse files
committed
Fix unique ids in JSON output
Fixes #287
1 parent 969860c commit f8a297b

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

src/export/export_format_json.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ void ExportFormatJSON::start_feature(const std::string& prefix, osmium::object_i
8787
m_buffer += R"(,"id":)";
8888
m_buffer += std::to_string(m_count + 1);
8989
} else if (options().unique_id == unique_id_type::type_id) {
90-
m_buffer += R"(,"id":)";
90+
m_buffer += R"(,"id":")";
9191
m_buffer += prefix;
9292
m_buffer += std::to_string(id);
93+
m_buffer += '"';
9394
}
9495
}
9596

test/export/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ endfunction()
1212

1313
check_export(geojson "-f geojson" input.osm output.geojson)
1414
check_export(geojsonseq "-f geojsonseq -x print_record_separator=false" input.osm output.geojsonseq)
15+
check_export(geojsonuid "-f geojsonseq -u type_id" input.osm output-uid.geojsonseq)
16+
check_export(geojsoncnt "-f geojsonseq -u counter" input.osm output-cnt.geojsonseq)
1517
check_export(pg "-f pg" input.osm output.pg)
1618

1719
check_export(missing-node "-f geojson" input-missing-node.osm output-missing-node.geojson)

test/export/output-cnt.geojsonseq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"type":"Feature","id":1,"geometry":{"type":"Point","coordinates":[2.0,1.5]},"properties":{"amenity":"post_box"}}
2+
{"type":"Feature","id":2,"geometry":{"type":"LineString","coordinates":[[1.0,1.0],[1.0,2.0],[1.0,3.0]]},"properties":{"highway":"track"}}
3+
{"type":"Feature","id":3,"geometry":{"type":"LineString","coordinates":[[1.0,1.0],[1.0,2.0],[2.0,1.5]]},"properties":{"barrier":"fence"}}
4+
{"type":"Feature","id":4,"geometry":{"type":"MultiPolygon","coordinates":[[[[1.0,1.0],[2.0,1.5],[1.0,2.0],[1.0,1.0]]]]},"properties":{"landuse":"forest"}}

test/export/output-uid.geojsonseq

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"type":"Feature","id":"n14","geometry":{"type":"Point","coordinates":[2.0,1.5]},"properties":{"amenity":"post_box"}}
2+
{"type":"Feature","id":"w20","geometry":{"type":"LineString","coordinates":[[1.0,1.0],[1.0,2.0],[1.0,3.0]]},"properties":{"highway":"track"}}
3+
{"type":"Feature","id":"w21","geometry":{"type":"LineString","coordinates":[[1.0,1.0],[1.0,2.0],[2.0,1.5]]},"properties":{"barrier":"fence"}}
4+
{"type":"Feature","id":"a61","geometry":{"type":"MultiPolygon","coordinates":[[[[1.0,1.0],[2.0,1.5],[1.0,2.0],[1.0,1.0]]]]},"properties":{"landuse":"forest"}}

0 commit comments

Comments
 (0)