重要
翻訳は あなたが参加できる コミュニティの取り組みです。このページは現在 73.68% 翻訳されています。
16.3. レッスン: インポートとエクスポート
Of course, a database with no easy way to migrate data into it and out of it would not be of much use. Fortunately, there are a number of tools that will let you easily move data into and out of PostgreSQL.
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 PostgreSQL table:
shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> | \
psql -d <databasename> -h <hostname> -U <username>
Windows では, 2ステップでインポート処理を実行します :
shp2pgsql -s <SRID> -c -D -I <path to shapefile> <schema>.<table> > import.sql
psql psql -d <databasename> -h <hostname> -U <username> -f import.sql
次のようなエラーが発生することがあります :
ERROR: operator class "gist_geometry_ops" does not exist for access method
"gist"
これは、インポートするデータの空間インデックスを その場 で作成することに関する既知の問題です。このエラーを回避するには、-I パラメータを除外してください。この場合、空間インデックスは直接作成されないので、データをインポートした後にデータベースで作成する必要があります。(空間インデックスの作成については、次のレッスンで説明します)。
16.3.2. pgsql2shp
pgsql2shp is a commandline tool to export PostgreSQL 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>
クエリを使用してデータをエクスポートするには :
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 PostgreSQL to many data formats. ogr2ogr is part of the GDAL library and has to be installed separately. To export a table from PostgreSQL to GML, you can use this command:
ogr2ogr -f GML export.gml PG:'dbname=<databasename> user=<username>
host=<hostname>' <Name of PostgreSQL-Table>
16.3.4. DB Manager
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 PostgreSQL. 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. 結論
データベースとの間でデータをインポート及びエクスポートは, 多様な方法で行うことができます. 異なるデータソースを使用する場合は特に, この機能(またはこの機能に似た機能)を使用します.
16.3.6. 次は?
次に,私たちが以前に作成したデータを参照する方法を見ていきます.