Skip to content
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

Broken 1.0.0 #394

Closed
roniemartinez opened this issue Nov 25, 2024 · 6 comments
Closed

Broken 1.0.0 #394

roniemartinez opened this issue Nov 25, 2024 · 6 comments

Comments

@roniemartinez
Copy link

Just updated from 0.12 to 1.0.0 and now getting the following errors when using parse()

  File "src/lxml/etree.pyx", line 3701, in lxml.etree._Validator.assert_
AssertionError: Element '{http://www.opengis.net/kml/2.2}Style': This element is not expected. Expected is one of ( {http://www.opengis.net/kml/2.2}Schema, {http://www.opengis.net/kml/2.2}AbstractFeatureGroup, {http://www.google.com/kml/ext/2.2}Tour, {http://www.opengis.net/kml/2.2}Document, {http://www.opengis.net/kml/2.2}Folder, {http://www.opengis.net/kml/2.2}Placemark, {http://www.opengis.net/kml/2.2}NetworkLink, {http://www.opengis.net/kml/2.2}GroundOverlay, {http://www.opengis.net/kml/2.2}ScreenOverlay, {http://www.opengis.net/kml/2.2}PhotoOverlay )., line 7

When using from_string(), features is empty.

@cleder
Copy link
Owner

cleder commented Nov 25, 2024

Your KML does not validate against the XML Schema.
You can read it without validations by passing validate=False or strict=False to the parse method

from fastkml.kml import KML
doc = KML.parse('path/to/your/file.kml', strict=False)
# or
doc = KML.parse('path/to/your/file.kml', validate=False)

@roniemartinez
Copy link
Author

@cleder Thanks but I've already tried all of these.

postcode_kml.from_string("<KML string>" strict=False)
postcode_kml.parse('path/to/your/file.kml', strict=False)
postcode_kml.parse('path/to/your/file.kml', validate=False)

All of them return an empty .features list

    document = postcode_kml.features[0]
               ~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

For reference, we are reading this KML file: https://www.doogal.co.uk/kml/PostcodeDistricts.kml

@roniemartinez
Copy link
Author

@cleder I think I found the issue now.

With this version, we can no longer create an instance like this as from_string() returns a new object.

postcode_kml = kml.KML()
postcode_kml.from_string(kml_file.read())

Instead:

postcode_kml = kml.KML.from_string(kml_file.read())

@cleder
Copy link
Owner

cleder commented Nov 25, 2024

Thanks, I added this to the documentation:
https://github.com/cleder/fastkml/blob/develop/docs/upgrading.rst
https://fastkml.readthedocs.io/en/latest/upgrading.html

@cleder
Copy link
Owner

cleder commented Nov 26, 2024

@roniemartinez when you find other issues migrating to 1.0, please open an issue or add your findings here ;-)

@roniemartinez
Copy link
Author

@cleder Sure thanks 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants