Copyright 2017. Japan Space Systems. All Rights Reserved. 1
宇宙APIレシピ集
Copyright 2017. Japan Space Systems. All Rights Reserved.
データベース
➢ ポイント
1. このレシピでは、無償データベースであるPostgreSQLの
インストール及びPostgreSQL上で地理空間情報を扱うた
めの拡張ソフトであるPostGISのインストールを行うこ
とができます。
2. このレシピでは、大量の衛星データを扱うために必要な
環境づくりの方法を身に着けることができます。
➢ 用意するもの
1. インターネットに接続できるLinuxマシン (OS CentOS
7.2)
必要に応じて、仮想マシンを作成する (参考: 仮想マシン
の構築)
➢ 操作
1. Linuxマシンを用意します。今回は、CentOS 7.2を用いま
す。データベースのインストール方法は、OSに依存しま
す。さらに、インターネット接続環境については、ネッ
トワーク管理者に問い合わせ、環境を構築してください。
2. Linuxマシンにコマンドラインでログインします。
3. データベース管理者ユーザpostgresを作成します。
2
コマンドラインでログインする
Windows PCからアクセスする際は、
TeraTermが便利である
Last login:
[root@centos ~] # useradd postgres
[root@centos ~] #
Copyright 2017. Japan Space Systems. All Rights Reserved.
4. プログラムをインストールするyumコマンドが、EPELリ
ポジトリにアクセスできるよう、EPELをインストールし
ます。
5. 地理空間情報(GIS)を扱うためのライブラリ群であるgdal
をインストールします。
データベース
3
[root@centos ~] # yum install –y epel-release
<省略>
完了しました!
[root@centos ~] #
[root@centos ~] # yum list gdal*
利用可能なパッケージ
gdal.x86_64 1.11.4-1.el7 epel
gdal-devel.x86_64 1.11.4-1.el7 epel
gdal-doc.noarch 1.11.4-1.el7 epel
gdal-java.x86_64 1.11.4-1.el7 epel
gdal-javadoc.noarch 1.11.4-1.el7 epel
gdal-libs.x86_64 1.11.4-1.el7 epel
gdal-perl.x86_64 1.11.4-1.el7 epel
gdal-python.x86_64 1.11.4-1. epel
[root@yew00922 ~]# yum –enablerepo=epel install –
y gdal
<省略>
完了しました!
[root@centos ~] # yum install –y proj proj-devel proj-
epsg
<省略>
完了しました!
[root@centos ~] #
3. EPELのインストール
4. gdal及び投影に必要
なprojライブラリ群をイ
ンストール
必要に応じて、利用可
能なライブラリ群を確
認する
Copyright 2017. Japan Space Systems. All Rights Reserved.
6. PostgreSQLをインストールします。
7. PostgreSQLを初期化します。
8. PostgreSQLを起動します。
9. PostgreSQlの自動起動を設定します。
データベース
4
[root@centos ~] # yum --enablerepo=epel install
postgresql-server postgresql-contrib postgresql-devel
<省略>
完了しました!
[root@centos ~] #
[root@centos ~] # find / -name postgresql-setup
/usr/bin/postgresql-setup
[root@yew00922 ~]# /usr/bin/postgresql-setup initdb
Initializing database ... OK
[root@centos ~] # systemctl start postgresql
[root@centos ~] # systemctl enable postgresql
[root@centos ~] # systemctl is-enabled postgresql
enabled
[root@centos ~] #
5. PostgreSQLのインス
トール
6. PostgreSQlの初期化
を行う
PostgreSQlを初期化す
るコマンドを探す
Copyright 2017. Japan Space Systems. All Rights Reserved.
10./var/lib/pgsql/data/postgresql.confを編集して、
PostgreSQLにアクセスできるIPアドレスを設定します。
今回は、’*’ (すべて)とします。
データベース
5
[root@centos ~] # cd /var/lib/pgsql/data
[root@centos ~] # cp postgresql.conf
postgresql.conf.oroginal
[root@centos ~] # vi postgresql.conf
#---------------------------------------------------------------------
---------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------
---------
# - Connection Settings -
#listen_addresses = 'localhost' # what IP
address(es) to listen on;
# comma-separated list of
addresses;
# defaults to 'localhost'; use
'*' for all
# (change requires restart)
# ADDED BY NAKAMURA-
SHINSAKU@JSPACESYSTEMS.OR.JP
listen_addresses = ‘*' # what IP address(es) to
listen on;
[root@centos ~] #
ファイルを編集する前
に、オリジナルを別名
で保存する
追記箇所
vi コマンドで編集する
Copyright 2017. Japan Space Systems. All Rights Reserved.
10./var/lib/pgsql/data/pg_hba.confを編集して、 PostgreSQL
への接続認証を設定します。今回は、localhostとします。
11.PostgreSQLを再起動します。
データベース
6
[root@centos ~] # cd /var/lib/pgsql/data
[root@centos ~] # cp pg_hba.conf
pg_hba.conf.oroginal
[root@centos ~] # vi pg_hba.conf
# TYPE DATABASE USER ADDRESS
METHOD
# "local" is for Unix domain socket connections only
# COMMENTED OUT BY NAKAMURA-
SHINSAKU@JSPACESYSTEMS.OR.JP ON JUNE
18, 2017
#local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32
ident
# IPv6 local connections:
#host all all ::1/128 ident
# ADDED BY NAKAMURA-
SHINSAKU@JSPACESYSTEMS.OR.JP ON JUNE
18, 2017
local all all peer
host all all 0.0.0.0/0 md5
[root@centos ~] # systemctl restart postgresql
[root@centos ~] #
ファイルを編集する前
に、オリジナルを別名
で保存する
修正箇所
vi コマンドで編集する
Copyright 2017. Japan Space Systems. All Rights Reserved.
12.データベース用のユーザを作成します。Postgresユーザ
は、PostgreSQL全体を管理するユーザなので、実運用用
のユーザは別途作成します。今回は、nakaとします。
13.postgresユーザになります。
14.createuserコマンドを持ちて、データベース用のnaka
ユーザを作成します。
15.psqlコマンドでPostgreSQLにアクセスします。
16.nakaユーザのパスワード及び権限を設定します。今回は、
管理者権限(SUPERUSER)、データベース作成権限
(CREATEDB)、複製権限(REPLICATION)を与えます。
データベース
7
[root@centos ~] # useradd naka
[root@centos ~] # passwd naka
[root@centos ~] # su - postgres
[postgres@centos ~] $ createuser naka
[postgres@centos ~] $ psql
postres=# ALTER ROLE naka PASSWORD ‘xxxx’;
postres=# ALTER ROLE naka SUPERUSER;
postres=# ALTER ROLE naka CREATEDB;
postres=# ALTER ROLE naka REPLICATION;
postres=# ¥q
[postgres@centos ~] $
各コマンド
(SQL文)の
最後にセミ
コロンをつ
けることを
忘れないこ
と
PostgreSQL環境
¥qでPostgreSQL環境から出る
Copyright 2017. Japan Space Systems. All Rights Reserved.
17.nakaユーザになります。
18.createdbコマンドで、sampleというデータベースを作成
します。
19.psqlコマンドで、作成したsampleデータベースにアクセ
スできるか確認します。
データベース
8
[postgres@centos ~] $ su – naka
[naka@centos ~] $ createdb sample
[naka@centos ~] $ psql –d sample
sample=#
sample=# ¥q
[naka@centos ~] $
Copyright 2017. Japan Space Systems. All Rights Reserved.
20.yumコマンドで、PostGISをインストールします。
21.nakaユーザになります。
22.psqlコマンドで、sampleデータベースにアクセスします。
23.PostGISでsampleデータベースを拡張します。
24.¥dコマンドで、GIS計算用テーブルが作成されたことを
確認します。
データベース
9
[root@centos ~] # yum –enablerepo=epel install
postgis
完了しました!
[root@centos ~] # su - naka
[naka@centos ~] $ psql –d sample
sample=# CREATE EXTENSION postgis;
CREATE EXTENSION
sample=# CREATE EXTENSION postgis_topology;
CREATE EXTENSION
sample=# ¥d
リレーションの一覧
スキーマ | 名前 | 型 | 所有者
----------+-------------------+----------+--------
public | geography_columns | ビュー | naka
public | geometry_columns | ビュー | naka
public | raster_columns | ビュー | naka
public | raster_overviews | ビュー | naka
public | spatial_ref_sys | テーブル | naka
(5 行)
sample=# ¥q
[naka@centos ~] $
GIS計算用テーブル
Copyright 2017. Japan Space Systems. All Rights Reserved.
データベース
➢ まめちしき (地理空間用データベース)
多量の衛星データを取り扱うためには、データベースが必要
です。

DatabaseDevelopment

  • 1.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 1 宇宙APIレシピ集
  • 2.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. データベース ➢ ポイント 1. このレシピでは、無償データベースであるPostgreSQLの インストール及びPostgreSQL上で地理空間情報を扱うた めの拡張ソフトであるPostGISのインストールを行うこ とができます。 2. このレシピでは、大量の衛星データを扱うために必要な 環境づくりの方法を身に着けることができます。 ➢ 用意するもの 1. インターネットに接続できるLinuxマシン (OS CentOS 7.2) 必要に応じて、仮想マシンを作成する (参考: 仮想マシン の構築) ➢ 操作 1. Linuxマシンを用意します。今回は、CentOS 7.2を用いま す。データベースのインストール方法は、OSに依存しま す。さらに、インターネット接続環境については、ネッ トワーク管理者に問い合わせ、環境を構築してください。 2. Linuxマシンにコマンドラインでログインします。 3. データベース管理者ユーザpostgresを作成します。 2 コマンドラインでログインする Windows PCからアクセスする際は、 TeraTermが便利である Last login: [root@centos ~] # useradd postgres [root@centos ~] #
  • 3.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 4. プログラムをインストールするyumコマンドが、EPELリ ポジトリにアクセスできるよう、EPELをインストールし ます。 5. 地理空間情報(GIS)を扱うためのライブラリ群であるgdal をインストールします。 データベース 3 [root@centos ~] # yum install –y epel-release <省略> 完了しました! [root@centos ~] # [root@centos ~] # yum list gdal* 利用可能なパッケージ gdal.x86_64 1.11.4-1.el7 epel gdal-devel.x86_64 1.11.4-1.el7 epel gdal-doc.noarch 1.11.4-1.el7 epel gdal-java.x86_64 1.11.4-1.el7 epel gdal-javadoc.noarch 1.11.4-1.el7 epel gdal-libs.x86_64 1.11.4-1.el7 epel gdal-perl.x86_64 1.11.4-1.el7 epel gdal-python.x86_64 1.11.4-1. epel [root@yew00922 ~]# yum –enablerepo=epel install – y gdal <省略> 完了しました! [root@centos ~] # yum install –y proj proj-devel proj- epsg <省略> 完了しました! [root@centos ~] # 3. EPELのインストール 4. gdal及び投影に必要 なprojライブラリ群をイ ンストール 必要に応じて、利用可 能なライブラリ群を確 認する
  • 4.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 6. PostgreSQLをインストールします。 7. PostgreSQLを初期化します。 8. PostgreSQLを起動します。 9. PostgreSQlの自動起動を設定します。 データベース 4 [root@centos ~] # yum --enablerepo=epel install postgresql-server postgresql-contrib postgresql-devel <省略> 完了しました! [root@centos ~] # [root@centos ~] # find / -name postgresql-setup /usr/bin/postgresql-setup [root@yew00922 ~]# /usr/bin/postgresql-setup initdb Initializing database ... OK [root@centos ~] # systemctl start postgresql [root@centos ~] # systemctl enable postgresql [root@centos ~] # systemctl is-enabled postgresql enabled [root@centos ~] # 5. PostgreSQLのインス トール 6. PostgreSQlの初期化 を行う PostgreSQlを初期化す るコマンドを探す
  • 5.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 10./var/lib/pgsql/data/postgresql.confを編集して、 PostgreSQLにアクセスできるIPアドレスを設定します。 今回は、’*’ (すべて)とします。 データベース 5 [root@centos ~] # cd /var/lib/pgsql/data [root@centos ~] # cp postgresql.conf postgresql.conf.oroginal [root@centos ~] # vi postgresql.conf #--------------------------------------------------------------------- --------- # CONNECTIONS AND AUTHENTICATION #--------------------------------------------------------------------- --------- # - Connection Settings - #listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) # ADDED BY NAKAMURA- SHINSAKU@JSPACESYSTEMS.OR.JP listen_addresses = ‘*' # what IP address(es) to listen on; [root@centos ~] # ファイルを編集する前 に、オリジナルを別名 で保存する 追記箇所 vi コマンドで編集する
  • 6.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 10./var/lib/pgsql/data/pg_hba.confを編集して、 PostgreSQL への接続認証を設定します。今回は、localhostとします。 11.PostgreSQLを再起動します。 データベース 6 [root@centos ~] # cd /var/lib/pgsql/data [root@centos ~] # cp pg_hba.conf pg_hba.conf.oroginal [root@centos ~] # vi pg_hba.conf # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only # COMMENTED OUT BY NAKAMURA- SHINSAKU@JSPACESYSTEMS.OR.JP ON JUNE 18, 2017 #local all all peer # IPv4 local connections: #host all all 127.0.0.1/32 ident # IPv6 local connections: #host all all ::1/128 ident # ADDED BY NAKAMURA- SHINSAKU@JSPACESYSTEMS.OR.JP ON JUNE 18, 2017 local all all peer host all all 0.0.0.0/0 md5 [root@centos ~] # systemctl restart postgresql [root@centos ~] # ファイルを編集する前 に、オリジナルを別名 で保存する 修正箇所 vi コマンドで編集する
  • 7.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 12.データベース用のユーザを作成します。Postgresユーザ は、PostgreSQL全体を管理するユーザなので、実運用用 のユーザは別途作成します。今回は、nakaとします。 13.postgresユーザになります。 14.createuserコマンドを持ちて、データベース用のnaka ユーザを作成します。 15.psqlコマンドでPostgreSQLにアクセスします。 16.nakaユーザのパスワード及び権限を設定します。今回は、 管理者権限(SUPERUSER)、データベース作成権限 (CREATEDB)、複製権限(REPLICATION)を与えます。 データベース 7 [root@centos ~] # useradd naka [root@centos ~] # passwd naka [root@centos ~] # su - postgres [postgres@centos ~] $ createuser naka [postgres@centos ~] $ psql postres=# ALTER ROLE naka PASSWORD ‘xxxx’; postres=# ALTER ROLE naka SUPERUSER; postres=# ALTER ROLE naka CREATEDB; postres=# ALTER ROLE naka REPLICATION; postres=# ¥q [postgres@centos ~] $ 各コマンド (SQL文)の 最後にセミ コロンをつ けることを 忘れないこ と PostgreSQL環境 ¥qでPostgreSQL環境から出る
  • 8.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 17.nakaユーザになります。 18.createdbコマンドで、sampleというデータベースを作成 します。 19.psqlコマンドで、作成したsampleデータベースにアクセ スできるか確認します。 データベース 8 [postgres@centos ~] $ su – naka [naka@centos ~] $ createdb sample [naka@centos ~] $ psql –d sample sample=# sample=# ¥q [naka@centos ~] $
  • 9.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. 20.yumコマンドで、PostGISをインストールします。 21.nakaユーザになります。 22.psqlコマンドで、sampleデータベースにアクセスします。 23.PostGISでsampleデータベースを拡張します。 24.¥dコマンドで、GIS計算用テーブルが作成されたことを 確認します。 データベース 9 [root@centos ~] # yum –enablerepo=epel install postgis 完了しました! [root@centos ~] # su - naka [naka@centos ~] $ psql –d sample sample=# CREATE EXTENSION postgis; CREATE EXTENSION sample=# CREATE EXTENSION postgis_topology; CREATE EXTENSION sample=# ¥d リレーションの一覧 スキーマ | 名前 | 型 | 所有者 ----------+-------------------+----------+-------- public | geography_columns | ビュー | naka public | geometry_columns | ビュー | naka public | raster_columns | ビュー | naka public | raster_overviews | ビュー | naka public | spatial_ref_sys | テーブル | naka (5 行) sample=# ¥q [naka@centos ~] $ GIS計算用テーブル
  • 10.
    Copyright 2017. JapanSpace Systems. All Rights Reserved. データベース ➢ まめちしき (地理空間用データベース) 多量の衛星データを取り扱うためには、データベースが必要 です。