debianにpgRoutingをインストールしたメモ
debianにpgRoutingをインストールした際のメモです。
Ubuntu用のリポジトリにあるpgRoutingはPostgreSQL 9.3をターゲットにしていますが、debianのPostgreSQLは9.1だったのでpgRoutingを自分でビルドしています。
整理してないので見にくいと思いますが気にしたら負けです。
PostGISとPROJ、GDALをインストールします。
$ sudo apt-get install postgresql-9.1-postgis proj-bin gdal-bin
pgRoutingをビルドします。
$ mkdir src $ cd src $ wget https://github.com/pgRouting/pgrouting/archive/v2.0.0.tar.gz $ tar zxvf v2.0.0.tar.gz $ cd pgrouting-2.0.0
README.mdに書かれている依存ライブラリは下記の通り。
足りない物をインストールします。
- C and C++ compilers
- Postgresql version >= 8.4 (9.1 or higher recommended)
- PostGIS version >= 1.5 (2.0 or higher recommended)
- The Boost Graph Library (BGL). Version >= [TBD]
- CMake >= 2.8.8
- (optional, for Driving Distance) CGAL >= [TBD]
- (optional, for Documentation) Sphinx >= [TBD]
Sphinxは要らないかなと思って入れてないです。
$ dpkg -l | grep postgis ii postgis 1.5.3-2 amd64 Geographic objects support for PostgreSQL -- common files ii postgresql-9.1-postgis 1.5.3-2 amd64 Geographic objects support for PostgreSQL 9.1
PostGISのバージョンは大丈夫そう。 その他のものをインストール。
$ sudo apt-get install build-essential libboost-graph-parallel-dev cmake libcgal-dev
ビルドを開始
$ mkdir build $ cd build $ cmake -DWITH_DD=ON .. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. -- PostgreSQL not found. CMake Error at CMakeLists.txt:122 (message): Please check your PostgreSQL installation. -- Configuring incomplete, errors occurred!
postgresql-server-dev-9.1が必要だったようで。
$ sudo apt-get install postgresql-server-dev-9.1
再チャレンジ
$ cmake -DWITH_DD=ON .. $ make $ sudo make install
pgRoutingはインストールできた。 続いてosm2pgroutingをビルドする。
$ sudo apt-get install expat $ cd ../../ $ wget https://github.com/pgRouting/osm2pgrouting/archive/master.zip $ unzip master.zip $ cd osm2pgrouting-master/ $ cmake -H. -Bbuild CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE): Could NOT find EXPAT (missing: EXPAT_LIBRARY EXPAT_INCLUDE_DIR) Call Stack (most recent call first): /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-2.8/Modules/FindEXPAT.cmake:50 (FIND_PACKAGE_HANDLE_STANDARD_ARGS) CMakeLists.txt:8 (FIND_PACKAGE) -- Configuring incomplete, errors occurred!
libexpat1-devも必要そう
$ sudo apt-get install libexpat1-dev $ cmake -H. -Bbuild $ make $ sudo make install
実行ファイルのシンボリックリンクを作成しておく
$ sudo ln -s /usr/share/bin/osm2pgrouting /usr/local/bin/
osmファイルをPostgreSQLにインポートしてみる。
$ cd ~/ $ sudo su - postgres $ createdb -U postgres ingress $ psql -U postgres -d ingress -c "CREATE EXTENSION postgis;" ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/postgis.control": No such file or directory
エクステンションが無いらしい。
aptのリポジトリで適切なものを見つけられなかったのでPostGISをアンインストールしてビルドする。
$ exit #postgresユーザから戻る $ sudo apt-get remove --purge postgis $ cd src $ wget http://download.osgeo.org/postgis/source/postgis-2.1.3.tar.gz $ tar zxvf postgis-2.1.3.tar.gz $ cd postgis-2.1.3 $ ./configure configure: error: could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.
うぐ、xml2-configな無いということでインストール。
$ sudo apt-get install libxml2-dev ./configure configure: error: could not find geos-config within the current path. You may need to try re-running configure with a --with-geosconfig parameter.
ぐぬぬ、今度はgeos-configがない…。
# sudo apt-get install libgeos-dev # ./configure configure: error: could not find proj_api.h - you may need to specify the directory of a PROJ.4 installation using --with-projdir
あばば、PROJのdevも必要なのか。
$ sudo apt-get install libproj-dev # ./configure configure: error: gdal-config not found. Use --without-raster or try --with-gdalconfig=<path to gdal-config>
ておい、GDALのdevも必要なんかい。
$ sudo apt-get install libgdal-dev $ ./configure
今度は通った。
$ make $ sudo make install
$ cd ~ $ sudo su - postgres $ psql -U postgres -d ingress -c "CREATE EXTENSION postgis;" $ psql -U postgres -d ingress -c "CREATE EXTENSION pgrouting;" $ osm2pgrouting -file "/home/k_zoar/map.osm" -conf "/usr/share/osm2pgrouting/mapconfig.xml" -dbname ingress -user postgres -clean host=127.0.0.1 user=postgres dbname=ingress port=5432 connection failed
ログにはこんな感じで吐き出されていた。
$ exit #postgresユーザから戻る $ sudo cat /var/log/postgresql/postgresql-9.1-main.log ~略~ LOG: could not receive data from client: Connection reset by peer
ググると設定ファイルを変更する必要があるらしいとのこと。 /etc/postgresql/9.1/main/pg_hba.confのMETHODを全部trustにしてPostgreSQLをリスタートする。
$ sudo vi /etc/postgresql/9.1/main/pg_hba.conf local all postgres trust local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust
再チャレンジ
$ cd ~ $ sudo su - postgres $ psql -U postgres -d ingress -c "CREATE EXTENSION postgis;" $ psql -U postgres -d ingress -c "CREATE EXTENSION pgrouting;" $ osm2pgrouting -file "/home/k_zoar/map.osm" -conf "/usr/share/osm2pgrouting/mapconfig.xml" -dbname ingress -user postgres -clean host=127.0.0.1 user=postgres dbname=ingress port=5432 connection success Trying to load config file /usr/share/osm2pgrouting/mapconfig.xml Trying to parse config Trying to load data Trying to parse data Split ways Dropping tables... Creating tables... NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "nodes_pkey" for table "nodes" Nodes table created 2create ways failed:NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "types_pkey" for table "types" Types table created Way_tag table created Relations table created Relation_ways table created NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "classes_pkey" for table "classes" Classes table created Adding tag types and classes to database... Adding relations to database... Adding nodes to database... Adding ways to database... Creating topology... NOTICE: PROCESSING: NOTICE: pgr_createTopology('ways',1e-05,'the_geom','gid','source','target','true') NOTICE: Performing checks, pelase wait ..... NOTICE: Creating Topology, Please wait... NOTICE: 1000 edges processed NOTICE: 2000 edges processed NOTICE: 3000 edges processed NOTICE: 4000 edges processed NOTICE: -------------> TOPOLOGY CREATED FOR 4910 edges NOTICE: Rows with NULL geometry or NULL id: 0 NOTICE: Vertices table for table public.ways is: public.ways_vertices_pgr NOTICE: ---------------------------------------------- Create Topology success ######################### size of streets: 1826 size of splitted ways : 4910 finished
登録できたっぽい。
さて、ここから先に進めればいいんだが。