Skip to content

Commit

Permalink
KML driver: writer: generate a Placemark id
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 11, 2024
1 parent b6edb51 commit 330df9d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions autotest/ogr/ogr_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def test_ogr_kml_write_schema(tmp_vsimem):
<SimpleField name="realfield" type="float"></SimpleField>
</Schema>
<Folder><name>lyr</name>
<Placemark>
<Placemark id="lyr.1">
<ExtendedData><SchemaData schemaUrl="#lyr">
<SimpleData name="strfield">strfield_val</SimpleData>
<SimpleData name="intfield">1</SimpleData>
Expand Down Expand Up @@ -648,7 +648,7 @@ def test_ogr_kml_two_layers(tmp_vsimem):
<Folder><name>empty</name>
</Folder>
<Folder><name>lyr</name>
<Placemark>
<Placemark id="lyr.1">
<ExtendedData><SchemaData schemaUrl="#lyr">
<SimpleData name="foo">bar</SimpleData>
</SchemaData></ExtendedData>
Expand Down
2 changes: 1 addition & 1 deletion autotest/utilities/test_ogr2ogr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ def test_ogr2ogr_49_bis(ogr2ogr_path, tmp_path):
"""<kml xmlns="http://www.opengis.net/kml/2.2">""",
"""<Document id="root_doc">""",
"""<Folder><name>grid</name>""",
""" <Placemark>""",
""" <Placemark id="grid.1">""",
""" <name>440750.000</name>""",
""" </Placemark>""",
"""</Folder>""",
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/kml/ogr_kml.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class OGRKMLLayer final : public OGRLayer
int iNextKMLId_;
bool bWriter_;
int nLayerNumber_;
int nWroteFeatureCount_;
GIntBig nWroteFeatureCount_;
bool bSchemaWritten_;
bool bClosedForWriting;
char *pszName_;
Expand Down
7 changes: 5 additions & 2 deletions ogr/ogrsf_frmts/kml/ogrkmllayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ OGRErr OGRKMLLayer::ICreateFeature(OGRFeature *poFeature)
VSIFPrintfL(fp, "<Folder><name>%s</name>\n", pszName_);
}

VSIFPrintfL(fp, " <Placemark>\n");
++nWroteFeatureCount_;
char *pszEscapedLayerName = OGRGetXML_UTF8_EscapedString(GetDescription());
VSIFPrintfL(fp, " <Placemark id=\"%s." CPL_FRMT_GIB "\">\n",
pszEscapedLayerName, nWroteFeatureCount_);
CPLFree(pszEscapedLayerName);

if (poFeature->GetFID() == OGRNullFID)
poFeature->SetFID(iNextKMLId_++);
Expand Down Expand Up @@ -561,7 +565,6 @@ OGRErr OGRKMLLayer::ICreateFeature(OGRFeature *poFeature)
}

VSIFPrintfL(fp, " </Placemark>\n");
nWroteFeatureCount_++;
return OGRERR_NONE;
}

Expand Down

0 comments on commit 330df9d

Please sign in to comment.