RT Sql Layer is a QGIS plugin written by Giuseppe Sucameli for Faunalia and Regione Toscana-SIGTA, which in turn is based upon the PostGIS Manager plugin from Martin Dobias. The plugin was slightly adapted to the PostGIS Viewer and was added following the post called Loading QGIS plugins into PyQGIS standalone applications (in Spanish). Likewise, it would be possible to adapt other QGIS plugins to be included in the PostGIS Viewer for pgAdmin.
Ubuntu/Linux screenshots:


PREREQUISITES
Python, PyQt4, PyQGIS, libqt4-sql-psql and psycopg2 (for the Query Builder).
How to install prerequisites in Windows: See this post, you will also need to install psycopg2 from OSGeo4W.
How to install prerequisites in Ubuntu/Linux: For QGIS, see downloads official page. For the other programs use apt-get or Synaptic.
INSTALLATION
This time the installation process has been reduced to extract one ZIP file (download the zip file here) into the appropriate path (on Windows: C:/Archivos de programa/PostgreSQL/8.4/bin/ whereas on Ubuntu/Linux: /usr/bin/) and 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:
sudo unzip postgis_viewer.zip -d /usr/bin/
sudo chmod 755 /usr/bin/postgis_viewer/ -R
Additionally, copy the next lines to /usr/share/pgadmin3/plugins.ini (if the file does not exist, you have to create it):
Title=View PostGIS layer
Command=$$PGBINDIR/postgis_viewer/postgis_viewer.py -h $$HOSTNAME -p $$PORT -U $$USERNAME -W $$PASSWORD -d $$DATABASE -s $$SCHEMA -t $$OBJECTNAME
Description=View PostGIS layer
Platform=unix
ServerType=postgresql
Database=Yes
SetPassword=Yes
On Windows edit C:/Archivos de programa/PostgreSQL/8.4/pgAdmin III/plugins.ini adding the following lines:
Title=View PostGIS layer
Command="$$PGBINDIR\postgis_viewer\postgis_viewer.bat" -h "$$HOSTNAME" -p "$$PORT" -U "$$USERNAME" -W "$$PASSWORD" -d "$$DATABASE" -s "$$SCHEMA" -t "$$OBJECTNAME"
Description=View PostGIS layer
KeyFile=$$PGBINDIR\postgis_viewer\postgis_viewer.bat
Platform=windows
ServerType=postgresql
Database=Yes
SetPassword=Yes
The postgis_viewer.bat file sets the OSGeo4W environment variables (Qt, Python, QGIS) to allow 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/8.4/ You should check that file if you get some troubles while running the plugin.
Windows screenshots:


