views:

111

answers:

2

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(asbinary(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?

A: 

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

dscher
Yea, how do I do that?
TIMEX
Something like this maybe: http://wolfram.kriesing.de/blog/index.php/2007/extend-djangos-user-class
dscher
A: 

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.

am