4

我可以从 Google Maps API 轻松获得 lat,long 对:

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

我有一个这样的模型:

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

但我找不到wktlatlng返回的获取方法gmaps。任何指针?

4

2 回答 2

4

在 django 中,contrib.gis有这方面的助手。

>>> from django.contrib.gis.geos import Point
>>> Point(0,1).wkt
'POINT (0.0000000000000000 1.0000000000000000)'
于 2011-10-06T01:05:48.123 回答
3

Shapely为此提供了一个不错的 API:

>>> 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)'
于 2011-10-03T20:09:39.323 回答