Skip to content

Commit 194b372

Browse files
committed
Populate top level id field
1 parent 5ff1520 commit 194b372

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

generator/src/main/java/de/westnordost/countryboundaries/GeoJsonWriter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class GeoJsonWriter
2020
{
2121
private static final String
2222
TYPE = "type",
23+
ID = "id",
2324
FEATURES = "features",
2425
COORDINATES = "coordinates",
2526
GEOMETRIES = "geometries",
@@ -69,6 +70,14 @@ private void writeFeature(JSONStringer b, Geometry g) throws JSONException
6970
{
7071
b.object();
7172
b.key(TYPE).value("Feature");
73+
if (g.getUserData() instanceof Map<?,?> && ((Map<?,?>) g.getUserData()).containsKey(ID))
74+
{
75+
Object id = ((Map<?, ?>) g.getUserData()).get(ID);
76+
if (id instanceof String || id instanceof Number)
77+
{
78+
b.key(ID).value(id);
79+
}
80+
}
7281
b.key(PROPERTIES);
7382
writeProperties(b, g.getUserData());
7483
b.key(GEOMETRY);

0 commit comments

Comments
 (0)