중요

번역은 여러분이 참여할 수 있는 커뮤니티 활동입니다. 이 페이지는 현재 57.89% 에서 번역되고 있습니다.

16.3. Lesson: 임포트와 엑스포트

물론, 데이터를 가져오거나 내보내기 힘든 데이터베이스는 쓸모가 없습니다. 다행히도 PostGIS에서 데이터를 쉽게 가져오거나 내보낼 수 있는 도구가 많이 있습니다.

16.3.1. shp2pgsql

shp2pgsql is a commandline tool to import ESRI Shapefile to the database. Under Unix, you can use the following command for importing a new PostGIS table:

shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> | \
  psql -d <databasename> -h <hostname> -U <username>

Under Windows, you have to perform the import process in two steps:

shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> > import.sql
psql psql -d <databasename> -h <hostname> -U <username> -f import.sql

You may encounter this error:

ERROR:  operator class "gist_geometry_ops" does not exist for access method
"gist"

This is a known issue regarding the creation in situ of a spatial index for the data you’re importing. To avoid the error, exclude the -I parameter. This will mean that no spatial index is being created directly, and you’ll need to create it in the database after the data have been imported. (The creation of a spatial index will be covered in the next lesson.)

16.3.2. pgsql2shp

pgsql2shp is a commandline tool to export PostGIS Tables, Views or SQL select queries. To do this under Unix:

pgsql2shp -f <path to new shapefile> -g <geometry column name> \
  -h <hostname> -U <username> <databasename> <table | view>

To export the data using a query:

pgsql2shp -f <path to new shapefile> -g <geometry column name> \
  -h <hostname> -U <username> "<query>"

16.3.3. ogr2ogr

ogr2ogr is a very powerful tool to convert data into and from postgis to many data formats. ogr2ogr is part of the GDAL library and has to be installed separately. To export a table from PostGIS to GML, you can use this command:

ogr2ogr -f GML export.gml PG:'dbname=<databasename> user=<username>
        host=<hostname>' <Name of PostGIS-Table>

16.3.4. DB 관리자

You may have noticed another option in the Database menu labeled DB Manager. This is a tool that provides a unified interface for interacting with spatial databases including PostGIS. It also allows you to import and export from databases to other formats. Since the next module is largely devoted to using this tool, we will only briefly mention it here.

16.3.5. In Conclusion

데이터베이스에(서) 데이터를 임포트하거나 엑스포트하는 방법은 여러 가지가 있습니다. 특히 서로 전혀 다른 데이터소스를 이용할 경우, 상시적으로 이 기능들, 또는 다른 비슷한 기능들을 사용하게 될 것입니다.

16.3.6. What’s Next?

다음으로 이전에 생성했던 데이터를 어떻게 쿼리할 수 있는지 알아보겠습니다.