Tuesday, May 11, 2010

How to Import Shape Files into RDBMS( PostgreSQL/POSTGIS)

How to Store Spatial Data or Shape Files into RDBMS( PostgreSQL/POSTGIS)




1 What is Shape file ?


   The shape file is coined by ESRI(Environmental System Research Institute).The shape file stores individual data type(Polygon or line or Point).The shape file is combination of different files (that is from 4 to 5 files combination)
        .shp
        .shx
        .dbf
        .xml
        .prj


2 )Why Spatial data should store in RDBMS ?


  The shape files are combination of files,if one file is missed ,the shape file will not work. Those are just static files , these files suppose to store in local disc ,single user access and the file sometimes can be corrupted or misplaced .So that the data will be lost.The data should store in the database.


How to store shape file into database(RDBMS) ?


There are different steps involved … that is


3) Install PostrgreSQL (Open source)
Referred URLs are


http://pginstaller.projects.postgresql.org/


or


http://askoh.net/misc/visualworks/installPostgreSQL/


4) Install PostGIS


http://www.gpsfiledepot.com/tutorials/installing-and-setting-up-postgresql-with-postgis/




5) Set Environment variables for shp2pgsql.exe




My Computer → Properties → Advanced → select Environment Variables


6) command for importing shapefile..blow are the steps
  
     i) Open commandline (Clt +r ->type cmd)
     ii)set shapefile path in commandline
     iii) And run below query
  
  shp2pgsql -s 24047 india.shp india > india.sql


About command :-
   24047 : is SRID
   india.shp : is shapefile name
   india :- is table name, the name which suppose to import into database
   india.sql :- is sql file,which suppose to run in the query builder


    


7) Convert Shape file to PostgreSQL/POSTGIS :-


8)  Run Sql Converted SQL file


and finally table will import into database postgresql and we can see the geometry column added in the imported table in the database.

No comments: