-
Notifications
You must be signed in to change notification settings - Fork 92
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
Cannot use GeometryCollection when shapely is installed #100
Comments
#137 drops shapely support |
Oh, but why? It was really practical being able to use shapely objects directly. 😿 |
Mainly to support |
Okay, fair enough, I'll give |
Maybe we could inject a geometry transformer function when constructing the KML, (e.g |
I finally got around to testing my code with fastkml 1.0a1 and it turns out it just works. shapely geometry is automatically converted to pygeoif geometry via |
Thanks for testing and letting me know, :-) Much appreciated! |
Seems like I wonder if that's intentional? |
No it is not intentional. |
Sure: #!/usr/bin/env python3
import fastkml
import pygeoif.geometry
g = pygeoif.geometry.Point(1, 1)
if fastkml.__version__ == "1.0a4":
p = fastkml.kml.Placemark()
p.geometry = g
else:
p = fastkml.kml.Placemark(geometry=g)
print(p.to_string()) $ python3 -m venv venv-fastkml-a4
$ python3 -m venv venv-fastkml-a6
$ ./venv-fastkml-a4/bin/pip install 'fastkml == 1.0a4'
$ ./venv-fastkml-a6/bin/pip install 'fastkml == 1.0a6'
$ ./venv-fastkml-a4/bin/python fastkml-interface.py
/tmp/venv-fastkml-a4/lib/python3.11/site-packages/fastkml/config.py:37: UserWarning: Package `lxml` missing. Pretty print will be disabled
warnings.warn("Package `lxml` missing. Pretty print will be disabled")
<kml:Placemark xmlns:kml="http://www.opengis.net/kml/2.2"><kml:visibility>1</kml:visibility><kml:Point><kml:coordinates>1.000000,1.000000</kml:coordinates></kml:Point></kml:Placemark>
$ ./venv-fastkml-a6/bin/python fastkml-interface.py
/tmp/venv-fastkml-a6/lib/python3.11/site-packages/fastkml/config.py:37: UserWarning: Package `lxml` missing. Pretty print will be disabled
warnings.warn("Package `lxml` missing. Pretty print will be disabled")
Traceback (most recent call last):
File "/tmp/fastkml-interface.py", line 13, in <module>
print(p.to_string())
^^^^^^^^^^^^^
File "/tmp/venv-fastkml-a6/lib/python3.11/site-packages/fastkml/base.py", line 116, in to_string
self.etree_element(
File "/tmp/venv-fastkml-a6/lib/python3.11/site-packages/fastkml/kml.py", line 1757, in etree_element
element.append(self._geometry.etree_element())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Point' object has no attribute 'etree_element' So yeah I can pretty confidently say the examples from https://fastkml.readthedocs.io/en/latest/usage_guide.html no longer work :-) |
There was a lot of refactoring in |
#239 is probably the place to look |
closing this in favour of #264 |
Right, it does indeed. ♥ And then there are some vaguely related issues:
And then I commented on 2 commits of yours pointing out other random breakages (XML namespaces, NetworkLink having no Link). |
These are the changes I had to make to make my project's tests pass locally: Shall I open a PR from develop...liskin:fastkml:fixes? |
PRs are always welcome ;-) |
The current develop (I have not cut a release for this yet) reintroduces the ability to pass a shapely or pygeoif (or anything else that supports the I can reintroduce a geometry property getter and setter on feature if this is needed (although probably under another name to avoid confusion, like geo_geometry) |
Oh, I see, I somehow missed the
Not really needed, I just found it a bit confusing that old versions of fastkml accepted |
I made some 'questionable' decisions for shortcuts 10 years ago, based on a use case I had back then. I never imagined it would have north of 100K downloads a month, in the first few years I was proud when it had 75 per month (IIRC) 😃 Version 1.0 should be more consistent, easier to work with and to contribute to. I appreciate your continuing contributions, your comments are very valuable to give me insights what users want to get out of this package 👍 |
Similar to #68.
When shapely is installed, GeometryCollection can't be used:
This fails with
ValueError("Illegal geometry type.")
, but it works just fine when fastkml uses pygeoif.I'm guessing it's because
fastkml/fastkml/geometry.py
Line 43 in 9f24722
and then
fastkml/fastkml/geometry.py
Line 275 in 9f24722
fails because
fastkml/fastkml/geometry.py
Line 128 in 9f24722
creates a shapely GeometryCollection, not pygeoif one.
The text was updated successfully, but these errors were encountered: