pyogrio icon indicating copy to clipboard operation
pyogrio copied to clipboard

Appending/over-writing KML file results in introduction of Z-dimension

Open nicholas-ys-tan opened this issue 8 months ago • 0 comments

This issue was encountered in writing the tests for PR #421.

When over-writing a KML file, a Z-dimension was undesirably added to the co-ordinates. This arose when testing appending to the KML file as it involves writing into an existing file. It appears that when writing to an existing file, the driver uses LIBKML even if driver='KML' is specified resulting in the addition of the Z-dimension The addition of a Z-dimension is an artifact of the LIBKML driver.

Investigation of the .kml file does suggest any appending or over-writing an existing KML file produces a file format consistent with the LIBKML driver.

points = [Point(10, 20), Point(30, 40), Point(50, 60)]
gdf = gpd.GeoDataFrame(geometry=points, crs="EPSG:4326")
output_path = r'/home/nicholas/dev/data/ogr_test/temporary_kml_file2.kml'
write_dataframe(
    gdf, output_path, layer="tmp_layer", driver="KML", use_arrow=True
)

write_dataframe(
    gdf, output_path, layer="tmp_layer", driver="KML", use_arrow=True
)

print(gdf_read.geometry)
0    POINT Z (10 20 0)
1    POINT Z (30 40 0)
2    POINT Z (50 60 0)
Name: geometry, dtype: geometry

It is possible that the KML driver does not allow the opening of a file in update mode (called via ogr_open executing GDALOpenEx with the GDAL_OF_UPDATE flag) which then silently falls back on the LIBKML driver.

Additionally, if the LIBKML driver is not available - as it is not in the ubuntu-small CIs, we are unable to append to the file and raises a misleading error message: "It might help to specify the correct driver explicitly by prefixing the file path with ':', e.g. 'CSV:path'" despite explicitly specifying the KML driver.

nicholas-ys-tan avatar Jun 15 '24 04:06 nicholas-ys-tan