-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field names mixed up writing via "KML" driver #916
Comments
A working minimal example would be very helpful. |
I just noticed the KML driver is not registered in the supported list of drivers: https://github.com/Toblerity/Fiona/blob/1.8.13.post1/fiona/drvsupport.py#L80 This does not necessarily mean that this driver does not work with Fiona. However, the KML data model is not entirely compatible with the GDAL/OGR data model. This is also mentioned in GDAL's documentation: https://gdal.org/drivers/vector/kml.html As Fiona assumes that a full OGR data model can be used, such drivers are typically excluded by Fiona. It could be that the driver is sensible to the order in which the fields are written (I'm just guessing). The driver has the following creation options:
These options can be passed to
|
Here is a simple script that can illustrate the problem. The data file
I had found the KML driver notes you reference above, but the addition of the My suspicion would be that the
Note that ogr has added the I don't have a C++ environment or I'd be happy to dig deeper. Thanks for your assistance. |
@wheeled For the above-mentioned reasons, I hope you understand that Fiona does not support KML. However, it is still strange that data can be written without error, but just the order of the fields is wrong. It looks like the order of the fields in the schema is relevant. The following code works:
whereas if one of the ExtendData fields is in front of |
I found the issue: |
The real issue is, that the KML driver automatically adds fields: https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrsf_frmts/kml/ogrkmllayer.cpp#L116-L120 https://github.com/Toblerity/Fiona/blob/master/fiona/ogrext.pyx#L1119-L1122 assumes that only the fields in the schema provided to Fiona exist. The same issue is also present for the DXF, GPX, GPSTrackMacker and DGN driver. Tested by adding:
|
So https://github.com/Toblerity/Fiona/blob/master/fiona/ogrext.pyx#L1119-L1122 explains how the fields get mixed up. If I simulate the behaviour of the
[note that this process remaps I understand that you are not necessarily keen to support KML, but if this issue also affects some other drivers would it be possible to classify it as a bug? I imagine the fix would be to check that the
This assumes that the driver will look after its own I apologise again that I am not set up to be able to test it. |
Expected behavior and actual behavior.
Attempting to save a GeoPandas dataframe using:
produces a KML file in which the value for
<name>
is taken from another field, and likewise<description>
. If the file is written the hard way (usingogr
) it is correct. Perhaps there are some kwargs that need to be passed along to correct this? In the example aboveNameField='name'
was an unsuccessful attempt.Correct KML using
ogr
:Incorrect KML using
Fiona
(see Placemark name and description):Steps to reproduce the problem.
I don't think there was anything special about the GeoDataFrame, but can provide a script and sample data if the answer is not trivial.
Operating system
Mac OS X 10.15.4
Fiona and GDAL version and provenance
Fiona 1.8.13.post1 loaded by PyCharm
GDAL 2.4.0 loaded by PyCharm
The text was updated successfully, but these errors were encountered: