2008年10月1日 星期三

Loading data into Postgis

Recently, I've tried to use Postgis and understand how it works. Perhaps, I can use it in the future. Postgis is not a standalone program but it is a spatial extension of Postgres, which is an open source object-relational database system.

To load data into Postgres with Postgis, I have the following is ingredients.

1. Postgres 8.3.4; It can be downloaded from http://www.postgresql.org/
2. A shape file data. You can use any shapefile you can find it anyway.
3. A compatible windows environment, I use my notebook running Windows XP for this test.

Steps:
1. Install Postgres;
During installation of Postgres, it will ask you to define superuser password. I define it by myself, otherwise, system will create a very secure password for you, which is impossible to remember. In addition, system will ask you to create a new window account for services control.
2. Using Application Stack Builder in Postgres to download and install Postgis.
You need the superuser password to complete this task.
3. Prepare environment to run
i. Copy the following files from Postgres to a c:\temp\pgtools
comerr32.dll
country.sql
gssapi32.dll
k5sprt32.dll
krb5_32.dll
libeay32.dll
libiconv-2.dll
libiconv2.dll
libintl3.dll
libpq.dll
pgsql2shp.exe
pg_dump.exe
psql.exe
shp2pgsql.exe
ssleay32.dll

ii. Copy the shapefile to c:\temp

4. Run the following command converting shapefile to postgres sql
>shp2pgsql c:\temp\country country > country.sql

After this, a country.sql will be created.

5. Run the following command to load the sql into postgres
>psql -d postgis -h localhost -U postgres -f country.sql

After step 5, you can open pgAdminIII to check your database and you will find a new table called "country".

沒有留言: