GeoDjango Point 对象提供与初始化时不同的 wkt。我做错了什么?
有人可以解释为什么 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很可能来自 __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
这是因为你不能用二进制格式表示每个数字。在 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.