For the most up-to-date code go to the PostGIS-Layer-Viewer repository at GitHub. You're invited to contribute there, enhancing/optimizing the plugin's code, solving an issue, or reporting bugs you might have found. You could even just say "thanks, I find this useful" with a simple GitHub 'Star'!
The already included SQL query builder seems to be a bit complex when all you need to accomplish is to run a single query. Because of that reason I added the QGIS plugin Fast SQL Layer, which lets you write your query in a simple console.
What is Fast SQL Layer?
Fast SQL Layer is a QGIS plugin written by Pablo T. Carreira to run SQL queries for PostGIS and SpatiaLite data. It also comes with its own SQL syntax highlighter. I have edited it a bit for integrating it to the PostGIS viewer.
Python, PyQt4, PyQGIS, libqt4-sql-psql, psycopg2 and pygments.
How to install prerequisites in Windows: See this post, you will also need to install psycopg2 and pygments from OSGeo4W.
How to install prerequisites in Ubuntu/Linux: For QGIS, see downloads official page. For the other programs/libs use apt-get or Synaptic.
Once you have the prerequisites installed, all you need to do is to extract one ZIP file (download the zip file here) into the appropriate path (on Windows: C:/Archivos de programa/PostgreSQL/9.1/bin/ whereas on Ubuntu/Linux: /usr/bin/) as well as edit the pgAdmin plugins.ini file.
On Ubuntu/Linux you will need the sudo command to extract and set the 755 permissions to the extracted files, this way:
Additionally, copy the next lines to /usr/share/pgadmin3/plugins.ini (if the file does not exist, you have to create it):
On Windows edit C:/Archivos de programa/PostgreSQL/9.1/pgAdmin III/plugins.ini adding the following lines:
The postgis_viewer.bat file sets the OSGeo4W environment variables (Qt, Python, QGIS) for allowing the execution of postgis_viewer.py The .bat file assumes OSGeo4W is installed in C:/ and PostgreSQL can be found in C:/Archivos de programa/PostgreSQL/9.1/ You should check that file if you get some troubles while running the plugin.
How can I use it?
You can use the PostGIS viewer from a command line (like in this post) as well as from pgAdmin. If the installation process went well, to see one of your spatial tables you need to select it in the pgAdmin's object browser, click in Plugins and then click in View PostGIS layer, this way:
Now you can write your SQL queries in the Query tab. Don't forget to provide an id field name and a geometry field name to get a well defined (valid) layer. If you get a new layer from your query but cannot see any geometry on the map, you probably need to adjust the id field name.
Update (2014.12.12), Version 1.6:
- v.1.6 supports raster layers stored in PostGIS (QGIS >= v.2.6)
- New tab About