Question

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?

Was it helpful?

Solution

In django, contrib.gis there are helpers for this.

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

OTHER TIPS

Shapely provides a nice API for that:

>>> import shapely
>>> from shapely.wkt import dumps, loads
>>> pt1 = loads('POINT (0.0000000000000000 0.0000000000000000)')
>>> pt1
<shapely.geometry.point.Point object at 0x1011436d0>
>>> dumps(pt1)
'POINT (0.0000000000000000 0.0000000000000000)'
>>> pt3 = shapely.geometry.point.Point(2, 3)
>>> dumps(pt3)
'POINT (2.0000000000000000 3.0000000000000000)'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top