How to assign to a Django PointField model attribute?

前端 未结 2 1174
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 16:40

Hi I have a Django Model as follows:

class Address(models.Model):
    geoCoords = models.PointField(null=True, blank=True,)

Now I create an

相关标签:
2条回答
  • 2020-12-08 17:10

    In newer versions of Django you can:

    from django.contrib.gis.geos import Point
    pnt = Point(1, 1)
    

    Plenty of examples available in https://docs.djangoproject.com/en/1.11/ref/contrib/gis/geos/

    0 讨论(0)
  • 2020-12-08 17:14

    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

    0 讨论(0)
提交回复
热议问题