-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Implement QgsGeometry.as_numpy and .as_shapely #58589
base: master
Are you sure you want to change the base?
Conversation
python/PyQt6/core/__init__.py.in
Outdated
@@ -540,6 +540,7 @@ QgsException.__doc__ = "Defines a QGIS exception class." | |||
|
|||
try: | |||
import numpy as _numpy | |||
import shapely as _shapely |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shapely related things should be put in another try block, so that the raster part can work only if numpy is available
What about geometries with Z/M coordinates? |
By utilizing QgsGeometry.asWkb() this is ~8.45 times faster than the previous implementation.
python/PyQt6/core/__init__.py.in
Outdated
def _geometry_as_shapely(self) -> _shapely.geometry.base.BaseGeometry: | ||
wkb_qbytearray = self.asWkb() # Get the geometry in WKB format (QByteArray) | ||
wkb_bytes = bytes(wkb_qbytearray) | ||
shapely_geom = _shapely.from_wkb(wkb_bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? It would save a copy of the data, and might squeeze out a bit more performance:
shapely_geom = _shapely.from_wkb(wkb_bytes) | |
shapely_geom = _shapely.from_wkb(wkb_qbytearray.data()) |
Description
Adds methods to QgsGeometry to convert it to a (list of) numpy array(s) or shapely object(s). This is part of qgis/QGIS-Enhancement-Proposals#227. This enhancement improves integration with NumPy and Shapely while keeping them an optional dependency.