KNOWN ISSUES
- With PyQt4 < 4.6 you will probably get some weird display of the layer properties when dragging a layer. You may check the PyQt4 version from a Python command line this way (If you get a version less than 4.6, you have to upgrade your PyQt4 installation):
>> from PyQt4.QtCore import *
>> VERSION_STR
'4.6'
- If you can not get the icons loaded in the plugin's window, check lines 62 and 65 of the postgis_viewer.py file. There you can edit the path to your postgis_viewer_imgs folder. Note that in Ubuntu/Linux you will probably need the full path whereas in Windows you just need a relative path (according to the tests done).
REFERENCES
- Ivan Mincik's PostGIS Viewer: https://github.com/imincik/QgsPostGIS-Viewer
- Send and receive a signal between 2 Qt applications: http://www.qtcentre.org/threads/38453-Send-and-receive-a-signal-between-2-Qt-applications.?p=176716#post176716
- Single Application: http://www.qtcentre.org/wiki/index.php?title=SingleApplication
- Quantum GIS Development Team, 2011. Quantum GIS, Geographic Information System API Documentation. Open Source Geospatial Foundation Project. Electronic document: http://doc.qgis.org/
- RT Sql Layer 1.0.14. Giuseppe Sucameli for Faunalia and Regione Toscana-SIGTA http://www.faunalia.it/qgis/rt_sql_layer.zip
comments
Ahora la consulta: He visto en las imagenes de tus publicaciones que estas visualizando una capa raster desde la base de datos.
En Ubuntu 10.10 tengo PostgreSQL 9.0 y Postgis 2.0.0SVN donde ya esta integrado la extension Postgis Raster (antes wktraster).
¿Cual debería ser la estructura de una tabla con información raster?.
¿Que detalle debo tener en cuenta para poder ver mis capas raster en el visor?
gracias.
bueno, probe el plugin con capas ráster en Windows, supongo funciona en Linux.
La estructura de las tablas la puedes consultar en este enlace (trac.osgeo.org/postgis/wiki/WKTRaster/Documentation01).
En todo caso, para cargarlas a tu BD debes usar la utilidad gdal2wktraster.py, en este enlace (trac.osgeo.org/postgis/wiki/WKTRasterTutorial01) hay un ejemplo de cómo cargar rásters.
Por lo demás, en tu base de datos seleccionarías tu tabla ráster y al dar click sobre el plugin de pgAdmin tu ráster sería cargado al visor.
NOTA: El constructor de consultas SQL hasta donde conozco, funciona solo para vectores.
Saludos.
Queria comentarte varios puntos:
-El visor de capas me funcionó en Ubuntu, pero solo con vectores. No he podido visualizar las capas raster cargadas en la base.
-Desde la versión Postgis 2.0.0.El comando para crear el sql a incorporar en la base de datos es "raster2pgsql.py".
-Ya tengo incorporadas las tablas raster en mi base con la estructura que me indicas. Pero no consigo visualizarlas en el visor de pgadmin.
Pregunta: ¿Has usado en Quantum Gis el plugin Postgis Wktraster? En Ubuntu y Windows tengo la misma version de QGIS (1.6). En Windows pude cargar las capas raster, pero no en Ubuntu. Me da el siguiente error: Could not connect PG: dbase....
Cuando pruebo la conexión a la base se conecta correctamente. Es mas el el plugin me permite seleccionar la capa, pero cuando intento cargarla me da el error que mencione.
Hasta ahora no puedo visualizar de ninguna forma (ni con Quantum, ni con el visor de pgadmin) mis capas raster.
Gracias.
Gracias por la información,
Tuxman
Ante todo darte las gracias por hacernos a los que no somos desarrolladores y trabajamos en temas GIS mas fácil. Conseguí instalar sin problemas la aplicación y funciona perfectamente, la verdad es que está muy bien ver las capas espaciales visualmente desde el propio postgis, yo había utilizado el phppgadmin pero modificado para que si contabas con una instalación de mapserver se pudiera visualizar la capa.
He estado intentando localizarlo de nuevo pero no lo he encontrado.
Un saludo
I just came across your promising looking PostGIS Viewer and have decided to test it. However, I've stumbled across an issue. Whenever I try to start the script from Konsole, I receive the following output
python /usr/bin/postgis_viewer/postgis_viewer.py -h localhost -p 5432 -U postgis -W MyPass -d postgis -s public -t roadtrl020
I: Starting viewer
I: Database connection was succesfull
E: Error. Exiting
Layer 'public.roadtrl020' doesn't exist. Be sure the selected object is either raster or vector layer.
I am connected to postgis database with credentials that've provided to script
ps ax | grep 5432
/usr/lib/postgresql/9.1/bin/psql -U postgis -d postgis_20 -W -p 5432
It happens in pgadmin too.Any ideas regarding this issue would be very welcome.
first of all, I recommend you using the newest version of the plugin [1].
Regarding the problem, please tell me whether this SQL query returns any row:
--
SELECT column_name FROM information_sch ema.columns
WHERE table_schema = 'public' AND
table_name = 'roadtrl020' AND
udt_name = 'geometry' LIMIT 1
--
If that's not the case, please let me know the CREATE TABLE statement for such a table.
Regards,
Tuxman
---------------------
[1] http://geotux.tuxfamily.org/index.php/en/geo-blogs/item/293-consola-sql-para-plugin-pgadmin-postgis-viewer
I have just found out that if you want to view postgis spatial tables through Postgis Viewer that it works only through pgAdminIII and for tables with geometry data type.
Now it works through pgAdmin but still fails via konsole (bash)
python /usr/bin/psviewer/postgis_viewer.py -h localhost -p 5432 -U postgis -W myPassword -d postgis -s public -t roads
and if the table is of 'geography data type' with the following error
"Layer 'x.y' doesn't exist. Be sure the selected object is either raster or vector layer."
All the best,
Damijan
the new version of the plug-in now includes support for the 'geography' type. Have a look at [1].
Concerning the problem you mention with the console, that's quite strange. If it fails from the console, it should also fail from pgAdmin, there is no reason (that I know) why it would behave differently. I haven't been able to replicate the problem but I'll keep an eye on it.
Thanks for your suggestions and your detailed reports.
Regards,
Tuxman
----------------
[1] http://geotux.tuxfamily.org/index.php/es/geo-noticias/item/293-consola-sql-para-plugin-pgadmin-postgis-viewer#comment-440
I have just restarted my PostgreSQL database and this issue mysteriously disappeared. I did hot upgrade of pg database two months ago and haven't stopped database and rebooted my system since then. However, I've just rebooted my system, started my database and voila it works now
Yay. Your plugin works from console and pgadmin
Cheers,
Damijan
did you test to run PostGIS Viewer with OSGeow64 (on windows 7)?
is it possible or not at all ?
I try without success ! dommage ...
Denis
Buenos días todos ,
is somebody test test to run PostGIS Viewer with OSGeow64 (on windows 7)?
is it possible or not at all ?
I try without success ! dommage ...
i just see icon 'view Postgis Layer" in pgAdmin3
Denis
RSS feed for comments to this post