0

I want to create an action that select many rows from PostGIS table to show many lines in QGIS.

How can I select many rows from table with Python to add these rows in a layer?

3
  • 2
    what do you mean registers?
    – Nathan W
    Commented Apr 22, 2013 at 11:36
  • registers = rows Commented Apr 22, 2013 at 13:45
  • do you just want to add a postgis layer using python? can you add more clarity?
    – vinayan
    Commented May 23, 2013 at 2:51

1 Answer 1

2

assigning an Action Type of Python you can add multiple column field values (separated with a space), as follows:

u'[% "col_name1" %]' + " " + u'[% "col_name2" %]' 

if you need to add data from numerous rows and create a new table view in QGIS, you should think about creating a plugin

3
  • Can I make a action python with that query?:SELECT * FROM pathways WHERE gid IN(SELECT mpp_path_id FROM meetingpoints_paths WHERE mpp_meeting_id = [% "gid" %]) Commented Apr 22, 2013 at 14:15
  • It looks like you are using PostGIS based on the "gid" primary key. However, if you were using sqlite/spatialite you could perform SQL using: import sqlite3; con = sqlite3.connect("mydatabase.sqlite"); cur = con.cursor(); cur.execute("SELECT...the rest of my SQL statement ")
    – user12711
    Commented Apr 22, 2013 at 14:43
  • the python sqlite3 module will not handle spatialite geometries. alternately, would want to import the pyspatialite module. and use pyspatialite.dbapi2.connect("mySpatialite_DB.sqlite") to establish an object for your cursor to perform SQL on
    – user12711
    Commented Apr 22, 2013 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.