You are here:GeoTux»Geo-Blogs»Geographic databases»Improvements in the PostGIS Viewer for pgAdmin

Statistics

Invitados: 26
Usuarios registrados: 3185
Usuarios en línea:
-
Registrados hoy:
-

Register

RSS

Blogs and News:
Recibe las actualizaciones en Geo-Noticias y Geo-Blogs

Get them by e-mail
Recibir Geo-Noticias y Geo-Blogs por e-mail

¿What is this about?

Sunday, 06 March 2011 06:00

Improvements in the PostGIS Viewer for pgAdmin

Written by  German Carrillo
Rate this item
(5 votes)
Due to some suggestions from Ivan Mincik and Iván Lizarazo, I have been adding a couple of functionalities to the postgis viewer plugin for pgAdmin. Now, it has raster support (PostGIS-WKTRaster) and a layer list widget for displaying layer properties. Additionally, some minor bugs have been fixed: antialiasing and map units detection.

 

Based on the Mauricio de Paulo's brand QGIS plugin called WKTRaster, I added raster support to the plugin. Likewise, the layer list widget for PyQGIS was slightly modified in order to get a basic table of contents displaying a number of layer properties.

 

It is a screenshot (Windows): 

Postgis viewer plugin for pgAdmin (Windows)

 

As the installation process now includes an images folder, which is actually optional, I think it is recommended to show it again:

 


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 both the postgis_viewer.py and postgis_viewer_imgs.zip files.

For Windows download postgis_viewer.py , postgis_viewer.bat and postgis_viewer_imgs.zip files.

 

 

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


Extract the postgis_viewer_imgs.zip file into /usr/bin (or the folder where you put postgis_viewer.py) and set execution permission:

  sudo unzip postgis_viewer_imgs.zip -d /usr/bin/ 
sudo chmod 755 /usr/bin/postgis_viewer_imgs/ -R

 

Windows:

Copy the postgis_viewer.py and postgis_viewer.bat files, and extract the postgis_viewer_imgs.zip file into C:/Program Files/PostgreSQL/8.4/bin/

Edit C:/Program Files/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:/Program Files/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 has been tested on PostgreSQL <9.1 and pgAdmin <1.13.

 

 

KNOWN ISSUES:

  • With PyQt4 < 2.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).

 

 

Finally, another screenshot (Ubuntu/Linux):

Postgis viewer plugin for pgAdmin (Linux)

 

--------------------------------------------------------------------------------------------------------

UPDATE (2011/03/09): INSTALL THE PLUGIN ON PostgreSQL 9.0 (pgAdmin 1.12)

 

In Windwows, users need to be aware of paths for installing the plugin on PostgreSQL 9.0. The following changes need to be  done.

 

(Only WINDOWS)

  • The folder to copy postgis_viewer.py, postgis_viewer.bat and extract postgis_viewer_imgs.zip is C:/Program Files/PostgreSQL/9.0/bin, however this may vary according to the installation of PostgreSQL 9.0.
  • The plugins.ini file should be edited from C:/Program Files/PostgreSQL/9.0/pgAdmin III/plugins.ini
  • The postgis_viewer.bat file should be edited changing the line that executes the postgis_viewer.py file. That line must be: python "C:/Program Files/PostgreSQL/9.0/bin\postgis_viewer.py" %*

 -------------------------------------------------------------------------------------------------------

 

 

REFERENCES

 

 

Last modified on Wednesday, 12 October 2011 18:48

comments  

 
0 # alelentz 2011-06-17 10:09
Hi folks

This is a very good tutorial for the installation of postgis-viewer.
But, the above plug-in requires the installation of OSGeo4W environment.
The files, postgis_viewer.bat and the postgis_viewer.py, contain some variables which correspond to OSGeo4W paths. Because, i have installed seperate all these programs(Postgr eSQL 9.0, PostGIS 1.5.2, Python 2.6, Quantum 1.6) which are contained at OSGeo4W, i must change these paths for the good operation of plug-in.
So, could anyone to show me how to configure these files???

Thanks in advance
Reply | Reply with quote | Quote
 
 
0 # Re:tuxman 2011-06-17 10:36
Hi alelentz,

in [1] (in Spanish only) I explained how to install and configure PyQGIS without OSGeo4W. It went good until QGIS 1.4. Then the package structure was changed and I've been unable to run it again (as standalone). Therefore, I had to start using OSGeo4W for PyQGIS and I'd recommend you using it. In that case you could still install PostgreSQL and PostGIS without OSGeo4W.

