How to assign Django PointField model attribute?

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 to set the coordinates of the GeoCoord field in (5.3, 6.2)? I cannot find any example of where this is assigned a point field. This is such a stupidly simple question. In fact, the coordinates that I would like to assign to A.geoCord are pygeocoder. This is a 2-element tuple of floats.

The Django PointFields documentation is mostly non-existent .

+7
python django geodjango
source share
2 answers

In newer versions of Django, you can:

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

Many examples are available at https://docs.djangoproject.com/en/1.11/ref/contrib/gis/geos/

+8
source share

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, pointing to the Spatial Reference System Identifier .

You can see more about how to draw different geometries here: https://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/#what-is-geos

+7
source share

All Articles