Comments (8)
@whatnick You shouldn't replace the newline character, you could just do myfile.read().encode('utf-8')
and you should be able to parse your file through fastkml. Although I think a user shouldn't do this encoding/decoding explicitly, it should be wrapped in their implementation and hide from user. @cleder
from fastkml.
Since the documentation hasn't been updated , even for Python 3 + , I wrote a detailed article here : https://medium.com/@wwaryan/the-definite-only-guide-to-fastkml-58b8e19b8454
Cheers!
from fastkml.
@whatnick You shouldn't replace the newline character, you could just do
myfile.read().encode('utf-8')
and you should be able to parse your file through fastkml. Although I think a user shouldn't do this encoding/decoding explicitly, it should be wrapped in their implementation and hide from user. @cleder
There should be a documentation update with the method you described presented to new users of this. Because right now if you follow along with the starter examples, you get an error only solved by using this snippet.
from fastkml.
yep, we need a documentation update here: https://fastkml.readthedocs.io/en/latest/usage_guide.html#read-a-kml-file-string
from fastkml.
At least when lxml
is configured, it seems like the from_string(...)
method actually expects bytes
, not a string
.
Ultimately, lxml
wants to decide the encoding from the encoding declaration in the document itself (like <?xml version="1.0" encoding="UTF-8"?>
) if it can.
Perhaps the method should be renamed to from_bytes(...)
?
from fastkml.
@samifouad I haven't worked with this lib for a while, not sure if they have already updated.
from fastkml.
Agree with the comumentation update
from fastkml.
None of this works. What else could I try? Thank you.
#with open(INPUT_KML_FILE, 'rb') as myfile: #AttributeError: 'bytes' object has no attribute 'encode'
#with open(INPUT_KML_FILE, 'rt', encoding="utf-8") as myfile: #ValueError
#with open(INPUT_KML_FILE, 'rt') as myfile: #ValueError
#with open(INPUT_KML_FILE, 'r') as myfile: #ValueError
#BAD doc=myfile.read()
doc = myfile.read().encode('utf-8')
k = kml.KML()
k.from_string(doc)
Edit: It worked with another KML file. Is there a way to get FastKML/lxml to say which line it didn't like?
k = kml.KML()
with open(INPUT_KML_FILE,'rb') as kmlFile:
k.from_string(kmlFile.read())
c:\fastkml>Edit.KML.py
Traceback (most recent call last):
File "C:\fastkml\Edit.KML.py", line 15, in <module>
k.from_string(kmlFile.read())
File "C:\Python38\lib\site-packages\fastkml\kml.py", line 101, in from_string
feature.from_element(document)
File "C:\Python38\lib\site-packages\fastkml\kml.py", line 991, in from_element
feature.from_element(folder)
File "C:\Python38\lib\site-packages\fastkml\kml.py", line 1030, in from_element
feature.from_element(folder)
File "C:\Python38\lib\site-packages\fastkml\kml.py", line 1035, in from_element
feature.from_element(placemark)
File "C:\Python38\lib\site-packages\fastkml\kml.py", line 1077, in from_element
geom.from_element(line)
File "C:\Python38\lib\site-packages\fastkml\geometry.py", line 413, in from_element
geom = self._get_geometry(element)
File "C:\Python38\lib\site-packages\fastkml\geometry.py", line 347, in _get_geometry
return LineString(coords)
File "C:\Python38\lib\site-packages\pygeoif\geometry.py", line 334, in __init__
raise ValueError
ValueError
from fastkml.
Related Issues (20)
- Add verbosity to `to_string`
- Make precision of coordinates configurable in `to_string`
- Validate against xsd schema
- etree_element dump fails if MultiGeometry is empty HOT 2
- Refactor gx.Track and gx.Multitrack
- Refactor data.py
- Modernize packaging HOT 1
- Use arrow instead of dateutil HOT 1
- Add ExtendedData to gx:Track
- Refactor TimeStamp And TimeSpan
- Refactor _AbstractView, Camera And LookAt
- Refactor Atom Link and _Person
- Refactor styles.py
- Test Documentation with doctest - Usage guide is broken for version 1.x HOT 2
- Improve the documentation with Examples HOT 1
- Refactor kml.py HOT 1
- Add from_file or load method to kml.KML
- Read all namespaces, not only kml from the document
- Remove unnecessary getters and setters HOT 1
- Refactor geometry.Polygon HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastkml.