I'm trying to add a PostGIS layer based on an attribute criterion. When I do this using the "Add PostGIS Layer" option on the menu, I can query for the attribute and it is added correctly. When I try to emulate this in Python, I get an error. Behold:
This works wonderfullly:
- Code: Select all
uriBase.setDataSource("public", "mo_county_base", "the_geom","")
self.iface.addVectorLayer(uriBase.uri(), "County", "postgres")
This throws an error:
- Code: Select all
uriData.setDataSource("public", "mo_county_base", "the_geom", "COUNTYNAME = 'Pike' AND GeometryType(the_geom) IN ('POLYGON','MULTIPOLYGON')")
self.iface.addVectorLayer(uriData.uri(), "Pike", "postgres")
Error:
Qgis was unable to determine the type and srid of column the_geom in "public"."mo_county_base". The database communication log was:
(There is nothing after the colon at the end.)
I copied the SQL parameter in the setDataSource from the MetaData of the layer after doing it manually. I dug into the code enough to figure out that it was expecting a parameter similar to the one I actually sent. But I wasn't able to find any working examples.
Does anyone have any ideas on this?
Thanks!
B