By the way, this is not the final version of this plug-in, have you looked at this (http://geotux.tuxfamily.org/index.php?option=com_myblog&task=view&id=278&Itemid=59〈=en)?

Regards,

Tuxman

-----------------
[1] http://geotux.tuxfamily.org/index.php?option=com_myblog&task=view&id=253&Itemid=59 (http://geotux.tuxfamily.org/index.php?option=com_myblog&task=view&id=253&Itemid=59)
Reply | Reply with quote | Quote
 
 
0 # Installation problems on Ubuntu 11.10radek 2011-10-27 02:25
Thanks a lot for tutorial!

I've trying to set up the tool on Ubuntu 11.10 (Postgres 9.1, PostGIS 1.5.3, pgadmin3 1.14.0-beta1, QGIS & Qt installed and working).

Unfortunately I cannot see the plugin in pgadmin :/

When trying to run it from command line, I get:

"E: Qt or QGIS not installed."

Could you please point me to any solutions to that?

Thanks :]
Reply | Reply with quote | Quote
 
 
0 # Re:tuxman 2011-10-27 09:01
Hi radek,

I haven't tested it on pgAdmin3 >= 1.13, anyway I would recommend you following these new and simplified steps:
http://geotux.tuxfamily.org/index.php/en/geo-blogs/item/278-constructor-de-consultas-sql-para-el-visor-de-capas-postgis-para-pgadmin-3

If the problem still persists, please go to the postgis_viewer.py file and try to run in a python console lines 42 to 50, one by one. This way you can discover if there is any PyQt4 module you are missing.

Tuxman
Reply | Reply with quote | Quote
 
 
0 # actually seekoblitz 2011-10-27 05:14
Congratulations on your post. I followed your step by step tutorial. the plugin name appears on the icon of pgadmin, but fails to appear for the fact I view the maps. There are two folders postgis_viewer. One in / usr / bin and another in / usr / bin / postgis_viewer. I have already put in both, and nothing worked. Do you have any suggestion about how I can dyscovery my mistake?
Ubuntu 10.10, pgadmin3 1.10.5-1.
Reply | Reply with quote | Quote
 
 
0 # actually seekoblitz 2011-10-27 05:36
I forgot sqy something. I can run post viewer, but, course, out of the pgadmin.
Reply | Reply with quote | Quote
 
 
0 # Re:tuxman 2011-10-27 08:51
Hi Rodrigo,

have you already tried the new version?:
http://geotux.tuxfamily.org/index.php/en/geo-blogs/item/278-constructor-de-consultas-sql-para-el-visor-de-capas-postgis-para-pgadmin-3

It has a simplified installation.

Tuxman
Reply | Reply with quote | Quote
 
 
0 # Re:koblitz 2011-11-01 12:48
Hi,
Yes, this was my first choice, but a more complex thought could solve the problem. Anyway, I threw out the installation that had postgis_viewer_ imgs and tried again with your suggestion. It did not work. The problem continues.

thanks for your answer,

saludo,
Koblitz
Reply | Reply with quote | Quote
 
 
0 # Re: actually seekoblitz 2011-11-01 13:19
Hi,
I began everything again and, it's work. Indeed I changed directly in the plugin.ini file. Put in there all my information, include the geometry column. The post_viewer open now through the icon 'plugin' from pgadmin. I can't see nothing in there, but I believe is a problem to know consult. Let's see. I made the right thing?
Reply | Reply with quote | Quote
 
 
0 # Re:tuxman 2011-11-01 20:32
Hi,

it can be because the directory "/usr/bin" is not registered as PostgreSQL bin path. Please go to pgAdmin3, File-->Options-->General tab-->PG bin path and check the folder. If it's in fact different, extract the postgis_viewer.zip file right there.

If that's not the problem, please take the plugins.ini content from the newest post of this series [1], as you see, they are a bit different. Just copy the content as it is, you don't need to edit anything to adjust it for your data or so.

If you still have troubles with this installation send me your plugins.ini file, or think of giving me access to your machine for a while, so I can take a closer look at this.

Regards,

Tuxman

--------------
[1] http://geotux.tuxfamily.org/index.php/en/geo-blogs/item/278-constructor-de-consultas-sql-para-el-visor-de-capas-postgis-para-pgadmin-3
Reply | Reply with quote | Quote
 
 
0 # re: actually seekoblitz 2011-11-03 15:50
Hi German,
I write plugin.ini exactly like recommend here. Ok it's work. thanks!
Reply | Reply with quote | Quote
 
 
0 # Please HelpNeeraj Kumar 2014-07-16 21:05
can anyone xplain this for qgis 2.0.1,posgresql 9.3.4 and postgis 2.1.3.
i have installed python 2.7.8 x64 bit, pyqt4 for python 2.7 and all.....Now i want to install postgis viewer in my database.
please explain in english soon.
Reply | Reply with quote | Quote
 

Add comment


Security code
Refresh

 

On-line users