再上一篇里面写了生成空白图片,现在运行官方demo。
运行的时候会提示proj的错误,然后在mapnik目录下运行.configure检查
显示proj插件并没有安装。。。。
安装proj,直接运行
yum install proj proj-datumgrid proj-devel
[root@d2f7045ea593 mapnik]# yum install proj proj-datumgrid proj-devel
Last metadata expiration check: 1 day, 18:40:13 ago on Mon 08 Apr 2024 12:40:06 PM UTC.
Package proj-6.3.2-4.el8.x86_64 is already installed.
Package proj-datumgrid-1.8-6.3.2.4.el8.noarch is already installed.
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
Installing:
proj-devel x86_64 6.3.2-4.el8 epel 89 k
Transaction Summary
========================================================================================================================
Install 1 Package
Total download size: 89 k
Installed size: 513 k
Is this ok [y/N]: y
Downloading Packages:
proj-devel-6.3.2-4.el8.x86_64.rpm 125 kB/s | 89 kB 00:00
------------------------------------------------------------------------------------------------------------------------
Total 39 kB/s | 89 kB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : proj-devel-6.3.2-4.el8.x86_64 1/1
Running scriptlet: proj-devel-6.3.2-4.el8.x86_64 1/1
Verifying : proj-devel-6.3.2-4.el8.x86_64 1/1
Installed:
proj-devel-6.3.2-4.el8.x86_64
Complete!
安装成功!
但是!!!!!!!有个很坑的点就是,mapnik 3.10版本好像不兼容proj的高版本。
我虽然已经安装完了,但是一直提示找不到proj
最后在官方的issuel里面看到了
试了下:
[root@d2f7045ea593 mapnik]# python3 scons/scons.py configure CUSTOM_DEFINES='-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1'
scons: Reading SConscript files ...
Welcome to Mapnik...
Configuring build environment...
SCons CONFIG found: 'config.py', variables will be inherited...
Configuring on Linux in *release mode*...
Checking for pkg-config... yes
Checking for freetype2... yes
Checking for dlfcn.h support ... yes
Checking if compiler (c++) supports -std=c++14 flag... (cached) yes
Checking for C library z... yes
Checking for C++ library icuuc... yes
Checking for ICU version >= 4.2... found: icu 60.3
(cached) Checking for C++ library harfbuzz... yes
Checking for HarfBuzz version >= 0.9.34... found: HarfBuzz 1.7.5
Checking for HarfBuzz with freetype support
(cached) yes
Searching for boost libs and headers... (cached)
Found boost libs: /usr/local/lib
Found boost headers: /usr/local/include
Checking for C++ header file boost/version.hpp... yes
Checking for Boost version >= 1.61... yes
Found boost lib version... 1_68
Checking for C++ library boost_system... yes
Checking for C++ library boost_filesystem... yes
Checking for C++ library boost_regex... yes
Checking for C++ library boost_program_options... yes
Checking whether Boost was compiled with C++11 scoped enums ... yes
Checking if boost_regex was built with ICU unicode support... (cached) yes
Checking for C library jpeg... yes
Checking for C library proj... yes
Checking for C library png... yes
Checking for C library webp... no
Could not find optional header or shared library for webp
Checking for C library tiff... yes
Checking for PROJ_LIB directory...pj_open_lib returned /usr/lib64/
Detected PROJ_LIB in environ, using env value instead: /usr/lib64
Checking for ICU data directory...icu-config returned b'/usr/share/icu/60.3'
Checking for GDAL data directory...Failed to detect (mapnik-config will have null value)
Checking for requested plugins dependencies...
Checking for gdal-config --libs... error: no result
no
Checking if gdal is ogr enabled... no
Checking for pg_config... yes
Checking for pg_config... yes
Checking for C library sqlite3... yes
Checking if SQLite supports RTREE... (cached) yes
Checking for cairo... yes
Checking for cairo lib and include paths... yes
Checking for cairo freetype font support ... yes
All Required dependencies found!
Overwriting and re-saving file 'config.py'...
Will hold custom path variables from commandline and python config file(s)...
Note: will build without these OPTIONAL dependencies:
- webp (WEBP C library | configure with WEBP_LIBS & WEBP_INCLUDES)
- gdal-config (gdal-config program | try setting GDAL_CONFIG SCons option)
- ogr (OGR-enabled GDAL C++ Library | configured using gdal-config program | try setting GDAL_CONFIG SCons option | more info: https://github.com/mapnik/mapnik/wiki/OGR)
Configure completed: run `make` to build or `make install`
可以看到里面检测proj ok了并且也没有提示之前proj.4的错误。
关于这个命令的参数解释:(3.10分支貌似还没更新兼容proj高版本的代码,但是master分支好像已经兼容了,但是没有版本。。。。,感觉proj6.0以下的版本应该也可以,先试了下这个命令结果成功了就没试6.0之下的版本)
最后就是常规编译,然后install
python3 scons/scons.py && \
python3 scons/scons.py install
然后运行官方demo试试:
在挂载的目录下看下,确实文件已经生成。
关于其它的bug:
如果要连接postgre库需要再安插件。。比如使用mapnik.PostGIS
layer.datasource = mapnik.PostGIS(
host=db_connection['host'],
port=db_connection['port'],
dbname=db_connection['dbname'],
user=db_connection['user'],
password=db_connection['password'],
table='\"GH_TG_TDYTQ\" AS data',
geometry_field='geom' # 假设几何字段为 geom
)
直接下载安装需要的包
[root@d2f7045ea593 mapnik]# yum install sqlite-devel
Last metadata expiration check: 1 day, 14:34:15 ago on Mon 08 Apr 2024 12:40:06 PM UTC.
Dependencies resolved.
========================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================
Installing:
sqlite-devel x86_64 3.26.0-15.el8 baseos 165 k
Installing dependencies:
sqlite x86_64 3.26.0-15.el8 baseos 668 k
Transaction Summary
========================================================================================================================
Install 2 Packages
Total download size: 833 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): sqlite-3.26.0-15.el8.x86_64.rpm 896 kB/s | 668 kB 00:00
(2/2): sqlite-devel-3.26.0-15.el8.x86_64.rpm 209 kB/s | 165 kB 00:00
------------------------------------------------------------------------------------------------------------------------
Total 1.0 MB/s | 833 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : sqlite-3.26.0-15.el8.x86_64 1/2
Installing : sqlite-devel-3.26.0-15.el8.x86_64 2/2
Running scriptlet: sqlite-devel-3.26.0-15.el8.x86_64 2/2
Verifying : sqlite-3.26.0-15.el8.x86_64 1/2
Verifying : sqlite-devel-3.26.0-15.el8.x86_64 2/2
Installed:
sqlite-3.26.0-15.el8.x86_64 sqlite-devel-3.26.0-15.el8.x86_64
Complete!
关于color的设置:
color = mapnik.Color('#f2eff9')
symbolizer = mapnik.PolygonSymbolizer()
symbolizer.stroke = color