I'm working in a layer with MultiPolygons and I'm trying to calculate the shortest distance between a MultiPolygon and a point which is contained in that MultiPolygon, using Django and PostGIS.
At first I check which MultiPolygon contains that Point and I store it in a variable:
mpoly = MPoly.objects.filter(geom__contains=location)
Then, I'm trying to calculate the distance between the point and the mpoly object using the psycopg2 interface:
curs.execute("SELECT ST_Distance(ST_GeogFromText(%s), ST_GeogFromText('SRID=4326;Point(24.050, 35.311)')) FROM MPoly" % mpoly)
But it raises the following syntax error:
Traceback (most recent call last): File "<console>", line 1, in <module> ProgrammingError: syntax error at or near ";" LINE 1: SELECT ST_Distance(ST_GeomFromText(SRID=4326;MULTIPOLYGON ((23.567..
I think that the error comes from "mpoly"'s format but why ? If I type in a Python interpreter >> mpoly, it prints: MultiPolygon object at 0x7fc8d5130