Created
December 15, 2016 23:10
-
-
Save byrney/068e8fba690031e48aeeba1e11f2c61c to your computer and use it in GitHub Desktop.
Add a postgis layer with a custom filter to QGIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
host='localhost' | |
port="5432" | |
db='rob' | |
user='rob' | |
password='password' | |
filter = "name = 'M5'" | |
uri = QgsDataSourceURI() | |
uri.setConnection(host, port, db, user, password) | |
uri.setDataSource("public", "dft_major_roads", "geom", filter ,"gid") | |
print uri.uri() | |
vlayer = QgsVectorLayer(uri.uri(), "M5", "postgres") | |
QgsMapLayerRegistry.instance().addMapLayer(vlayer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment