GeoDjango not recognizing PostGIS functions (using RDS)

326 views
Skip to first unread message

Matthew O'Grady

unread,
Oct 8, 2014, 9:22:02 PM10/8/14
to geod...@googlegroups.com
I am trying to convert this PostGIS query to a Django statement.

The PostGIS query would be:

select * from gis.zipcodes where ST_Contains(geom, ST_GeomFromText('POINT(-74.0863037109375 40.704586878965245)', 4269));

where geom is the multipolygon geometry column. I tried this by doing:

pnt = GEOSGeometry('SRID=4269;POINT(-74.0863037109375 40.704586878965245)')  Zipcode.objects.filter(geom__contains=pnt)

but received the error "No function matches the given name and argument types. You might need to add explicit type casts." I then tried making a raw query like:

Zipcode.objects.raw("select * from gis.zipcodes where ST_Contains(geom, ST_GeomFromText('POINT(-74.0863037109 40.704586879)', 4269))")

Other, non-spatial queries work fine.  My guess is that Django isn't recognizing the PostGIS extensions but I'm not sure why. I have:

  • -added django.contrib.gis to INSTALLED_APPS
  • -set db ENGINE to django.contrib.gis.db.backends.postgis 
  • -added POSTGIS_VERSION = ( 2, 1 ) to settings
  • -added POSTGIS_TEMPLATE = 'template1' to my settings
  • -set Zipcode.objects = geo_models.GeoManager() in the model class
  • -run CREATE EXTENSION postgis; on my database

I've also tried running the query Zipcode.objects.raw("select postgis_full_version()") which fails in a similar fashion.


File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 111, in get_response

response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Python/2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(*args, **kwargs) File "/Library/Python/2.7/site-packages/django/views/generic/base.py", line 69, in view return self.dispatch(request, *args, **kwargs) File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 403, in dispatch response = self.handle_exception(exc) File "/Library/Python/2.7/site-packages/rest_framework/views.py", line 400, in dispatch response = handler(request, *args, **kwargs) File "/Library/Python/2.7/site-packages/rest_framework/decorators.py", line 50, in handler return func(*args, **kwargs) File "/data/django-apis/hcpro/proapp/views.py", line 47, in zipcode_from_coord print raw_qs[0] File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 1598, in __getitem__ return list(self)[k] File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 1535, in __iter__ query = iter(self.query) File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py", line 76, in __iter__ self._execute_query() File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py", line 90, in _execute_query self.cursor.execute(self.sql, self.params) File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 81, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) File "/Library/Python/2.7/site-packages/django/db/utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) ProgrammingError: function st_geomfromtext(unknown, integer) does not exist LINE 1: ...elect * from gis.zipcodes where ST_Contains(geom, ST_GeomFro... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.

larry price

unread,
Oct 9, 2014, 11:34:55 AM10/9/14
to geod...@googlegroups.com
You may not have your permissions set up correctly.


That is, postgis is installed but the db user used by django may not be able to call any postgis functions, that might explain the error
ProgrammingError: function st_geomfromtext(unknown, integer) does not exist

the link included above should help you sort that out.

--
You received this message because you are subscribed to the Google Groups "geodjango" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geodjango+...@googlegroups.com.
To post to this group, send email to geod...@googlegroups.com.
Visit this group at http://groups.google.com/group/geodjango.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages