Ivan Mincik has created a pgAdmin plugin that works as a command-line PostGIS viewer as well. The viewer could be useful for spatial databases administrators using pgAdmin.
It is not intended to add major functionalities to the viewer, but if it is required, it could be extended with all the power of Python and QGIS libraries. The PostGIS Viewer allows to display spatial tables and views from spatial databases.
PREREQUISITES
Python, PyQt4, PyQGIS and libqt4-sql-psql.
How to install prerequisites in Windows: See this post.
How to install prerequisites in Ubuntu/Linux: For QGIS, see downloads official page. For the other programs use apt-get or Synaptic.
DOWNLOADS
For Ubuntu/Linux download the postgis_viewer.py file.
For Windows download postgis_viewer.py and postgis_viewer.bat
HOW TO USE THE VIEWER FROM A COMMAND LINE
Ubuntu/Linux: Set the execution permission:
$ sudo chmod 755 postgis_viewer.py
Run the Python file setting some parameters:
$ postgis_viewer.py -h localhost -U postgres -W secreto -s public -t pais -d geodb &
If you run the command once more with another table, it will be loaded to the same application:
$ postgis_viewer.py -h localhost -U postgres -W secreto -s public -t rios -d geodb
Windows:
Be sure you have the QGIS libraries enabled and run in a command line:
$ c:\Python25\python.exe postgis_viewer.py -h localhost -U postgres -W secreto -s public -t pais -d geodb &
INSTALLATION AS A pgAdmin PLUGIN (PostgreSQL 8.4)
Ubuntu/Linux:
Copy the postgis_viewer.py file into one of the folders of the environment variable PATH, for instance, /usr/bin/
$ sudo cp postgis_viewer.py /usr/bin/
Set the execution permission:
$ sudo chmod 755 /usr/bin/postgis_viewer.py
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=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
Windows:
Copy the postgis_viewer.py and postgis_viewer.bat files to C:/Archivos de programa/PostgreSQL/8.4/bin/
Edit C:/Archivos de programa/PostgreSQL/8.4/pgAdmin III/plugins.ini adding the following lines:
Title=View PostGIS layer
Command="$$PGBINDIR\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.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.
NOTE: The steps are based on PostgreSQL 8.4 and pgAdmin 1.10.
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
comments
Estoy usando POstgreSQL 9.0 Pgadmin3 1.12.1. Gracias por tu ayuda.
Por otro lado, si no estoy mal el mecanismo de plugins de pgAdmin ha cambiado para la versión que tú manejas. Así que voy a revisar ese nuevo mecanismo, hago unas pruebas y te comento.
Saludos.
he revisado el plugin en PostgreSQL sobre Windows puesto que mi Ubuntu es un poco añejo y no tengo acceso a PostgreSQL 9.0 aún.
Escribí una pequeña actualización que puedes visitar en este enlace (http://geotux.tuxfamily.org/index.php?option=com_myblog&task=view&id=277&Itemid=59#actualizacion1). El mecanismo de plugins de pgAdmin cambió para la versión 1.13, pero la que tú usas funciona igual a la expuesta en el post. Como ves en en elnlace a la actualización, los cambios para PostgreSQL 9.0 se hacen sobre Windows puesto que allí las rutas varían. En Ubuntu/Linux las rutas no deberían representar problemas.
En todo caso, vuelve a crear/editar el archivo plugins.ini puesto que había dejado un par de espacios que ya no deben aparecer. Para ello sigue de nuevo la guía de instalación del post Mejoras en el visor de capas PostGIS para pgAdmin 3 (http://geotux.tuxfamily.org/index.php?option=com_myblog&task=view&id=277&Itemid=59).
Si continua el fallo, asegúrate que tu directorio PGBIN esté apuntando a /usr/bin, esto lo puedes verificar desde pgAdmin dando click en File --> Options en la variable PG Bin Path.
Si aún continua el fallo envíame tu archivo plugins.ini
Saludos,
Tuxman
Efectivamente era un problema en los espacios del archivo plugins.ini. Ahora si se abre el visor.
Jugando con este archivo encontré el problema por el cual no se cargaba el plugin PSQL console.
Nuevamente muchas gracias.
Si no te molesta estoy comentando sobre este plugin en Diaspora* alpha.
Saludos.
This is the project I maintained for a while:
https://github.com/gacarrillor/postgis-layer-viewer
If you're interested, you can create an issue there, I could eventually update it when QGIS 3 is released.
Regards,
Tuxman
RSS feed for comments to this post