python 升级后 geodjango 创建 GEOS 多几何体失败 (M1)
我在模型上有一个 @property,它为与数据集关联的所有几何图形获取边界框。这段代码几年来一直运行良好。现在,在一台新的 M1 mac 笔记本电脑上,我升级了 Python(3.7.4 到 3.9.7),GDAL 和 GEOS 的配置很困难。但据我了解,django.contrib.gis 包含这些库自己的版本。相关代码片段:
from django.contrib.gis.geos import GeometryCollection, MultiPoint, Point
from places.models import PlaceGeom
from datasets.models import Dataset
class Dataset(models.Model):
fields …
@property
def bounds(self):
dsgeoms=PlaceGeom.objects.values_list(‘geom’,flat=True).filter(place__dataset=self.label)
print(tuple(dsgeoms[:2]))
# (<Point object at 0x12ee39988>, <Point object at 0x12ee39a08>)
gc = GeometryCollection(tuple(dsgeoms[:2]))
return json.loads(gc.envelope.geojson) if pg_geoms.count() > 0 else None
创建 GeometryCollection 时崩溃,没有真正的线索说明原因, 在 PyCharm 中: django shell 中的“进程已完成,退出代码为 138(被信号 10:SIGBUS 中断)”
: 浏览器中的“67692总线错误./manage.py shell”
: 只是退出 runserver
所以我只是尝试了 Geodjango 文档中的示例 https ://docs.djangoproject.com/en/2.2/ref/contrib/gis/geos/,虽然点和线串创建有效,但几何集合和多点没有,shell错误 “68483 分段错误 ./manage.py shell”
我很困惑,但在尝试使用 Shapely 和多个转换构建 bbox 之前,我想我会寻求帮助
I have an @property on a model that gets a bounding box for all the geometries associated with a dataset. This code has worked fine for a couple of years. Now, on a new M1 mac laptop, I upgraded Python (3.7.4 to 3.9.7) and the configuration of GDAL and GEOS was difficult. But as I understand, django.contrib.gis includes its own versions of those libraries. Relevent code snippets:
from django.contrib.gis.geos import GeometryCollection, MultiPoint, Point
from places.models import PlaceGeom
from datasets.models import Dataset
class Dataset(models.Model):
fields …
@property
def bounds(self):
dsgeoms=PlaceGeom.objects.values_list(‘geom’,flat=True).filter(place__dataset=self.label)
print(tuple(dsgeoms[:2]))
# (<Point object at 0x12ee39988>, <Point object at 0x12ee39a08>)
gc = GeometryCollection(tuple(dsgeoms[:2]))
return json.loads(gc.envelope.geojson) if pg_geoms.count() > 0 else None
This crashes when creating the GeometryCollection with no real clue as to why,
in PyCharm:
“process finished with exit code 138 (interrupted by signal 10: SIGBUS)”
in django shell:
“67692 bus error ./manage.py shell”
in browser:
simply quits runserver
So I simply tried the examples from the Geodjango docs at https://docs.djangoproject.com/en/2.2/ref/contrib/gis/geos/, and though the Point and LineString creation worked, GeometryCollection and MultiPoint did not, with the shell error
"68483 segmentation fault ./manage.py shell"
I'm stumped, but before I try building the bbox with Shapely and multiple transformations, thought I'd ask for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GitHub 上的 @bpartridge 提供了答案和修复此问题的补丁,此处:
https://github.com/libgeos/geos/issues/528#issuecomment- 997327327
TLDR; -- Django 2.2 对 GEOS 的调用很宽松,早期的 GEOS 版本“原谅”了它,但后来的版本则不然。
The answer and a patch to fix this were provided by @bpartridge on GitHub, here:
https://github.com/libgeos/geos/issues/528#issuecomment-997327327
TLDR; -- Django 2.2 was lax in its call to GEOS, which earlier GEOS versions 'forgave' but later ones do not.