Reputation: 3670
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?
Upvotes: 4
Views: 3509
Reputation: 3670
In django, contrib.gis
has helpers for this.
>>> from django.contrib.gis.geos import Point
>>> Point(0,1).wkt
'POINT (0.0000000000000000 1.0000000000000000)'
Upvotes: 4
Reputation: 34408
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)'
Upvotes: 3