gpt4 book ai didi

python - django-rest-framework-gis GeoFeatureModelSerializer 在序列化时返回更改/不正确的坐标

转载 作者:行者123 更新时间:2023-11-30 22:12:35 25 4
gpt4 key购买 nike

目前,我有一个 GeometryField,其中包含一个 Polygon,它是一个 GEOSGeometry。我打印了多边形的坐标,它们看起来很好,就在我指定的位置。然后,我保存模型的实例,然后使用 GeoFeatureModelSerializer 反序列化,却发现我的多边形坐标已更改为非常小的且接近赤道的坐标。

这是最初存储在数据库中的 GeometryField 中存储的 GEOSGeometry

POLYGON ((-79.94751781225206 40.44287206073545, 
-79.94751781225206 40.44385187931003,
-79.94502872228624 40.44385187931003,
-79.94502872228624 40.44287206073545,
-79.94751781225206 40.44287206073545))

这是使用 GeoFeatureModelSerializer 序列化并返回之后的结果。

[[-0.000718176362453, 0.000363293553554], 
[-0.000718176362453, 0.000363316438548],
[-0.000718135112337, 0.000363316438548],
[-0.000718135112337, 0.000363293553554],
[-0.000718176362453, 0.000363293553554]]

我不知道是什么原因造成的。

提前非常感谢。

最佳答案

此问题已通过指定 SRID 解决。根据 Django 文档,SRID 是

Choosing an appropriate SRID for your model is an important decision that the developer should consider carefully. The SRID is an integer specifier that corresponds to the projection system that will be used to interpret the data in the spatial database. (https://docs.djangoproject.com/en/2.0/ref/contrib/gis/model-api/)

我对具有特定 SRID 的多边形执行操作并返回具有不同 SRID 的另一个多边形。我只需使用 GEOSGeometry(polygon, srid=some_value) 将要返回的多边形“转换”到我想要的 SRID。基本上,我返回的多边形被投影为我不想要的其他格式。

关于python - django-rest-framework-gis GeoFeatureModelSerializer 在序列化时返回更改/不正确的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51049316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com