久しぶりに Ubuntuを起動するとまたディスクエラーが起きた。 今回は android を動かしたことが関係しているかも知れないが、 多分、Ubuntu は絶えず動かしていないと、うまく更新されないのだろう。
sudo apt install gcc make perlを実行して、再起動した。
sudo adduser hatada vboxsf sudo adduser postgres sudo adduser postgres vboxsf
これまでに何度も経験しているので、すんなりインストールできた[2021.4.6]。
前回と同じ PostgreSQLバージョン12をインストールした。
sudo apt install postgresql postgis
su - postgres で入って psql を実行すると バージョンは 12.6 と確認できた。
設定ファイルの変更は sudo gedit /etc/postgresql/12/main/postgresql.conf で行う。
とりあえずは shared_buffers = 1024MB の設定変更のみとする。
psql で PostgreSQL上のユーザ(ロール) postgres にパスワードを設定した。
postgres=# alter user postgres with password 'postgres'; postgres=# \q
postgresqlをリスタートする。
/etc/init.d/postgresql restart
osm2pgsqlのインストールは簡単である。
sudo apt install osm2pgsql
これで osm2pgsql version 1.2.1 がインストールされた。
データベースは psql で作成する。
su - postgres psql postgres=# create database osm; osm=# create extension postgis;
共有フォルダを設定する。
テストとして kanto_tc.o5m インポートしてみた。
osm2pgsql -W --slim --number-processes 3 -C 3000 --drop -c -d osm -p japan -U postgres \ -H localhost -P 5432 -S /media/sf_gisdata/mapnik/japan_osm.style /media/sf_o5m/kanto_tc.o5m
コンパイルしてのインストールであり、依存関係が多いため、厄介である。
今年(2021年)の1月に Mapnik 3.1 がリリースされた。
過不足があるかも知れないが、以下を実行する (最初に実行したのは1行目だけ。後は、configure エラーなどで追加した)。
sudo apt install clang git python zlib1g-dev clang pkg-config curl sudo apt install libicu-dev libharfbuzz-dev sudo apt install libfreetype6 libfreetype6-dev sudo apt install libboost-all-dev sudo apt install libgdal-dev
そのあと、以下の手順でインストールする。
git clone https://github.com/mapnik/mapnik.git cd mapnik git checkout v3.1.0 git submodule update --init ./configure make make test sudo make install
make で次の Notice が出た。 Notice は Warning のようなものだろうか? make は継続された。
Notice: dependencies not met for plugin 'sqlite', not building... Notice: dependencies not met for plugin 'ogr', not building... Notice: dependencies not met for plugin 'gdal', not building...
Depends
Build system dependencies are:
* C++ compiler supporting `-std=c++11` (like >= g++ 4.8 or >= clang++ 3.4)
* >= 2 GB RAM (> 5 GB for g++)
* Python 2.4-2.7
* Scons (a copy is bundled)
Mapnik Core depends on:
* Boost
- >= 1.47 is required and >= 1.56 recommended
- These libraries are used:
- filesystem
- system
- regex (optionally built with icu regex support)
- program_options (optionally for mapnik command line programs)
* libicuuc >= 4.0 (ideally >= 4.2) - International Components for Unicode
* libz - Zlib compression
* libfreetype - Freetype2 for font support (Install requires freetype-config)
* libxml2 - XML parsing (Install requires xml2-config)
* libharfbuzz - an OpenType text shaping engine (>=0.9.34 needed for CSS font-feature-settings support)
Mapnik Core optionally depends on:
* libpng >= 1.2.x - PNG graphics (Default enabled, if found)
* libjpeg - JPEG graphics (Default enabled, if found)
* libtiff - TIFF graphics (Default enabled, if found)
* libwebp - WEBP graphics (Default enabled, if found)
* libproj - PROJ.4 projection library (Default enabled, if found)
Additional optional dependencies:
* Cairo >= 1.6.0 - Graphics library for output formats like PDF, PS, and SVG
- pkg-config - Required for building with cairo support
* PostgreSQL (for PostGIS plugin support)
- libpq - PostreSQL libraries
- pg_config - PostgreSQL installation capabilities
* libgdal - GDAL/OGR input (For gdal and ogr plugin support) (>= GDAL 2.0.2 for thread safety - https://github.com/mapnik/mapnik/issues/3339)
* libsqlite3 - SQLite input (needs RTree support builtin) (sqlite plugin support)
Instructions for installing many of these dependencies on
various platforms can be found at the Mapnik Wiki:
https://github.com/mapnik/mapnik/wiki/Mapnik-Installation
## Building
The build system uses SCons, a pure python equivalent to autotools or cmake.
We provide a simple Makefile wrapper that can be used like:
./configure && make && make install
For help on what options are accepted do:
./configure --help
To interact with the local copy of scons directly you can do:
python scons/scons.py configure
You can also use a globally installed scons:
scons configure
If you want to clean your build do:
make clean
If you experience odd configure errors, try cleaning the configure caches:
make distclean
To install in a custom location do:
./configure PREFIX=/opt/mapnik
To pass custom CXXFLAGS or LDFLAGS do:
./configure CUSTOM_CXXFLAGS="-g -I/usr/include" CUSTOM_LDFLAGS="-L/usr/lib"
To pass custom paths to a dependency, like boost, do:
./configure BOOST_INCLUDES=/opt/boost/include BOOST_LIBS=/opt/boost/lib
To pass custom paths to a dependency, like icu, do:
./configure ICU_INCLUDES=/usr/local/include ICU_LIBS=/usr/local/include
For more details on usage see:
https://github.com/mapnik/mapnik/wiki/UsingScons
## Testing Installation
You can run the Mapnik tests locally (without installing) like:
make test
## Python Bindings
Python bindings are not included by default. You'll need to add those separately.
* Build from source: https://github.com/mapnik/python-mapnik
## Learning Mapnik
### Help
Mapnik has an active community of talented users and developers making beautiful maps.
If you need help or want to participate starting points include:
- Sign up and post to the mailing list: http://mapnik.org/contact/
- Join and ask questions on the #mapnik channel on irc://irc.freenode.net/mapnik
- Add your help questions to https://github.com/mapnik/mapnik-support
### Cartographers
TileMill, which uses Mapnik internally, offers great step by step tutorials for
learning advanced map styling: http://mapbox.com/tilemill/docs/crashcourse/introduction/
### Programmers
Mapnik is great for building your own mapping applications. Visit
https://github.com/mapnik/mapnik/wiki/LearningMapnik for basic
tutorials on how to programmatically use Mapnik.
### Contributers
Read docs/contributing.md for resources for getting involved with Mapnik development.
Notice: dependencies not met for plugin 'sqlite', not building...
Notice: dependencies not met for plugin 'ogr', not building...
Notice: dependencies not met for plugin 'gdal', not building...
ICU_VERSION="57.1"
BOOST_VERSION="1.73.0"
function install_mason_deps() {
install ccache 3.3.1
install zlib 1.2.8
install jpeg_turbo 1.5.1 libjpeg
install libpng 1.6.28 libpng
install libtiff 4.0.7 libtiff
install libpq 9.6.2
install sqlite 3.17.0 libsqlite3
install expat 2.2.0 libexpat
install icu ${ICU_VERSION}
install proj 4.9.3 libproj
install pixman 0.34.0 libpixman-1
install cairo 1.14.8 libcairo
install webp 0.6.0 libwebp
install libgdal 2.1.3 libgdal
install boost ${BOOST_VERSION}
install boost_libsystem ${BOOST_VERSION}
install boost_libfilesystem ${BOOST_VERSION}
install boost_libprogram_options ${BOOST_VERSION}
install boost_libregex_icu57 ${BOOST_VERSION}
# technically boost thread and python are not a core dep, but installing
# here by default helps make python-mapnik builds easier
install boost_libthread ${BOOST_VERSION}
install boost_libpython ${BOOST_VERSION}
install freetype 2.7.1 libfreetype
install harfbuzz 1.4.4-ft libharfbuzz
}
インストール手順は以下の通りである。テストは省略した。
v3.1.0 tarball をダウンロードしてmapnik-v3.0.24に展開する cd mapnik-v3.0.24 ./configure make install
Mapnikのヘッダファイルは /usr/local/include/mapnik にインストールされた。
プラグインは /usr/local/lib/mapnik/input にインストールされた。
sudo make install としたことが関係しているのか、パーミッションが不適切なため 次のようにして変更した。
sudo chmod -R a=rX,u+w /usr/local/include/mapnik sudo chmod -R a=rX,u+w /usr/local/lib/mapnik/fonts
自作プログラムをコンパイルすると次のエラーとなった。 save_to_stream のプロトタイプ宣言は /usr/local/include/mapnik/image_util.hpp にある。 libmapnik.so は /usr/local/lib にある。
g++ src/render.cpp -g -o bin/render \ > -std=c++14 -L/usr/lib -L/usr/local/lib -I/usr/local/include \ > -I/usr/local/include/mapnik -lmapnik -licuuc -pthread /usr/bin/ld: /tmp/ccbIw9M0.o: in function `Write(int, int, int, int, mapnik::image<mapnik::rgba8_t>*)': /media/sf_gis/src/render.cpp:194: undefined reference to `void mapnik::save_to_stream<mapnik::image<mapnik::rgba8_t> >(mapnik::image<mapnik::rgba8_t> const&, std::ostream&, std::string const&)' /usr/bin/ld: /tmp/ccbIw9M0.o: in function `Initialize(int)': ...`mapnik::datasource_cache::register_datasources(std::string const&, bool)' `mapnik::freetype_engine::register_fonts(std::string const&, bool)' `mapnik::freetype_engine::face_names()' `mapnik::projection::projection(std::string const&, bool)' `mapnik::Map::Map(int, int, std::string const&)' `mapnik::load_map(mapnik::Map&, std::string const&, bool, std::string)'
-lmapnik を省くとエラーが増える。
データベースのデータファイル以外はWindowsとの共有フォルダに置いているため、 Ubuntuをインストールしなおしても、消えることはない。 当面、前回のシステムでコンパイルしたプログラムを使用する。
レンダリングの準備を行う。海岸線データは shp ファイルでダウンロードする。このままでもレンダリングできるが、 高速レンダリングのために、データベースにインポートする。
shp2pgsql -I -s 3857 /media/sf_gisdata/mapnik/world_boundaries/land_polygons land_polygons | psql \ -h localhost -p 5432 -d osm -U postgresexport PROJ_LIB=/usr/share/proj
自作プログラムの実行では環境変数の設定が必要になった。
export PROJ_LIB=/home/hatada/mapnik/mason_packages/linux-x86_64/proj/7.2.1/share/proj
しかし、pngファイルが全く生成されない。
printenv で全ての環境変数が表示される。特定の環境変数は printenv '環境変数名' で表示される。