Geodjango查询几何返回指针而不是几何
我试图从这个模型中获取查询集中的单个 MultiPolygon 几何图形:
class local_administrative_unit(models.Model):
lau_id = models.IntegerField(primary_key=True)
lau_name = models.CharField(max_length=150)
adm_level_2 = models.ForeignKey('administrative_level_2', on_delete=models.PROTECT)
geom = models.MultiPolygonField(srid=4326)
在 Django shell 中尝试这种方式:
local_administrative_unit.objects.get(lau_id=1).geom
返回:
<MultiPolygon object at 0x7fb12af0ab10>
当我将其传递给 Centroid 函数时,它与我的不同寻找:
Centroid(Value(<MultiPolygon object at 0x7fb12af0ac90>))
您能告诉我如何获得实际的几何图形以便之后使用它 - 例如计算该多边形的质心吗?看起来我得到了一个指向我正在寻找的东西的指针,而不是实际的东西。
提前致谢。
I am trying to get a single MultiPolygon geometry in a Queryset from this model:
class local_administrative_unit(models.Model):
lau_id = models.IntegerField(primary_key=True)
lau_name = models.CharField(max_length=150)
adm_level_2 = models.ForeignKey('administrative_level_2', on_delete=models.PROTECT)
geom = models.MultiPolygonField(srid=4326)
trying it this way in the Django shell:
local_administrative_unit.objects.get(lau_id=1).geom
which returned:
<MultiPolygon object at 0x7fb12af0ab10>
when I pass this to the Centroid function, it does not what I was looking for:
Centroid(Value(<MultiPolygon object at 0x7fb12af0ac90>))
Can you please tell me how I get the actual geometry to use it afterwards - for example for calculating the Centroid of that polygon? Looks like I am getting a pointer to what I am looking for instead of the actual thing.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
同时,我找到了我错过的东西。基本上,所有这些都在。 Geodjango首先访问几何形状时,创建A 地理测定法对象,然后可以使用某些属性来做事。
在上面的情况下,这意味着:
foo 将几何对象作为初始示例中的几何对象,要以通常可用的形式获取质心,我们可以使用一些属性:
这将计算质心和返回然后在著名的文本中。
Meanwhile I found what i missed. It is basically all explained in the GeoDjango Tutorial which i appearently overlooked before. GeoDjango creates a GEOSGeometry object when the geometry is first accessed on which certain properties then can be used to do stuff.
In the above case this means:
foo holds the geometry object as the one in the initial example, to get the centroid in a generally useable form we can just use some properties:
This will calculate the centroid and return it then in well-known text.