Forums

Some questions regarding GeoDjango and MySQL

Hi everyone o/

I am new to python anywhere. I came here looking for a hosting solution that would satisfies one of my customer's requirements and I must say I am not disapointed.

It took me less than 1 hour to setup the test website, wich, having tried other hosting companies during the last week, is really impressive - and it supports python 3!

While my test website is now properly set up for the MySQL backend (I'm on a free plan but my customer will sign up for a 5$ plan) I ran into some trouble when querying the Django ORMĀ for all entries of a table that lives in a certain radius.

Here is the actual query:

places = Places.objects.filter(location__coords__distance_lte=(user_pos,radius))

This query returns the following error:

NotImplementedError - Distance operations not available on this spatial backend.

I can't try on PostGIS, so I'm wondering if:

  • The PostGIS backend is available on PA
  • The query will not raise this error when using the PostGIS backend
  • As a backup strategy, Spatialite is available on PA

Does someone on the forum have any answer? Anyway, thank you for your awesome work on PythonAnywhere, I think this might become my default solution to host customers by now! :D

  • PistGIS is available with the Postgres stuff
  • I haven't ran your query so not 100% confident. But I would assume it should work
  • for spatialite, I just checked that you can access it using pyspatialite. In particular, setup a virtualenv and pip install pyspatialite into it

Alright, thank you for your time!

:)

I just noticed that postgres is not included by default in the paid plans.

pyspatialite is indeed available, but for python 2. Is there any way to install pyspatialite or some alternative for python 3?

I cannot afford to port my whole backend to python 2 :D

If you need to install modules, you can do it yourself. See the help site for details.

I do not need to install modules. I can't install pyspatialite as indicated in conrad's reply because I'm working with a python 3 backend. Pyspatialite does not support python 3. MySQL can't do the job and postgres is not included in paid plans, which I did not know before.

Telling me that the only way to get a geo-aware python 3 Django installation was to pay not only the hacker account but also a 15$ postgres plan would have been fair.

Is there any way to sort this problem out?

So this offers a glimmer of hope (other than upgrading to postgres plan):

sqlite3
SELECT load_extension('path-to-libspatialite.so');
SELECT sqlite_version(), spatialite_version();

and that returns a valid version for spatialite.

the path to libspatialite.so is from what I compiled following django instructions:

wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.0.tar.gz
tar xaf libspatialite-4.1.0.tar.gz
cd libspatialite-4.1.0
./configure --prefix=/home/my-user-name/my-test-folder --enable-freexl=no "CFLAGS=-m64" "CXXFLAGS=-m64" "LDFLAGS=-m64"
make && make install

after this, you will find libspatialite.so in ./lib/

My hypothesis is that django may have it's own adapter for libspatialite, since it has it's own ORM. So you may not need pyspatialite at all if you are using django.

It would be worthwhile to just check if you can get spatialite to work out of the box with django. Otherwise, it sounds like if you can automate the load extension call and put it into a script, you can then set the SPATIALITE_LIBRARY_PATH variable in settings.py and all will be good.

Spatialite indeed works out of the box, I just tought that compiling programs was not possible (as pointed out in old posts), I should have checked that.

Anyway, thank you again, the website is now running properly with the last version of spatialite.

We have a version of the spatialite library available at

/usr/lib/x86_64-linux-gnu/libspatialite.so.5

which is version 4.1.1 apparently -- not sure if that might work instead of compiling your own from scratch?

It works too o/

I did not find it while looking on the /usr/lib folder - I am not really used to Debian based distros, and I was looking for the wrong filename anyway - so thank you very much!

Everything is now properly configured and appears to be working.