如何分配给Django PointField模型属性? [英] How to assign to a Django PointField model attribute?
问题描述
class Address(models.Model):
geoCoords = models.PointField(null = True,blank = True,)
现在我创建一个这个模型的实例:
A =地址()
如何将A的geoCoord字段的坐标设置为(5.3,6.2)?我找不到以这种方式分配点字段的任何示例。这是一个愚蠢的简单问题。实际上,我想分配给A.geoCord的坐标来自pygeocoder。它是一个2项的浮点数元组。
Django PointFields上的文档基本上是 不存在
您可以使用:
from django.contrib.gis.geos import GEOSGeometry
A.geoCoords = GEOSGeometry('POINT(LON LAT)',srid = 4326)#
其中 lat
和 lon
意味着纬度
和经度
, srid
是可选的,指示空间参考系统标识符
。
您可以在此处查看有关如何绘制不同几何的更多信息: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/#what-is-geos
Hi I have a Django Model as follows:
class Address(models.Model):
geoCoords = models.PointField(null=True, blank=True,)
Now I create an instance of this model:
A = Address()
How can I set the coordinates of A's geoCoord field to (5.3, 6.2)? I can't find any example of where a point field is assigned to in this way. It's such a stupidly simple question. Actually, the coordinates I would like to assign to A.geoCord are from pygeocoder. It is a 2-item tuple of floats.
The documentation on Django PointFields is basically non-existant.
You can use:
from django.contrib.gis.geos import GEOSGeometry
A.geoCoords = GEOSGeometry('POINT(LON LAT)', srid=4326) #
where lat
and lon
mean latitude
and longitude
, respectively and srid
is optional, indicating the Spatial Reference System Identifier
.
You can see more on how to draw different geometries here: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/#what-is-geos
这篇关于如何分配给Django PointField模型属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!