Skip to content

Commit

Permalink
Merge pull request #10473 from rouault/fix_qgis_58208
Browse files Browse the repository at this point in the history
LIBKML: fix LIBKML_RESOLVE_STYLE=YES when reading a KML file with dataset-level styles (3.9.1 regression)
  • Loading branch information
rouault committed Aug 10, 2024
2 parents cc36c5c + 5275ee1 commit 95025b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
22 changes: 22 additions & 0 deletions autotest/ogr/ogr_libkml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,13 @@ def test_ogr_libkml_read_write_style(tmp_vsimem):
"style1_highlight", 'SYMBOL(id:"http://style1_highlight",c:#10325476)'
)
ds.SetStyleTable(style_table)
lyr = ds.CreateLayer("test")
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetStyleString("@style1_normal")
lyr.CreateFeature(feat)
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetStyleString("@unknown_style")
lyr.CreateFeature(feat)
ds = None

with gdaltest.vsi_open(
Expand Down Expand Up @@ -1429,6 +1436,21 @@ def test_ogr_libkml_read_write_style(tmp_vsimem):
print(data)
pytest.fail(styles)

ds = ogr.Open(tmp_vsimem / "ogr_libkml_read_write_style_write.kml")
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
assert f.GetStyleString() == "@style1_normal"
f = lyr.GetNextFeature()
assert f.GetStyleString() == "@unknown_style"

with gdaltest.config_option("LIBKML_RESOLVE_STYLE", "YES"):
ds = ogr.Open(tmp_vsimem / "ogr_libkml_read_write_style_write.kml")
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
assert f.GetStyleString() == 'SYMBOL(id:"http://style1_normal",c:#67452301)'
f = lyr.GetNextFeature()
assert f.GetStyleString() == "@unknown_style"


###############################################################################
# Test writing Update
Expand Down
14 changes: 4 additions & 10 deletions ogr/ogrsf_frmts/libkml/ogrlibkmlfeaturestyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,10 @@ void kml2featurestyle(FeaturePtr poKmlFeature, OGRLIBKMLDataSource *poOgrDS,
else
{
const size_t nPathLen = poOgrDS->GetStylePath().size();

if (nPathLen == 0)
{
if (!osUrl.empty() && osUrl[0] == '#')
osStyleString = std::string("@").append(osUrl.c_str() + 1);
}
else if (osUrl.size() > nPathLen &&
strncmp(osUrl.c_str(), poOgrDS->GetStylePath().c_str(),
nPathLen) == 0 &&
osUrl[nPathLen] == '#')
if (osUrl.size() > nPathLen && osUrl[nPathLen] == '#' &&
(nPathLen == 0 ||
strncmp(osUrl.c_str(), poOgrDS->GetStylePath().c_str(),
nPathLen) == 0))
{
/***** should we resolve the style *****/
const char *pszResolve =
Expand Down

0 comments on commit 95025b3

Please sign in to comment.