Question

Hi Stackoverflow people,

I am having trouble to understand how POINT references in GeoDjango are translated to query statements.

jpic's advice helped me very much to capture the query statements in the console, but the print out does not make any sense to me.

In my view.py function (saving the form), I have the following line:

savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))

with u_lng and u_lat as the user coordinated (taken from the session information). u_lat and u_lng are degree values as decimals.

However when I check the sql statement as suggested, I see that the POINT was translated to

ST_GeomFromEWKB(E'\001\001\000\000 \346\020\000\000\352\036~\243\302\256H\300\352X\245\364L\3515\300'::bytea)

in the sql statement and which is rejected by sql with the error message

ERROR:  invalid byte sequence for encoding "UTF8": 0x00

What is the correct way to translate lng, lat points into postgis with GeoDjango?

Thank you for your help to understand this matter better!

Was it helpful?

Solution

I'm far from an expert on the subject. But I've once written some code that saved a certain point in postgis database using Django.

The way I did it was:

model_instance.coords = Point(geo_point.latitude, geo_point.longitude)

OTHER TIPS

It seems that the error message originates from a little bug in

django/contrib/gis/db/backends/postgis/adapter.py

Explanations for the exact problem and the patch can be found here:

I have patch the four line in the adapter.py and the error is gone.

Thank you for all your help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top