GeoDjango Point 对象提供与初始化时不同的 wkt。我做错了什么?

发布于 2024-08-05 21:32:24 字数 606 浏览 10 评论 0原文

有人可以解释为什么 geodjango 中点对象的 wkt (众所周知的文本)会返回与对象初始化时不同的坐标吗?我必须想象这是我做错的事情,而不是地理。 wkt 应该看起来像:“POINT (-122.432534 37.764021)”,但它看起来像:“POINT (-122.4325340000000040 37.7640209999999996)”

这个舍入来自哪里?它使得我无法执行像 Location.objects.get(pnt="POINT (-122.432534 37.764021)") 这样的查询,因为它认为它们是(稍微)不同的点!

>>> from django.contrib.gis.geos import Point
>>> p = Point(-122.432534,37.764021)
>>> p
<Point object at 0x239c1e4>
>>> p.wkt
'POINT (-122.4325340000000040 37.7640209999999996)'
>>> p.x
-122.432534
>>> p.y
37.764021

Can someone please explain why the wkt (well-known text) of a point object in geodjango would be returning what seems to be different coordinates than the object was initialized with? I've got to imagine it's something I'm doing wrong, and not geos. The wkt should look like: "POINT (-122.432534 37.764021)" but instead it looks like: 'POINT (-122.4325340000000040 37.7640209999999996)'

Where is this rounding coming from? It's making it so that I can't do a query like Location.objects.get(pnt="POINT (-122.432534 37.764021)") because it thinks they are (ever so slightly) different points!

>>> from django.contrib.gis.geos import Point
>>> p = Point(-122.432534,37.764021)
>>> p
<Point object at 0x239c1e4>
>>> p.wkt
'POINT (-122.4325340000000040 37.7640209999999996)'
>>> p.x
-122.432534
>>> p.y
37.764021

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只想待在家 2024-08-12 21:32:24

这很可能来自 __str__ 或 __repr__。对这些数字执行任何操作(叉积、保存到数据库)并获得相同的精度应该可以证实这一点。

干杯

This is very likely coming from __str__ or __repr__. Doing anything to those numbers (cross products, saving to the db) and getting the same precision back should confirm this.

Cheers

音盲 2024-08-12 21:32:24

这是因为你不能用二进制格式表示每个数字。在 Python 解释器中,尝试输入“1.1”(它将返回 1.1000000000000001)。同样,float(0.37765021) = 0.37765020999999999。

It's because you cannot represent every number in binary format. In the Python interpreter, try typing '1.1' (it will return as 1.1000000000000001). Along the same lines, float(0.37765021) = 0.37765020999999999.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文