Wednesday, April 18, 2012

How to connect spatial database(PostGIS) with QGIS?

In this section, I am showing the 3 basic steps to connect PostGIS database with a widely used open source desktop based gis, QGIS. 

Step1: Install PostGIS with Spatial database support extension
i.                    If PostgreSQL is already installed è Launch ‘Application stack builder’ from startup menu in windows 7.
ii.                  Select the appropriate instance of PGSQL from dropdown list and Click NEXT.
iii.                Expand ‘Categories’è Expand ‘Spatial Extensions’ è Select appropriate PostGIS version(1.5)  for the already installed PGSQL version(8.4).
iv.                    Follow the instructions to install the PostGIS extension.

Step2:  Loading spatial data into PostGIS
i.                    Open the PgAdmin window (above installation should install a ‘Shapefile to PostGIS importer’ plugin.)
ii.                   Select the database and click on ‘Plugins’ and select ‘Shapefiel to PostGIS importer’ plugin.
iii.                If the plugin is not available under the ‘Plugins’. We can also get it from “C:\Program Files (x86)\PostgreSQL\8.4\bin\postgisgui\shp2pgsql-gui.exe”
iv.                 Select the desired shp file to put into PostGIS.
v.                    We need to put the appropriate SRID for the imported file. SRID column contains datum information of the imported shapefile into the PostGIS. There are unique SRID for the different projection and datum types.
Such as:
NAD 1983- 4269
WGS 84- 4326
 Another important thing to keep on mind during file import is is the datatype. In my case I used GEOGRAPY data type(refer page 27 -28) in the book, PostGIS in Action.
vi.                  Above step feeds the spatial information into the database with two additional fields, one for vector geometry id and another for vector geometry with datum information.

Step3:  Retrieving spatial data from PostGIS into Web based applications and Desktop based applications.
i.                    We can view and project above data using Qgis(An open source GIS alternative to ESRI’s ArcGIS) in desktop based environment. Similarly, we can use Geoserver or UMN Mapserver view data in the Web.

The core technologies behind Qgis and GRASS are similar. Qgis is easy to use, support GDAL, Python, PostGIS, and has nice GUI. In the same time we can get strength of GRASS by calling GRASS’s functionality form   the QGIS. 

ii.                  Install Qgis
iii.        Open the Qgis è Click layer èselect ‘Add from PostGIS’, which gives you the following windows.

iv.        Click connect, you should able to see the shape layer as below.

v.          Finally you will able to see the vector layer in the layer and this layer can be treated as an ordinary shp. file added in the ESRI ArcMap.

PostGIS , PostgreGIS , QGIS , spatial database


Post a Comment


© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me