pythonlatitude-longitudepostgisgeodjangowkt

get Well Known Text from lat long


I can get easily a lat,long pair from the Google Maps API:

from googlemaps import GoogleMaps
gmaps = GoogleMaps(GOOGLEMAPS_API_KEY)
gmaps.address_to_latlng('Jose Javier Diaz 440 Cordoba Argentina')
>>>> (-31.4464489, -64.191219899999993)

And I have a model like this:

from django import models
class MaapPoint(models.Model):
   geom = models.PointField(srid=DEFAULT_SRID)

But I can't find a way to get the wkt from the latlng returned by gmaps. Any pointer?


Solution

  • In django, contrib.gis has helpers for this.

    >>> from django.contrib.gis.geos import Point
    >>> Point(0,1).wkt
    'POINT (0.0000000000000000 1.0000000000000000)'