Problems with Point Field

22 views
Skip to first unread message

Ismail Dhorat

unread,
Nov 17, 2009, 4:30:05 AM11/17/09
to geodjango
Hi Guys, I have a strange issue with a PointField()

I am pretty new to geodjango. I have a PointField defined in my model:

location = models.PointField(srid=2029)

I also have a csv file, with a bunch of values ... the values are
contains the long/lats as well... i have written a script to load the
data into the db. In the case of the location, its loading a string
with POINT(lat lon).

The data loads without any errors:

However, when viewing the records in dango admin that particular field
does not show any data. However running an SQL query on the DB
displays the data. (Marker: 7465 , Saanetcare below)

While entering POINT(lat lon) into the admin and saving the entry,
shows the data in the admin, but not when running an SQL query.
(marker: 12345, Test Below)

spatialite> select * from poi_place where marker_id in (12345, 7465,
7466);
6514|7465|-25.75996|28.2114|Saanetcare - Jakaaranda Hospital||10|POINT
(28.2114 -25.75996)
6516|12345|-26.097615|28.051069|Test|This is a test|1|

When running a distance filter on the queryset, results for only
marker id 12345 (i.e those saved via admin) are returned even though
others match.

Any ideas why?

Thanks in Advance

Robert Coup

unread,
Nov 17, 2009, 3:48:21 PM11/17/09
to geod...@googlegroups.com
On Tue, Nov 17, 2009 at 10:30 PM, Ismail Dhorat <idh...@gmail.com> wrote:
>
> I also have a csv file, with a bunch of values ... the values are
> contains the long/lats as well... i have written a script to load the
> data into the db. In the case of the location, its loading a string
> with POINT(lat lon).

you want to specify it as POINT(lon lat).

> When running a distance filter on the queryset, results for only
> marker id 12345 (i.e those saved via admin) are returned even though
> others match.

distance() queries in lon/lat are measured in degrees: see
http://geodjango.org/docs/db-api.html#distance-queries for details.

Rob :)
--
Koordinates Ltd.
PO Box 1604, Shortland St, Auckland 1140, New Zealand
Phone +64-9-966 0433 Fax +64-9-969 0045
Web http://koordinates.com/

Ismail Dhorat

unread,
Nov 19, 2009, 7:00:56 AM11/19/09
to geod...@googlegroups.com
Hi Rob,

Thanks for the response, i figured out you need to enter use the ORM
to save data to the field. (I was doing it via normal Python / SQL) .

So the data is actually being saved right now , i also removed the
SRID (so now its back to the default) and it seems to correctly save
the data.

Distance queries however do not produce the 'correct' results, or
results that shouldnt really be returned. For example the following
query:

q = Place.objects.filter(location__distance_lt=(Point(28.099497,
-26.094479), D(m=1)))

returns +-2000 objects, even thou the radius is being set as 1m. Some
of the objects returned i know are not within the radius... actually
the result of this query should be no records.

Anyone know why this would happen or how to fix it? Could it have to
do with how the db was created? I have followed the ffg steps for the
db creation & populating the data

- manage.py syncdb (create tables)
- spataialite dbname < init.sql (spatialite init sql)
- load csv
- script to update location field based on the Lon & Lat

I have tried running the init.sql first however if i get an error when
trying to load the data (geographic constraint error from spatialite)

Regards,
Ismail
> --
>
> You received this message because you are subscribed to the Google Groups "geodjango" group.
> To post to this group, send email to geod...@googlegroups.com.
> To unsubscribe from this group, send email to geodjango+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/geodjango?hl=.
>
>
>
Reply all
Reply to author
Forward
0 new messages