Tuesday, 9 October 2007

Import spatial data (shapefile) into PostgreSQL

1. Open console, execute following commands:
cd $ShapeDir
shp2pgsql -W UTF-8 <filename>.shp <schema>.<tablename> ><filename>.sql


2. Open file that has just created, insert string "WITH OIDS" before character ";" of command CREATE TABLE, and then save that file.

3. Continue to execute the command:
psql -h <hostname> -U <username> -d <databasename> -f <filename>.sql

4. Open pgAdmin3 (or phpPgAdmin), open Query Tool and input following lines:
CREATE INDEX <indexname> ON <tablename> USING gist (<spatial_attribute>);
VACUUM ANALYZE <tablename>


Ex:
shp2pgsql -W UTF-8 hcm_road.shp public.hcm_road > hcm_road.sql

psql -h 127.0.0.1 -U postgres -d hcmcity -f hcm_road.sql

CREATE INDEX hcm_road_the_geom_gist ON hcm_road USING gist (the_geom);

VACUUM ANALYZE hcm_road


* Note: if you want to export data from PostgreSQL to shapefile, using command pgsql2shp.

Wednesday, 3 October 2007

Install PostgreSQL 8.2 with PostGIS on Ubuntu

On Ubuntu 7.10
Open console, execute following command:
sudo apt-get install postgresql-8.2 postgresql-client-8.2 postgresql-client-common postgresql-common postgresql-server-dev-8.2 postgresql-contrib-8.2
libgeos-dev proj postgis postgresql-8.2-postgis

Note: /usr/lib/postgresql/8.2/lib ---> directory contains file
liblwgeom.so


On Ubuntu 7.04
1. Open console, execute following command:
sudo apt-get install postgresql-8.2 postgresql-client-8.2 postgresql-client-common postgresql-common postgresql-server-dev-8.2 postgresql-contrib-8.2 libgeos-dev proj flex postgis

2. Download postgis-1.3.x.tar.gz and decompress.

3. Execute following commands:
cd ${postgis-1.3.x}
./configure


Result:

SUMMARY
-------------------------------------------------------

HOST_OS: linux-gnu

PGSQL: /usr/bin/pg_config
GEOS: /usr/bin/geos-config (with C-API)
(ldflags: -L/usr/lib)
PROJ: prefix=/usr libdir=/usr/lib
ICONV: 1

PORTNAME: linux
PREFIX: /usr
EPREFIX: ${prefix}
DOC: /usr/share/doc/postgresql-doc-8.2/contrib
DATA: ${datarootdir}
MAN: ${datarootdir}/man
BIN: /usr/lib/postgresql/8.2/bin
EXT: /usr/lib/postgresql/8.2/lib (\$$libdir)
-------------------------------------------------------


Note: EXT: /usr/lib/postgresql/8.2/lib ---> directory contains file liblwgeom.so


4. Compile & Install
make
sudo make install

Cài đặt xvnkb trên Ubuntu

1. Cài đặt các package :
sudo apt-get install build-essential
sudo apt-get install xorg-dev


2. Download xvnkb-0.2.9a.tar.bz2 và decompress.
3. Thực hiện các lệnh sau :
cd xvnkb-0.2.9a/
./autogen.sh
./configure --use-extstroke

4. Sửa file config.h :
gedit config.h

thành :

#define __VK_CONFIG_H
#define VK_CHECK_SPELLING
#define VK_USE_EXTSTROKE
#define VK_NEED_UCHAR

(bỏ đi một vài dòng bị lỗi)

5. Compile & Install
make
sudo make install


6. Nếu muốn xvnkb tự động chạy lúc khởi động, bạn vào menu System > Preferences > Sessions, chọn New và nhập vào ô Command như sau: xvnkb --method=telex --charset=utf8 (trong đó method là telex, vni hoặc viqr; charset là utf8, tcvn, viscii, vps hoặc viqr). Bây giờ xvnkb sẽ khởi động mặc định với kiểu gõ (method) và bảng mã (charset) mà bạn đã chọn.

Theo http://saylinux.wordpress.com/