You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For geometries without SRID, the output remains unchanged. I have switched to using to_wkb (which is a wrapper around dumps) for better performance. The Buffer | None type hint was also incorrect because this overridden method never returns None.
While working on this, I made some small optimizations to the loader:
classGeometryBinaryLoader(Loader):
format=Format.BINARYdefload(self, data: Buffer) ->BaseGeometry:
returnfrom_wkb(bytes(data))
classGeometryLoader(Loader):
defload(self, data: Buffer) ->BaseGeometry:
# it's a hex string in binaryreturnfrom_wkb(bytes(data))
I replaced loads usage with from_wkb (which is a wrapper around loads). In the binary case, it avoids an isinstance call + conditional check, as bytes(bytes) is very efficient and avoids copying in the CPython implementation. In the text case, it avoids bytes copy + conditional check, and simply reuses the binary implementation: from my testing, from_wkb seems to be very flexible, accepting bytes, hex strings, and hex bytes:
Note
If you're planning to use any part or all of the suggested code, please add me to the commit's Co-authored-by list. I enjoy collecting contributions to open source projects 🙂.
register_shapely ignores SRID when dumping geometries.
I was able to resolve the issue by updating the dumper logic as follows:
For geometries without SRID, the output remains unchanged. I have switched to using to_wkb (which is a wrapper around dumps) for better performance. The
Buffer | Nonetype hint was also incorrect because this overridden method never returns None.While working on this, I made some small optimizations to the loader:
I replaced loads usage with from_wkb (which is a wrapper around loads). In the binary case, it avoids an isinstance call + conditional check, as bytes(bytes) is very efficient and avoids copying in the CPython implementation. In the text case, it avoids bytes copy + conditional check, and simply reuses the binary implementation: from my testing, from_wkb seems to be very flexible, accepting bytes, hex strings, and hex bytes:
Note
If you're planning to use any part or all of the suggested code, please add me to the commit's Co-authored-by list. I enjoy collecting contributions to open source projects 🙂.