开发者

How hard is it to modify the Django Models?

I am doing geolocation, and Django does not have a PointField. So, I am forced to writing in RAW SQL. GeoDjango, the Django library, does not support the following query for MYSQL databases (can someone verify that for me?)

 cursor.execute("SELECT id FROM l_tag WHERE\
               (GLength(LineStringFromWKB(LineString(asbi开发者_如何学运维nary(utm),asbinary(PointFromWKB(point(%s, %s)))))) < %s + accuracy + %s)\

I don't nkow why GeoDjango library cannot do this in MYSQL database. I hate writing RAW SQL for calculating distances between two points. Is there a way I can create my own library for Django that can handle this? If so, how hard is it?


Why don't you just extend a class that's already there? Just curious and wish I could help you specifically.


GeoDjango does have a PointField.

It looks like you're trying to do a dwithin field lookup, which does not work on MySQL (as of April 2010), but does in Postgres:

class Tag(Model): point = PointField()

Tag.objects.filter(point__dwithin=(point,D(mi=4)))

Careful with this kind of query, as it requires a table scan. If you can tolerate selecting all points within a rectangular region, you could use the bounding box contained query:

Tag.objects.filter(point__contained=geom)

where geom is a polygon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