我专注django.contrib.gis.geos.Point
于更好地创建和处理具有明确纬度和经度的点。
我当前的代码:
from django.contrib.gis.geos import Point
class LLPoint(Point):
def __init__(self, *args, **kwargs):
lat = kwargs.get('latitude')
lng = kwargs.get('longitude')
if lat and lng:
super(LLPoint, self).__init__(lng, lat)
elif lat or lng:
raise TypeError(u'You must both declare latitude and longitude, '
'not just one of them.')
else:
super(LLPoint, self).__init__(*args, **kwargs)
def __unicode__(self):
c = self.coordinates()
return u'LLPoint Lat: %.5f Lng: %.5f' % (c['latitude'], c['longitude'])
def coordinates(self):
return {
'latitude': self.coords[1],
'longitude': self.coords[0]
}
问题是:
>>> LLPoint(latitude=10.0, longitude=20.0)
<Point object at 0xdeadbeef>
为什么它返回一个Point
对象?这样我就不能使用我在子类中声明的任何东西。如果我尝试用存根类重现问题,它会起作用。这可能很愚蠢,但我看不到。