본문 바로가기
정보기술/웹&데이터베이스

Shape file 을 PostGIS 데이터베이스에 넣는 방법

by fermi 2011. 7. 1.
Requirement:
- PostgreSQL
- PostGIS
- 데이터베이스를 생성할 때는 postgis 데이터베이스를 template로 생성하여야 한다.

방법:
- PostgreSQL 의 bin 디렉토리에 포함된 shp2pgsql.exe 를 이용하여 shapefile 을 sql 스크립트로 변환한 후 스크립트 실행
- shape 파일 과 함께 제공되는 dbf, prj, shx 정보가 같은 디렉토리에 있어야 한다.
- 사용법은 shp2pgsql.exe shapfilename schema.tablename > scriptfilename.sql
ex) shp2pgsql.exe TM_WORLD_BORDERS_SIMPL-0.3.shp public.world_borders_simple > TM_WORLD_BORDERS_SIMPL-0.3.sql
- 스크립트 실행은 PgAdmin III 를 이용해도 될 것이고 (확인 필요), 본인은 PostgreSQL Maestro 에서 데이터베이스 프로파일을 선택한 후 우클릭하면 나타나는 팝업 메뉴에서 Database Tools > Execute script from file 기능을 이용하였다.

참고자료:
http://khayer.wordpress.com/2009/10/29/creating-database-and-importing-shape-file-in-postgis/
http://www.paolocorti.net/2006/07/27/migrating-shapefiles-to-postgis/

활용예:
World borders dataset 을 PostgreSQL 데이터베이스에 저장할 수 있다.
http://thematicmapping.org/downloads/world_borders.php