Compare commits

..

No commits in common. "master" and "issue-4177" have entirely different histories.

2510 changed files with 70451 additions and 504701 deletions

View file

@ -1,94 +0,0 @@
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: Consecutive
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
# AlwaysBreakAfterReturnType:
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BitFieldColonSpacing: After
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: false # see AllowShortEnumsOnASingleLine
AfterFunction: true # see AllowShortFunctionsOnASingleLine
AfterNamespace: false
AfterStruct: true
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: AfterComma
BreakStringLiterals: true
ColumnLimit: 120
CompactNamespaces: false
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: true
EmptyLineAfterAccessModifier: Leave
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentPPDirectives: None
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
# PackConstructorInitializers: CurrentLine # only clang-format > 14
PointerAlignment: Left
#QualifierAlignment: Left # only clang-format > 14
ReferenceAlignment: Left
ReflowComments: true
SortIncludes: Never
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeInheritanceColon: true
Standard: c++14
BinPackParameters: false
BreakBeforeInheritanceComma: false
IncludeCategories:
# Headers in <> without extension.
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
Priority: 1
# Headers in <> from specific external libraries.
- Regex: '<(boost)\/'
Priority: 2
# Headers in <> from specific external libraries.
- Regex: '<(mapnik)\/'
Priority: 3
# Headers in <> with extension.
- Regex: '<([A-Za-z0-9.\Q/-_\E])+>'
Priority: 4
# Headers in "" with extension.
- Regex: '"([A-Za-z0-9.\Q/-_\E])+"'
Priority: 5

1
.gitattributes vendored
View file

@ -1,2 +1 @@
*.svg text eol=lf *.svg text eol=lf
scons/** linguist-vendored

View file

@ -1,85 +0,0 @@
name: Run tests with coverage
description: Runs all mapnik tests with coverage
inputs:
cmake-preset:
description: The used CMake preset
required: true
runs:
using: composite
steps:
- name: Set PROJ_LIB
shell: bash
run: |
cmake --preset ${{ inputs.cmake-preset }} -N -L | grep -o "PROJ_LIB=.*" >> ${GITHUB_ENV}
- name: Set TEST_WRAPPER (Windows)
if: runner.os == 'Windows'
shell: bash
run: |-
echo "TEST_WRAPPER=OpenCppCoverage \
--cover_children \
--export_type binary \
--modules '*.input' \
--modules '*libmapnik*' \
--modules 'mapnik*.exe' \
--quiet \
--sources '${{ github.workspace }}' \
--" >> ${GITHUB_ENV}
- name: Test
shell: bash
env:
UPDATE: 1
run: |
${TEST_WRAPPER:-} ctest --preset ${{ inputs.cmake-preset }}
- name: Test visuals
continue-on-error: true
working-directory: build/out
shell: bash
run: |
${TEST_WRAPPER:-} ./mapnik-test-visual -j ${CTEST_PARALLEL_LEVEL} --output-dir visual-test-result
- name: Pack visual test results
working-directory: build/out
shell: bash
run: |
tar -vzcf visual-test-results.tar.gz visual-test-result
- name: Upload visual test results
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.cmake-preset }}-visual-tests-${{ github.sha }}
path: build/out/visual-test-results.tar.gz
- name: Run Benchmarks (Linux & macOS)
working-directory: build/out
if: runner.os != 'Windows'
shell: bash
run: |
./run_benchmarks
- name: Collect coverage (Linux & macOS)
working-directory: build
if: runner.os != 'Windows'
shell: bash
run: |
if [ "${RUNNER_OS}" == "macOS" ]; then
LCOV_EXTRA_OPTIONS="--ignore-errors count,gcov,inconsistent,range,unused --keep-going"
fi
lcov ${LCOV_EXTRA_OPTIONS:-} --directory . --capture --output-file coverage.info
lcov ${LCOV_EXTRA_OPTIONS:-} --remove coverage.info '/usr/*' '*/vcpkg_installed/*' '/.cache/*' '*/test/*' --output-file coverage.info
lcov ${LCOV_EXTRA_OPTIONS:-} --list coverage.info
- name: Upload coverage to Codecov (Linux & macOS)
if: runner.os != 'Windows'
uses: codecov/codecov-action@v4
with:
files: build/coverage.info
- name: Upload coverage to Codecov (Windows)
if: runner.os == 'Windows'
uses: codecov/codecov-action@v4
with:
files: ctest.cov,build/out/mapnik-test-visual.cov

View file

@ -1,136 +0,0 @@
name: Build and Test
on:
push:
branches:
- "*"
pull_request:
branches-ignore:
- "no-ci-*"
env:
VCPKG_BINARY_SOURCES: clear;x-gha,readwrite
VCPKG_RELEASE: 2024.06.15
jobs:
checkSource:
name: Check Source Code
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: pre-commit/action@v3.0.1
buildAndTest:
name: >-
Build & Test
(${{ matrix.os }})
(C++ ${{ matrix.cxx-standard }})
${{ startsWith(matrix.os, 'macos-') && (matrix.os == 'macos-14' && '(ARM64)' || '(AMD64)') || '' }}
needs: checkSource
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-14
- ubuntu-22.04
- windows-2022
cxx-standard:
- 17
steps:
- name: Checkout Mapnik
uses: actions/checkout@v4
with:
submodules: recursive
- name: Checkout vcpkg
uses: actions/checkout@v4
with:
path: vcpkg
ref: ${{ env.VCPKG_RELEASE }}
repository: microsoft/vcpkg
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install required system packages
shell: bash
run: |
if [ "${RUNNER_OS}" == "Linux" ]; then
sudo apt-get update
sudo apt-get -y install \
autoconf \
autoconf-archive \
automake \
gperf \
lcov \
libxxf86vm-dev \
ninja-build \
postgresql-client
elif [ "${RUNNER_OS}" == "macOS" ]; then
brew install \
autoconf \
autoconf-archive \
automake \
lcov \
libtool \
ninja \
vcpkg
elif [ "${RUNNER_OS}" == "Windows" ]; then
choco install \
ninja \
OpenCppCoverage
echo "C:\Program Files\OpenCppCoverage" >> ${GITHUB_PATH}
fi
- name: Enable Developer Command Prompt (Windows)
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
- name: Set CMAKE_BUILD_PARALLEL_LEVEL, CTEST_PARALLEL_LEVEL & PRESET
shell: bash
run: |
PRESET=$(echo "${RUNNER_OS}" | perl -ne "print lc")-ci
if [ "${RUNNER_OS}" == "Linux" ]; then
echo "CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)" >> ${GITHUB_ENV}
echo "CTEST_PARALLEL_LEVEL=$(nproc)" >> ${GITHUB_ENV}
elif [ "${RUNNER_OS}" == "macOS" ]; then
echo "CMAKE_BUILD_PARALLEL_LEVEL=$(sysctl -n hw.logicalcpu)" >> ${GITHUB_ENV}
echo "CTEST_PARALLEL_LEVEL=$(sysctl -n hw.logicalcpu)" >> ${GITHUB_ENV}
PRESET=${PRESET}-${{ matrix.os == 'macos-14' && 'arm64' || 'x64' }}
elif [ "${RUNNER_OS}" == "Windows" ]; then
echo "CMAKE_BUILD_PARALLEL_LEVEL=$(pwsh -Command '(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors')" >> ${GITHUB_ENV}
echo "CTEST_PARALLEL_LEVEL=$(pwsh -Command '(Get-CimInstance -ClassName Win32_ComputerSystem).NumberOfLogicalProcessors')" >> ${GITHUB_ENV}
fi
echo "PRESET=${PRESET}" >> ${GITHUB_ENV}
- name: Configure CMake
shell: bash
run: |
cmake \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DCMAKE_CXX_STANDARD:STRING=${{ matrix.cxx-standard }} \
-DUSE_MEMORY_MAPPED_FILE:BOOL=ON \
-LA \
--preset ${PRESET}
- name: Build
shell: bash
run: |
cmake \
--build \
--preset ${PRESET}
- name: Run Tests
uses: ./.github/actions/run_tests
with:
cmake-preset: ${{ env.PRESET }}

View file

@ -1,55 +0,0 @@
name: Release Linux
on:
push:
branches:
- "*"
pull_request:
branches-ignore:
- "no-ci-*"
env:
PRESET: linux-ci-release
jobs:
build:
runs-on: "ubuntu-22.04"
steps:
- name: checkout mapnik
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: "Install required system packages"
shell: bash
run: |
sudo apt update
sudo apt install -y ninja-build\
libicu-dev \
libfreetype6-dev \
libharfbuzz-dev \
libxml2-dev \
libjpeg-dev \
libtiff-dev \
libwebp-dev \
libcairo2-dev \
libproj-dev \
libgdal-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-regex-dev
- name: Configure CMake
run: cmake -LA --preset ${{ env.PRESET }}
- name: Build
run: cmake --build --preset ${{ env.PRESET }}
- name: Package
run: cmake --build --preset ${{ env.PRESET }} --target package
- name: Upload mapnik debian package
uses: actions/upload-artifact@v4
with:
name: ${{ env.PRESET }}-deb
path: build/mapnik-*.deb

7
.gitignore vendored
View file

@ -1,6 +1,4 @@
.DS_Store .DS_Store
.vscode
.cache
*.gcov *.gcov
*.gcda *.gcda
*.gcno *.gcno
@ -58,8 +56,3 @@ demo/viewer/ui_layer_info.h
test/standalone/*-bin test/standalone/*-bin
test/unit/run test/unit/run
test/visual/run test/visual/run
# cmake
build
.vs
CMakeUserPresets.json

View file

@ -1,16 +0,0 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
files: ^.*\.cmake|CMakeLists\.txt$
- id: end-of-file-fixer
files: ^.*\.cmake|CMakeLists\.txt$
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.3
hooks:
- id: clang-format
types_or: [c++, c]

111
.travis.yml Normal file
View file

@ -0,0 +1,111 @@
language: generic
git:
depth: 10
submodules: false
env:
global:
- CCACHE_TEMPDIR=/tmp/.ccache-temp
- CCACHE_COMPRESS=1
- PREFIX=/tmp/mapnik
- secure: "F6ivqDNMBQQnrDGA9+7IX+GDswuIqQQd7YPJdQqa2Ked9jddAQDeJClb05ig3JlwfOlYLGZOd43ZX0pKuMtI2Gbkwz211agGP9S3YunwlRg8iWtJlO5kYFUdKCmJNhjg4icfkGELCgwXn+zuEWFSLpkPcjqAFKFlQrIJeAJJgKM="
cache:
directories:
- $HOME/.ccache
dist: trusty
sudo: false
matrix:
include:
- os: linux
name: Linux gcc-6
env: >-
CXX="ccache g++-6"
CC="gcc-6"
addons:
postgresql: "9.5"
apt:
sources: [ 'ubuntu-toolchain-r-test']
packages: [ 'libstdc++-6-dev', 'g++-6', 'xutils-dev', 'postgresql-9.5-postgis-2.3' ]
- os: linux
name: Linux clang-3.9
env: >-
CXX="ccache clang++-3.9 -Qunused-arguments"
CC="clang-3.9"
ENABLE_GLIBC_WORKAROUND=true
before_install:
- export LINKFLAGS="-fuse-ld=gold-2.26"
addons:
postgresql: "9.5"
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'clang-3.9', 'libstdc++-4.9-dev', 'xutils-dev', 'postgresql-9.5-postgis-2.3' ]
- os: linux
name: Linux clang-3.9 + coverage
env: >-
CXX="ccache clang++-3.9 -Qunused-arguments"
CC="clang-3.9"
COVERAGE=true
QUIET=true
before_install:
- export LINKFLAGS="-fuse-ld=gold-2.26"
- export LLVM_COV="llvm-cov-3.9"
addons:
postgresql: "9.5"
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'clang-3.9', 'llvm-3.9', 'libstdc++-4.9-dev', 'xutils-dev', 'postgresql-9.5-postgis-2.3' ]
- os: osx
name: OSX clang
# https://docs.travis-ci.com/user/languages/objective-c/#Supported-OS-X-iOS-SDK-versions
osx_image: xcode7.3 # upgrades clang from 6 -> 7
env: >-
CXX="ccache clang++ -Qunused-arguments"
install:
- source scripts/travis-common.sh
# workaround travis rvm bug
# http://superuser.com/questions/1044130/why-am-i-having-how-can-i-fix-this-error-shell-session-update-command-not-f
- on 'osx' rvm get head || true
- export PATH=${PREFIX}/bin:$(pwd)/mason_packages/.link/bin:${PATH}
- export COVERAGE=${COVERAGE:-false}
- export BENCH=${BENCH:-false}
- on 'osx' export DATA_PATH=$(brew --prefix)/var/postgres
- on 'osx' rm -rf ${DATA_PATH}
- on 'osx' initdb ${DATA_PATH} -E utf8
- on 'osx' pg_ctl -w start -l postgres.log --pgdata ${DATA_PATH};
- on 'osx' cat postgres.log;
- on 'osx' createuser -s postgres
- psql -c 'create database template_postgis;' -U postgres
- psql -c 'create extension postgis;' -d template_postgis -U postgres
- enabled ${COVERAGE} curl -S -f https://codecov.io/bash -o codecov
- enabled ${COVERAGE} chmod +x codecov
before_script:
- export JOBS=${JOBS:-4}
- export HEAVY_JOBS=${HEAVY_JOBS:-2}
- export SCONSFLAGS='--debug=time'
- source bootstrap.sh
- ccache --version
- ccache -p || true
- ccache --show-stats || true
- commit_message_parse
script:
- git_submodule_update --init deps/
- configure BENCHMARK=${BENCH} ENABLE_GLIBC_WORKAROUND=${ENABLE_GLIBC_WORKAROUND:-false} QUIET=${QUIET:-false}
#- cat config.log => comment out to reduce log size limit on travis-ci
# we limit the `make` to 40 min
# to ensure that slow builds still upload their
# ccache results and therefore should be faster
# (and might work) for the next build
- DEADLINE=$(( $(date +%s) + 40 * 60 ))
- scripts/travis-command-wrapper.py -s "date" -i 120 --deadline="$DEADLINE" make
- test_ok && git_submodule_update --init --depth=50 test/
- test_ok && make test
- test_ok && enabled ${COVERAGE} coverage
- test_ok && enabled ${BENCH} make bench
- ./scripts/check_glibcxx.sh

View file

@ -6,44 +6,12 @@ Developers: Please commit along with changes.
For a complete change history, see the git log. For a complete change history, see the git log.
## Mapnik 4.0.3
Released October 30th, 2024 ## UNRELEASED
(Packaged from [05389e3c7](https://github.com/mapnik/mapnik/commit/05389e3c7))
- Remove 'final' specifier from invalid_featureset implementation
(issues with dynamic_cast<> when building using Apple clang version 16.0.0 on darwin-arm64)
- Rename invalid_featureset to empty_featureset
- Upgrade to SCons v4.8.1
- Fix unit tests e.g #endif statement (via @bgardner-noggin)
## Mapnik 4.0.2
Released August 21st, 2024
- CMake build - set `SOVERSION` to `${MAPNIK_MAJOR_VERSION}.${MAPNIK_MINOR_VERSION}`
- Upgraded SCons build system to v4.8.0
## Mapnik 4.0.1
- Use CMAKE_INSTALL_LIBDIR for libdir in pkg-config files
- Support gcc 14
- Improved accuracy of bounding box re-projections. Automatic spliting at (0, 0) and merging results.
- Fixes missing features when using WGS 84 / Arctic Polar Stereographic (`epsg:4326 <-> epsg:3995`)
- Added `area_of_use` method to `mapnik::projection`
## Mapnik 4.0.0
#### Notice #### Notice
- Mapnik now requires C++17 compliant compiler (`-std=c++17`) - Mapnik now requires C++14 compliant compiler (`-std=c++14`)
- Mapnik now supports CMake as a build system. See [#4191](https://github.com/mapnik/mapnik/pull/4191) and the [docs](https://github.com/mapnik/mapnik/blob/master/docs/cmake-usage.md) for more info.
#### Breaking Changes
- Reworked datasource plugin system. Plugins now need to implement a class with the macros in `datasource_plugin.hpp` ([#4291](https://github.com/mapnik/mapnik/pull/4291))
- mapnik now has a global `mapnik::setup()` method which have to be called before any other functions of mapnik. Defined in `mapnik.hpp`. Currently there is a auto setup functionality. It can be disabled using the cmake option `DISABLE_MAPNIK_AUTOSETUP=ON`. Note: In order not to insert this change into every code base, it is currently still called during the dynamic initialisation time. However, if mapnik is compiled statically, this function must be called. ([#4291](https://github.com/mapnik/mapnik/pull/4291))
#### Core #### Core
@ -59,8 +27,6 @@ Released August 21st, 2024
- Slightly improved `sql_utils::table_from_sql` ([2587bb3](https://github.com/mapnik/mapnik/commit/2587bb3a1d8db397acfa8dcc2d332da3a8a9399f)) - Slightly improved `sql_utils::table_from_sql` ([2587bb3](https://github.com/mapnik/mapnik/commit/2587bb3a1d8db397acfa8dcc2d332da3a8a9399f))
- Added wrappers for proper quoting in SQL query construction: `sql_utils::identifier`, `sql_utils::literal` ([7b21713](https://github.com/mapnik/mapnik/commit/7b217133e2749b82c2638551045c4edbece15086)) - Added wrappers for proper quoting in SQL query construction: `sql_utils::identifier`, `sql_utils::literal` ([7b21713](https://github.com/mapnik/mapnik/commit/7b217133e2749b82c2638551045c4edbece15086))
- Added two-argument `sql_utils::unquote`, `sql_utils::unquote_copy` that also collapse inner quotes ([a4e8ea2](https://github.com/mapnik/mapnik/commit/a4e8ea21be297d89bbf36ba594d6c661a7a9ac81)) - Added two-argument `sql_utils::unquote`, `sql_utils::unquote_copy` that also collapse inner quotes ([a4e8ea2](https://github.com/mapnik/mapnik/commit/a4e8ea21be297d89bbf36ba594d6c661a7a9ac81))
- Fixed mapnik static build with static plugins ([#4291](https://github.com/mapnik/mapnik/pull/4291))
- Reworked mapnik::enumeration<...> ([#4372](https://github.com/mapnik/mapnik/pull/4372))
#### Plugins #### Plugins

View file

@ -1,34 +0,0 @@
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: mapnik
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Artem
family-names: Pavlenko
identifiers:
- type: url
value: 'https://github.com/mapnik/mapnik'
description: GitHub Repository
- type: swh
value: >-
swh:1:dir:3f5758e17e9d54016ca694268da68cf6856fab58
description: Software Archive
repository-code: 'https://github.com/mapnik/mapnik'
url: 'https://mapnik.org/'
abstract: >-
Mapnik is an open source toolkit for developing
mapping applications. At the core is a C++ shared
library providing algorithms and patterns for
spatial data access and visualization.
keywords:
- mapping
- gis
- cartography
- beautiful-maps
- rendering
license: LGPL-2.1

View file

@ -1,472 +0,0 @@
cmake_minimum_required(VERSION 3.15)
# 3.15 is required since the Boost::XXXX targets was first added. https://cmake.org/cmake/help/latest/module/FindBoost.html#imported-targets
# 3.14 is required since SQLite3 Module was first added. https://cmake.org/cmake/help/latest/module/FindSQLite3.html#findsqlite3
include(cmake/GetVersion.cmake)
get_mapnik_version()
project(mapnik
VERSION ${MAPNIK_MAJOR_VERSION}.${MAPNIK_MINOR_VERSION}.${MAPNIK_PATCH_VERSION}
HOMEPAGE_URL "https://mapnik.org/"
DESCRIPTION "Mapnik is an open source toolkit for developing mapping applications"
LANGUAGES CXX
)
message(STATUS "mapnik version: ${PROJECT_VERSION}")
# https://cliutils.gitlab.io/modern-cmake/chapters/features/ides.html
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL ON) # with newer cmake versions put all find_package in global scope
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(FeatureSummary)
include(MapnikOption)
include(MapnikMinimumVersions)
include(MapnikFindPackage)
include(MapnikInstall)
include(CTest)
add_feature_info(BUILD_TESTING BUILD_TESTING "Adds tests")
mapnik_option(INSTALL_DEPENDENCIES "if ON, all dependencies (eg. required dlls) will be copied into CMAKE_INSTALL_PREFIX/MAPNIK_BIN_DIR." ON)
mapnik_option(BUILD_SHARED_LIBS "build mapnik dynamic(ON) or static(OFF)" ON)
mapnik_option(BUILD_SHARED_PLUGINS "build dynamic plugins" ${BUILD_SHARED_LIBS}) # use BUILD_SHARED_LIBS as default option
mapnik_option(BUILD_SHARED_CRT "(only windows with msvc) use msvc shared crt" ON)
if(WIN32 AND BUILD_SHARED_PLUGINS AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "static libmapnik and dynamic plugins won't work correctly")
endif()
mapnik_option(USE_EXTERNAL_MAPBOX_GEOMETRY "Use a external mapnik/geometry.hpp. If off, use the submodule" OFF)
mapnik_option(USE_EXTERNAL_MAPBOX_POLYLABEL "Use a external mapnik/polylabel. If off, use the submodule" OFF)
mapnik_option(USE_EXTERNAL_MAPBOX_PROTOZERO "Use a external mapnik/protozero. If off, use the submodule" OFF)
mapnik_option(USE_EXTERNAL_MAPBOX_VARIANT "Use a external mapnik/variant. If off, use the submodule" OFF)
mapnik_option(USE_JPEG "adds jpeg support" ON)
mapnik_option(USE_PNG "adds png support" ON)
mapnik_option(USE_TIFF "adds tiff support" ON)
mapnik_option(USE_WEBP "adds webp support" ON)
mapnik_option(USE_LIBXML2 "adds libxml2 support" ON)
mapnik_option(USE_CAIRO "adds the cairo renderer" ON)
mapnik_option(USE_PROJ "adds proj support" ON)
mapnik_option(USE_GRID_RENDERER "adds grid renderer" ON)
mapnik_option(USE_SVG_RENDERER "adds svg renderer" ON)
mapnik_option(USE_BIGINT "uses 64 bit instead of 32" ON)
mapnik_option(USE_BOOST_FILESYSTEM "use boost::filesytem even if `std::filesystem` is available (since c++17)" OFF)
mapnik_option(USE_MEMORY_MAPPED_FILE "uses file cache" ON)
mapnik_option(USE_MULTITHREADED "enables the multithreaded features (threadsafe)" ON)
mapnik_option(USE_NO_ATEXIT "disable atexit" OFF)
mapnik_option(USE_NO_DLCLOSE "disable dlclose" OFF)
mapnik_option(USE_DEBUG_OUTPUT "enables some debug messages for development" OFF)
mapnik_option(USE_LOG "enables logging output. See log severity level." OFF)
# 0 = debug
# 1 = warn
# 2 = error
# 3 = none
set(USE_LOG_SEVERITY "1" CACHE STRING "sets the logging severity (only applies when USE_LOG is ON")
mapnik_option(USE_STATS "Enable statistics reporting" OFF)
mapnik_option(DISABLE_MAPNIK_AUTOSETUP "disables the autosetup. Need to call mapnik::setup() then" OFF)
mapnik_option(USE_PLUGIN_INPUT_CSV "adds plugin input csv" ON)
mapnik_option(USE_PLUGIN_INPUT_GDAL "adds plugin input gdal" ON)
mapnik_option(USE_PLUGIN_INPUT_GEOBUF "adds plugin input geobuf" ON)
mapnik_option(USE_PLUGIN_INPUT_GEOJSON "adds plugin input geojson" ON)
mapnik_option(USE_PLUGIN_INPUT_OGR "adds plugin input ogr" ON)
mapnik_option(USE_PLUGIN_INPUT_PGRASTER "adds plugin input pgraster" ON)
mapnik_option(USE_PLUGIN_INPUT_POSTGIS "adds plugin input postgis" ON)
mapnik_option(USE_PLUGIN_INPUT_RASTER "adds plugin input raster" ON)
mapnik_option(USE_PLUGIN_INPUT_SHAPE "adds plugin input shape" ON)
mapnik_option(USE_PLUGIN_INPUT_SQLITE "adds plugin input sqlite" ON)
mapnik_option(USE_PLUGIN_INPUT_TOPOJSON "adds plugin input topojson" ON)
mapnik_option(BUILD_DEMO_VIEWER "builds the demo viewer" ON)
mapnik_option(BUILD_DEMO_CPP "builds the demo c++ application" ON)
mapnik_option(BUILD_BENCHMARK "builds benchmark project" ON)
mapnik_option(BUILD_UTILITY_GEOMETRY_TO_WKB "builds the utility program geometry_to_wkb" ON)
mapnik_option(BUILD_UTILITY_MAPNIK_INDEX "builds the utility program mapnik_index" ON)
mapnik_option(BUILD_UTILITY_MAPNIK_RENDER "builds the utility program mapnik_render" ON)
mapnik_option(BUILD_UTILITY_OGRINDEX "builds the utility program ogrindex" OFF)
mapnik_option(BUILD_UTILITY_PGSQL2SQLITE "builds the utility program pgsql2sqlite" ON)
mapnik_option(BUILD_UTILITY_SHAPEINDEX "builds the utility program shapeindex" ON)
mapnik_option(BUILD_UTILITY_SVG2PNG "builds the utility program svg2png" ON)
mapnik_option(USE_BOOST_REGEX_ICU_WORKAROUND "if you don't use your system libraries and get double linked icu libraries set this to ON" OFF)
mapnik_option(USE_GLIBC_WORKAROUND "see https://github.com/mapnik/mapnik/pull/3792 if you building with libstdc++-4.9" OFF)
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES)
feature_summary(FILENAME "${CMAKE_CURRENT_BINARY_DIR}/features.log" WHAT ENABLED_FEATURES DISABLED_FEATURES)
include(GNUInstallDirs)
# See for more details: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html
set(MAPNIK_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE STRING "Install directory for binaries")
set(MAPNIK_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Install directory for libraries")
set(MAPNIK_ARCHIVE_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Install directory for archives")
set(MAPNIK_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Install directory for the headers")
set(MAPNIK_CMAKE_DIR ${MAPNIK_LIB_DIR}/cmake/mapnik CACHE STRING "Install directory of the cmake targets")
set(MAPNIK_PKGCONF_DIR ${MAPNIK_LIB_DIR}/pkgconfig CACHE STRING "Install directory for the .pc files for pkg-config")
set(MAPNIK_OUTPUT_DIR "${CMAKE_BINARY_DIR}/out")
if(WIN32)
set(DEFAULT_PLUGINS_INSTALL_DIR ${MAPNIK_BIN_DIR}/mapnik/input)
else()
set(DEFAULT_PLUGINS_INSTALL_DIR ${MAPNIK_LIB_DIR}/mapnik/input)
endif()
set(PLUGINS_INSTALL_DIR ${DEFAULT_PLUGINS_INSTALL_DIR} CACHE STRING "installs the plugins in the specified directory")
message(STATUS "Installing plugins to ${PLUGINS_INSTALL_DIR}")
set(FONTS_INSTALL_DIR ${MAPNIK_LIB_DIR}/mapnik/fonts CACHE STRING "installs the fonts in the specified directory")
message(STATUS "Installing fonts to ${FONTS_INSTALL_DIR}")
set(MAPNIK_COMPILE_DEFS "")
set(MAPNIK_OPTIONAL_LIBS "")
set(MAPNIK_OPTIONAL_LIBS_INCLUDE "")
#############################
#############################
# Begin project configuration
#############################
#############################
set(CMAKE_CXX_STANDARD 17 CACHE STRING "Sets the c++ standard. c++17 is minimum.")
set(CMAKE_CXX_STANDARD_REQUIRED ON) # require the specified CMAKE_CXX_STANDARD
set(CMAKE_CXX_EXTENSIONS OFF CACHE STRING "Enables the compiler specific extensions.") # Fallsback to -std=c++<ver> if off
message(STATUS "Using c++${CMAKE_CXX_STANDARD}")
message(STATUS "Using c++ extensions: ${CXX_EXTENSIONS}")
# add debug postfix to the libraries
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "sets the debug library postfix on mapnik, wkt and json")
message(STATUS "postfix for debug libraries: ${CMAKE_DEBUG_POSTFIX}")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${BUILD_SHARED_CRT}>:DLL>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${MAPNIK_OUTPUT_DIR}/lib")
# needs to be before the first call of find_boost.
if(CMAKE_CXX_STANDARD VERSION_LESS 17)
list(APPEND MAPNIK_COMPILE_DEFS BOOST_SPIRIT_X3_HIDE_CXX17_WARNING)
endif()
if(USE_MULTITHREADED)
set(Boost_USE_MULTITHREADED ON)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_THREADSAFE)
else()
set(Boost_USE_MULTITHREADED OFF)
endif()
mapnik_find_package(PkgConfig REQUIRED)
mapnik_find_threads()
mapnik_find_package(ICU REQUIRED COMPONENTS uc i18n data)
mapnik_find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS regex)
if(CMAKE_CXX_STANDARD VERSION_LESS 17)
set(USE_BOOST_FILESYSTEM ON CACHE BOOL "Use boost::filesystem" FORCE)
endif()
if(USE_BOOST_FILESYSTEM)
mapnik_find_package(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS filesystem system)
endif()
list(APPEND MAPNIK_COMPILE_DEFS BOOST_REGEX_HAS_ICU)
if(USE_BOOST_REGEX_ICU_WORKAROUND)
message(STATUS "using boost regex workaround")
set_property(TARGET Boost::regex PROPERTY INTERFACE_LINK_LIBRARIES)
endif()
include(CheckBoostRegexIcu)
check_boost_regex()
if(BOOST_REGEX_HAS_ICU)
message(STATUS "boost regex has icu support")
list(APPEND MAPNIK_COMPILE_DEFS BOOST_REGEX_HAS_ICU)
endif()
mapnik_find_package(Freetype REQUIRED)
# try to find harfbuzz with the native configuration and fallback to our "own" FindHarfBuzz
mapnik_find_package(harfbuzz CONFIG QUIET)
if(harfbuzz_FOUND)
message(STATUS "Found harfbuzz native cmake")
list(APPEND MAPNIK_OPTIONAL_LIBS harfbuzz::harfbuzz)
else()
# Use pkg-config when harfbuzz is not found.
# It might be possible that in future version harfbuzz could only be found via pkg-config.
# harfbuzz related discussion: https://github.com/harfbuzz/harfbuzz/issues/2653
message(STATUS "harfbuzz not found via cmake. Searching via pkg-config...")
mapnik_pkg_check_modules(harfbuzz REQUIRED IMPORTED_TARGET harfbuzz>=${HARFBUZZ_MIN_VERSION})
list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::harfbuzz)
endif()
if(USE_EXTERNAL_MAPBOX_GEOMETRY)
# this is used to provide a way to specify include dirs with CACHE VARIABLES
if(NOT MAPBOX_GEOMETRY_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/geometry.hpp")
find_path(MAPBOX_GEOMETRY_INCLUDE_DIRS "mapbox/geometry.hpp" REQUIRED)
endif()
else()
set(MAPBOX_GEOMETRY_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/geometry/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(NOT MAPBOX_GEOMETRY_INCLUDE_DIRS)
message(FATAL_ERROR "Set -DMAPBOX_GEOMETRY_INCLUDE_DIRS to the mapbox/geometry.hpp include dir")
endif()
if(USE_EXTERNAL_MAPBOX_POLYLABEL)
if(NOT MAPBOX_POLYLABEL_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/polylabel")
find_path(MAPBOX_POLYLABEL_INCLUDE_DIRS "mapbox/polylabel.hpp")
endif()
else()
set(MAPBOX_POLYLABEL_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/polylabel/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(NOT MAPBOX_POLYLABEL_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_POLYLABEL_INCLUDE_DIRS to the mapbox/geometry include dir")
endif()
if(USE_EXTERNAL_MAPBOX_PROTOZERO)
if(NOT MAPBOX_PROTOZERO_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/protozero")
find_path(MAPBOX_PROTOZERO_INCLUDE_DIRS "protozero/pbf_message.hpp")
endif()
else()
set(MAPBOX_PROTOZERO_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/protozero/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(NOT MAPBOX_PROTOZERO_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_PROTOZERO_INCLUDE_DIRS to the mapbox/protozero include dir")
endif()
if(USE_EXTERNAL_MAPBOX_VARIANT)
if(NOT MAPBOX_VARIANT_INCLUDE_DIRS)
message(STATUS "Searching for the include dir of mapbox/variant")
find_path(MAPBOX_VARIANT_INCLUDE_DIRS "mapbox/variant.hpp")
endif()
else()
set(MAPBOX_VARIANT_INCLUDE_DIRS
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/variant/include>
$<INSTALL_INTERFACE:include>
)
endif()
if(NOT MAPBOX_VARIANT_INCLUDE_DIRS)
message(FATAL_ERROR "Set MAPBOX_VARIANT_INCLUDE_DIRS to the mapbox/variant include dir")
endif()
# (used by MapnikInstall.cmake. properties are needed since "set(...)" will be out of scope
set_property(GLOBAL PROPERTY TARGETS "")
set_property(GLOBAL PROPERTY PLUGINS "")
set_property(GLOBAL PROPERTY MAPNIK_UTILITIES "")
if(USE_GLIBC_WORKAROUND)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_ENABLE_GLIBC_WORKAROUND)
endif()
if(USE_BIGINT)
list(APPEND MAPNIK_COMPILE_DEFS BIGINT)
endif()
if(USE_BOOST_FILESYSTEM)
list(APPEND MAPNIK_COMPILE_DEFS USE_BOOST_FILESYSTEM)
list(APPEND MAPNIK_OPTIONAL_LIBS Boost::filesystem)
endif()
if(USE_MEMORY_MAPPED_FILE)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_MEMORY_MAPPED_FILE)
endif()
if(USE_NO_ATEXIT)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_NO_ATEXIT)
endif()
if(USE_NO_DLCLOSE)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_NO_DLCLOSE)
endif()
if(USE_DEBUG_OUTPUT)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_DEBUG)
endif()
if(USE_LOG)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_LOG MAPNIK_DEFAULT_LOG_SEVERITY=${USE_LOG_SEVERITY})
endif()
if(USE_STATS)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_STATS)
endif()
if(USE_LIBXML2)
mapnik_find_package(LibXml2 REQUIRED)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_LIBXML2)
list(APPEND MAPNIK_OPTIONAL_LIBS LibXml2::LibXml2)
endif()
if(USE_PNG)
mapnik_find_package(PNG REQUIRED)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_PNG)
list(APPEND MAPNIK_OPTIONAL_LIBS PNG::PNG)
endif()
if(USE_JPEG)
mapnik_find_package(JPEG REQUIRED)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_JPEG)
list(APPEND MAPNIK_OPTIONAL_LIBS JPEG::JPEG)
endif()
if(USE_TIFF)
mapnik_find_package(TIFF REQUIRED)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_TIFF)
list(APPEND MAPNIK_OPTIONAL_LIBS TIFF::TIFF)
endif()
if(USE_WEBP)
mapnik_pkg_check_modules(WebP REQUIRED IMPORTED_TARGET libwebp)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_WEBP)
list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::WebP)
endif()
if(USE_CAIRO)
mapnik_pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo)
list(APPEND MAPNIK_COMPILE_DEFS HAVE_CAIRO)
list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::Cairo)
endif()
if(USE_PROJ)
#https://proj.org/development/cmake.html
mapnik_find_package(PROJ QUIET)
# currently the cmake files are not installed, when installing proj via apt-get. So search via pkg-config
if(NOT PROJ_FOUND)
message(STATUS "PROJ not found via FindPROJ. Searching via pkg-config...")
mapnik_pkg_check_modules(PROJ REQUIRED IMPORTED_TARGET proj>=${PROJ_MIN_VERSION})
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" _dummy "${PROJ_VERSION}")
set(PROJ_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(PROJ_VERSION_MINOR "${CMAKE_MATCH_2}")
set(PROJ_VERSION_PATCH "${CMAKE_MATCH_3}")
list(APPEND MAPNIK_OPTIONAL_LIBS PkgConfig::PROJ)
else()
if(PROJ_VERSION VERSION_LESS PROJ_MIN_VERSION)
message(FATAL_ERROR "Proj needs to be at least version ${PROJ_MIN_VERSION}")
endif()
list(APPEND MAPNIK_OPTIONAL_LIBS ${PROJ_LIBRARIES})
list(APPEND MAPNIK_OPTIONAL_LIBS_INCLUDE $<BUILD_INTERFACE:${PROJ_INCLUDE_DIRS}>)
endif()
math(EXPR MAPNIK_PROJ_VERSION "${PROJ_VERSION_MAJOR}*10000 + ${PROJ_VERSION_MINOR}*100 + ${PROJ_VERSION_PATCH}" OUTPUT_FORMAT DECIMAL)
message(STATUS "Using mapnik PROJ version: ${MAPNIK_PROJ_VERSION}")
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_USE_PROJ MAPNIK_PROJ_VERSION=${MAPNIK_PROJ_VERSION})
endif()
if(USE_GRID_RENDERER)
list(APPEND MAPNIK_COMPILE_DEFS GRID_RENDERER)
endif()
if(USE_SVG_RENDERER)
list(APPEND MAPNIK_COMPILE_DEFS SVG_RENDERER)
endif()
if(NOT WIN32)
message(STATUS "Compiling with -DMAPNIK_HAS_DLCFN")
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_HAS_DLCFN)
list(APPEND MAPNIK_OPTIONAL_LIBS ${CMAKE_DL_LIBS})
endif()
if(NOT BUILD_SHARED_PLUGINS)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_STATIC_PLUGINS)
endif()
# when building static, this have to be public so that all depending libs know about
if(NOT BUILD_SHARED_LIBS)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_STATIC_DEFINE)
endif()
if(DISABLE_MAPNIK_AUTOSETUP)
list(APPEND MAPNIK_COMPILE_DEFS MAPNIK_DISABLE_AUTOSETUP)
endif()
# force utf-8 source code processing
# see https://docs.microsoft.com/de-de/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
add_compile_options(
"$<$<CXX_COMPILER_ID:MSVC>:/utf-8>"
"$<$<CXX_COMPILER_ID:MSVC>:/EHsc>"
)
add_library(core INTERFACE)
add_library(mapnik::core ALIAS core)
target_include_directories(core INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${MAPBOX_GEOMETRY_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_POLYLABEL_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_VARIANT_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${MAPBOX_PROTOZERO_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/deps>
$<INSTALL_INTERFACE:include>
${MAPNIK_OPTIONAL_LIBS_INCLUDE}
)
target_link_libraries(core INTERFACE
Threads::Threads
ICU::uc
ICU::data
ICU::i18n
Boost::headers
Boost::regex
Freetype::Freetype
${MAPNIK_OPTIONAL_LIBS}
)
target_compile_definitions(core INTERFACE ${MAPNIK_COMPILE_DEFS})
mapnik_install(core)
###
# forward declaring libraries to consume them when building static plugins (circle deps between mapnik <-> plugin_target)
add_library(mapnik "")
add_library(mapnik::mapnik ALIAS mapnik)
add_library(wkt STATIC "")
add_library(mapnik::wkt ALIAS wkt)
add_library(json STATIC "")
add_library(mapnik::json ALIAS json)
# end forward declaration
###
add_subdirectory(deps)
add_subdirectory(plugins)
add_subdirectory(src)
add_subdirectory(utils)
add_subdirectory(demo)
if(BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
if(BUILD_TESTING)
add_subdirectory(test)
endif()
file(COPY fonts DESTINATION "${MAPNIK_OUTPUT_DIR}")
feature_summary(FILENAME "${CMAKE_CURRENT_BINARY_DIR}/packages.log" WHAT PACKAGES_FOUND PACKAGES_NOT_FOUND INCLUDE_QUIET_PACKAGES)
# start package mapnik
include(MapnikExport)
include(MapnikExportPkgConfig)
install(DIRECTORY include/mapnik/ DESTINATION "${MAPNIK_INCLUDE_DIR}/mapnik")
install(DIRECTORY deps/agg/include/ DESTINATION "${MAPNIK_INCLUDE_DIR}/mapnik/agg")
install(DIRECTORY deps/mapnik DESTINATION "${MAPNIK_INCLUDE_DIR}")
file(GLOB TTF_FONT_FILES "fonts/*/*/*.ttf")
install(FILES ${TTF_FONT_FILES} DESTINATION "${FONTS_INSTALL_DIR}")
if(NOT USE_EXTERNAL_MAPBOX_GEOMETRY)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/geometry/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}")
endif()
if(NOT USE_EXTERNAL_MAPBOX_POLYLABEL)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/polylabel/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}")
endif()
if(NOT USE_EXTERNAL_MAPBOX_PROTOZERO)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/protozero/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}")
endif()
if(NOT USE_EXTERNAL_MAPBOX_VARIANT)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/deps/mapbox/variant/include/" DESTINATION "${MAPNIK_INCLUDE_DIR}")
endif()
mapnik_install_targets()
include(pack)

View file

@ -1,350 +0,0 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "use-ninja",
"hidden": true,
"generator": "Ninja",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "default-build-dir",
"hidden": true,
"binaryDir": "${sourceDir}/build"
},
{
"name": "debug-build",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"USE_DEBUG_OUTPUT": "ON",
"USE_LOG": "ON",
"USE_LOG_SEVERITY": "0"
}
},
{
"name": "release-with-debug-build",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"USE_DEBUG_OUTPUT": "OFF",
"USE_LOG": "OFF"
}
},
{
"name": "release-build",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"USE_DEBUG_OUTPUT": "OFF",
"USE_LOG": "OFF"
}
},
{
"name": "use-clang",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_CXX_FLAGS": "-stdlib=libc++",
"CMAKE_EXE_LINKER_FLAGS": "-stdlib=libc++",
"CMAKE_SHARED_LINKER_FLAGS": "-stdlib=libc++"
}
},
{
"name": "use-gcc",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "use-msvc-cl",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
}
},
{
"name": "use-msvc-clang-cl",
"hidden": true,
"inherits": [
"default-build-dir",
"use-ninja"
],
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
}
},
{
"name": "linux-clang-debug",
"displayName": "Linux clang debug",
"inherits": [
"use-clang",
"debug-build"
]
},
{
"name": "linux-clang-release",
"displayName": "Linux clang release",
"inherits": [
"use-clang",
"release-build"
]
},
{
"name": "linux-gcc-debug",
"displayName": "Linux gcc debug",
"inherits": [
"use-gcc",
"debug-build"
]
},
{
"name": "linux-gcc-release",
"displayName": "Linux gcc release",
"inherits": [
"use-gcc",
"release-build"
]
},
{
"name": "windows-arch-x64",
"hidden": true,
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolset": {
"value": "host=x64",
"strategy": "external"
}
},
{
"name": "windows-default",
"displayName": "Windows x64 Debug",
"hidden": true,
"inherits": [
"use-msvc-cl",
"windows-arch-x64"
],
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Windows"
]
}
}
},
{
"name": "windows-debug",
"displayName": "Windows x64 Debug",
"inherits": [
"windows-default",
"debug-build"
]
},
{
"name": "windows-release",
"displayName": "Windows x64 Release",
"inherits": [
"windows-default",
"release-build"
]
},
{
"name": "ci-options",
"hidden": true,
"cacheVariables": {
"BUILD_TESTING": "ON",
"BUILD_DEMO_VIEWER": "OFF",
"DISABLE_MAPNIK_AUTOSETUP": "ON"
},
"toolchainFile": "vcpkg/scripts/buildsystems/vcpkg.cmake"
},
{
"name": "windows-ci",
"description": "used by the ci pipeline",
"inherits": [
"windows-release",
"ci-options"
],
"cacheVariables": {
"INSTALL_DEPENDENCIES": "ON",
"ADDITIONAL_LIBARIES_PATHS": "${sourceDir}/build/vcpkg_installed/x64-windows/bin"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-windows/share/proj"
}
},
{
"name": "linux-ci",
"description": "used by the ci pipeline",
"inherits": [
"release-with-debug-build",
"use-gcc",
"ci-options"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "--coverage"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-linux/share/proj"
}
},
{
"name": "linux-ci-release",
"description": "used by the ci pipeline for releasing",
"inherits": [
"release-build",
"linux-gcc-release"
],
"cacheVariables": {
"BUILD_TESTING": "OFF",
"BUILD_DEMO_VIEWER": "OFF",
"USE_MEMORY_MAPPED_FILE": "ON"
}
},
{
"name": "macos-ci-arm64",
"description": "used by the ci pipeline",
"inherits": [
"use-ninja",
"release-with-debug-build",
"default-build-dir",
"ci-options"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-fprofile-arcs -ftest-coverage"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/vcpkg_installed/arm64-osx/share/proj"
}
},
{
"name": "macos-ci-x64",
"description": "used by the ci pipeline",
"inherits": [
"use-ninja",
"release-with-debug-build",
"default-build-dir",
"ci-options"
],
"cacheVariables": {
"CMAKE_CXX_FLAGS": "-fprofile-arcs -ftest-coverage"
},
"environment": {
"PROJ_LIB": "${sourceDir}/build/vcpkg_installed/x64-osx/share/proj"
}
}
],
"buildPresets": [
{
"name": "windows-debug",
"configurePreset": "windows-debug"
},
{
"name": "windows-release",
"configurePreset": "windows-release"
},
{
"name": "linux-clang-debug",
"configurePreset": "linux-clang-debug"
},
{
"name": "linux-clang-release",
"configurePreset": "linux-clang-release"
},
{
"name": "linux-gcc-debug",
"configurePreset": "linux-gcc-debug"
},
{
"name": "linux-gcc-release",
"configurePreset": "linux-gcc-release"
},
{
"name": "windows-ci",
"configurePreset": "windows-ci"
},
{
"name": "linux-ci",
"configurePreset": "linux-ci"
},
{
"name": "linux-ci-release",
"configurePreset": "linux-ci-release"
},
{
"name": "macos-ci-arm64",
"configurePreset": "macos-ci-arm64"
},
{
"name": "macos-ci-x64",
"configurePreset": "macos-ci-x64"
}
],
"testPresets": [
{
"name": "test-default",
"hidden": true,
"output": {
"outputOnFailure": true
},
"execution": {
"noTestsAction": "error",
"stopOnFailure": false
}
},
{
"name": "windows-ci",
"configurePreset": "windows-ci",
"inherits": [
"test-default"
]
},
{
"name": "linux-ci",
"configurePreset": "linux-ci",
"inherits": [
"test-default"
]
},
{
"name": "macos-ci-arm64",
"configurePreset": "macos-ci-arm64",
"inherits": [
"test-default"
]
},
{
"name": "macos-ci-x64",
"configurePreset": "macos-ci-x64",
"inherits": [
"test-default"
]
}
]
}

View file

@ -2,13 +2,6 @@
Mapnik runs on Linux, OS X, Windows, and BSD systems. Mapnik runs on Linux, OS X, Windows, and BSD systems.
## Package managers
### vcpkg
To install mapnik with vcpkg type `vcpkg install mapnik`. It will install a minimal version of mapnik and all the needed dependencies.
To install more features, type `vcpkg search mapnik` to see all available features.
## Source build
First clone mapnik from github and initialize submodules First clone mapnik from github and initialize submodules
```bash ```bash
@ -42,8 +35,8 @@ To use a Python interpreter that is not named `python` for your build, do
something like the following instead: something like the following instead:
```bash ```bash
$ PYTHON=python3 ./configure $ PYTHON=python2 ./configure
$ make PYTHON=python3 $ make PYTHON=python2
``` ```
NOTE: the above will not work on windows, rather see https://github.com/mapnik/mapnik/wiki/WindowsInstallation NOTE: the above will not work on windows, rather see https://github.com/mapnik/mapnik/wiki/WindowsInstallation
@ -71,15 +64,15 @@ For troubleshooting help see https://github.com/mapnik/mapnik/wiki/InstallationT
Build system dependencies are: Build system dependencies are:
* C++ compiler supporting `-std=c++17` (like >= g++ 9 or >= clang++ 5) * C++ compiler supporting `-std=c++11` (like >= g++ 4.8 or >= clang++ 3.4)
* \>= 2 GB RAM (> 5 GB for g++) * >= 2 GB RAM (> 5 GB for g++)
* Python 3 * Python 2.4-2.7
* Scons (a copy is bundled) or CMake >= 3.15 see [docs/cmake-usage.md](./docs/cmake-usage.md) * Scons (a copy is bundled)
Mapnik Core depends on: Mapnik Core depends on:
* Boost * Boost
- \>= 1.73 is required - >= 1.47 is required and >= 1.56 recommended
- These libraries are used: - These libraries are used:
- filesystem - filesystem
- system - system
@ -97,7 +90,7 @@ Mapnik Core optionally depends on:
* libjpeg - JPEG graphics (Default enabled, if found) * libjpeg - JPEG graphics (Default enabled, if found)
* libtiff - TIFF graphics (Default enabled, if found) * libtiff - TIFF graphics (Default enabled, if found)
* libwebp - WEBP graphics (Default enabled, if found) * libwebp - WEBP graphics (Default enabled, if found)
* libproj >= 7.2.0 - PROJ projection library (Default enabled, if found) * libproj - PROJ.4 projection library (Default enabled, if found)
Additional optional dependencies: Additional optional dependencies:
@ -191,7 +184,7 @@ If you need help or want to participate starting points include:
### Cartographers ### Cartographers
TileMill, which uses Mapnik internally, offers great step by step tutorials for TileMill, which uses Mapnik internally, offers great step by step tutorials for
learning advanced map styling: https://tilemill-project.github.io/tilemill/docs/crashcourse/introduction/ learning advanced map styling: http://mapbox.com/tilemill/docs/crashcourse/introduction/
### Programmers ### Programmers

View file

@ -8,7 +8,7 @@ _/ _/ _/_/_/ _/_/_/ _/ _/ _/ _/ _/
_/ _/
``` ```
[![TravisCI](https://api.travis-ci.com/mapnik/mapnik.svg?branch=master)](http://travis-ci.com/mapnik/mapnik) [![TravisCI](https://api.travis-ci.org/mapnik/mapnik.svg?branch=master)](http://travis-ci.org/mapnik/mapnik)
[![codecov](https://codecov.io/gh/mapnik/mapnik/branch/master/graph/badge.svg)](https://codecov.io/gh/mapnik/mapnik) [![codecov](https://codecov.io/gh/mapnik/mapnik/branch/master/graph/badge.svg)](https://codecov.io/gh/mapnik/mapnik)
Mapnik is an open source toolkit for developing mapping applications. At the core is a C++ shared library providing algorithms and patterns for spatial data access and visualization. Mapnik is an open source toolkit for developing mapping applications. At the core is a C++ shared library providing algorithms and patterns for spatial data access and visualization.

View file

@ -1,6 +1,6 @@
# This file is part of Mapnik (c++ mapping toolkit) # This file is part of Mapnik (c++ mapping toolkit)
# #
# Copyright (C) 2024 Artem Pavlenko # Copyright (C) 2017 Artem Pavlenko
# #
# Mapnik is free software; you can redistribute it and/or # Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
@ -16,13 +16,15 @@
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import print_function # support python2
import os import os
import sys import sys
import re import re
import platform import platform
from glob import glob from glob import glob
from copy import copy from copy import copy
from subprocess import run, Popen, PIPE from subprocess import Popen, PIPE
from SCons.SConf import SetCacheMode from SCons.SConf import SetCacheMode
import pickle import pickle
@ -32,8 +34,19 @@ try:
except: except:
HAS_DISTUTILS = False HAS_DISTUTILS = False
from shlex import quote as shquote try:
from subprocess import DEVNULL # Python 3.3+
from shlex import quote as shquote
except:
# Python 2.7
from pipes import quote as shquote
try:
# Python 3.3+
from subprocess import DEVNULL
except:
# Python 2.7
DEVNULL = open(os.devnull, 'w')
LIBDIR_SCHEMA_DEFAULT='lib' LIBDIR_SCHEMA_DEFAULT='lib'
severities = ['debug', 'warn', 'error', 'none'] severities = ['debug', 'warn', 'error', 'none']
@ -43,7 +56,7 @@ ICU_LIBS_DEFAULT='/usr/'
DEFAULT_CC = "cc" DEFAULT_CC = "cc"
DEFAULT_CXX = "c++" DEFAULT_CXX = "c++"
DEFAULT_CXX_STD = "17" DEFAULT_CXX_STD = "14"
DEFAULT_CXX_CXXFLAGS = " -DU_USING_ICU_NAMESPACE=0" DEFAULT_CXX_CXXFLAGS = " -DU_USING_ICU_NAMESPACE=0"
DEFAULT_CXX_LINKFLAGS = "" DEFAULT_CXX_LINKFLAGS = ""
if sys.platform == 'darwin': if sys.platform == 'darwin':
@ -64,10 +77,9 @@ SCONS_CONFIGURE_CACHE = 'config.cache'
SCONF_TEMP_DIR = '.sconf_temp' SCONF_TEMP_DIR = '.sconf_temp'
# auto-search directories for boost libs/headers # auto-search directories for boost libs/headers
BOOST_SEARCH_PREFIXES = ['/usr/local','/opt/local','/sw','/usr',] BOOST_SEARCH_PREFIXES = ['/usr/local','/opt/local','/sw','/usr',]
BOOST_MIN_VERSION = '1.73' BOOST_MIN_VERSION = '1.61'
#CAIRO_MIN_VERSION = '1.8.0' #CAIRO_MIN_VERSION = '1.8.0'
PROJ_MIN_VERSION = (7, 2, 0)
PROJ_MIN_VERSION_STRING = "%s.%s.%s" % PROJ_MIN_VERSION
HARFBUZZ_MIN_VERSION = (0, 9, 34) HARFBUZZ_MIN_VERSION = (0, 9, 34)
HARFBUZZ_MIN_VERSION_STRING = "%s.%s.%s" % HARFBUZZ_MIN_VERSION HARFBUZZ_MIN_VERSION_STRING = "%s.%s.%s" % HARFBUZZ_MIN_VERSION
@ -80,8 +92,7 @@ pretty_dep_names = {
'gdal':'GDAL C++ library | configured using gdal-config program | try setting GDAL_CONFIG SCons option | more info: https://github.com/mapnik/mapnik/wiki/GDAL', 'gdal':'GDAL C++ library | configured using gdal-config program | try setting GDAL_CONFIG SCons option | more info: https://github.com/mapnik/mapnik/wiki/GDAL',
'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', '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',
'cairo':'Cairo C library | configured using pkg-config | try setting PKG_CONFIG_PATH SCons option', 'cairo':'Cairo C library | configured using pkg-config | try setting PKG_CONFIG_PATH SCons option',
'proj':'Proj C Projections library | configure with PROJ_LIBS & PROJ_INCLUDES | more info: http://trac.osgeo.org/proj/', 'proj':'Proj.4 C Projections library | configure with PROJ_LIBS & PROJ_INCLUDES | more info: http://trac.osgeo.org/proj/',
'proj-min-version':'libproj >=%s required' % PROJ_MIN_VERSION_STRING,
'pg':'Postgres C Library required for PostGIS plugin | configure with pg_config program or configure with PG_LIBS & PG_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/PostGIS', 'pg':'Postgres C Library required for PostGIS plugin | configure with pg_config program or configure with PG_LIBS & PG_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/PostGIS',
'sqlite3':'SQLite3 C Library | configure with SQLITE_LIBS & SQLITE_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/SQLite', 'sqlite3':'SQLite3 C Library | configure with SQLITE_LIBS & SQLITE_INCLUDES | more info: https://github.com/mapnik/mapnik/wiki/SQLite',
'jpeg':'JPEG C library | configure with JPEG_LIBS & JPEG_INCLUDES', 'jpeg':'JPEG C library | configure with JPEG_LIBS & JPEG_INCLUDES',
@ -105,7 +116,7 @@ pretty_dep_names = {
'boost_regex_icu':'libboost_regex built with optional ICU unicode support is needed for unicode regex support in mapnik.', 'boost_regex_icu':'libboost_regex built with optional ICU unicode support is needed for unicode regex support in mapnik.',
'sqlite_rtree':'The SQLite plugin requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)', 'sqlite_rtree':'The SQLite plugin requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)',
'pgsql2sqlite_rtree':'The pgsql2sqlite program requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)', 'pgsql2sqlite_rtree':'The pgsql2sqlite program requires libsqlite3 built with RTREE support (-DSQLITE_ENABLE_RTREE=1)',
'PROJ_LIB':'The directory where proj stores its data files. Must exist for proj to work correctly', 'PROJ_LIB':'The directory where proj4 stores its data files. Must exist for proj4 to work correctly',
'GDAL_DATA':'The directory where GDAL stores its data files. Must exist for GDAL to work correctly', 'GDAL_DATA':'The directory where GDAL stores its data files. Must exist for GDAL to work correctly',
'ICU_DATA':'The directory where icu stores its data files. If ICU reports a path, it must exist. ICU can also be built without .dat files and in that case this path is empty' 'ICU_DATA':'The directory where icu stores its data files. If ICU reports a path, it must exist. ICU can also be built without .dat files and in that case this path is empty'
} }
@ -131,6 +142,7 @@ PLUGINS = { # plugins with external dependencies
def init_environment(env): def init_environment(env):
env.Decider('MD5-timestamp') env.Decider('MD5-timestamp')
env.SourceCode(".", None)
env['ORIGIN'] = Literal('$ORIGIN') env['ORIGIN'] = Literal('$ORIGIN')
env['ENV']['ORIGIN'] = '$ORIGIN' env['ENV']['ORIGIN'] = '$ORIGIN'
if os.environ.get('RANLIB'): if os.environ.get('RANLIB'):
@ -368,6 +380,7 @@ opts.AddVariables(
BoolVariable('ENABLE_GLIBC_WORKAROUND', "Workaround known GLIBC symbol exports to allow building against libstdc++-4.8 without binaries needing throw_out_of_range_fmt", 'False'), BoolVariable('ENABLE_GLIBC_WORKAROUND', "Workaround known GLIBC symbol exports to allow building against libstdc++-4.8 without binaries needing throw_out_of_range_fmt", 'False'),
# http://www.scons.org/wiki/GoFastButton # http://www.scons.org/wiki/GoFastButton
# http://stackoverflow.com/questions/1318863/how-to-optimize-an-scons-script # http://stackoverflow.com/questions/1318863/how-to-optimize-an-scons-script
BoolVariable('FAST', "Make SCons faster at the cost of less precise dependency tracking", 'False'),
BoolVariable('PRIORITIZE_LINKING', 'Sort list of lib and inc directories to ensure preferential compiling and linking (useful when duplicate libs)', 'True'), BoolVariable('PRIORITIZE_LINKING', 'Sort list of lib and inc directories to ensure preferential compiling and linking (useful when duplicate libs)', 'True'),
('LINK_PRIORITY','Priority list in which to sort library and include paths (default order is internal, other, frameworks, user, then system - see source of `sort_paths` function for more detail)',','.join(DEFAULT_LINK_PRIORITY)), ('LINK_PRIORITY','Priority list in which to sort library and include paths (default order is internal, other, frameworks, user, then system - see source of `sort_paths` function for more detail)',','.join(DEFAULT_LINK_PRIORITY)),
@ -409,9 +422,9 @@ opts.AddVariables(
BoolVariable('WEBP', 'Build Mapnik with WEBP read', 'True'), BoolVariable('WEBP', 'Build Mapnik with WEBP read', 'True'),
PathVariable('WEBP_INCLUDES', 'Search path for libwebp include files', '/usr/include', PathVariable.PathAccept), PathVariable('WEBP_INCLUDES', 'Search path for libwebp include files', '/usr/include', PathVariable.PathAccept),
PathVariable('WEBP_LIBS','Search path for libwebp library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), PathVariable('WEBP_LIBS','Search path for libwebp library files','/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept),
BoolVariable('PROJ', 'Build Mapnik with proj support to enable transformations between many different projections', 'True'), BoolVariable('PROJ', 'Build Mapnik with proj4 support to enable transformations between many different projections', 'True'),
PathVariable('PROJ_INCLUDES', 'Search path for libproj include files', '/usr/include', PathVariable.PathAccept), PathVariable('PROJ_INCLUDES', 'Search path for PROJ.4 include files', '/usr/include', PathVariable.PathAccept),
PathVariable('PROJ_LIBS', 'Search path for libproj library files', '/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept), PathVariable('PROJ_LIBS', 'Search path for PROJ.4 library files', '/usr/' + LIBDIR_SCHEMA_DEFAULT, PathVariable.PathAccept),
('PG_INCLUDES', 'Search path for libpq (postgres client) include files', ''), ('PG_INCLUDES', 'Search path for libpq (postgres client) include files', ''),
('PG_LIBS', 'Search path for libpq (postgres client) library files', ''), ('PG_LIBS', 'Search path for libpq (postgres client) library files', ''),
('FREETYPE_INCLUDES', 'Search path for Freetype include files', ''), ('FREETYPE_INCLUDES', 'Search path for Freetype include files', ''),
@ -467,9 +480,8 @@ opts.AddVariables(
BoolVariable('MAPNIK_RENDER', 'Compile and install a utility to render a map to an image', 'True'), BoolVariable('MAPNIK_RENDER', 'Compile and install a utility to render a map to an image', 'True'),
BoolVariable('COLOR_PRINT', 'Print build status information in color', 'True'), BoolVariable('COLOR_PRINT', 'Print build status information in color', 'True'),
BoolVariable('BIGINT', 'Compile support for 64-bit integers in mapnik::value', 'True'), BoolVariable('BIGINT', 'Compile support for 64-bit integers in mapnik::value', 'True'),
BoolVariable('USE_BOOST_FILESYSTEM','Use boost::filesytem even if `std::filesystem` is available (since c++17)', 'False'),
BoolVariable('QUIET', 'Reduce build verbosity', 'False'), BoolVariable('QUIET', 'Reduce build verbosity', 'False'),
) )
# variables to pickle after successful configure step # variables to pickle after successful configure step
# these include all scons core variables as well as custom # these include all scons core variables as well as custom
@ -536,7 +548,6 @@ pickle_store = [# Scons internal variables
'SQLITE_LINKFLAGS', 'SQLITE_LINKFLAGS',
'BOOST_LIB_VERSION_FROM_HEADER', 'BOOST_LIB_VERSION_FROM_HEADER',
'BIGINT', 'BIGINT',
'USE_BOOST_FILESYSTEM',
'HOST', 'HOST',
'QUERIED_GDAL_DATA', 'QUERIED_GDAL_DATA',
'QUERIED_ICU_DATA', 'QUERIED_ICU_DATA',
@ -683,7 +694,7 @@ def parse_config(context, config, checks='--libs --cflags'):
# and thus breaks knowledge below that gdal worked # and thus breaks knowledge below that gdal worked
# TODO - upgrade our scons logic to support Framework linking # TODO - upgrade our scons logic to support Framework linking
if env['PLATFORM'] == 'Darwin': if env['PLATFORM'] == 'Darwin':
if value and '-framework GDAL' in value: if value and b'-framework GDAL' in value:
env['LIBS'].append('gdal') env['LIBS'].append('gdal')
if os.path.exists('/Library/Frameworks/GDAL.framework/unix/lib'): if os.path.exists('/Library/Frameworks/GDAL.framework/unix/lib'):
env['LIBPATH'].insert(0,'/Library/Frameworks/GDAL.framework/unix/lib') env['LIBPATH'].insert(0,'/Library/Frameworks/GDAL.framework/unix/lib')
@ -922,44 +933,67 @@ def CheckGdalData(context, silent=False):
context.Result('Failed to detect (mapnik-config will have null value)') context.Result('Failed to detect (mapnik-config will have null value)')
return value return value
def proj_version(context):
context.Message('Checking for Proj version >=%s...' % PROJ_MIN_VERSION_STRING)
ret, out = context.TryRun("""
#include "proj.h"
#include <stdio.h>
#define PROJ_VERSION_ATLEAST(major,minor,micro) \
((major)*10000+(minor)*100+(micro) <= \
PROJ_VERSION_MAJOR*10000+PROJ_VERSION_MINOR*100+PROJ_VERSION_PATCH)
int main()
{
printf("%d;%d.%d.%d", PROJ_VERSION_ATLEAST{min-version}, PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH);
return 0;
}
""".replace("{min-version}", str(PROJ_MIN_VERSION)),'.c')
if not ret:
context.Result('error (could not get version from proj.h)')
else:
ok_str, found_version_str = out.strip().split(';', 1)
major,minor,patch = found_version_str.split('.')
ret = int(ok_str), int(major)*10000+int(minor)*100+int(patch)
if ret:
context.Result('yes (found Proj %s)' % found_version_str)
else:
context.Result('no (found Proj %s)' % found_version_str)
return ret
def CheckProjData(context, silent=False): def CheckProjData(context, silent=False):
if not silent: if not silent:
context.Message('Checking for PROJ_LIB directory...') context.Message('Checking for PROJ_LIB directory...')
result = run(['pkg-config', 'proj', '--variable=datadir'], stdout=PIPE) ret, out = context.TryRun("""
value = result.stdout.decode('utf-8').strip()
// This is narly, could eventually be replaced using https://github.com/OSGeo/proj.4/pull/551]
#include <proj_api.h>
#include <iostream>
#include <cstring>
static void my_proj4_logger(void * user_data, int /*level*/, const char * msg)
{
std::string* posMsg = static_cast<std::string*>(user_data);
*posMsg += msg;
}
// https://github.com/OSGeo/gdal/blob/ddbf6d39aa4b005a77ca4f27c2d61a3214f336f8/gdal/alg/gdalapplyverticalshiftgrid.cpp#L616-L633
std::string find_proj_path(const char * pszFilename) {
std::string osMsg;
std::string osFilename;
projCtx ctx = pj_ctx_alloc();
pj_ctx_set_app_data(ctx, &osMsg);
pj_ctx_set_debug(ctx, PJ_LOG_DEBUG_MAJOR);
pj_ctx_set_logger(ctx, my_proj4_logger);
PAFile f = pj_open_lib(ctx, pszFilename, "rb");
if( f )
{
pj_ctx_fclose(ctx, f);
}
size_t nPos = osMsg.find("fopen(");
if( nPos != std::string::npos )
{
osFilename = osMsg.substr(nPos + strlen("fopen("));
nPos = osFilename.find(")");
if( nPos != std::string::npos )
osFilename = osFilename.substr(0, nPos);
}
pj_ctx_free(ctx);
return osFilename;
}
int main() {
std::string result = find_proj_path(" ");
std::cout << result;
if (result.empty()) {
return -1;
}
return 0;
}
""", '.cpp')
value = out.strip()
if silent: if silent:
context.did_show_result=1 context.did_show_result=1
if os.path.exists(value): if ret:
context.Result('`pkg-config proj --variable=datadir` returned:\n%s ' % value) context.Result('pj_open_lib returned %s' % value)
else: else:
value = None
context.Result('Failed to detect (mapnik-config will have null value)') context.Result('Failed to detect (mapnik-config will have null value)')
return value return value
@ -1196,7 +1230,7 @@ int main()
context.Result(ret) context.Result(ret)
return ret return ret
__cplusplus = {'14':'201402L', '17':'201703L', '20':'202002L'} __cplusplus = {'14':'201402L', '17':'201703L'}
def supports_cxx_std (context, silent=False): def supports_cxx_std (context, silent=False):
cplusplus_string = __cplusplus[env['CXX_STD']] cplusplus_string = __cplusplus[env['CXX_STD']]
@ -1226,7 +1260,6 @@ conf_tests = { 'prioritize_paths' : prioritize_paths,
'FindBoost' : FindBoost, 'FindBoost' : FindBoost,
'CheckBoost' : CheckBoost, 'CheckBoost' : CheckBoost,
'CheckIcuData' : CheckIcuData, 'CheckIcuData' : CheckIcuData,
'proj_version' : proj_version,
'CheckProjData' : CheckProjData, 'CheckProjData' : CheckProjData,
'CheckGdalData' : CheckGdalData, 'CheckGdalData' : CheckGdalData,
'CheckCairoHasFreetype' : CheckCairoHasFreetype, 'CheckCairoHasFreetype' : CheckCairoHasFreetype,
@ -1258,7 +1291,12 @@ def GetMapnikLibVersion():
return version_string return version_string
if not preconfigured: if not preconfigured:
color_print(4,'Configuring build environment...') color_print(4,'Configuring build environment...')
if not env['FAST']:
SetCacheMode('force')
if env['USE_CONFIG']: if env['USE_CONFIG']:
if not env['CONFIG'].endswith('.py'): if not env['CONFIG'].endswith('.py'):
color_print(1,'SCons CONFIG file specified is not a python file, will not be read...') color_print(1,'SCons CONFIG file specified is not a python file, will not be read...')
@ -1527,7 +1565,7 @@ if not preconfigured:
env['SKIPPED_DEPS'].append('jpeg') env['SKIPPED_DEPS'].append('jpeg')
if env['PROJ']: if env['PROJ']:
OPTIONAL_LIBSHEADERS.append(['proj', 'proj.h', False,'C','-DMAPNIK_USE_PROJ']) OPTIONAL_LIBSHEADERS.append(['proj', 'proj_api.h', False,'C','-DMAPNIK_USE_PROJ4'])
inc_path = env['%s_INCLUDES' % 'PROJ'] inc_path = env['%s_INCLUDES' % 'PROJ']
lib_path = env['%s_LIBS' % 'PROJ'] lib_path = env['%s_LIBS' % 'PROJ']
env.AppendUnique(CPPPATH = fix_path(inc_path)) env.AppendUnique(CPPPATH = fix_path(inc_path))
@ -1545,25 +1583,11 @@ if not preconfigured:
env['SKIPPED_DEPS'].append('png') env['SKIPPED_DEPS'].append('png')
if env['WEBP']: if env['WEBP']:
if env.get('WEBP_LIBS') or env.get('WEBP_INCLUDES'): OPTIONAL_LIBSHEADERS.append(['webp', 'webp/decode.h', False,'C','-DHAVE_WEBP'])
OPTIONAL_LIBSHEADERS.append(['webp', 'webp/decode.h', False,'C','-DHAVE_WEBP']) inc_path = env['%s_INCLUDES' % 'WEBP']
inc_path = env['WEBP_INCLUDES'] lib_path = env['%s_LIBS' % 'WEBP']
lib_path = env['WEBP_LIBS'] env.AppendUnique(CPPPATH = fix_path(inc_path))
env.AppendUnique(CPPPATH = fix_path(inc_path)) env.AppendUnique(LIBPATH = fix_path(lib_path))
env.AppendUnique(LIBPATH = fix_path(lib_path))
else:
cmd = 'pkg-config libwebp --libs --cflags'
if env['RUNTIME_LINK'] == 'static':
cmd += ' --static'
temp_env = Environment(ENV=os.environ)
try:
temp_env.ParseConfig(cmd)
for lib in temp_env['LIBS']:
env.AppendUnique(LIBPATH = fix_path(lib))
for inc in temp_env['CPPPATH']:
env.AppendUnique(CPPPATH = fix_path(inc))
except OSError as e:
pass
else: else:
env['SKIPPED_DEPS'].append('webp') env['SKIPPED_DEPS'].append('webp')
@ -1610,12 +1634,6 @@ if not preconfigured:
if env['BIGINT']: if env['BIGINT']:
env.Append(CPPDEFINES = '-DBIGINT') env.Append(CPPDEFINES = '-DBIGINT')
if int(env['CXX_STD']) < 17:
env['USE_BOOST_FILESYSTEM'] = True
if env['USE_BOOST_FILESYSTEM']:
env.Append(CPPDEFINES = '-DUSE_BOOST_FILESYSTEM')
if env['THREADING'] == 'multi': if env['THREADING'] == 'multi':
thread_flag = thread_suffix thread_flag = thread_suffix
else: else:
@ -1635,13 +1653,12 @@ if not preconfigured:
# The other required boost headers. # The other required boost headers.
BOOST_LIBSHEADERS = [ BOOST_LIBSHEADERS = [
['system', 'boost/system/system_error.hpp', True],
['filesystem', 'boost/filesystem/operations.hpp', True],
['regex', 'boost/regex.hpp', True], ['regex', 'boost/regex.hpp', True],
['program_options', 'boost/program_options.hpp', False] ['program_options', 'boost/program_options.hpp', False]
] ]
if env['USE_BOOST_FILESYSTEM']:
BOOST_LIBSHEADERS.append(['system', 'boost/system/system_error.hpp', True])
BOOST_LIBSHEADERS.append(['filesystem', 'boost/filesystem/operations.hpp', True])
# if requested, sort LIBPATH and CPPPATH before running CheckLibWithHeader tests # if requested, sort LIBPATH and CPPPATH before running CheckLibWithHeader tests
if env['PRIORITIZE_LINKING']: if env['PRIORITIZE_LINKING']:
conf.prioritize_paths(silent=True) conf.prioritize_paths(silent=True)
@ -1700,13 +1717,6 @@ if not preconfigured:
else: else:
color_print(4, 'Could not find optional header or shared library for %s' % libname) color_print(4, 'Could not find optional header or shared library for %s' % libname)
env['SKIPPED_DEPS'].append(libname) env['SKIPPED_DEPS'].append(libname)
elif libname == 'proj':
result, version = conf.proj_version()
if not result:
env['SKIPPED_DEPS'].append('proj-min-version')
else:
env.Append(CPPDEFINES = define)
env.Append(CPPDEFINES = "-DMAPNIK_PROJ_VERSION=%d" % version)
else: else:
env.Append(CPPDEFINES = define) env.Append(CPPDEFINES = define)
else: else:
@ -2162,6 +2172,13 @@ if not HELP_REQUESTED:
Export('plugin_base') Export('plugin_base')
if env['FAST']:
# caching is 'auto' by default in SCons
# But let's also cache implicit deps...
EnsureSConsVersion(0,98)
SetOption('implicit_cache', 1)
SetOption('max_drift', 1)
# Build agg first, doesn't need anything special # Build agg first, doesn't need anything special
if env['RUNTIME_LINK'] == 'shared': if env['RUNTIME_LINK'] == 'shared':
SConscript('deps/agg/build.py') SConscript('deps/agg/build.py')

39
appveyor.yml Normal file
View file

@ -0,0 +1,39 @@
environment:
msvs_toolset: 14
FASTBUILD: 1
matrix:
- platform: x64
configuration: Release
os: Visual Studio 2015
#shallow_clone: true
# limit clone to latest 5 commits
clone_depth: 5
services:
- postgresql94 #if changing this, also change PATH below
install:
- SET PGUSER=postgres
- SET PGPASSWORD=Password12!
- SET PATH=C:\Program Files\PostgreSQL\9.4\bin\;%PATH%
build_script:
- scripts\build-appveyor.bat
after_build:
- 7z a visual-test-results.zip C:\tmp\mapnik-visual-images\visual-test-results
artifacts:
- path: mapnik-gyp\msbuild-summary.txt
name: msbuild-summary.txt
- path: mapnik-gyp\msbuild-errors.txt
name: msbuild-errors.txt
- path: mapnik-gyp\msbuild-warnings.txt
name: msbuild-warnings.txt
- path: visual-test-results.zip
name: visual-test-results.zip
test: off
deploy: off

View file

@ -1,52 +0,0 @@
project(mapnik-benchmark)
set(BENCHMARK_SRCS
src/normalize_angle.cpp
src/test_array_allocation.cpp
src/test_expression_parse.cpp
src/test_face_ptr_creation.cpp
src/test_font_registration.cpp
src/test_getline.cpp
src/test_marker_cache.cpp
src/test_noop_rendering.cpp
src/test_numeric_cast_vs_static_cast.cpp
src/test_offset_converter.cpp
src/test_png_encoding1.cpp
src/test_png_encoding2.cpp
src/test_polygon_clipping_rendering.cpp
src/test_polygon_clipping.cpp
src/test_proj_transform1.cpp
src/test_quad_tree.cpp
src/test_rendering_shared_map.cpp
src/test_rendering.cpp
src/test_to_bool.cpp
src/test_to_double.cpp
src/test_to_int.cpp
src/test_to_string1.cpp
src/test_to_string2.cpp
src/test_utf_encoding.cpp
)
function(mapnik_create_benchmark)
get_filename_component(BENCHNAME ${ARGV0} NAME_WE)
set(TARGET_NAME "mapnik-benchmark-${BENCHNAME}")
add_executable(${TARGET_NAME} ${ARGV0})
target_include_directories(${TARGET_NAME} PRIVATE include)
target_link_libraries(${TARGET_NAME} PRIVATE
mapnik::agg
mapnik::mapnik
ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?)
)
set_target_properties(${TARGET_NAME} PROPERTIES
OUTPUT_NAME "${BENCHNAME}"
)
endfunction()
foreach(benchmark ${BENCHMARK_SRCS})
mapnik_create_benchmark(${benchmark})
endforeach()
file(COPY data DESTINATION "${MAPNIK_OUTPUT_DIR}/benchmark")
file(COPY run_benchmarks
DESTINATION "${MAPNIK_OUTPUT_DIR}"
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE GROUP_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ
)

View file

@ -9,7 +9,6 @@ test_env = env.Clone()
test_env['LIBS'] = [env['MAPNIK_NAME']] test_env['LIBS'] = [env['MAPNIK_NAME']]
test_env.AppendUnique(LIBS=copy(env['LIBMAPNIK_LIBS'])) test_env.AppendUnique(LIBS=copy(env['LIBMAPNIK_LIBS']))
test_env.AppendUnique(LIBS='mapnik-wkt') test_env.AppendUnique(LIBS='mapnik-wkt')
test_env.AppendUnique(LIBS='sqlite3')
if env['PLATFORM'] == 'Linux': if env['PLATFORM'] == 'Linux':
test_env.AppendUnique(LIBS='dl') test_env.AppendUnique(LIBS='dl')
test_env.AppendUnique(LIBS='rt') test_env.AppendUnique(LIBS='rt')

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]> <!DOCTYPE Map[]>
<Map <Map
srs="epsg:4326" srs="+init=epsg:4326"
background-color="#dfd8c9"> background-color="#dfd8c9">
<Style name="style"> <Style name="style">
@ -10,7 +10,7 @@
</Rule> </Rule>
</Style> </Style>
<Layer name="layer" <Layer name="layer"
srs="epsg:4326"> srs="+init=epsg:4326">
<StyleName>style</StyleName> <StyleName>style</StyleName>
<Datasource> <Datasource>
<Parameter name="file">./valid.geotiff.tif</Parameter> <Parameter name="file">./valid.geotiff.tif</Parameter>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]> <!DOCTYPE Map[]>
<Map <Map
srs="epsg:4326" srs="+init=epsg:4326"
background-color="#dfd8c9"> background-color="#dfd8c9">
<Style name="style"> <Style name="style">
@ -10,7 +10,7 @@
</Rule> </Rule>
</Style> </Style>
<Layer name="layer" <Layer name="layer"
srs="epsg:4326"> srs="+init=epsg:4326">
<StyleName>style</StyleName> <StyleName>style</StyleName>
<Datasource> <Datasource>
<Parameter name="file">./valid.geotiff.tif</Parameter> <Parameter name="file">./valid.geotiff.tif</Parameter>

View file

@ -2,7 +2,6 @@
#define MAPNIK_BENCH_FRAMEWORK_HPP #define MAPNIK_BENCH_FRAMEWORK_HPP
// mapnik // mapnik
#include <mapnik/mapnik.hpp>
#include <mapnik/debug.hpp> #include <mapnik/debug.hpp>
#include <mapnik/params.hpp> #include <mapnik/params.hpp>
#include <mapnik/value/types.hpp> #include <mapnik/value/types.hpp>
@ -11,38 +10,47 @@
// stl // stl
#include <chrono> #include <chrono>
#include <cmath> // log10, round #include <cmath> // log10, round
#include <cstdio> // snprintf #include <cstdio> // snprintf
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <set>
#include <sstream>
#include <thread> #include <thread>
#include <mutex>
#include <vector> #include <vector>
namespace benchmark { namespace benchmark {
template<typename T> template <typename T>
using milliseconds = std::chrono::duration<T, std::milli>; using milliseconds = std::chrono::duration<T, std::milli>;
template<typename T> template <typename T>
using seconds = std::chrono::duration<T>; using seconds = std::chrono::duration<T>;
class test_case class test_case
{ {
protected: protected:
mapnik::parameters params_; mapnik::parameters params_;
std::size_t threads_; std::size_t threads_;
std::size_t iterations_; std::size_t iterations_;
public:
public:
test_case(mapnik::parameters const& params) test_case(mapnik::parameters const& params)
: params_(params) : params_(params),
, threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))) threads_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("threads", 0))),
, iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0))) iterations_(mapnik::safe_cast<std::size_t>(*params.get<mapnik::value_integer>("iterations", 0)))
{} {}
std::size_t threads() const { return threads_; } std::size_t threads() const
std::size_t iterations() const { return iterations_; } {
mapnik::parameters const& params() const { return params_; } return threads_;
}
std::size_t iterations() const
{
return iterations_;
}
mapnik::parameters const& params() const
{
return params_;
}
virtual bool validate() const = 0; virtual bool validate() const = 0;
virtual bool operator()() const = 0; virtual bool operator()() const = 0;
}; };
@ -50,25 +58,21 @@ class test_case
// gathers --long-option values in 'params'; // gathers --long-option values in 'params';
// returns the index of the first non-option argument, // returns the index of the first non-option argument,
// or negated index of an ill-formed option argument // or negated index of an ill-formed option argument
inline int parse_args(int argc, char** argv, mapnik::parameters& params) inline int parse_args(int argc, char** argv, mapnik::parameters & params)
{ {
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i) {
{
const char* opt = argv[i]; const char* opt = argv[i];
if (opt[0] != '-') if (opt[0] != '-') {
{
// non-option argument, return its index // non-option argument, return its index
return i; return i;
} }
if (opt[1] != '-') if (opt[1] != '-') {
{
// we only accept --long-options, but instead of throwing, // we only accept --long-options, but instead of throwing,
// just issue a warning and let the caller decide what to do // just issue a warning and let the caller decide what to do
std::clog << argv[0] << ": invalid option '" << opt << "'\n"; std::clog << argv[0] << ": invalid option '" << opt << "'\n";
return -i; // negative means ill-formed option #i return -i; // negative means ill-formed option #i
} }
if (opt[2] == '\0') if (opt[2] == '\0') {
{
// option-list terminator '--' // option-list terminator '--'
return i + 1; return i + 1;
} }
@ -76,18 +80,15 @@ inline int parse_args(int argc, char** argv, mapnik::parameters& params)
// take option name without the leading '--' // take option name without the leading '--'
std::string key(opt + 2); std::string key(opt + 2);
size_t eq = key.find('='); size_t eq = key.find('=');
if (eq != std::string::npos) if (eq != std::string::npos) {
{
// one-argument form '--foo=bar' // one-argument form '--foo=bar'
params[key.substr(0, eq)] = key.substr(eq + 1); params[key.substr(0, eq)] = key.substr(eq + 1);
} }
else if (i + 1 < argc) else if (i + 1 < argc) {
{
// two-argument form '--foo' 'bar' // two-argument form '--foo' 'bar'
params[key] = std::string(argv[++i]); params[key] = std::string(argv[++i]);
} }
else else {
{
// missing second argument // missing second argument
std::clog << argv[0] << ": missing option '" << opt << "' value\n"; std::clog << argv[0] << ": missing option '" << opt << "' value\n";
return -i; // negative means ill-formed option #i return -i; // negative means ill-formed option #i
@ -98,8 +99,7 @@ inline int parse_args(int argc, char** argv, mapnik::parameters& params)
inline void handle_common_args(mapnik::parameters const& params) inline void handle_common_args(mapnik::parameters const& params)
{ {
if (auto severity = params.get<std::string>("log")) if (auto severity = params.get<std::string>("log")) {
{
if (*severity == "debug") if (*severity == "debug")
mapnik::logger::set_severity(mapnik::logger::debug); mapnik::logger::set_severity(mapnik::logger::debug);
else if (*severity == "warn") else if (*severity == "warn")
@ -109,37 +109,37 @@ inline void handle_common_args(mapnik::parameters const& params)
else if (*severity == "none") else if (*severity == "none")
mapnik::logger::set_severity(mapnik::logger::none); mapnik::logger::set_severity(mapnik::logger::none);
else else
std::clog << "ignoring option --log='" << *severity << "' (allowed values are: debug, warn, error, none)\n"; std::clog << "ignoring option --log='" << *severity
<< "' (allowed values are: debug, warn, error, none)\n";
} }
} }
inline int handle_args(int argc, char** argv, mapnik::parameters& params) inline int handle_args(int argc, char** argv, mapnik::parameters & params)
{ {
int res = parse_args(argc, argv, params); int res = parse_args(argc, argv, params);
handle_common_args(params); handle_common_args(params);
return res; return res;
} }
#define BENCHMARK(test_class, name) \ #define BENCHMARK(test_class,name) \
int main(int argc, char** argv) \ int main(int argc, char** argv) \
{ \ { \
mapnik::setup(); \ try \
try \ { \
{ \ mapnik::parameters params; \
mapnik::parameters params; \ benchmark::handle_args(argc,argv,params); \
benchmark::handle_args(argc, argv, params); \ test_class test_runner(params); \
test_class test_runner(params); \ auto result = run(test_runner,name); \
auto result = run(test_runner, name); \ testing::run_cleanup(); \
testing::run_cleanup(); \ return result; \
return result; \ } \
} \ catch (std::exception const& ex) \
catch (std::exception const& ex) \ { \
{ \ std::clog << ex.what() << "\n"; \
std::clog << ex.what() << "\n"; \ testing::run_cleanup(); \
testing::run_cleanup(); \ return -1; \
return -1; \ } \
} \ } \
}
struct big_number_fmt struct big_number_fmt
{ {
@ -148,9 +148,7 @@ struct big_number_fmt
const char* u; const char* u;
big_number_fmt(int width, double value, int base = 1000) big_number_fmt(int width, double value, int base = 1000)
: w(width) : w(width), v(value), u("")
, v(value)
, u("")
{ {
static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0"; static const char* suffixes = "\0\0k\0M\0G\0T\0P\0E\0Z\0Y\0\0";
u = suffixes; u = suffixes;
@ -166,7 +164,7 @@ struct big_number_fmt
} }
}; };
template<typename T> template <typename T>
int run(T const& test_runner, std::string const& name) int run(T const& test_runner, std::string const& name)
{ {
try try
@ -197,7 +195,8 @@ int run(T const& test_runner, std::string const& name)
std::mutex mtx_ready; std::mutex mtx_ready;
std::unique_lock<std::mutex> lock_ready(mtx_ready); std::unique_lock<std::mutex> lock_ready(mtx_ready);
auto stub = [&](T const& test_copy) { auto stub = [&](T const& test_copy)
{
// workers will wait on this mutex until the main thread // workers will wait on this mutex until the main thread
// constructs all of them and starts measuring time // constructs all of them and starts measuring time
std::unique_lock<std::mutex> my_lock(mtx_ready); std::unique_lock<std::mutex> my_lock(mtx_ready);
@ -207,14 +206,14 @@ int run(T const& test_runner, std::string const& name)
std::vector<std::thread> tg; std::vector<std::thread> tg;
tg.reserve(num_threads); tg.reserve(num_threads);
for (auto i = num_threads; i-- > 0;) for (auto i = num_threads; i-- > 0; )
{ {
tg.emplace_back(stub, test_runner); tg.emplace_back(stub, test_runner);
} }
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
lock_ready.unlock(); lock_ready.unlock();
// wait for all workers to finish // wait for all workers to finish
for (auto& t : tg) for (auto & t : tg)
{ {
if (t.joinable()) if (t.joinable())
t.join(); t.join();
@ -228,8 +227,7 @@ int run(T const& test_runner, std::string const& name)
else else
{ {
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
do do {
{
test_runner(); test_runner();
elapsed = std::chrono::high_resolution_clock::now() - start; elapsed = std::chrono::high_resolution_clock::now() - start;
total_iters += num_iters; total_iters += num_iters;
@ -244,24 +242,17 @@ int run(T const& test_runner, std::string const& name)
std::clog << std::left << std::setw(43) << name; std::clog << std::left << std::setw(43) << name;
std::clog << std::resetiosflags(std::ios::adjustfield); std::clog << std::resetiosflags(std::ios::adjustfield);
if (num_threads > 0) if (num_threads > 0) {
{ std::clog << ' ' << std::setw(3) << num_threads
std::clog << ' ' << std::setw(3) << num_threads << " worker" << (num_threads > 1 ? "s" : " "); << " worker" << (num_threads > 1 ? "s" : " ");
} }
else else {
{
std::clog << " main thread"; std::clog << " main thread";
} }
std::snprintf(msg, std::snprintf(msg, sizeof(msg),
sizeof(msg), " %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n",
" %*.0f%s iters %6.0f milliseconds %*.0f%s i/t/s\n", itersf.w, itersf.v, itersf.u, dur_total,
itersf.w, ips.w, ips.v, ips.u);
itersf.v,
itersf.u,
dur_total,
ips.w,
ips.v,
ips.u);
std::clog << msg; std::clog << msg;
return 0; return 0;
} }
@ -275,15 +266,18 @@ int run(T const& test_runner, std::string const& name)
struct sequencer struct sequencer
{ {
sequencer(int argc, char** argv) sequencer(int argc, char** argv)
: exit_code_(0) : exit_code_(0)
{ {
benchmark::handle_args(argc, argv, params_); benchmark::handle_args(argc, argv, params_);
} }
int done() const { return exit_code_; } int done() const
{
return exit_code_;
}
template<typename Test, typename... Args> template <typename Test, typename... Args>
sequencer& run(std::string const& name, Args&&... args) sequencer & run(std::string const& name, Args && ...args)
{ {
// Test instance lifetime is confined to this function // Test instance lifetime is confined to this function
Test test_runner(params_, std::forward<Args>(args)...); Test test_runner(params_, std::forward<Args>(args)...);
@ -292,11 +286,11 @@ struct sequencer
return *this; // allow chaining calls return *this; // allow chaining calls
} }
protected: protected:
mapnik::parameters params_; mapnik::parameters params_;
int exit_code_; int exit_code_;
}; };
} // namespace benchmark }
#endif // MAPNIK_BENCH_FRAMEWORK_HPP #endif // MAPNIK_BENCH_FRAMEWORK_HPP

View file

@ -5,31 +5,32 @@
#include <mapnik/image_util.hpp> #include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp> #include <mapnik/image_reader.hpp>
namespace benchmark { namespace benchmark {
bool compare_images(std::string const& src_fn, std::string const& dest_fn) bool compare_images(std::string const& src_fn,std::string const& dest_fn)
{
std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn, "png"));
if (!reader1.get())
{ {
throw mapnik::image_reader_exception("Failed to load: " + dest_fn); std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png"));
if (!reader1.get())
{
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
}
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
if (!reader2.get())
{
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
}
const mapnik::image_any desc_any = reader1->read(0,0,reader1->width(), reader1->height());
const mapnik::image_any src_any = reader2->read(0,0,reader2->width(), reader2->height());
mapnik::image_rgba8 const& dest = mapnik::util::get<mapnik::image_rgba8>(desc_any);
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
return compare(dest, src, 0, true) == 0;
} }
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn, "png"));
if (!reader2.get())
{
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
}
const mapnik::image_any desc_any = reader1->read(0, 0, reader1->width(), reader1->height());
const mapnik::image_any src_any = reader2->read(0, 0, reader2->width(), reader2->height());
mapnik::image_rgba8 const& dest = mapnik::util::get<mapnik::image_rgba8>(desc_any);
mapnik::image_rgba8 const& src = mapnik::util::get<mapnik::image_rgba8>(src_any);
return compare(dest, src, 0, true) == 0;
} }
} // namespace benchmark
#endif // MAPNIK_COMPARE_IMAGES_HPP #endif // MAPNIK_COMPARE_IMAGES_HPP

View file

@ -1,65 +0,0 @@
#!/bin/bash
BASE=.
function run {
local runner="$BASE/$1 --log=none"
local threads="$2"
local iters="$3"
shift 3
$runner --threads 0 --iterations $iters "$@"
if test $threads -gt 0; then
$runner --threads $threads --iterations $((iters/threads)) "$@"
fi
}
run test_getline 30 10000000
#run test_array_allocation 20 100000
#run test_png_encoding1 10 1000
#run test_png_encoding2 10 50
#run test_to_string1 10 100000
#run test_to_string2 10 100000
#run test_polygon_clipping 10 1000
#run test_polygon_clipping_rendering 10 100
run test_proj_transform1 10 100
run test_expression_parse 10 10000
run test_face_ptr_creation 10 1000
run test_font_registration 10 100
run test_offset_converter 10 1000
#run normalize_angle 0 1000000 --min-duration=0.2
# commented since this is really slow on travis
: '
$BASE/test_rendering \
--name "text rendering" \
--map benchmark/data/roads.xml \
--extent 1477001.12245,6890242.37746,1480004.49012,6892244.62256 \
--width 600 \
--height 600 \
--iterations 20 \
--threads 10
'
$BASE/test_rendering \
--name "gdal tiff rendering" \
--map benchmark/data/gdal-wgs.xml \
--extent -180.0,-120.0,180.0,120.0 \
--width 600 \
--height 600 \
--iterations 20 \
--threads 10
$BASE/test_rendering \
--name "raster tiff rendering" \
--map benchmark/data/raster-wgs.xml \
--extent -180.0,-120.0,180.0,120.0 \
--width 600 \
--height 600 \
--iterations 20 \
--threads 10
$BASE/test_quad_tree \
--iterations 10000 \
--threads 1
$BASE/test_quad_tree \
--iterations 1000 \
--threads 10

View file

@ -2,23 +2,20 @@
#include <mapnik/util/math.hpp> #include <mapnik/util/math.hpp>
template<typename T> template <typename T>
struct bench_func : benchmark::test_case struct bench_func : benchmark::test_case
{ {
T (*const func_)(T); T (* const func_)(T);
T const value_; T const value_;
bench_func(mapnik::parameters const& params, T (*func)(T), T value) bench_func(mapnik::parameters const& params, T (*func)(T), T value)
: test_case(params) : test_case(params), func_(func), value_(value) {}
, func_(func)
, value_(value)
{}
bool validate() const { return true; } bool validate() const { return true; }
bool operator()() const bool operator() () const
{ {
for (auto i = this->iterations_; i-- > 0;) for (auto i = this->iterations_; i-- > 0; )
{ {
func_(value_); func_(value_);
} }
@ -26,47 +23,47 @@ struct bench_func : benchmark::test_case
} }
}; };
#define BENCH_FUNC1(func, value) run<bench_func<double>>(#func "(" #value ")", func, value) #define BENCH_FUNC1(func, value) \
run<bench_func<double>>(#func "(" #value ")", func, value)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.BENCH_FUNC1(mapnik::util::normalize_angle, +3) .BENCH_FUNC1(mapnik::util::normalize_angle, +3)
.BENCH_FUNC1(mapnik::util::normalize_angle, +6) .BENCH_FUNC1(mapnik::util::normalize_angle, +6)
.BENCH_FUNC1(mapnik::util::normalize_angle, +9) .BENCH_FUNC1(mapnik::util::normalize_angle, +9)
.BENCH_FUNC1(mapnik::util::normalize_angle, +12) .BENCH_FUNC1(mapnik::util::normalize_angle, +12)
.BENCH_FUNC1(mapnik::util::normalize_angle, +15) .BENCH_FUNC1(mapnik::util::normalize_angle, +15)
.BENCH_FUNC1(mapnik::util::normalize_angle, +20) .BENCH_FUNC1(mapnik::util::normalize_angle, +20)
.BENCH_FUNC1(mapnik::util::normalize_angle, +30) .BENCH_FUNC1(mapnik::util::normalize_angle, +30)
.BENCH_FUNC1(mapnik::util::normalize_angle, +40) .BENCH_FUNC1(mapnik::util::normalize_angle, +40)
.BENCH_FUNC1(mapnik::util::normalize_angle, +50) .BENCH_FUNC1(mapnik::util::normalize_angle, +50)
.BENCH_FUNC1(mapnik::util::normalize_angle, +70) .BENCH_FUNC1(mapnik::util::normalize_angle, +70)
.BENCH_FUNC1(mapnik::util::normalize_angle, +90) .BENCH_FUNC1(mapnik::util::normalize_angle, +90)
.BENCH_FUNC1(mapnik::util::normalize_angle, +110) .BENCH_FUNC1(mapnik::util::normalize_angle, +110)
.BENCH_FUNC1(mapnik::util::normalize_angle, +130) .BENCH_FUNC1(mapnik::util::normalize_angle, +130)
.BENCH_FUNC1(mapnik::util::normalize_angle, +157) .BENCH_FUNC1(mapnik::util::normalize_angle, +157)
.BENCH_FUNC1(mapnik::util::normalize_angle, +209) .BENCH_FUNC1(mapnik::util::normalize_angle, +209)
.BENCH_FUNC1(mapnik::util::normalize_angle, +314) .BENCH_FUNC1(mapnik::util::normalize_angle, +314)
.BENCH_FUNC1(mapnik::util::normalize_angle, +628) .BENCH_FUNC1(mapnik::util::normalize_angle, +628)
.BENCH_FUNC1(mapnik::util::normalize_angle, +942) .BENCH_FUNC1(mapnik::util::normalize_angle, +942)
.BENCH_FUNC1(mapnik::util::normalize_angle, -3) .BENCH_FUNC1(mapnik::util::normalize_angle, -3)
.BENCH_FUNC1(mapnik::util::normalize_angle, -6) .BENCH_FUNC1(mapnik::util::normalize_angle, -6)
.BENCH_FUNC1(mapnik::util::normalize_angle, -9) .BENCH_FUNC1(mapnik::util::normalize_angle, -9)
.BENCH_FUNC1(mapnik::util::normalize_angle, -12) .BENCH_FUNC1(mapnik::util::normalize_angle, -12)
.BENCH_FUNC1(mapnik::util::normalize_angle, -15) .BENCH_FUNC1(mapnik::util::normalize_angle, -15)
.BENCH_FUNC1(mapnik::util::normalize_angle, -20) .BENCH_FUNC1(mapnik::util::normalize_angle, -20)
.BENCH_FUNC1(mapnik::util::normalize_angle, -30) .BENCH_FUNC1(mapnik::util::normalize_angle, -30)
.BENCH_FUNC1(mapnik::util::normalize_angle, -40) .BENCH_FUNC1(mapnik::util::normalize_angle, -40)
.BENCH_FUNC1(mapnik::util::normalize_angle, -50) .BENCH_FUNC1(mapnik::util::normalize_angle, -50)
.BENCH_FUNC1(mapnik::util::normalize_angle, -70) .BENCH_FUNC1(mapnik::util::normalize_angle, -70)
.BENCH_FUNC1(mapnik::util::normalize_angle, -90) .BENCH_FUNC1(mapnik::util::normalize_angle, -90)
.BENCH_FUNC1(mapnik::util::normalize_angle, -110) .BENCH_FUNC1(mapnik::util::normalize_angle, -110)
.BENCH_FUNC1(mapnik::util::normalize_angle, -130) .BENCH_FUNC1(mapnik::util::normalize_angle, -130)
.BENCH_FUNC1(mapnik::util::normalize_angle, -157) .BENCH_FUNC1(mapnik::util::normalize_angle, -157)
.BENCH_FUNC1(mapnik::util::normalize_angle, -209) .BENCH_FUNC1(mapnik::util::normalize_angle, -209)
.BENCH_FUNC1(mapnik::util::normalize_angle, -314) .BENCH_FUNC1(mapnik::util::normalize_angle, -314)
.BENCH_FUNC1(mapnik::util::normalize_angle, -628) .BENCH_FUNC1(mapnik::util::normalize_angle, -628)
.BENCH_FUNC1(mapnik::util::normalize_angle, -942) .BENCH_FUNC1(mapnik::util::normalize_angle, -942)
.done(); .done();
} }

View file

@ -14,19 +14,15 @@
#define FULL_ZERO_CHECK #define FULL_ZERO_CHECK
inline void ensure_zero(uint8_t* data, uint32_t size) inline void ensure_zero(uint8_t * data, uint32_t size) {
{
#ifdef FULL_ZERO_CHECK #ifdef FULL_ZERO_CHECK
for (std::size_t i = 0; i < size; ++i) for (std::size_t i=0;i<size;++i) {
{ if (data[i] != 0) {
if (data[i] != 0)
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
} }
#else #else
if (data[0] != 0) if (data[0] != 0) {
{
throw std::runtime_error("found non zero value"); throw std::runtime_error("found non zero value");
} }
#endif #endif
@ -34,262 +30,274 @@ inline void ensure_zero(uint8_t* data, uint32_t size)
class test1 : public benchmark::test_case class test1 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1(mapnik::parameters const& params) test1(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ // NOTE: sizeof(uint8_t) == 1
// NOTE: sizeof(uint8_t) == 1 uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_); memcpy(data, &array_[0], size_);
memcpy(data, &array_[0], size_); ensure_zero(data,size_);
ensure_zero(data, size_); free(data);
free(data); }
} return true;
return true;
} }
}; };
class test1b : public benchmark::test_case class test1b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1b(mapnik::parameters const& params) test1b(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ // NOTE: sizeof(uint8_t) == 1
// NOTE: sizeof(uint8_t) == 1 uint8_t *data = (uint8_t *)malloc(sizeof(uint8_t)*size_);
uint8_t* data = (uint8_t*)malloc(sizeof(uint8_t) * size_); memset(data, 0, sizeof(uint8_t)*size_);
memset(data, 0, sizeof(uint8_t) * size_); ensure_zero(data,size_);
ensure_zero(data, size_); free(data);
free(data); }
} return true;
return true;
} }
}; };
class test1c : public benchmark::test_case class test1c : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test1c(mapnik::parameters const& params) test1c(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ uint8_t *data = static_cast<uint8_t *>(::operator new(sizeof(uint8_t) * size_));
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_)); std::fill(data,data + size_,0);
std::fill(data, data + size_, 0); ensure_zero(data,size_);
ensure_zero(data, size_); ::operator delete(data);
::operator delete(data); }
} return true;
return true;
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ uint8_t * data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t)*size_));
uint8_t* data = static_cast<uint8_t*>(::operator new(sizeof(uint8_t) * size_)); memcpy(data, &array_[0], size_);
memcpy(data, &array_[0], size_); ensure_zero(data,size_);
ensure_zero(data, size_); ::operator delete(data),data=0;
::operator delete(data), data = 0; }
} return true;
return true;
} }
}; };
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; }
bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i)
{
std::vector<uint8_t> data(size_);
ensure_zero(&data[0], data.size());
}
return true; return true;
} }
bool operator()() const
{
for (std::size_t i=0;i<iterations_;++i) {
std::vector<uint8_t> data(size_);
ensure_zero(&data[0],data.size());
}
return true;
}
}; };
class test3b : public benchmark::test_case class test3b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3b(mapnik::parameters const& params) test3b(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::vector<uint8_t> data(0);
std::vector<uint8_t> data(0); data.resize(size_,0);
data.resize(size_, 0); ensure_zero(&data[0],data.size());
ensure_zero(&data[0], data.size()); }
} return true;
return true;
} }
}; };
class test3c : public benchmark::test_case class test3c : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3c(mapnik::parameters const& params) test3c(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::vector<uint8_t> data(0);
std::vector<uint8_t> data(0); data.assign(size_,0);
data.assign(size_, 0); ensure_zero(&data[0],data.size());
ensure_zero(&data[0], data.size()); }
} return true;
return true;
} }
}; };
class test3d : public benchmark::test_case class test3d : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test3d(mapnik::parameters const& params) test3d(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::deque<uint8_t> data(size_);
std::deque<uint8_t> data(size_); for (std::size_t i=0;i<size_;++i) {
for (std::size_t i = 0; i < size_; ++i) if (data[i] != 0) {
{ throw std::runtime_error("found non zero value");
if (data[i] != 0) }
{ }
throw std::runtime_error("found non zero value"); }
} return true;
}
}
return true;
} }
}; };
class test4 : public benchmark::test_case class test4 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test4(mapnik::parameters const& params) test4(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ uint8_t *data = (uint8_t *)calloc(size_,sizeof(uint8_t));
uint8_t* data = (uint8_t*)calloc(size_, sizeof(uint8_t)); ensure_zero(data,size_);
ensure_zero(data, size_); free(data);
free(data); }
} return true;
return true;
} }
}; };
class test5 : public benchmark::test_case class test5 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test5(mapnik::parameters const& params) test5(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::string data(array_.begin(),array_.end());
std::string data(array_.begin(), array_.end()); ensure_zero((uint8_t *)&data[0],size_);
ensure_zero((uint8_t*)&data[0], size_); }
} return true;
return true;
} }
}; };
class test5b : public benchmark::test_case class test5b : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<char> array_; std::vector<char> array_;
test5b(mapnik::parameters const& params) test5b(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::string data(&array_[0],array_.size());
std::string data(&array_[0], array_.size()); ensure_zero((uint8_t *)&data[0],size_);
ensure_zero((uint8_t*)&data[0], size_); }
} return true;
return true;
} }
}; };
@ -300,23 +308,24 @@ class test5b : public benchmark::test_case
class test6 : public benchmark::test_case class test6 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test6(mapnik::parameters const& params) test6(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ std::valarray<uint8_t> data(static_cast<uint8_t>(0),static_cast<size_t>(size_));
std::valarray<uint8_t> data(static_cast<uint8_t>(0), static_cast<size_t>(size_)); ensure_zero(&data[0],size_);
ensure_zero(&data[0], size_); }
} return true;
return true;
} }
}; };
@ -326,45 +335,45 @@ class test6 : public benchmark::test_case
class test7 : public benchmark::test_case class test7 : public benchmark::test_case
{ {
public: public:
uint32_t size_; uint32_t size_;
std::vector<uint8_t> array_; std::vector<uint8_t> array_;
test7(mapnik::parameters const& params) test7(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, size_(*params.get<mapnik::value_integer>("size", 256 * 256)) size_(*params.get<mapnik::value_integer>("size",256*256)),
, array_(size_, 0) array_(size_,0) { }
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ boost::container::static_vector<uint8_t,256*256> data(size_,0);
boost::container::static_vector<uint8_t, 256 * 256> data(size_, 0); ensure_zero(&data[0],size_);
ensure_zero(&data[0], size_); }
} return true;
return true;
} }
}; };
#endif #endif
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test4>("calloc") .run<test4>("calloc")
.run<test1>("malloc/memcpy") .run<test1>("malloc/memcpy")
.run<test1b>("malloc/memset") .run<test1b>("malloc/memset")
.run<test1c>("operator new/std::fill") .run<test1c>("operator new/std::fill")
.run<test2>("operator new/memcpy") .run<test2>("operator new/memcpy")
.run<test3>("vector(N)") .run<test3>("vector(N)")
.run<test3b>("vector/resize") .run<test3b>("vector/resize")
.run<test3c>("vector/assign") .run<test3c>("vector/assign")
.run<test3d>("deque(N)") .run<test3d>("deque(N)")
.run<test5>("std::string range") .run<test5>("std::string range")
.run<test5b>("std::string &[0]") .run<test5b>("std::string &[0]")
.run<test6>("valarray") .run<test6>("valarray")
#if BOOST_VERSION >= 105400 #if BOOST_VERSION >= 105400
.run<test7>("static_vector") .run<test7>("static_vector")
#endif #endif
.done(); .done();
} }

View file

@ -7,12 +7,10 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string expr_; std::string expr_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") expr_("((([mapnik::geometry_type]=2) and ([oneway]=1)) and ([class]='path'))") {}
{}
bool validate() const bool validate() const
{ {
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
@ -20,25 +18,24 @@ class test : public benchmark::test_case
bool ret = (result == expr_); bool ret = (result == expr_);
if (!ret) if (!ret)
{ {
std::clog << result << " != " << expr_ << "\n"; std::clog << result << " != " << expr_ << "\n";
} }
return ret; return ret;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ mapnik::expression_ptr expr = mapnik::parse_expression(expr_);
mapnik::expression_ptr expr = mapnik::parse_expression(expr_); }
} return true;
return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
test test_runner(params); test test_runner(params);
return run(test_runner, "expr parsing"); return run(test_runner,"expr parsing");
} }

View file

@ -4,10 +4,9 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{}
bool validate() const bool validate() const
{ {
std::size_t count = 0; std::size_t count = 0;
@ -23,15 +22,14 @@ class test : public benchmark::test_case
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) if (f) ++count;
++count;
} }
return count == expected_count; return count == expected_count;
} }
bool operator()() const bool operator()() const
{ {
std::size_t expected_count = mapnik::freetype_engine::face_names().size(); std::size_t expected_count = mapnik::freetype_engine::face_names().size();
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
std::size_t count = 0; std::size_t count = 0;
mapnik::freetype_engine::font_file_mapping_type font_file_mapping; mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
@ -45,11 +43,9 @@ class test : public benchmark::test_case
font_cache, font_cache,
mapnik::freetype_engine::get_mapping(), mapnik::freetype_engine::get_mapping(),
mapnik::freetype_engine::get_cache()); mapnik::freetype_engine::get_cache());
if (f) if (f) ++count;
++count;
} }
if (count != expected_count) if (count != expected_count) {
{
std::clog << "warning: face creation not working as expected\n"; std::clog << "warning: face creation not working as expected\n";
} }
} }
@ -59,16 +55,15 @@ class test : public benchmark::test_case
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
bool success = mapnik::freetype_engine::register_fonts("./fonts", true); bool success = mapnik::freetype_engine::register_fonts("./fonts", true);
if (!success) if (!success) {
{ std::clog << "warning, did not register any new fonts!\n";
std::clog << "warning, did not register any new fonts!\n"; return -1;
return -1;
} }
std::size_t face_count = mapnik::freetype_engine::face_names().size(); std::size_t face_count = mapnik::freetype_engine::face_names().size();
test test_runner(params); test test_runner(params);
return run(test_runner, (boost::format("font_engine: creating %ld faces") % (face_count)).str()); return run(test_runner,(boost::format("font_engine: creating %ld faces") % (face_count)).str());
} }

View file

@ -1,18 +1,21 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/font_engine_freetype.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/foreach.hpp>
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{} bool validate() const
bool validate() const { return mapnik::freetype_engine::register_fonts("./fonts", true); } {
return mapnik::freetype_engine::register_fonts("./fonts", true);
}
bool operator()() const bool operator()() const
{ {
unsigned long count = 0; unsigned long count = 0;
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
mapnik::freetype_engine::register_fonts("./fonts", true); mapnik::freetype_engine::register_fonts("./fonts", true);
count++; count++;
@ -21,4 +24,4 @@ class test : public benchmark::test_case
} }
}; };
BENCHMARK(test, "font registration") BENCHMARK(test,"font registration")

View file

@ -1,20 +1,22 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include "../plugins/input/csv/csv_getline.hpp" #include "../plugins/input/csv/csv_getline.hpp"
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, line_data_("this is one line\nand this is a second line\nand a third line") line_data_("this is one line\nand this is a second line\nand a third line")
{ {
auto line_data = params.get<std::string>("line"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
{ {
line_data_ = *line_data; line_data_ = *line_data;
} }
} }
bool validate() const bool validate() const
{ {
@ -23,15 +25,14 @@ class test : public benchmark::test_case
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
std::getline(s, csv_line, newline); std::getline(s,csv_line,newline);
if (csv_line != first) if (csv_line != first)
{ {
return true; return true;
} }
else else
{ {
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
} }
return true; return true;
} }
@ -41,28 +42,29 @@ class test : public benchmark::test_case
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
std::getline(s, csv_line, newline); std::getline(s,csv_line,newline);
} }
return true; return true;
} }
}; };
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
public: public:
std::string line_data_; std::string line_data_;
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, line_data_("this is one line\nand this is a second line\nand a third line") line_data_("this is one line\nand this is a second line\nand a third line")
{ {
auto line_data = params.get<std::string>("line"); boost::optional<std::string> line_data = params.get<std::string>("line");
if (line_data) if (line_data)
{ {
line_data_ = *line_data; line_data_ = *line_data;
} }
} }
bool validate() const bool validate() const
{ {
@ -72,15 +74,14 @@ class test2 : public benchmark::test_case
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
csv_utils::getline_csv(s, csv_line, newline, quote); csv_utils::getline_csv(s,csv_line,newline,quote);
if (csv_line != first) if (csv_line != first)
{ {
return true; return true;
} }
else else
{ {
std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" std::clog << "Error: the parsed line (" << csv_line << ") should be a subset of the original line (" << line_data_ << ") (ensure you pass a line with a \\n)\n";
<< line_data_ << ") (ensure you pass a line with a \\n)\n";
} }
return true; return true;
} }
@ -91,9 +92,9 @@ class test2 : public benchmark::test_case
std::string csv_line; std::string csv_line;
std::stringstream s; std::stringstream s;
s << line_data_; s << line_data_;
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
csv_utils::getline_csv(s, csv_line, newline, quote); csv_utils::getline_csv(s,csv_line,newline,quote);
} }
return true; return true;
} }
@ -101,19 +102,18 @@ class test2 : public benchmark::test_case
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
int return_value = 0; int return_value = 0;
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
{ {
test test_runner(params); test test_runner(params);
return_value = return_value | run(test_runner, "std::getline"); return_value = return_value | run(test_runner,"std::getline");
} }
{ {
test2 test_runner2(params); test2 test_runner2(params);
return_value = return_value | run(test_runner2, "csv_utils::getline_csv"); return_value = return_value | run(test_runner2,"csv_utils::getline_csv");
} }
} }
catch (std::exception const& ex) catch (std::exception const& ex)

View file

@ -4,32 +4,34 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::vector<std::string> images_; std::vector<std::string> images_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, images_{"./test/data/images/dummy.jpg", images_{
"./test/data/images/dummy.jpeg", "./test/data/images/dummy.jpg",
"./test/data/images/dummy.png", "./test/data/images/dummy.jpeg",
"./test/data/images/dummy.tif", "./test/data/images/dummy.png",
"./test/data/images/dummy.tiff", "./test/data/images/dummy.tif",
//"./test/data/images/landusepattern.jpeg", // will fail since it is a png "./test/data/images/dummy.tiff",
//"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png //"./test/data/images/landusepattern.jpeg", // will fail since it is a png
"./test/data/svg/octocat.svg", //"./test/data/images/xcode-CgBI.png", // will fail since its an invalid png
"./test/data/svg/place-of-worship-24.svg", "./test/data/svg/octocat.svg",
"./test/data/svg/point_sm.svg", "./test/data/svg/place-of-worship-24.svg",
"./test/data/svg/point.svg", "./test/data/svg/point_sm.svg",
"./test/data/svg/airfield-12.svg"} "./test/data/svg/point.svg",
{} "./test/data/svg/airfield-12.svg"
bool validate() const { return true; } } {}
bool validate() const
{
return true;
}
bool operator()() const bool operator()() const
{ {
unsigned count = 0; unsigned count = 0;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
for (auto filename : images_) for (auto filename : images_)
{ {
auto marker = mapnik::marker_cache::instance().find(filename, true); auto marker = mapnik::marker_cache::instance().find(filename,true);
} }
++count; ++count;
} }
@ -37,4 +39,4 @@ class test : public benchmark::test_case
} }
}; };
BENCHMARK(test, "marker cache") BENCHMARK(test,"marker cache")

View file

@ -14,38 +14,40 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{}
bool validate() const { return true; } bool validate() const
{
return true;
}
bool operator()() const bool operator()() const
{ {
mapnik::Map m(256, 256, "epsg:3857"); mapnik::Map m(256,256,"+init=epsg:3857");
mapnik::parameters params; mapnik::parameters params;
params["type"] = "memory"; params["type"]="memory";
auto ds = std::make_shared<mapnik::memory_datasource>(params); auto ds = std::make_shared<mapnik::memory_datasource>(params);
// add whitespace to trigger phony "reprojection" // add whitespace to trigger phony "reprojection"
mapnik::layer lay("layer", m.srs() + " "); mapnik::layer lay("layer",m.srs() + " ");
lay.set_datasource(ds); lay.set_datasource(ds);
lay.add_style("style"); lay.add_style("style");
m.add_layer(lay); m.add_layer(lay);
// dummy style to ensure that layer is processed // dummy style to ensure that layer is processed
m.insert_style("style", mapnik::feature_type_style()); m.insert_style("style",mapnik::feature_type_style());
// dummy bbox, but "valid" because minx and miny are less // dummy bbox, but "valid" because minx and miny are less
// with an invalid bbox then layer.visible() returns false // with an invalid bbox then layer.visible() returns false
// and the initial rendering setup is not run // and the initial rendering setup is not run
m.zoom_to_box(mapnik::box2d<double>(-1, -1, 0, 0)); m.zoom_to_box(mapnik::box2d<double>(-1,-1,0,0));
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
mapnik::image_rgba8 im(256, 256); mapnik::image_rgba8 im(256,256);
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
BENCHMARK(test, "rendering with reprojection") BENCHMARK(test,"rendering with reprojection")

View file

@ -9,25 +9,23 @@ class test_static : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public:
public:
test_static(mapnik::parameters const& params) test_static(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, step_(STEP_NUM) step_(STEP_NUM),
, start_(START_NUM) start_(START_NUM) {}
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
double c = static_cast<double>(start_) * value_; double c = static_cast<double>(start_) * value_;
if (c >= 256.0) if (c >= 256.0) c = 255.0;
c = 255.0; if (c < 0.0) c = 0.0;
if (c < 0.0)
c = 0.0;
x = static_cast<std::uint8_t>(c); x = static_cast<std::uint8_t>(c);
value_ += step_; value_ += step_;
} }
@ -35,36 +33,35 @@ class test_static : public benchmark::test_case
} }
}; };
using boost::numeric::negative_overflow;
using boost::numeric::positive_overflow; using boost::numeric::positive_overflow;
using boost::numeric::negative_overflow;
class test_numeric : public benchmark::test_case class test_numeric : public benchmark::test_case
{ {
double step_; double step_;
std::uint8_t start_; std::uint8_t start_;
public:
public:
test_numeric(mapnik::parameters const& params) test_numeric(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, step_(STEP_NUM) step_(STEP_NUM),
, start_(START_NUM) start_(START_NUM) {}
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
double value_ = 0.0; double value_ = 0.0;
std::uint8_t x; std::uint8_t x;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ try {
try
{
x = boost::numeric_cast<std::uint8_t>(start_ * value_); x = boost::numeric_cast<std::uint8_t>(start_ * value_);
} }
catch (negative_overflow&) catch(negative_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::min(); x = std::numeric_limits<std::uint8_t>::min();
} }
catch (positive_overflow&) catch(positive_overflow&)
{ {
x = std::numeric_limits<std::uint8_t>::max(); x = std::numeric_limits<std::uint8_t>::max();
} }
@ -76,6 +73,8 @@ class test_numeric : public benchmark::test_case
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup(); return benchmark::sequencer(argc, argv)
return benchmark::sequencer(argc, argv).run<test_static>("static_cast").run<test_numeric>("numeric_cast").done(); .run<test_static>("static_cast")
.run<test_numeric>("numeric_cast")
.done();
} }

View file

@ -14,36 +14,31 @@ struct fake_path
cont_type::iterator itr_; cont_type::iterator itr_;
fake_path(std::initializer_list<double> l) fake_path(std::initializer_list<double> l)
: fake_path(l.begin(), l.size()) : fake_path(l.begin(), l.size()) {
{} }
fake_path(std::vector<double> const& v) fake_path(std::vector<double> const &v)
: fake_path(v.begin(), v.size()) : fake_path(v.begin(), v.size()) {
{} }
template<typename Itr> template <typename Itr>
fake_path(Itr itr, size_t sz) fake_path(Itr itr, size_t sz) {
{
size_t num_coords = sz >> 1; size_t num_coords = sz >> 1;
vertices_.reserve(num_coords); vertices_.reserve(num_coords);
for (size_t i = 0; i < num_coords; ++i) for (size_t i = 0; i < num_coords; ++i) {
{
double x = *itr++; double x = *itr++;
double y = *itr++; double y = *itr++;
unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO; unsigned cmd = (i == 0) ? mapnik::SEG_MOVETO : mapnik::SEG_LINETO;
vertices_.push_back(std::make_tuple(x, y, cmd)); vertices_.push_back(std::make_tuple(x, y, cmd));
if (i == num_coords - 1) if (i == num_coords - 1) cmd = mapnik::SEG_END;
cmd = mapnik::SEG_END;
vertices_.push_back(std::make_tuple(x, y, cmd)); vertices_.push_back(std::make_tuple(x, y, cmd));
} }
itr_ = vertices_.begin(); itr_ = vertices_.begin();
} }
unsigned vertex(double* x, double* y) unsigned vertex(double *x, double *y) {
{ if (itr_ == vertices_.end()) {
if (itr_ == vertices_.end())
{
return mapnik::SEG_END; return mapnik::SEG_END;
} }
*x = std::get<0>(*itr_); *x = std::get<0>(*itr_);
@ -53,30 +48,33 @@ struct fake_path
return cmd; return cmd;
} }
void rewind(unsigned) { itr_ = vertices_.begin(); } void rewind(unsigned) {
itr_ = vertices_.begin();
}
}; };
class test_offset : public benchmark::test_case class test_offset : public benchmark::test_case
{ {
public: public:
test_offset(mapnik::parameters const& params) test_offset(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
std::vector<double> path; std::vector<double> path;
int mysize = 2500; int mysize = 2500;
int x1 = 0; int x1 = 0;
path.reserve(mysize * 2); path.reserve(mysize*2);
for (int i = 0; i < mysize; i++) for( int i = 0; i < mysize; i++ )
{ {
path.push_back(i); path.push_back( i );
path.push_back(0); path.push_back( 0 );
} }
fake_path fpath(path); fake_path fpath(path);
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
mapnik::offset_converter<fake_path> off_path(fpath); mapnik::offset_converter<fake_path> off_path(fpath);
off_path.set_offset(10); off_path.set_offset(10);
unsigned cmd; unsigned cmd;
@ -90,15 +88,15 @@ class test_offset : public benchmark::test_case
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
int return_value = 0; int return_value = 0;
{ {
test_offset test_runner(params); test_offset test_runner(params);
return_value = run(test_runner, "offset_test"); return_value = run(test_runner,"offset_test");
} }
return return_value; return return_value;
} }

View file

@ -4,23 +4,23 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
mapnik::image_rgba8 im_; mapnik::image_rgba8 im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, im_(256, 256) im_(256,256) {}
{} bool validate() const
bool validate() const { return true; } {
return true;
}
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
out.clear(); out.clear();
out = mapnik::save_to_string(im_, "png8:m=h:z=1"); out = mapnik::save_to_string(im_,"png8:m=h:z=1");
} }
return true; return true;
} }
}; };
BENCHMARK(test, "encoding blank png") BENCHMARK(test,"encoding blank png")

View file

@ -1,41 +1,37 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include "compare_images.hpp" #include "compare_images.hpp"
#include <memory>
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::shared_ptr<mapnik::image_rgba8> im_; std::shared_ptr<mapnik::image_rgba8> im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {
{
std::string filename("./benchmark/data/multicolor.png"); std::string filename("./benchmark/data/multicolor.png");
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename, "png")); std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename,"png"));
if (!reader.get()) if (!reader.get())
{ {
throw mapnik::image_reader_exception("Failed to load: " + filename); throw mapnik::image_reader_exception("Failed to load: " + filename);
} }
im_ = std::make_shared<mapnik::image_rgba8>(reader->width(), reader->height()); im_ = std::make_shared<mapnik::image_rgba8>(reader->width(),reader->height());
reader->read(0, 0, *im_); reader->read(0,0,*im_);
} }
bool validate() const bool validate() const
{ {
std::string expected("./benchmark/data/multicolor-hextree-expected.png"); std::string expected("./benchmark/data/multicolor-hextree-expected.png");
std::string actual("./benchmark/data/multicolor-hextree-actual.png"); std::string actual("./benchmark/data/multicolor-hextree-actual.png");
mapnik::save_to_file(*im_, actual, "png8:m=h:z=1"); mapnik::save_to_file(*im_,actual, "png8:m=h:z=1");
return benchmark::compare_images(actual, expected); return benchmark::compare_images(actual,expected);
} }
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
out.clear(); out.clear();
out = mapnik::save_to_string(*im_, "png8:m=h:z=1"); out = mapnik::save_to_string(*im_,"png8:m=h:z=1");
} }
return true; return true;
} }
}; };
BENCHMARK(test, "encoding multicolor png") BENCHMARK(test,"encoding multicolor png")

View file

@ -39,31 +39,30 @@ void render(mapnik::geometry::multi_polygon<double> const& geom,
mapnik::box2d<double> const& extent, mapnik::box2d<double> const& extent,
std::string const& name) std::string const& name)
{ {
using path_type = using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::geometry::polygon_vertex_adapter<double>>;
mapnik::transform_path_adapter<mapnik::view_transform, mapnik::geometry::polygon_vertex_adapter<double>>;
using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>; using ren_base = agg::renderer_base<agg::pixfmt_rgba32_plain>;
using renderer = agg::renderer_scanline_aa_solid<ren_base>; using renderer = agg::renderer_scanline_aa_solid<ren_base>;
mapnik::image_rgba8 im(256, 256); mapnik::image_rgba8 im(256,256);
mapnik::fill(im, mapnik::color("white")); mapnik::fill(im, mapnik::color("white"));
mapnik::box2d<double> padded_extent(155, 134, 665, 466); // extent; mapnik::box2d<double> padded_extent(155,134,665,466);//extent;
padded_extent.pad(10); padded_extent.pad(10);
mapnik::view_transform tr(im.width(), im.height(), padded_extent, 0, 0); mapnik::view_transform tr(im.width(),im.height(),padded_extent,0,0);
agg::rendering_buffer buf(im.bytes(), im.width(), im.height(), im.row_size()); agg::rendering_buffer buf(im.bytes(),im.width(),im.height(), im.row_size());
agg::pixfmt_rgba32_plain pixf(buf); agg::pixfmt_rgba32_plain pixf(buf);
ren_base renb(pixf); ren_base renb(pixf);
renderer ren(renb); renderer ren(renb);
mapnik::proj_transform prj_trans(mapnik::projection("epsg:4326"), mapnik::projection("epsg:4326")); mapnik::proj_transform prj_trans(mapnik::projection("+init=epsg:4326"),mapnik::projection("+init=epsg:4326"));
ren.color(agg::rgba8(127, 127, 127, 255)); ren.color(agg::rgba8(127,127,127,255));
agg::rasterizer_scanline_aa<> ras; agg::rasterizer_scanline_aa<> ras;
for (auto const& poly : geom) for (auto const& poly : geom)
{ {
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
path_type path(tr, va, prj_trans); path_type path(tr,va,prj_trans);
ras.add_path(path); ras.add_path(path);
} }
agg::scanline_u8 sl; agg::scanline_u8 sl;
agg::render_scanlines(ras, sl, ren); agg::render_scanlines(ras, sl, ren);
mapnik::save_to_file(im, name); mapnik::save_to_file(im,name);
} }
class test1 : public benchmark::test_case class test1 : public benchmark::test_case
@ -71,15 +70,15 @@ class test1 : public benchmark::test_case
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public:
public:
using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>; using conv_clip = agg::conv_clip_polygon<mapnik::geometry::polygon_vertex_adapter<double>>;
test1(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent) test1(mapnik::parameters const& params,
: test_case(params) std::string const& wkt_in,
, wkt_in_(wkt_in) mapnik::box2d<double> const& extent)
, extent_(extent) : test_case(params),
, expected_("./benchmark/data/polygon_clipping_agg") wkt_in_(wkt_in),
{} extent_(extent),
expected_("./benchmark/data/polygon_clipping_agg") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -100,8 +99,14 @@ class test1 : public benchmark::test_case
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy()); clipped.clip_box(
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
clipped.rewind(0); clipped.rewind(0);
mapnik::geometry::polygon<double> poly2; mapnik::geometry::polygon<double> poly2;
@ -113,8 +118,7 @@ class test1 : public benchmark::test_case
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; x0 = x; y0 = y;
y0 = y;
} }
if (cmd == mapnik::SEG_CLOSE) if (cmd == mapnik::SEG_CLOSE)
@ -122,7 +126,7 @@ class test1 : public benchmark::test_case
ring.emplace_back(x0, y0); ring.emplace_back(x0, y0);
break; break;
} }
ring.emplace_back(x, y); ring.emplace_back(x,y);
} }
poly2.push_back(std::move(ring)); poly2.push_back(std::move(ring));
// interior rings // interior rings
@ -131,31 +135,30 @@ class test1 : public benchmark::test_case
{ {
if (cmd == mapnik::SEG_MOVETO) if (cmd == mapnik::SEG_MOVETO)
{ {
x0 = x; x0 = x; y0 = y;
y0 = y;
} }
else if (cmd == mapnik::SEG_CLOSE) else if (cmd == mapnik::SEG_CLOSE)
{ {
ring.emplace_back(x0, y0); ring.emplace_back(x0,y0);
poly2.push_back(std::move(ring)); poly2.push_back(std::move(ring));
ring.clear(); ring.clear();
continue; continue;
} }
ring.emplace_back(x, y); ring.emplace_back(x,y);
} }
std::string expect = expected_ + ".png"; std::string expect = expected_+".png";
std::string actual = expected_ + "_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon<double> mp; mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2); mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp); auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
std::clog << "generating expected image: " << expect << "\n"; std::clog << "generating expected image: " << expect << "\n";
render(mp, env, expect); render(mp,env,expect);
} }
render(mp, env, actual); render(mp,env,actual);
return benchmark::compare_images(actual, expect); return benchmark::compare_images(actual,expect);
} }
bool operator()() const bool operator()() const
{ {
@ -175,28 +178,29 @@ class test1 : public benchmark::test_case
return false; return false;
} }
bool valid = true; bool valid = true;
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
unsigned count = 0; unsigned count = 0;
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter<double> va(poly); mapnik::geometry::polygon_vertex_adapter<double> va(poly);
conv_clip clipped(va); conv_clip clipped(va);
clipped.clip_box(extent_.minx(), extent_.miny(), extent_.maxx(), extent_.maxy()); clipped.clip_box(
extent_.minx(),
extent_.miny(),
extent_.maxx(),
extent_.maxy());
unsigned cmd; unsigned cmd;
double x, y; double x,y;
// NOTE: this rewind is critical otherwise // NOTE: this rewind is critical otherwise
// agg_conv_adapter_vpgen will give garbage // agg_conv_adapter_vpgen will give garbage
// values for the first vertex // values for the first vertex
clipped.rewind(0); clipped.rewind(0);
while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) while ((cmd = clipped.vertex(&x, &y)) != mapnik::SEG_END) {
{
count++; count++;
} }
unsigned expected_count = 30; unsigned expected_count = 30;
if (count != expected_count) if (count != expected_count) {
{ std::clog << "test1: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
std::clog << "test1: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -204,19 +208,20 @@ class test1 : public benchmark::test_case
} }
}; };
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string wkt_in_; std::string wkt_in_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
std::string expected_; std::string expected_;
public:
public: test3(mapnik::parameters const& params,
test3(mapnik::parameters const& params, std::string const& wkt_in, mapnik::box2d<double> const& extent) std::string const& wkt_in,
: test_case(params) mapnik::box2d<double> const& extent)
, wkt_in_(wkt_in) : test_case(params),
, extent_(extent) wkt_in_(wkt_in),
, expected_("./benchmark/data/polygon_clipping_boost") extent_(extent),
{} expected_("./benchmark/data/polygon_clipping_boost") {}
bool validate() const bool validate() const
{ {
mapnik::geometry::geometry<double> geom; mapnik::geometry::geometry<double> geom;
@ -229,12 +234,12 @@ class test3 : public benchmark::test_case
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon<double>>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
mapnik::geometry::linear_ring<double> bbox; mapnik::geometry::linear_ring<double> bbox;
@ -244,15 +249,15 @@ class test3 : public benchmark::test_case
bbox.emplace_back(extent_.maxx(), extent_.miny()); bbox.emplace_back(extent_.maxx(), extent_.miny());
bbox.emplace_back(extent_.minx(), extent_.miny()); bbox.emplace_back(extent_.minx(), extent_.miny());
std::deque<mapnik::geometry::polygon<double>> result; std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(bbox, poly, result); boost::geometry::intersection(bbox, poly, result);
std::string expect = expected_ + ".png"; std::string expect = expected_+".png";
std::string actual = expected_ + "_actual.png"; std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon<double> mp; mapnik::geometry::multi_polygon<double> mp;
for (auto const& _geom : result) for (auto const& _geom: result)
{ {
// std::clog << boost::geometry::dsv(geom) << "\n"; //std::clog << boost::geometry::dsv(geom) << "\n";
mp.emplace_back(_geom); mp.emplace_back(_geom);
} }
mapnik::geometry::geometry<double> geom2(mp); mapnik::geometry::geometry<double> geom2(mp);
@ -260,10 +265,10 @@ class test3 : public benchmark::test_case
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr)) if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{ {
std::clog << "generating expected image: " << expect << "\n"; std::clog << "generating expected image: " << expect << "\n";
render(mp, env, expect); render(mp,env,expect);
} }
render(mp, env, actual); render(mp,env,actual);
return benchmark::compare_images(actual, expect); return benchmark::compare_images(actual,expect);
} }
bool operator()() const bool operator()() const
{ {
@ -277,12 +282,12 @@ class test3 : public benchmark::test_case
std::clog << "empty geom!\n"; std::clog << "empty geom!\n";
return false; return false;
} }
if (!geom.is<mapnik::geometry::polygon<double>>()) if (!geom.is<mapnik::geometry::polygon<double> >())
{ {
std::clog << "not a polygon!\n"; std::clog << "not a polygon!\n";
return false; return false;
} }
mapnik::geometry::polygon<double>& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom); mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly); mapnik::geometry::correct(poly);
mapnik::geometry::linear_ring<double> bbox; mapnik::geometry::linear_ring<double> bbox;
@ -293,25 +298,22 @@ class test3 : public benchmark::test_case
bbox.emplace_back(extent_.minx(), extent_.miny()); bbox.emplace_back(extent_.minx(), extent_.miny());
bool valid = true; bool valid = true;
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
std::deque<mapnik::geometry::polygon<double>> result; std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(bbox, poly, result); boost::geometry::intersection(bbox, poly, result);
unsigned count = 0; unsigned count = 0;
for (auto const& _geom : result) for (auto const& _geom : result)
{ {
mapnik::geometry::polygon_vertex_adapter<double> va(_geom); mapnik::geometry::polygon_vertex_adapter<double> va(_geom);
unsigned cmd; unsigned cmd;
double x, y; double x,y;
while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) {
{
++count; ++count;
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) if (count != expected_count) {
{ std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
std::clog << "test3: clipping failed: processed " << count << " verticies but expected "
<< expected_count << "\n";
valid = false; valid = false;
} }
} }
@ -498,8 +500,8 @@ public:
} }
unsigned expected_count = 29; unsigned expected_count = 29;
if (count != expected_count) { if (count != expected_count) {
std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << std::clog << "test3: clipping failed: processed " << count << " verticies but expected " << expected_count << "\n";
expected_count << "\n"; valid = false; valid = false;
} }
} }
} }
@ -510,18 +512,14 @@ expected_count << "\n"; valid = false;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
// polygon/rect clipping // polygon/rect clipping
// IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, // IN : POLYGON ((155 203, 233 454, 315 340, 421 446, 463 324, 559 466, 665 253, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
// 183 228, 200 264, 155 203),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 // RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106))
// 287, 249 334, 229 191, 313 190)) RECT : POLYGON ((181 106, 181 470, 631 470, 631 106, 181 106)) OUT (expected) // OUT (expected)
// POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 // POLYGON ((181 286.6666666666667, 233 454, 315 340, 421 446, 463 324, 559 466, 631 321.3207547169811, 631 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249 334, 229 191, 313 190))
// 234.38686131386862, 528 178, 394 229, 329 138, 212 134, 183 228, 200 264, 181 238.24444444444444, 181
// 286.6666666666667),(313 190, 440 256, 470 248, 510 305, 533 237, 613 263, 553 397, 455 262, 405 378, 343 287, 249
// 334, 229 191, 313 190))
#if 0 #if 0
mapnik::box2d<double> clipping_box(181,106,631,470); mapnik::box2d<double> clipping_box(181,106,631,470);
std::string filename_("./benchmark/data/polygon.wkt"); std::string filename_("./benchmark/data/polygon.wkt");
@ -546,5 +544,5 @@ int main(int argc, char** argv)
} }
*/ */
#endif #endif
return 0; // return_value; return 0;// return_value;
} }

View file

@ -8,52 +8,53 @@ class test : public benchmark::test_case
{ {
std::string xml_; std::string xml_;
mapnik::box2d<double> extent_; mapnik::box2d<double> extent_;
public:
public: test(mapnik::parameters const& params,
test(mapnik::parameters const& params, std::string const& xml, mapnik::box2d<double> const& extent) std::string const& xml,
: test_case(params) mapnik::box2d<double> const& extent)
, xml_(xml) : test_case(params),
, extent_(extent) xml_(xml),
{} extent_(extent)
{}
bool validate() const bool validate() const
{ {
mapnik::Map m(256, 256); mapnik::Map m(256,256);
mapnik::load_map(m, xml_); mapnik::load_map(m,xml_);
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
mapnik::image_rgba8 im(m.width(), m.height()); mapnik::image_rgba8 im(m.width(),m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
ren.apply(); ren.apply();
// mapnik::save_to_file(im.data(),"test.png"); //mapnik::save_to_file(im.data(),"test.png");
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
mapnik::Map m(256, 256); mapnik::Map m(256,256);
mapnik::load_map(m, xml_); mapnik::load_map(m,xml_);
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
mapnik::image_rgba8 im(m.width(), m.height()); mapnik::image_rgba8 im(m.width(),m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
mapnik::box2d<double> z1(-20037508.3428, -8317435.0606, 20037508.3428, 18399242.7298); mapnik::box2d<double> z1(-20037508.3428,-8317435.0606,20037508.3428,18399242.7298);
// bbox for 16/10491/22911.png // bbox for 16/10491/22911.png
mapnik::box2d<double> z16(-13622912.929097254, 6026906.8062295765, -13621689.93664469, 6028129.79868214); mapnik::box2d<double> z16(-13622912.929097254,6026906.8062295765,-13621689.93664469,6028129.79868214);
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1) .run<test>("polygon clip render z1", "benchmark/data/polygon_rendering_clip.xml", z1)
.run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1) .run<test>("polygon noclip render z1", "benchmark/data/polygon_rendering_no_clip.xml", z1)
.run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16) .run<test>("polygon clip render z16", "benchmark/data/polygon_rendering_clip.xml", z16)
.run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16) .run<test>("polygon noclip render z16", "benchmark/data/polygon_rendering_no_clip.xml", z16)
.done(); .done();
} }

View file

@ -9,47 +9,46 @@ class test : public benchmark::test_case
std::string dest_; std::string dest_;
mapnik::box2d<double> from_; mapnik::box2d<double> from_;
mapnik::box2d<double> to_; mapnik::box2d<double> to_;
bool defer_proj_init_; bool defer_proj4_init_;
public:
public:
test(mapnik::parameters const& params, test(mapnik::parameters const& params,
std::string const& src, std::string const& src,
std::string const& dest, std::string const& dest,
mapnik::box2d<double> const& from, mapnik::box2d<double> const& from,
mapnik::box2d<double> const& to, mapnik::box2d<double> const& to,
bool defer_proj) bool defer_proj)
: test_case(params) : test_case(params),
, src_(src) src_(src),
, dest_(dest) dest_(dest),
, from_(from) from_(from),
, to_(to) to_(to),
, defer_proj_init_(defer_proj) defer_proj4_init_(defer_proj) {}
{}
bool validate() const bool validate() const
{ {
mapnik::projection src(src_, defer_proj_init_); mapnik::projection src(src_,defer_proj4_init_);
mapnik::projection dest(dest_, defer_proj_init_); mapnik::projection dest(dest_,defer_proj4_init_);
mapnik::proj_transform tr(src, dest); mapnik::proj_transform tr(src,dest);
mapnik::box2d<double> bbox = from_; mapnik::box2d<double> bbox = from_;
if (!tr.forward(bbox)) if (!tr.forward(bbox)) return false;
return false; return ((std::fabs(bbox.minx() - to_.minx()) < .5) &&
return ((std::fabs(bbox.minx() - to_.minx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) && (std::fabs(bbox.maxx() - to_.maxx()) < .5) &&
(std::fabs(bbox.miny() - to_.miny()) < .5) && (std::fabs(bbox.maxy() - to_.maxy()) < .5)); (std::fabs(bbox.miny() - to_.miny()) < .5) &&
(std::fabs(bbox.maxy() - to_.maxy()) < .5)
);
} }
bool operator()() const bool operator()() const
{ {
mapnik::projection src(src_, defer_proj_init_); for (std::size_t i=0;i<iterations_;++i)
mapnik::projection dest(dest_, defer_proj_init_);
mapnik::proj_transform tr(src, dest);
for (std::size_t i = 0; i < iterations_; ++i)
{ {
for (int j = -180; j < 180; j = j + 5) for (int j=-180;j<180;j=j+5)
{ {
for (int k = -85; k < 85; k = k + 5) for (int k=-85;k<85;k=k+5)
{ {
mapnik::box2d<double> box(j, k, j, k); mapnik::projection src(src_,defer_proj4_init_);
if (!tr.forward(box)) mapnik::projection dest(dest_,defer_proj4_init_);
throw std::runtime_error("could not transform coords"); mapnik::proj_transform tr(src,dest);
mapnik::box2d<double> box(j,k,j,k);
if (!tr.forward(box)) throw std::runtime_error("could not transform coords");
} }
} }
} }
@ -57,21 +56,19 @@ class test : public benchmark::test_case
} }
}; };
// echo -180 -60 | cs2cs -f "%.10f" epsg:4326 +to epsg:3857 // echo -180 -60 | cs2cs -f "%.10f" +init=epsg:4326 +to +init=epsg:3857
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup(); mapnik::box2d<double> from(-180,-80,180,80);
mapnik::box2d<double> from(-180, -80, 180, 80); mapnik::box2d<double> to(-20037508.3427892476,-15538711.0963092316,20037508.3427892476,15538711.0963092316);
mapnik::box2d<double> to(-20037508.3427892476, -15538711.0963092316, 20037508.3427892476, 15538711.0963092316); std::string from_str("+init=epsg:4326");
std::string from_str("epsg:4326"); std::string to_str("+init=epsg:3857");
std::string to_str("epsg:3857");
std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); std::string from_str2("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m " std::string to_str2("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over");
"+nadgrids=@null +wktext +no_defs +over");
return benchmark::sequencer(argc, argv) return benchmark::sequencer(argc, argv)
.run<test>("lonlat->merc epsg (internal)", from_str, to_str, from, to, true) .run<test>("lonlat->merc epsg", from_str, to_str, from, to, true)
.run<test>("lonlat->merc literal (libproj)", from_str2, to_str2, from, to, true) .run<test>("lonlat->merc literal", from_str2, to_str2, from, to, true)
.run<test>("merc->lonlat epsg (internal)", to_str, from_str, to, from, true) .run<test>("merc->lonlat epsg", to_str, from_str, to, from, true)
.run<test>("merc->lonlat literal (libproj)", to_str2, from_str2, to, from, true) .run<test>("merc->lonlat literal", to_str2, from_str2, to, from, true)
.done(); .done();
} }

View file

@ -6,41 +6,43 @@ using quad_tree_type = mapnik::quad_tree<std::size_t>;
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{}
bool validate() const { return true; } bool validate() const
{
return true;
}
bool operator()() const bool operator()() const
{ {
std::random_device rd; std::random_device rd;
std::default_random_engine engine(rd()); std::default_random_engine engine(rd());
std::uniform_int_distribution<int> uniform_dist(0, 2048); std::uniform_int_distribution<int> uniform_dist(0, 2048);
quad_tree_type tree(mapnik::box2d<double>(0, 0, 2048, 2048)); quad_tree_type tree(mapnik::box2d<double>(0,0,2048,2048));
// populate //populate
for (size_t i = 0; i < iterations_; ++i) for (size_t i = 0; i < iterations_; ++i)
{ {
int cx = uniform_dist(engine); int cx = uniform_dist(engine);
int cy = uniform_dist(engine); int cy = uniform_dist(engine);
int sx = 0.2 * uniform_dist(engine); int sx = 0.2 * uniform_dist(engine);
int sy = 0.2 * uniform_dist(engine); int sy = 0.2 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy); mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
tree.insert(i, box); tree.insert(i, box);
} }
// bounding box query // bounding box query
std::size_t count = 0; std::size_t count=0;
for (size_t i = 0; i < iterations_; ++i) for (size_t i = 0; i < iterations_; ++i)
{ {
int cx = uniform_dist(engine); int cx = uniform_dist(engine);
int cy = uniform_dist(engine); int cy = uniform_dist(engine);
int sx = 0.4 * uniform_dist(engine); int sx = 0.4 * uniform_dist(engine);
int sy = 0.4 * uniform_dist(engine); int sy = 0.4 * uniform_dist(engine);
mapnik::box2d<double> box(cx - sx, cy - sy, cx + sx, cy + sy); mapnik::box2d<double> box(cx - sx,cy - sy, cx + sx, cy + sy);
auto itr = tree.query_in_box(box); auto itr = tree.query_in_box(box);
auto end = tree.query_end(); auto end = tree.query_end();
for (; itr != end; ++itr) for ( ;itr != end; ++itr)
{ {
++count; ++count;
} }
@ -49,4 +51,4 @@ class test : public benchmark::test_case
} }
}; };
BENCHMARK(test, "quad_tree creation") BENCHMARK(test,"quad_tree creation")

View file

@ -15,25 +15,24 @@ class test : public benchmark::test_case
mapnik::value_integer height_; mapnik::value_integer height_;
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, xml_() xml_(),
, extent_() extent_(),
, width_(*params.get<mapnik::value_integer>("width", 256)) width_(*params.get<mapnik::value_integer>("width",256)),
, height_(*params.get<mapnik::value_integer>("height", 256)) height_(*params.get<mapnik::value_integer>("height",256)),
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 1.0)) scale_factor_(*params.get<mapnik::value_double>("scale_factor",1.0)),
, preview_(*params.get<std::string>("preview", "")) preview_(*params.get<std::string>("preview",""))
{ {
const auto map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
{ {
throw std::runtime_error("please provide a --map <path to xml> arg"); throw std::runtime_error("please provide a --map <path to xml> arg");
} }
xml_ = *map; xml_ = *map;
const auto ext = params.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
if (ext && !ext->empty()) if (ext && !ext->empty())
{ {
if (!extent_.from_string(*ext)) if (!extent_.from_string(*ext))
@ -44,74 +43,67 @@ class test : public benchmark::test_case
{ {
throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg"); throw std::runtime_error("please provide a --extent=<minx,miny,maxx,maxy> arg");
}*/ }*/
}
}
bool validate() const bool validate() const
{ {
mapnik::Map m(width_, height_); mapnik::Map m(width_,height_);
mapnik::load_map(m, xml_, true); mapnik::load_map(m,xml_,true);
if (extent_.valid()) if (extent_.valid()) {
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} } else {
else
{
m.zoom_all(); m.zoom_all();
} }
mapnik::image_rgba8 im(m.width(), m.height()); mapnik::image_rgba8 im(m.width(),m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
ren.apply(); ren.apply();
if (!preview_.empty()) if (!preview_.empty()) {
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im, preview_); mapnik::save_to_file(im,preview_);
} }
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) if (!preview_.empty()) {
{
return false; return false;
} }
mapnik::Map m(width_, height_); mapnik::Map m(width_,height_);
mapnik::load_map(m, xml_); mapnik::load_map(m,xml_);
if (extent_.valid()) if (extent_.valid()) {
{
m.zoom_to_box(extent_); m.zoom_to_box(extent_);
} } else {
else
{
m.zoom_all(); m.zoom_all();
} }
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
mapnik::image_rgba8 im(m.width(), m.height()); mapnik::image_rgba8 im(m.width(),m.height());
mapnik::agg_renderer<mapnik::image_rgba8> ren(m, im, scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(m,im,scale_factor_);
ren.apply(); ren.apply();
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
int return_value = 0; int return_value = 0;
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
const auto name = params.get<std::string>("name"); boost::optional<std::string> name = params.get<std::string>("name");
if (!name) if (!name)
{ {
std::clog << "please provide a name for this test\n"; std::clog << "please provide a name for this test\n";
return -1; return -1;
} }
mapnik::freetype_engine::register_fonts("./fonts/", true); mapnik::freetype_engine::register_fonts("./fonts/",true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{ {
test test_runner(params); test test_runner(params);
return_value = run(test_runner, *name); return_value = run(test_runner,*name);
} }
} }
catch (std::exception const& ex) catch (std::exception const& ex)

View file

@ -12,15 +12,14 @@
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <stdexcept> #include <stdexcept>
template<typename Renderer> template <typename Renderer> void process_layers(Renderer & ren,
void process_layers(Renderer& ren, mapnik::request const& m_req,
mapnik::request const& m_req, mapnik::projection const& map_proj,
mapnik::projection const& map_proj, std::vector<mapnik::layer> const& layers,
std::vector<mapnik::layer> const& layers, double scale_denom)
double scale_denom)
{ {
unsigned layers_size = layers.size(); unsigned layers_size = layers.size();
for (unsigned i = 0; i < layers_size; ++i) for (unsigned i=0; i < layers_size; ++i)
{ {
mapnik::layer const& lyr = layers[i]; mapnik::layer const& lyr = layers[i];
if (lyr.visible(scale_denom)) if (lyr.visible(scale_denom))
@ -51,28 +50,27 @@ class test : public benchmark::test_case
double scale_factor_; double scale_factor_;
std::string preview_; std::string preview_;
mutable mapnik::image_rgba8 im_; mutable mapnik::image_rgba8 im_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, xml_() xml_(),
, extent_() extent_(),
, width_(*params.get<mapnik::value_integer>("width", 256)) width_(*params.get<mapnik::value_integer>("width",256)),
, height_(*params.get<mapnik::value_integer>("height", 256)) height_(*params.get<mapnik::value_integer>("height",256)),
, m_(new mapnik::Map(width_, height_)) m_(new mapnik::Map(width_,height_)),
, scale_factor_(*params.get<mapnik::value_double>("scale_factor", 2.0)) scale_factor_(*params.get<mapnik::value_double>("scale_factor",2.0)),
, preview_(*params.get<std::string>("preview", "")) preview_(*params.get<std::string>("preview","")),
, im_(m_->width(), m_->height()) im_(m_->width(),m_->height())
{ {
const auto map = params.get<std::string>("map"); boost::optional<std::string> map = params.get<std::string>("map");
if (!map) if (!map)
{ {
throw std::runtime_error("please provide a --map=<path to xml> arg"); throw std::runtime_error("please provide a --map=<path to xml> arg");
} }
xml_ = *map; xml_ = *map;
auto ext = params.get<std::string>("extent"); boost::optional<std::string> ext = params.get<std::string>("extent");
mapnik::load_map(*m_, xml_, true); mapnik::load_map(*m_,xml_,true);
if (ext && !ext->empty()) if (ext && !ext->empty())
{ {
if (!extent_.from_string(*ext)) if (!extent_.from_string(*ext))
@ -89,44 +87,42 @@ class test : public benchmark::test_case
bool validate() const bool validate() const
{ {
mapnik::request m_req(width_, height_, extent_); mapnik::request m_req(width_,height_,extent_);
mapnik::attributes variables; mapnik::attributes variables;
m_req.set_buffer_size(m_->buffer_size()); m_req.set_buffer_size(m_->buffer_size());
mapnik::projection map_proj(m_->srs(), true); mapnik::projection map_proj(m_->srs(),true);
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im_, scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im_,scale_factor_);
ren.start_map_processing(*m_); ren.start_map_processing(*m_);
std::vector<mapnik::layer> const& layers = m_->layers(); std::vector<mapnik::layer> const& layers = m_->layers();
process_layers(ren, m_req, map_proj, layers, scale_denom); process_layers(ren,m_req,map_proj,layers,scale_denom);
ren.end_map_processing(*m_); ren.end_map_processing(*m_);
if (!preview_.empty()) if (!preview_.empty()) {
{
std::clog << "preview available at " << preview_ << "\n"; std::clog << "preview available at " << preview_ << "\n";
mapnik::save_to_file(im_, preview_); mapnik::save_to_file(im_,preview_);
} }
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
if (!preview_.empty()) if (!preview_.empty()) {
{
return false; return false;
} }
for (unsigned i = 0; i < iterations_; ++i) for (unsigned i=0;i<iterations_;++i)
{ {
mapnik::request m_req(width_, height_, extent_); mapnik::request m_req(width_,height_,extent_);
mapnik::image_rgba8 im(m_->width(), m_->height()); mapnik::image_rgba8 im(m_->width(),m_->height());
mapnik::attributes variables; mapnik::attributes variables;
m_req.set_buffer_size(m_->buffer_size()); m_req.set_buffer_size(m_->buffer_size());
mapnik::projection map_proj(m_->srs(), true); mapnik::projection map_proj(m_->srs(),true);
double scale_denom = mapnik::scale_denominator(m_req.scale(), map_proj.is_geographic()); double scale_denom = mapnik::scale_denominator(m_req.scale(),map_proj.is_geographic());
scale_denom *= scale_factor_; scale_denom *= scale_factor_;
mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_, m_req, variables, im, scale_factor_); mapnik::agg_renderer<mapnik::image_rgba8> ren(*m_,m_req,variables,im,scale_factor_);
ren.start_map_processing(*m_); ren.start_map_processing(*m_);
std::vector<mapnik::layer> const& layers = m_->layers(); std::vector<mapnik::layer> const& layers = m_->layers();
process_layers(ren, m_req, map_proj, layers, scale_denom); process_layers(ren,m_req,map_proj,layers,scale_denom);
ren.end_map_processing(*m_); ren.end_map_processing(*m_);
bool diff = false; bool diff = false;
mapnik::image_rgba8 const& dest = im; mapnik::image_rgba8 const& dest = im;
@ -137,36 +133,34 @@ class test : public benchmark::test_case
const unsigned int* row_to = dest.get_row(y); const unsigned int* row_to = dest.get_row(y);
for (unsigned int x = 0; x < width_; ++x) for (unsigned int x = 0; x < width_; ++x)
{ {
if (row_from[x] != row_to[x]) if (row_from[x] != row_to[x]) diff = true;
diff = true;
} }
} }
if (diff) if (diff) throw std::runtime_error("images differ");
throw std::runtime_error("images differ");
} }
return true; return true;
} }
}; };
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
int return_value = 0; int return_value = 0;
try try
{ {
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
const auto name = params.get<std::string>("name"); boost::optional<std::string> name = params.get<std::string>("name");
if (!name) if (!name)
{ {
std::clog << "please provide a name for this test\n"; std::clog << "please provide a name for this test\n";
return -1; return -1;
} }
mapnik::freetype_engine::register_fonts("./fonts/", true); mapnik::freetype_engine::register_fonts("./fonts/",true);
mapnik::datasource_cache::instance().register_datasources("./plugins/input/"); mapnik::datasource_cache::instance().register_datasources("./plugins/input/");
{ {
test test_runner(params); test test_runner(params);
return_value = run(test_runner, *name); return_value = run(test_runner,*name);
} }
} }
catch (std::exception const& ex) catch (std::exception const& ex)

View file

@ -4,31 +4,27 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, value_("true") value_("true") {}
{}
bool validate() const bool validate() const
{ {
bool result = false; bool result = false;
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
if (!result) if (!result) return result;
return result; mapnik::util::string2bool(value_,result);
mapnik::util::string2bool(value_, result);
return (result == true); return (result == true);
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
bool result = false; bool result = false;
mapnik::util::string2bool(value_, result); mapnik::util::string2bool(value_,result);
mapnik::util::string2bool(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2bool(value_.data(),value_.data()+value_.size(),result);
} }
return true; return true;
} }
}; };
BENCHMARK(test, "string->bool") BENCHMARK(test,"string->bool")

View file

@ -4,36 +4,29 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, value_("1.23456789") value_("1.23456789") {}
{}
bool validate() const bool validate() const
{ {
double result = 0; double result = 0;
if (!mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result)) if (!mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result)) return false;
return false; if (result != 1.23456789) return false;
if (result != 1.23456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2double(value_, result)) if (!mapnik::util::string2double(value_,result)) return false;
return false; if (result != 1.23456789) return false;
if (result != 1.23456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
double result = 0; double result = 0;
mapnik::util::string2double(value_, result); mapnik::util::string2double(value_,result);
mapnik::util::string2double(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2double(value_.data(),value_.data()+value_.size(),result);
} }
return true; return true;
} }
}; };
BENCHMARK(test, "string->double") BENCHMARK(test,"string->double")

View file

@ -4,36 +4,29 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string value_; std::string value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, value_("123456789") value_("123456789") {}
{}
bool validate() const bool validate() const
{ {
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
if (!mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result)) if (!mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result)) return false;
return false; if (result != 123456789) return false;
if (result != 123456789)
return false;
result = 0; result = 0;
if (!mapnik::util::string2int(value_, result)) if (!mapnik::util::string2int(value_,result)) return false;
return false; if (result != 123456789) return false;
if (result != 123456789)
return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
mapnik::value_integer result = 0; mapnik::value_integer result = 0;
mapnik::util::string2int(value_, result); mapnik::util::string2int(value_,result);
mapnik::util::string2int(value_.data(), value_.data() + value_.size(), result); mapnik::util::string2int(value_.data(),value_.data()+value_.size(),result);
} }
return true; return true;
} }
}; };
BENCHMARK(test, "string->int") BENCHMARK(test,"string->int")

View file

@ -4,28 +4,25 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, value_(-0.1234) value_(-0.1234) {}
{}
bool validate() const bool validate() const
{ {
std::string s; std::string s;
mapnik::util::to_string(s, value_); mapnik::util::to_string(s,value_);
return (s == "-0.1234"); return (s == "-0.1234");
} }
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
out.clear(); out.clear();
mapnik::util::to_string(out, value_); mapnik::util::to_string(out,value_);
} }
return true; return true;
} }
}; };
BENCHMARK(test, "to_string double->string") BENCHMARK(test,"to_string double->string")

View file

@ -4,12 +4,10 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
double value_; double value_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, value_(-0.1234) value_(-0.1234) {}
{}
bool validate() const bool validate() const
{ {
std::ostringstream s; std::ostringstream s;
@ -19,8 +17,7 @@ class test : public benchmark::test_case
bool operator()() const bool operator()() const
{ {
std::string out; std::string out;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{
std::ostringstream s; std::ostringstream s;
s << value_; s << value_;
out = s.str(); out = s.str();
@ -29,4 +26,4 @@ class test : public benchmark::test_case
} }
}; };
BENCHMARK(test, "ostringstream double->string") BENCHMARK(test,"ostringstream double->string")

View file

@ -1,41 +1,34 @@
#include "bench_framework.hpp" #include "bench_framework.hpp"
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/util/from_u8string.hpp>
#include <mapnik/value.hpp> #include <mapnik/value.hpp>
#include <boost/locale.hpp> #include <boost/locale.hpp>
#ifndef __linux__ #ifndef __linux__
#include <codecvt> #include <codecvt>
#endif
using mapnik::util::from_u8string;
#ifndef __linux__
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, utf8_(from_u8string(u8"שלום")) utf8_(u8"שלום") {}
{}
bool validate() const bool validate() const
{ {
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
std::u32string utf32 = utf32conv.from_bytes(utf8_); std::u32string utf32 = utf32conv.from_bytes(utf8_);
if (utf32.size() != 4) if (utf32.size() != 4) return false;
return false; if (utf32[0] != 0x5e9 &&
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) utf32[1] != 0x5dc &&
return false; utf32[2] != 0x5d5 &&
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv; std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> utf32conv;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ utf32 = utf32conv.from_bytes(utf8_);
utf32 = utf32conv.from_bytes(utf8_);
} }
return true; return true;
} }
@ -46,28 +39,26 @@ class test : public benchmark::test_case
class test2 : public benchmark::test_case class test2 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test2(mapnik::parameters const& params) test2(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, utf8_(from_u8string(u8"שלום")) utf8_(u8"שלום") {}
{}
bool validate() const bool validate() const
{ {
std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.size() != 4) if (utf32.size() != 4) return false;
return false; if (utf32[0] != 0x5e9 &&
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) utf32[1] != 0x5dc &&
return false; utf32[2] != 0x5d5 &&
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
std::u32string utf32; std::u32string utf32;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); }
}
return true; return true;
} }
}; };
@ -75,30 +66,28 @@ class test2 : public benchmark::test_case
class test3 : public benchmark::test_case class test3 : public benchmark::test_case
{ {
std::string utf8_; std::string utf8_;
public:
public:
test3(mapnik::parameters const& params) test3(mapnik::parameters const& params)
: test_case(params) : test_case(params),
, utf8_(from_u8string(u8"שלום")) utf8_(u8"שלום") {}
{}
bool validate() const bool validate() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(), utf8_.size()); mapnik::value_unicode_string utf32 = tr_.transcode(utf8_.data(),utf8_.size());
// std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_); //std::u32string utf32 = boost::locale::conv::utf_to_utf<char32_t>(utf8_);
if (utf32.length() != 4) if (utf32.length() != 4) return false;
return false; if (utf32[0] != 0x5e9 &&
if (utf32[0] != 0x5e9 && utf32[1] != 0x5dc && utf32[2] != 0x5d5 && utf32[3] != 0x5dd) utf32[1] != 0x5dc &&
return false; utf32[2] != 0x5d5 &&
utf32[3] != 0x5dd) return false;
return true; return true;
} }
bool operator()() const bool operator()() const
{ {
mapnik::transcoder tr_("utf-8"); mapnik::transcoder tr_("utf-8");
mapnik::value_unicode_string utf32; mapnik::value_unicode_string utf32;
for (std::size_t i = 0; i < iterations_; ++i) for (std::size_t i=0;i<iterations_;++i) {
{ utf32 = tr_.transcode(utf8_.data(),utf8_.size());
utf32 = tr_.transcode(utf8_.data(), utf8_.size());
} }
return true; return true;
} }
@ -106,19 +95,18 @@ class test3 : public benchmark::test_case
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
mapnik::setup();
mapnik::parameters params; mapnik::parameters params;
benchmark::handle_args(argc, argv, params); benchmark::handle_args(argc,argv,params);
int return_value = 0; int return_value = 0;
#ifndef __linux__ #ifndef __linux__
test test_runner(params); test test_runner(params);
return_value = return_value | run(test_runner, "utf encode std::codecvt"); return_value = return_value | run(test_runner,"utf encode std::codecvt");
#else #else
std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n"; std::clog << "skipping 'utf encode std::codecvt' test since <codecvt> is not supported on __linux__\n";
#endif #endif
test2 test_runner2(params); test2 test_runner2(params);
return_value = return_value | run(test_runner2, "utf encode boost::locale"); return_value = return_value | run(test_runner2,"utf encode boost::locale");
test3 test_runner3(params); test3 test_runner3(params);
return_value = return_value | run(test_runner3, "utf encode ICU"); return_value = return_value | run(test_runner3,"utf encode ICU");
return return_value; return return_value;
} }

View file

@ -2,12 +2,16 @@
class test : public benchmark::test_case class test : public benchmark::test_case
{ {
public: public:
test(mapnik::parameters const& params) test(mapnik::parameters const& params)
: test_case(params) : test_case(params) {}
{} bool validate() const
bool validate() const { return true; } {
void operator()() const {} return true;
}
void operator()() const
{
}
}; };
BENCHMARK(test, "test name") BENCHMARK(test,"test name")

174
bootstrap.sh Executable file
View file

@ -0,0 +1,174 @@
#!/usr/bin/env bash
: '
todo
- docs for base setup: sudo apt-get -y install zlib1g-dev make git
- shrink icu data
'
MASON_VERSION="70dd16d2"
function setup_mason() {
if [[ ! -d ./.mason ]]; then
git clone https://github.com/mapbox/mason.git .mason || return
elif ! git -C .mason rev-parse -q --verify "$MASON_VERSION" >/dev/null; then
git -C .mason fetch --all || true # non-fatal
fi
git -C .mason checkout --detach "$MASON_VERSION" -- || return
case ":$PATH:" in
*":$PWD/.mason:"*) : already there ;;
*) export PATH="$PWD/.mason:$PATH" ;;
esac
export CXX=${CXX:-clang++}
export CC=${CC:-clang}
}
function install() {
MASON_PLATFORM_ID=$(mason env MASON_PLATFORM_ID)
if [[ ! -d ./mason_packages/${MASON_PLATFORM_ID}/${1}/${2} ]]; then
mason install $1 $2
if [[ ${3:-false} != false ]]; then
LA_FILE=$(mason prefix $1 $2)/lib/$3.la
if [[ -f ${LA_FILE} ]]; then
perl -i -p -e 's:\Q$ENV{HOME}/build/mapbox/mason\E:$ENV{PWD}:g' ${LA_FILE}
else
echo "$LA_FILE not found"
fi
fi
fi
# the rm here is to workaround https://github.com/mapbox/mason/issues/230
rm -f ./mason_packages/.link/mason.ini
mason link $1 $2
}
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
}
MASON_LINKED_ABS=$(pwd)/mason_packages/.link
MASON_LINKED_REL=./mason_packages/.link
export C_INCLUDE_PATH="${MASON_LINKED_ABS}/include"
export CPLUS_INCLUDE_PATH="${MASON_LINKED_ABS}/include"
export LIBRARY_PATH="${MASON_LINKED_ABS}/lib"
function make_config() {
echo "
CXX = '$CXX'
CC = '$CC'
CUSTOM_CXXFLAGS = '-D_GLIBCXX_USE_CXX11_ABI=0'
RUNTIME_LINK = 'static'
INPUT_PLUGINS = 'all'
PATH = '${MASON_LINKED_REL}/bin'
PKG_CONFIG_PATH = '${MASON_LINKED_REL}/lib/pkgconfig'
PATH_REMOVE = '/usr:/usr/local'
PATH_REPLACE = '$HOME/build/mapbox/mason/mason_packages:./mason_packages'
BOOST_INCLUDES = '${MASON_LINKED_REL}/include'
BOOST_LIBS = '${MASON_LINKED_REL}/lib'
ICU_INCLUDES = '${MASON_LINKED_REL}/include'
ICU_LIBS = '${MASON_LINKED_REL}/lib'
HB_INCLUDES = '${MASON_LINKED_REL}/include'
HB_LIBS = '${MASON_LINKED_REL}/lib'
PNG_INCLUDES = '${MASON_LINKED_REL}/include/libpng16'
PNG_LIBS = '${MASON_LINKED_REL}/lib'
JPEG_INCLUDES = '${MASON_LINKED_REL}/include'
JPEG_LIBS = '${MASON_LINKED_REL}/lib'
TIFF_INCLUDES = '${MASON_LINKED_REL}/include'
TIFF_LIBS = '${MASON_LINKED_REL}/lib'
WEBP_INCLUDES = '${MASON_LINKED_REL}/include'
WEBP_LIBS = '${MASON_LINKED_REL}/lib'
PROJ_INCLUDES = '${MASON_LINKED_REL}/include'
PROJ_LIBS = '${MASON_LINKED_REL}/lib'
PG_INCLUDES = '${MASON_LINKED_REL}/include'
PG_LIBS = '${MASON_LINKED_REL}/lib'
FREETYPE_INCLUDES = '${MASON_LINKED_REL}/include/freetype2'
FREETYPE_LIBS = '${MASON_LINKED_REL}/lib'
SVG_RENDERER = True
CAIRO_INCLUDES = '${MASON_LINKED_REL}/include'
CAIRO_LIBS = '${MASON_LINKED_REL}/lib'
SQLITE_INCLUDES = '${MASON_LINKED_REL}/include'
SQLITE_LIBS = '${MASON_LINKED_REL}/lib'
BENCHMARK = True
CPP_TESTS = True
PGSQL2SQLITE = True
XMLPARSER = 'ptree'
SVG2PNG = True
"
}
# NOTE: the `mapnik-settings.env` is used by test/run (which is run by `make test`)
function setup_runtime_settings() {
echo "export PROJ_LIB=${MASON_LINKED_ABS}/share/proj" > mapnik-settings.env
echo "export ICU_DATA=${MASON_LINKED_ABS}/share/icu/${ICU_VERSION}" >> mapnik-settings.env
echo "export GDAL_DATA=${MASON_LINKED_ABS}/share/gdal" >> mapnik-settings.env
}
# turn arguments of the form NAME=VALUE into exported variables;
# any other arguments are reported and cause error return status
function export_variables() {
local arg= ret=0
for arg
do
if [[ "$arg" =~ ^[[:alpha:]][_[:alnum:]]*= ]]
then
export "$arg"
else
printf >&2 "bootstrap.sh: invalid argument: %s\n" "$arg"
ret=1
fi
done
return $ret
}
function main() {
export_variables "$@" || return
# setup_mason must not run in subshell, because it sets default
# values of CC, CXX and adds mason to PATH, which we want to keep
# when sourced
setup_mason || return
(
# this is wrapped in subshell to allow sourcing this script
# without having the terminal closed on error
set -eu
set -o pipefail
install_mason_deps
make_config > ./config.py
setup_runtime_settings
printf "\n\e[1;32m%s\e[m\n" "bootstrap successful, now run:"
echo ""
echo " ./configure && make"
echo ""
)
}
main "$@"

View file

@ -1,23 +0,0 @@
include(CheckCXXSourceRuns)
function(check_boost_regex)
set(CMAKE_REQUIRED_LIBRARIES ICU::uc ICU::data ICU::i18n Boost::headers Boost::regex)
check_cxx_source_runs([[
#include <boost/regex/icu.hpp>
#include <unicode/unistr.h>
int main()
{
U_NAMESPACE_QUALIFIER UnicodeString ustr;
try {
boost::u32regex pattern = boost::make_u32regex(ustr);
}
// an exception is fine, still indicates support is
// likely compiled into regex
catch (...) {
return 0;
}
return 0;
}
]] BOOST_REGEX_HAS_ICU)
set(BOOST_REGEX_HAS_ICU ${BOOST_REGEX_HAS_ICU} PARENT_SCOPE)
endfunction(check_boost_regex)

View file

@ -1,14 +0,0 @@
macro(get_mapnik_version)
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/mapnik/version.hpp VERSION_FILE)
string(REGEX MATCH "MAPNIK_MAJOR_VERSION ([0-9]*)" _ ${VERSION_FILE})
set(MAPNIK_MAJOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "MAPNIK_MINOR_VERSION ([0-9]*)" _ ${VERSION_FILE})
set(MAPNIK_MINOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "MAPNIK_PATCH_VERSION ([0-9]*)" _ ${VERSION_FILE})
set(MAPNIK_PATCH_VERSION ${CMAKE_MATCH_1})
set(MAPNIK_VERSION ${MAPNIK_MAJOR_VERSION}.${MAPNIK_MINOR_VERSION}.${MAPNIK_PATCH_VERSION})
endmacro()

View file

@ -1,68 +0,0 @@
include(CMakePackageConfigHelpers)
### exports mapnik cmake config files (mapnikConfigVersion and mapnikConfig)
function(mapnik_export_cmake_config)
# export mapnik configuration
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake"
VERSION ${MAPNIK_VERSION}
COMPATIBILITY ExactVersion
)
get_property(MAPNIK_UTILITIES GLOBAL PROPERTY MAPNIK_UTILITIES)
# generate all find_dependency and pkg_config calls
set(mapnik_find_deps)
foreach(dep IN LISTS mapnik_deps)
set(ver_comment "# ${dep} used with version ${mapnik_${dep}_version}")
set(mapnik_find_deps "${mapnik_find_deps}\n${ver_comment}\n")
if(mapnik_${dep}_find_args)
list(REMOVE_DUPLICATES mapnik_${dep}_find_args)
list(JOIN mapnik_${dep}_find_args " " m_args_joined)
set(mapnik_find_deps "${mapnik_find_deps}find_dependency(${dep} ${m_args_joined})")
else()
list(JOIN mapnik_${dep}_pkg_args " " m_args_joined)
set(mapnik_find_deps "${mapnik_find_deps}pkg_check_modules(${dep} ${m_args_joined})")
endif()
endforeach()
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/mapnikConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake"
INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR}
PATH_VARS MAPNIK_INCLUDE_DIR PLUGINS_INSTALL_DIR FONTS_INSTALL_DIR mapnik_find_deps MAPNIK_UTILITIES
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/mapnikConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/mapnikConfigVersion.cmake"
DESTINATION ${MAPNIK_CMAKE_DIR}
)
endfunction()
mapnik_export_cmake_config()
install(EXPORT MapnikTargets
DESTINATION ${MAPNIK_CMAKE_DIR}
FILE mapnikTargets.cmake
NAMESPACE mapnik::
)
### install plugin cmake config files ###
# Create configuration dependend files for the plugin install dirs.
# some package managers are using different paths per configuration.
string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_l)
set(m_mapnik_plugin_file_name mapnikPlugins-${_build_type})
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake.in" "set(MAPNIK_PLUGINS_DIR_${_build_type_l} \"@PACKAGE_PLUGINS_INSTALL_DIR@\" CACHE STRING \"\")\n")
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake"
PATH_VARS PLUGINS_INSTALL_DIR
INSTALL_DESTINATION ${MAPNIK_CMAKE_DIR}
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${m_mapnik_plugin_file_name}.cmake"
DESTINATION ${MAPNIK_CMAKE_DIR}
)

View file

@ -1,92 +0,0 @@
function(create_pkg_config_file _target _lib_name _description)
string(CONFIGURE [[
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/@MAPNIK_LIB_DIR@
Name: @_lib_name@
Description: @_description@
Version: @MAPNIK_VERSION@
Libs: -L"${libdir}" -l$<TARGET_FILE_BASE_NAME:@_target@>$<TARGET_PROPERTY:@_target@,$<CONFIG>_POSTFIX>
Cflags: -I"${includedir}" -I"${includedir}/mapnik" ]]
_contents @ONLY)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_lib_name}-$<CONFIG>.pc
CONTENT "${_contents}"
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${_lib_name}-$<CONFIG>.pc
DESTINATION ${MAPNIK_PKGCONF_DIR}
RENAME ${_lib_name}.pc
)
endfunction()
function(create_pkg_config_file_mapnik _lib_name _description)
get_target_property(m_compile_defs core INTERFACE_COMPILE_DEFINITIONS)
string(JOIN " -D" m_str_compile_defs ${m_compile_defs})
if(m_str_compile_defs)
set(m_str_compile_defs "-D${m_str_compile_defs}")
endif()
set(m_requires
libmapnikwkt
libmapnikjson
icu-uc
icu-i18n
harfbuzz
freetype2
)
if(USE_LIBXML2)
list(APPEND m_requires libxml-2.0)
endif()
if(USE_PNG)
list(APPEND m_requires libpng)
endif()
if(USE_JPEG)
list(APPEND m_requires libjpeg)
endif()
if(USE_TIFF)
list(APPEND m_requires libtiff-4)
endif()
if(USE_WEBP)
list(APPEND m_requires libwebp)
endif()
if(USE_CAIRO)
list(APPEND m_requires cairo)
endif()
if(USE_PROJ)
list(APPEND m_requires "proj >= ${PROJ_MIN_VERSION}")
endif()
string(JOIN " " m_requires ${m_requires})
string(CONFIGURE [[
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/@MAPNIK_LIB_DIR@
fonts_dir=${prefix}/@FONTS_INSTALL_DIR@
plugins_dir=${prefix}/@PLUGINS_INSTALL_DIR@
Name: @_lib_name@
Description: @_description@
Version: @MAPNIK_VERSION@
Requires: @m_requires@
Libs: -L"${libdir}" -l$<TARGET_FILE_BASE_NAME:mapnik>$<TARGET_PROPERTY:mapnik,$<CONFIG>_POSTFIX>
Cflags: -I"${includedir}" -I"${includedir}/mapnik" -I"${includedir}/mapnik/agg" @m_str_compile_defs@]]
_contents @ONLY)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_lib_name}-$<CONFIG>.pc
CONTENT "${_contents}"
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${_lib_name}-$<CONFIG>.pc
DESTINATION ${MAPNIK_PKGCONF_DIR}
RENAME ${_lib_name}.pc
)
endfunction()
create_pkg_config_file(wkt libmapnikwkt "wkt library")
create_pkg_config_file(json libmapnikjson "json library")
create_pkg_config_file_mapnik("libmapnik" "mapnik library")

View file

@ -1,64 +0,0 @@
function(mapnik_set_dep_version dep var)
string(TOUPPER ${dep} m_package_name_upc)
set(m_package_name ${dep})
if(${m_package_name}_VERSION_STRING)
set(${var} ${${m_package_name}_VERSION_STRING} PARENT_SCOPE)
elseif(${m_package_name}_VERSION)
set(${var} ${${m_package_name}_VERSION} PARENT_SCOPE)
elseif(${m_package_name_upc}_VERSION_STRING)
set(${var} ${${m_package_name_upc}_VERSION_STRING} PARENT_SCOPE)
elseif(${m_package_name_upc}_VERSION)
set(${var} ${${m_package_name_upc}_VERSION} PARENT_SCOPE)
endif()
endfunction()
function(mapnik_print_package_info dep)
message(STATUS "Using ${dep} version: ${mapnik_${dep}_version}")
endfunction()
macro(mapnik_find_package dep)
find_package(${dep} ${ARGN})
if(${dep}_FOUND)
list(APPEND mapnik_deps ${dep})
if(mapnik_${dep}_find_args)
list(APPEND mapnik_${dep}_find_args ${ARGN})
else()
set(mapnik_${dep}_find_args ${ARGN})
endif()
mapnik_set_dep_version(${dep} mapnik_${dep}_version)
mapnik_print_package_info(${dep})
else()
message(STATUS "not found: ${dep}")
endif()
endmacro()
macro(mapnik_pkg_check_modules dep)
pkg_check_modules(${dep} ${ARGN})
if(${dep}_FOUND)
list(APPEND mapnik_deps ${dep})
set(mapnik_${dep}_pkg_args ${ARGN})
mapnik_set_dep_version(${dep} mapnik_${dep}_version)
mapnik_print_package_info(${dep})
else()
message(STATUS "not found: ${dep}")
endif()
endmacro()
macro(mapnik_find_threads)
find_package(Threads REQUIRED)
if(CMAKE_THREAD_LIBS_INIT)
message(STATUS "Using Threads (system libraries)")
elseif(CMAKE_USE_WIN32_THREADS_INIT)
message(STATUS "Using Threads (win32 threads)")
elseif(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Using Threads (pthread)")
elseif(CMAKE_HP_PTHREADS_INIT)
message(STATUS "Using Threads (HP thread)")
else()
message(STATUS "Using Threads (unknown backend)")
endif()
endmacro()

View file

@ -1,98 +0,0 @@
#
# Install library targets that consuming users need.
#
function(mapnik_install _target)
install(TARGETS ${_target}
EXPORT MapnikTargets
INCLUDES DESTINATION ${MAPNIK_INCLUDE_DIR}
RUNTIME DESTINATION ${MAPNIK_BIN_DIR}
COMPONENT MapnikRuntime
LIBRARY DESTINATION ${MAPNIK_LIB_DIR}
COMPONENT MapnikRuntime
NAMELINK_COMPONENT MapnikDevelopment
ARCHIVE DESTINATION ${MAPNIK_ARCHIVE_DIR}
COMPONENT MapnikDevelopment
)
get_target_property(TARGET_TYPE "${_target}" TYPE)
if (TARGET_TYPE STREQUAL "SHARED_LIBRARY")
set_property(GLOBAL APPEND PROPERTY TARGETS ${_target})
endif()
endfunction()
#
# Install plugins
#
function(mapnik_install_plugin _target)
if(NOT BUILD_SHARED_PLUGINS)
return()
endif()
install(TARGETS ${_target}
RUNTIME DESTINATION ${PLUGINS_INSTALL_DIR}
COMPONENT MapnikPluginRuntime
LIBRARY DESTINATION ${PLUGINS_INSTALL_DIR}
COMPONENT MapnikPluginRuntime
NAMELINK_COMPONENT MapnikPluginDevelopment
ARCHIVE DESTINATION ${PLUGINS_INSTALL_DIR}
COMPONENT MapnikPluginDevelopment
)
set_property(GLOBAL APPEND PROPERTY PLUGINS ${_target})
endfunction()
#
# Install executables. These are available via COMPONENTS in find_package
#
function(mapnik_install_utility _target)
set(_target_name "mapnikUtilityTargets_${_target}")
install(TARGETS ${_target}
EXPORT ${_target_name}
INCLUDES DESTINATION ${MAPNIK_INCLUDE_DIR}
RUNTIME DESTINATION ${MAPNIK_BIN_DIR}
COMPONENT MapnikRuntime
LIBRARY DESTINATION ${MAPNIK_LIB_DIR}
COMPONENT MapnikRuntime
NAMELINK_COMPONENT MapnikDevelopment
ARCHIVE DESTINATION ${MAPNIK_ARCHIVE_DIR}
COMPONENT MapnikDevelopment
)
install(EXPORT ${_target_name}
FILE ${_target_name}.cmake
NAMESPACE mapnik::
DESTINATION ${MAPNIK_CMAKE_DIR}
)
set_property(GLOBAL APPEND PROPERTY MAPNIK_UTILITIES ${_target})
endfunction()
function(mapnik_install_targets)
if(INSTALL_DEPENDENCIES AND WIN32)
# https://cmake.org/cmake/help/latest/policy/CMP0087.html
cmake_policy(SET CMP0087 NEW)
get_property(_installed_utilities GLOBAL PROPERTY MAPNIK_UTILITIES)
get_property(_installed_targets GLOBAL PROPERTY TARGETS)
get_property(_installed_plugins GLOBAL PROPERTY PLUGINS)
set(_internal_executables "")
set(_internal_libraries "")
foreach(_target IN LISTS _installed_utilities)
list(APPEND _internal_executables "\${CMAKE_INSTALL_PREFIX}/${MAPNIK_BIN_DIR}/$<TARGET_FILE_NAME:${_target}>")
endforeach()
foreach(_target IN LISTS _installed_targets)
list(APPEND _internal_libraries "\${CMAKE_INSTALL_PREFIX}/${MAPNIK_BIN_DIR}/$<TARGET_FILE_NAME:${_target}>")
endforeach()
foreach(_target IN LISTS _installed_plugins)
list(APPEND _internal_libraries "\${CMAKE_INSTALL_PREFIX}/${PLUGINS_INSTALL_DIR}/$<TARGET_FILE_NAME:${_target}>")
endforeach()
# all other executables get auto detected and fixed.
if(_internal_executables)
list(GET _internal_executables 0 _internal_executables)
endif()
INSTALL(CODE "
message(STATUS \"internal_executables: ${_internal_executables}\")
message(STATUS \"internal_libraries: ${_internal_libraries}\")
message(STATUS \"ADDITIONAL_LIBARIES_PATHS: ${ADDITIONAL_LIBARIES_PATHS}\")
include(BundleUtilities)
fixup_bundle(\"${_internal_executables}\" \"${_internal_libraries}\" \"${ADDITIONAL_LIBARIES_PATHS}\")
" COMPONENT MapnikRuntime)
endif()
endfunction()

View file

@ -1,3 +0,0 @@
set(BOOST_MIN_VERSION 1.73)
set(HARFBUZZ_MIN_VERSION 0.9.34)
set(PROJ_MIN_VERSION 7.2.0)

View file

@ -1,4 +0,0 @@
macro(mapnik_option option_name option_description option_default_value)
option(${option_name} "${option_description}" ${option_default_value})
add_feature_info(${option_name} ${option_name} "${option_description}")
endmacro()

View file

@ -1,16 +0,0 @@
function(format_dir dir)
file(GLOB_RECURSE sources
"${dir}/*.cpp"
"${dir}/*.hpp"
)
execute_process(COMMAND clang-format -style=file -i ${sources})
endfunction()
format_dir(benchmark)
format_dir(demo)
format_dir(include)
format_dir(plugins)
format_dir(src)
format_dir(test)
format_dir(utils)

View file

@ -1,52 +0,0 @@
@PACKAGE_INIT@
set_and_check(MAPNIK_INCLUDE_DIR "@PACKAGE_MAPNIK_INCLUDE_DIR@" CACHE STRING "")
set_and_check(MAPNIK_FONTS_DIR "@PACKAGE_FONTS_INSTALL_DIR@" CACHE STRING "")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/Modules/")
include(CMakeFindDependencyMacro)
find_dependency(Threads REQUIRED)
@mapnik_find_deps@
include("${CMAKE_CURRENT_LIST_DIR}/mapnikTargets.cmake")
set(_supported_components @MAPNIK_UTILITIES@)
foreach(_comp ${mapnik_FIND_COMPONENTS})
if (NOT _comp IN_LIST _supported_components)
set(mapnik_FOUND False)
set(mapnik_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/mapnikUtilityTargets_${_comp}.cmake")
endforeach()
get_filename_component(_plugin_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_plugin_dir}/mapnikPlugins-*.cmake")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()
function(mapnik_find_plugin_dir PLUGIN_DIR)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_l)
set(_plugin_dir "${MAPNIK_PLUGINS_DIR_${_build_type_l}}")
# only release has more then one configuration
if(NOT _plugin_dir)
set(_all_rel_cfgs RELEASE RELWITHDEBINFO MINSIZEREL)
list(FIND _all_rel_cfgs ${_build_type_l} _is_rel_cfg)
# check if the current configuration is a known release configuration
if(${_is_rel_cfg} GREATER_EQUAL 0)
foreach(_rel_cfg IN LISTS _all_rel_cfgs)
set(_plugin_dir "${MAPNIK_PLUGINS_DIR_${_rel_cfg}}")
if(_plugin_dir)
break()
endif()
endforeach()
endif()
endif()
if(NOT _plugin_dir)
message(WARNING "Could not find a plugin install dir for configuration ${_build_type_l}")
endif()
set(${PLUGIN_DIR} ${_plugin_dir} PARENT_SCOPE)
endfunction()

View file

@ -1,18 +0,0 @@
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_NAME "mapnik")
set(CPACK_PACKAGE_CONTACT "ubuntu-mathis@outlook.com")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://mapnik.org")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_GENERATOR "DEB;TGZ")
set(CPACK_SOURCE_IGNORE_FILES
\\.git/
build/
".*~$"
out/
\\.vs/
\\.vscode/
)
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)

18
configure vendored
View file

@ -1,32 +1,18 @@
#! /usr/bin/env bash #! /bin/sh
set -eu set -eu
: ${PYTHON:=python} : ${PYTHON:=python}
# Only some shells (Bash and Z shell) support arrays. Therefore,
# the following code provides an alternative for users calling the script
# with shells other than Bash or Z shell (e.g. Debian users using Dash).
THE_SHELL=$(basename $SHELL)
if [ "$THE_SHELL" != "bash" ] && [ "$THE_SHELL" != "zsh" ]; then
if [ -f mapnik-settings.env ]; then
echo "WARNING: Reading from mapnik-settings.env is supported with Bash or Z shell only."
fi
$PYTHON scons/scons.py --implicit-deps-changed configure "$@"
exit 0
fi
# mapnik-settings.env is an optional file to store # mapnik-settings.env is an optional file to store
# environment variables that should be used before # environment variables that should be used before
# running tests like PROJ_LIB, GDAL_DATA, and ICU_DATA # running tests like PROJ_LIB, GDAL_DATA, and ICU_DATA
# These do not normally need to be set except when # These do not normally need to be set except when
# building against binary versions of dependencies like # building against binary versions of dependencies like
# done via bootstrap.sh # done via bootstrap.sh
if [ -f mapnik-settings.env ]; then if [ -f mapnik-settings.env ]; then
echo "Inheriting from mapnik-settings.env" echo "Inheriting from mapnik-settings.env"
. ./mapnik-settings.env . ./mapnik-settings.env
VARS=( $(cat mapnik-settings.env) )
fi fi
$PYTHON scons/scons.py --implicit-deps-changed configure ${VARS[*]:-} "$@" $PYTHON scons/scons.py --implicit-deps-changed configure "$@"

View file

@ -1,7 +0,0 @@
if(BUILD_DEMO_VIEWER)
add_subdirectory(viewer)
endif()
if(BUILD_DEMO_CPP)
add_subdirectory(c++)
endif()

View file

@ -1,6 +0,0 @@
add_executable(mapnik-demo rundemo.cpp)
target_link_libraries(mapnik-demo PRIVATE
mapnik::agg
mapnik::mapnik
ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?)
)

View file

@ -41,7 +41,7 @@ if env['HAS_CAIRO']:
demo_env.Append(CPPDEFINES = '-DHAVE_CAIRO') demo_env.Append(CPPDEFINES = '-DHAVE_CAIRO')
libraries = [env['MAPNIK_NAME']] libraries = [env['MAPNIK_NAME']]
libraries.extend([copy(env['LIBMAPNIK_LIBS']), 'sqlite3', 'pthread']) libraries.extend(copy(env['LIBMAPNIK_LIBS']))
rundemo = demo_env.Program('rundemo', source, LIBS=libraries) rundemo = demo_env.Program('rundemo', source, LIBS=libraries)
Depends(rundemo, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME'])) Depends(rundemo, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include <mapnik/mapnik.hpp>
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
#include <mapnik/rule.hpp> #include <mapnik/rule.hpp>
@ -46,21 +45,19 @@
#include <iostream> #include <iostream>
int main(int, char**)
int main ( int, char** )
{ {
using namespace mapnik; using namespace mapnik;
const std::string srs_lcc = const std::string srs_lcc="+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs";
"+proj=lcc +ellps=GRS80 +lat_0=49 +lon_0=-95 +lat+1=49 +lat_2=77 +datum=NAD83 +units=m +no_defs"; const std::string srs_merc="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";
const std::string srs_merc = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 "
"+units=m +nadgrids=@null +wktext +no_defs +over"; try {
mapnik::setup();
try
{
std::cout << " running demo ... \n"; std::cout << " running demo ... \n";
datasource_cache::instance().register_datasources("plugins/input/"); datasource_cache::instance().register_datasources("plugins/input/");
freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf"); freetype_engine::register_font("fonts/dejavu-fonts-ttf-2.37/ttf/DejaVuSans.ttf");
Map m(800, 600); Map m(800,600);
m.set_background(parse_color("white")); m.set_background(parse_color("white"));
m.set_srs(srs_merc); m.set_srs(srs_merc);
// create styles // create styles
@ -96,13 +93,13 @@ int main(int, char**)
rule r; rule r;
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(0, 0, 0)); put(line_sym,keys::stroke,color(0,0,0));
put(line_sym, keys::stroke_width, 1.0); put(line_sym,keys::stroke_width,1.0);
dash_array dash; dash_array dash;
dash.emplace_back(8, 4); dash.emplace_back(8,4);
dash.emplace_back(2, 2); dash.emplace_back(2,2);
dash.emplace_back(2, 2); dash.emplace_back(2,2);
put(line_sym, keys::stroke_dasharray, dash); put(line_sym,keys::stroke_dasharray,dash);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
provlines_style.add_rule(std::move(r)); provlines_style.add_rule(std::move(r));
@ -130,10 +127,10 @@ int main(int, char**)
r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4")); r.set_filter(parse_expression("[CLASS] = 3 or [CLASS] = 4"));
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(171, 158, 137)); put(line_sym,keys::stroke,color(171,158,137));
put(line_sym, keys::stroke_width, 2.0); put(line_sym,keys::stroke_width,2.0);
put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); put(line_sym,keys::stroke_linecap,ROUND_CAP);
put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
roads34_style.add_rule(std::move(r)); roads34_style.add_rule(std::move(r));
@ -147,10 +144,10 @@ int main(int, char**)
r.set_filter(parse_expression("[CLASS] = 2")); r.set_filter(parse_expression("[CLASS] = 2"));
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(171, 158, 137)); put(line_sym,keys::stroke,color(171,158,137));
put(line_sym, keys::stroke_width, 4.0); put(line_sym,keys::stroke_width,4.0);
put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); put(line_sym,keys::stroke_linecap,ROUND_CAP);
put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
roads2_style_1.add_rule(std::move(r)); roads2_style_1.add_rule(std::move(r));
@ -163,10 +160,10 @@ int main(int, char**)
r.set_filter(parse_expression("[CLASS] = 2")); r.set_filter(parse_expression("[CLASS] = 2"));
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(255, 250, 115)); put(line_sym,keys::stroke,color(255,250,115));
put(line_sym, keys::stroke_width, 2.0); put(line_sym,keys::stroke_width,2.0);
put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); put(line_sym,keys::stroke_linecap,ROUND_CAP);
put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
roads2_style_2.add_rule(std::move(r)); roads2_style_2.add_rule(std::move(r));
@ -180,10 +177,10 @@ int main(int, char**)
r.set_filter(parse_expression("[CLASS] = 1")); r.set_filter(parse_expression("[CLASS] = 1"));
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(188, 149, 28)); put(line_sym,keys::stroke,color(188,149,28));
put(line_sym, keys::stroke_width, 7.0); put(line_sym,keys::stroke_width,7.0);
put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); put(line_sym,keys::stroke_linecap,ROUND_CAP);
put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
roads1_style_1.add_rule(std::move(r)); roads1_style_1.add_rule(std::move(r));
@ -196,10 +193,10 @@ int main(int, char**)
r.set_filter(parse_expression("[CLASS] = 1")); r.set_filter(parse_expression("[CLASS] = 1"));
{ {
line_symbolizer line_sym; line_symbolizer line_sym;
put(line_sym, keys::stroke, color(242, 191, 36)); put(line_sym,keys::stroke,color(242,191,36));
put(line_sym, keys::stroke_width, 5.0); put(line_sym,keys::stroke_width,5.0);
put(line_sym, keys::stroke_linecap, line_cap_enum::ROUND_CAP); put(line_sym,keys::stroke_linecap,ROUND_CAP);
put(line_sym, keys::stroke_linejoin, line_join_enum::ROUND_JOIN); put(line_sym,keys::stroke_linejoin,ROUND_JOIN);
r.append(std::move(line_sym)); r.append(std::move(line_sym));
} }
roads1_style_2.add_rule(std::move(r)); roads1_style_2.add_rule(std::move(r));
@ -215,11 +212,10 @@ int main(int, char**)
text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>(); text_placements_ptr placement_finder = std::make_shared<text_placements_dummy>();
placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book"; placement_finder->defaults.format_defaults.face_name = "DejaVu Sans Book";
placement_finder->defaults.format_defaults.text_size = 10.0; placement_finder->defaults.format_defaults.text_size = 10.0;
placement_finder->defaults.format_defaults.fill = color(0, 0, 0); placement_finder->defaults.format_defaults.fill = color(0,0,0);
placement_finder->defaults.format_defaults.halo_fill = color(255, 255, 200); placement_finder->defaults.format_defaults.halo_fill = color(255,255,200);
placement_finder->defaults.format_defaults.halo_radius = 1.0; placement_finder->defaults.format_defaults.halo_radius = 1.0;
placement_finder->defaults.set_format_tree( placement_finder->defaults.set_format_tree(std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
std::make_shared<mapnik::formatting::text_node>(parse_expression("[GEONAME]")));
put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder); put<text_placements_ptr>(text_sym, keys::text_placements_, placement_finder);
r.append(std::move(text_sym)); r.append(std::move(text_sym));
} }
@ -232,9 +228,9 @@ int main(int, char**)
// Provincial polygons // Provincial polygons
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/boundaries"; p["file"]="demo/data/boundaries";
p["encoding"] = "utf8"; p["encoding"]="utf8";
layer lyr("Provinces"); layer lyr("Provinces");
lyr.set_datasource(datasource_cache::instance().create(p)); lyr.set_datasource(datasource_cache::instance().create(p));
@ -246,8 +242,8 @@ int main(int, char**)
// Drainage // Drainage
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/qcdrainage"; p["file"]="demo/data/qcdrainage";
layer lyr("Quebec Hydrography"); layer lyr("Quebec Hydrography");
lyr.set_datasource(datasource_cache::instance().create(p)); lyr.set_datasource(datasource_cache::instance().create(p));
lyr.set_srs(srs_lcc); lyr.set_srs(srs_lcc);
@ -257,8 +253,8 @@ int main(int, char**)
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/ontdrainage"; p["file"]="demo/data/ontdrainage";
layer lyr("Ontario Hydrography"); layer lyr("Ontario Hydrography");
lyr.set_datasource(datasource_cache::instance().create(p)); lyr.set_datasource(datasource_cache::instance().create(p));
lyr.set_srs(srs_lcc); lyr.set_srs(srs_lcc);
@ -269,8 +265,8 @@ int main(int, char**)
// Provincial boundaries // Provincial boundaries
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/boundaries_l"; p["file"]="demo/data/boundaries_l";
layer lyr("Provincial borders"); layer lyr("Provincial borders");
lyr.set_srs(srs_lcc); lyr.set_srs(srs_lcc);
lyr.set_datasource(datasource_cache::instance().create(p)); lyr.set_datasource(datasource_cache::instance().create(p));
@ -281,8 +277,8 @@ int main(int, char**)
// Roads // Roads
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/roads"; p["file"]="demo/data/roads";
layer lyr("Roads"); layer lyr("Roads");
lyr.set_srs(srs_lcc); lyr.set_srs(srs_lcc);
lyr.set_datasource(datasource_cache::instance().create(p)); lyr.set_datasource(datasource_cache::instance().create(p));
@ -297,8 +293,8 @@ int main(int, char**)
// popplaces // popplaces
{ {
parameters p; parameters p;
p["type"] = "shape"; p["type"]="shape";
p["file"] = "demo/data/popplaces"; p["file"]="demo/data/popplaces";
p["encoding"] = "utf8"; p["encoding"] = "utf8";
layer lyr("Populated Places"); layer lyr("Populated Places");
lyr.set_srs(srs_lcc); lyr.set_srs(srs_lcc);
@ -307,28 +303,28 @@ int main(int, char**)
m.add_layer(lyr); m.add_layer(lyr);
} }
m.zoom_to_box(box2d<double>(-8024477.28459, 5445190.38849, -7381388.20071, 5662941.44855)); m.zoom_to_box(box2d<double>(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855));
image_rgba8 buf(m.width(), m.height()); image_rgba8 buf(m.width(),m.height());
agg_renderer<image_rgba8> ren(m, buf); agg_renderer<image_rgba8> ren(m,buf);
ren.apply(); ren.apply();
std::string msg("These maps have been rendered using AGG in the current directory:\n"); std::string msg("These maps have been rendered using AGG in the current directory:\n");
#ifdef HAVE_JPEG #ifdef HAVE_JPEG
save_to_file(buf, "demo.jpg", "jpeg"); save_to_file(buf,"demo.jpg","jpeg");
msg += "- demo.jpg\n"; msg += "- demo.jpg\n";
#endif #endif
#ifdef HAVE_PNG #ifdef HAVE_PNG
save_to_file(buf, "demo.png", "png"); save_to_file(buf,"demo.png","png");
save_to_file(buf, "demo256.png", "png8"); save_to_file(buf,"demo256.png","png8");
msg += "- demo.png\n"; msg += "- demo.png\n";
msg += "- demo256.png\n"; msg += "- demo256.png\n";
#endif #endif
#ifdef HAVE_TIFF #ifdef HAVE_TIFF
save_to_file(buf, "demo.tif", "tiff"); save_to_file(buf,"demo.tif","tiff");
msg += "- demo.tif\n"; msg += "- demo.tif\n";
#endif #endif
#ifdef HAVE_WEBP #ifdef HAVE_WEBP
save_to_file(buf, "demo.webp", "webp"); save_to_file(buf,"demo.webp","webp");
msg += "- demo.webp\n"; msg += "- demo.webp\n";
#endif #endif
msg += "Have a look!\n"; msg += "Have a look!\n";
@ -336,8 +332,8 @@ int main(int, char**)
#if defined(HAVE_CAIRO) #if defined(HAVE_CAIRO)
// save to pdf/svg files // save to pdf/svg files
save_to_cairo_file(m, "cairo-demo.pdf"); save_to_cairo_file(m,"cairo-demo.pdf");
save_to_cairo_file(m, "cairo-demo.svg"); save_to_cairo_file(m,"cairo-demo.svg");
/* we could also do: /* we could also do:
@ -346,38 +342,38 @@ int main(int, char**)
but instead let's build up a surface for more flexibility but instead let's build up a surface for more flexibility
*/ */
cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m.width(), m.height()), cairo_surface_ptr image_surface(
cairo_surface_closer()); cairo_image_surface_create(CAIRO_FORMAT_ARGB32,m.width(),m.height()),
cairo_surface_closer());
double scale_factor = 1.0; double scale_factor = 1.0;
cairo_ptr image_context(create_context(image_surface)); cairo_ptr image_context(create_context(image_surface));
mapnik::cairo_renderer<cairo_ptr> png_render(m, image_context, scale_factor); mapnik::cairo_renderer<cairo_ptr> png_render(m,image_context,scale_factor);
png_render.apply(); png_render.apply();
// we can now write to png with cairo functionality // we can now write to png with cairo functionality
cairo_surface_write_to_png(&*image_surface, "cairo-demo.png"); cairo_surface_write_to_png(&*image_surface, "cairo-demo.png");
// but we can also benefit from quantization by converting // but we can also benefit from quantization by converting
// to a mapnik image object and then saving that // to a mapnik image object and then saving that
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
cairo_image_surface_get_height(&*image_surface));
cairo_image_to_rgba8(im_data, image_surface); cairo_image_to_rgba8(im_data, image_surface);
save_to_file(im_data, "cairo-demo256.png", "png8"); save_to_file(im_data, "cairo-demo256.png","png8");
cairo_surface_finish(&*image_surface); cairo_surface_finish(&*image_surface);
std::cout << "Three maps have been rendered using Cairo in the current directory:\n" std::cout << "Three maps have been rendered using Cairo in the current directory:\n"
"- cairo-demo.png\n" "- cairo-demo.png\n"
"- cairo-demo256.png\n" "- cairo-demo256.png\n"
"- cairo-demo.pdf\n" "- cairo-demo.pdf\n"
"- cairo-demo.svg\n" "- cairo-demo.svg\n"
"Have a look!\n"; "Have a look!\n";
#endif #endif
// save map definition (data + style) // save map definition (data + style)
save_map(m, "map.xml"); save_map(m, "map.xml");
} }
catch (std::exception const& ex) catch ( std::exception const& ex )
{ {
std::cerr << "### std::exception: " << ex.what() << std::endl; std::cerr << "### std::exception: " << ex.what() << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
catch (...) catch ( ... )
{ {
std::cerr << "### Unknown exception." << std::endl; std::cerr << "### Unknown exception." << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;

View file

@ -1,64 +0,0 @@
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(PROJECT_SOURCES
about_dialog.cpp
info_dialog.cpp
layerdelegate.cpp
layerlistmodel.cpp
layerwidget.cpp
layer_info_dialog.cpp
main.cpp
mainwindow.cpp
mapwidget.cpp
styles_model.cpp
forms/about.ui
forms/info.ui
forms/layer_info.ui
mapnik_viewer.qrc
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(mapnik-viewer
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
if(ANDROID)
add_library(mapnik-viewer SHARED
${PROJECT_SOURCES}
)
else()
add_executable(mapnik-viewer
${PROJECT_SOURCES}
)
endif()
endif()
set_target_properties(mapnik-viewer PROPERTIES
AUTOUIC_SEARCH_PATHS forms
AUTORCC ON
AUTOUIC ON
AUTOMOC ON
)
target_link_libraries(mapnik-viewer PRIVATE
Qt${QT_VERSION_MAJOR}::Widgets
mapnik::agg
mapnik::mapnik
ICU::data ICU::i18n ICU::uc # needed for the static build (TODO: why isn't this correctly propagated from mapnik::mapnik?)
)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/viewer.ini
"[mapnik]
plugins_dir=${PLUGINS_INSTALL_DIR}
fonts/1/dir=${FONTS_INSTALL_DIR}
fonts/size=1"
)
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(mapnik-viewer)
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/viewer.ini DESTINATION bin)
mapnik_install_utility(mapnik-viewer)

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,10 +17,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "about_dialog.hpp" #include "about_dialog.hpp"
about_dialog::about_dialog(QWidget* parent)
: QDialog(parent) about_dialog::about_dialog(QWidget *parent)
: QDialog(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#if !defined ABOUT_DIALOG_HPP #if !defined ABOUT_DIALOG_HPP
#define ABOUT_DIALOG_HPP #define ABOUT_DIALOG_HPP
@ -25,12 +27,12 @@
class about_dialog : public QDialog class about_dialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
about_dialog(QWidget* parent = 0); about_dialog(QWidget * parent = 0);
private:
private: Ui::Dialog ui;
Ui::Dialog ui;
}; };
#endif // ABOUT_DIALOG_HPP
#endif //ABOUT_DIALOG_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,22 +17,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "info_dialog.hpp" #include "info_dialog.hpp"
info_dialog::info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent)
: QDialog(parent)
{
ui.setupUi(this);
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name"));
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
ui.tableWidget->setRowCount(info.size()); info_dialog::info_dialog(QVector<QPair<QString,QString> > const& info, QWidget *parent)
ui.tableWidget->setColumnCount(2); : QDialog(parent)
for (int i = 0; i < info.size(); ++i) {
{ ui.setupUi(this);
QTableWidgetItem* keyItem = new QTableWidgetItem(info[i].first); ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
QTableWidgetItem* valueItem = new QTableWidgetItem(info[i].second); ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
ui.tableWidget->setItem(i, 0, keyItem);
ui.tableWidget->setItem(i, 1, valueItem); ui.tableWidget->setRowCount(info.size());
} ui.tableWidget->setColumnCount(2);
for (int i=0;i<info.size();++i)
{
QTableWidgetItem *keyItem = new QTableWidgetItem(info[i].first);
QTableWidgetItem *valueItem = new QTableWidgetItem(info[i].second);
ui.tableWidget->setItem(i,0,keyItem);
ui.tableWidget->setItem(i,1,valueItem);
}
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef INFO_DIALOG_HPP #ifndef INFO_DIALOG_HPP
#define INFO_DIALOG_HPP #define INFO_DIALOG_HPP
@ -25,12 +27,12 @@
class info_dialog : public QDialog class info_dialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
info_dialog(QVector<QPair<QString, QString>> const& info, QWidget* parent = 0); info_dialog(QVector<QPair<QString,QString> > const& info,QWidget * parent = 0);
private:
private: Ui::InfoDialog ui;
Ui::InfoDialog ui;
}; };
#endif // INFO_DIALOG_HPP
#endif //INFO_DIALOG_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layer_info_dialog.hpp" #include "layer_info_dialog.hpp"
// mapnik // mapnik
@ -25,13 +26,14 @@
#include <mapnik/params_impl.hpp> #include <mapnik/params_impl.hpp>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
: QDialog(parent) layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget *parent)
: QDialog(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
ui.tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Name")); ui.tableWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Name"));
ui.tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Value")); ui.tableWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Value"));
// Layer name // Layer name
ui.layerNameEdit->setText(QString(lay.name().c_str())); ui.layerNameEdit->setText(QString(lay.name().c_str()));
@ -48,17 +50,17 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
ui.tableWidget->setColumnCount(2); ui.tableWidget->setColumnCount(2);
mapnik::parameters::const_iterator pos; mapnik::parameters::const_iterator pos;
int index = 0; int index=0;
for (pos = ps.begin(); pos != ps.end(); ++pos) for (pos = ps.begin();pos != ps.end();++pos)
{ {
std::optional<std::string> result; boost::optional<std::string> result;
mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result), pos->second); mapnik::util::apply_visitor(mapnik::value_extractor_visitor<std::string>(result),pos->second);
if (result) if (result)
{ {
QTableWidgetItem* keyItem = new QTableWidgetItem(QString(pos->first.c_str())); QTableWidgetItem *keyItem = new QTableWidgetItem(QString(pos->first.c_str()));
QTableWidgetItem* valueItem = new QTableWidgetItem(QString((*result).c_str())); QTableWidgetItem *valueItem = new QTableWidgetItem(QString((*result).c_str()));
ui.tableWidget->setItem(index, 0, keyItem); ui.tableWidget->setItem(index,0,keyItem);
ui.tableWidget->setItem(index, 1, valueItem); ui.tableWidget->setItem(index,1,valueItem);
++index; ++index;
} }
} }
@ -67,5 +69,5 @@ layer_info_dialog::layer_info_dialog(mapnik::layer& lay, QWidget* parent)
Ui::LayerInfoDialog& layer_info_dialog::getUI() Ui::LayerInfoDialog& layer_info_dialog::getUI()
{ {
return ui; return ui;
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,25 +17,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYER_INFO_DIALOG_HPP #ifndef LAYER_INFO_DIALOG_HPP
#define LAYER_INFO_DIALOG_HPP #define LAYER_INFO_DIALOG_HPP
#include "ui_layer_info.h" #include "ui_layer_info.h"
#include <QDialog> #include <QDialog>
namespace mapnik { namespace mapnik
{
class layer; class layer;
} }
class layer_info_dialog : public QDialog class layer_info_dialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
layer_info_dialog(mapnik::layer& l, QWidget* parent = 0); layer_info_dialog(mapnik::layer& l, QWidget * parent = 0);
Ui::LayerInfoDialog& getUI(); Ui::LayerInfoDialog& getUI();
private:
private: Ui::LayerInfoDialog ui;
Ui::LayerInfoDialog ui;
}; };
#endif // LAYER_INFO_DIALOG_HPP
#endif //LAYER_INFO_DIALOG_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,32 +17,38 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <QtGui> #include <QtGui>
#include "layerdelegate.hpp" #include "layerdelegate.hpp"
LayerDelegate::LayerDelegate(QObject* parent) LayerDelegate::LayerDelegate(QObject *parent)
: QAbstractItemDelegate(parent) : QAbstractItemDelegate(parent)
{} {
}
void LayerDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const void LayerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{ {
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(QPen(QColor(255, 0, 0), 1)); painter->setPen(QPen(QColor(255,0,0),1));
if (option.state & QStyle::State_Selected) if (option.state & QStyle::State_Selected)
painter->setBrush(QBrush(QColor(0, 0, 255, 64))); painter->setBrush(QBrush(QColor(0, 0, 255, 64)));
else else
painter->setBrush(QBrush(QColor(255, 0, 0, 64))); painter->setBrush(QBrush(QColor(255, 0, 0, 64)));
painter->drawRoundedRect(option.rect, 4, 4);
painter->drawRoundRect(option.rect,4,4);
if (option.state & QStyle::State_Selected) if (option.state & QStyle::State_Selected)
painter->setBrush(option.palette.highlightedText()); painter->setBrush(option.palette.highlightedText());
else else
painter->setBrush(QBrush(QColor(255, 120, 0, 127))); painter->setBrush(QBrush(QColor(255, 120, 0, 127)));
} }
QSize LayerDelegate::sizeHint(const QStyleOptionViewItem& /* option */, const QModelIndex& /* index */) const QSize LayerDelegate::sizeHint(const QStyleOptionViewItem & /* option */,
const QModelIndex & /* index */) const
{ {
return QSize(120, 24); return QSize(120,24);
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,10 +33,12 @@ class LayerDelegate : public QAbstractItemDelegate
{ {
Q_OBJECT Q_OBJECT
public: public:
LayerDelegate(QObject* parent = 0); LayerDelegate(QObject *parent = 0);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter *painter, const QStyleOptionViewItem &option,
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index ) const;
}; };
#endif // LAYER_DELEGATE_HPP #endif //LAYER_DELEGATE_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,26 +17,27 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layerlistmodel.hpp" #include "layerlistmodel.hpp"
#include <QIcon> #include <QIcon>
#include <QBrush>
#include <iostream>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
using mapnik::Map; using mapnik::Map;
LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject* parent) LayerListModel::LayerListModel(std::shared_ptr<Map> map,QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent),
, map_(map) map_(map) {}
{}
int LayerListModel::rowCount(QModelIndex const&) const int LayerListModel::rowCount(QModelIndex const&) const
{ {
if (map_) if (map_) return map_->layers().size();
return map_->layers().size(); return 0;
return 0;
} }
QVariant LayerListModel::data(QModelIndex const& index, int role) const QVariant LayerListModel::data(QModelIndex const& index,int role) const
{ {
if (!index.isValid() || !map_) if (!index.isValid() || !map_)
return QVariant(); return QVariant();
@ -59,16 +60,9 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
else if (role == Qt::CheckStateRole) else if (role == Qt::CheckStateRole)
{ {
if (map_->layers().at(index.row()).active()) if (map_->layers().at(index.row()).active())
return QVariant(Qt::Checked); return QVariant(Qt::Checked);
else else
return QVariant(Qt::Unchecked); return QVariant(Qt::Unchecked);
}
else if (role == Qt::ForegroundRole)
{
if (map_->layers().at(index.row()).active())
return QBrush(QColor("black"));
else
return QBrush(QColor("lightgrey"));
} }
else else
{ {
@ -76,7 +70,8 @@ QVariant LayerListModel::data(QModelIndex const& index, int role) const
} }
} }
QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant LayerListModel::headerData(int section, Qt::Orientation orientation,
int role) const
{ {
if (role != Qt::DisplayRole) if (role != Qt::DisplayRole)
return QVariant(); return QVariant();
@ -87,37 +82,38 @@ QVariant LayerListModel::headerData(int section, Qt::Orientation orientation, in
return QString("TODO Row %1").arg(section); return QString("TODO Row %1").arg(section);
} }
bool LayerListModel::setData(const QModelIndex& index, const QVariant& value, int role) bool LayerListModel::setData(const QModelIndex &index,
const QVariant &value, int role)
{ {
if (!map_) if (!map_) return false;
return false;
if (index.isValid() && role == Qt::CheckStateRole) if (index.isValid() && role == Qt::CheckStateRole)
{ {
int status = value.toInt(); int status = value.toInt();
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers()); std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
layers.at(index.row()).set_active(status); layers.at(index.row()).set_active(status);
emit dataChanged(index, index); emit dataChanged(index, index);
return true; return true;
} }
return false; return false;
} }
Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
{ {
Qt::ItemFlags flags = QAbstractItemModel::flags(index); Qt::ItemFlags flags = QAbstractItemModel::flags(index);
if (index.isValid()) if (index.isValid())
flags |= Qt::ItemIsUserCheckable; flags |= Qt::ItemIsUserCheckable;
return flags; return flags;
} }
boost::optional<mapnik::layer&> LayerListModel::map_layer(int i) boost::optional<mapnik::layer&> LayerListModel::map_layer(int i)
{ {
if (map_) if (map_)
{ {
std::vector<mapnik::layer>& layers = const_cast<std::vector<mapnik::layer>&>(map_->layers()); std::vector<mapnik::layer> & layers = const_cast<std::vector<mapnik::layer>& >(map_->layers());
if (i < int(layers.size())) if (i < int(layers.size()))
return boost::optional<mapnik::layer&>(layers[i]); return boost::optional<mapnik::layer&>(layers[i]);
} }
return boost::optional<mapnik::layer&>(); return boost::optional<mapnik::layer&>();
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYER_LIST_MODEL_HPP #ifndef LAYER_LIST_MODEL_HPP
#define LAYER_LIST_MODEL_HPP #define LAYER_LIST_MODEL_HPP
@ -30,18 +32,20 @@
class LayerListModel : public QAbstractListModel class LayerListModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
LayerListModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0); LayerListModel(std::shared_ptr<mapnik::Map> map, QObject * parent = 0);
int rowCount(const QModelIndex& parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation,
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); int role = Qt::DisplayRole) const;
Qt::ItemFlags flags(QModelIndex const& index) const; bool setData(const QModelIndex &index, const QVariant &value,
boost::optional<mapnik::layer&> map_layer(int i); int role = Qt::EditRole);
Qt::ItemFlags flags(QModelIndex const& index) const;
boost::optional<mapnik::layer&> map_layer(int i);
private: private:
std::shared_ptr<mapnik::Map> map_; std::shared_ptr<mapnik::Map> map_;
}; };
#endif // LAYER_LIST_MODEL_HPP #endif //LAYER_LIST_MODEL_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "layerwidget.hpp" #include "layerwidget.hpp"
#include <qabstractitemdelegate.h> #include <qabstractitemdelegate.h>
#include <qapplication.h> #include <qapplication.h>
@ -28,63 +29,72 @@
#include <qscrollbar.h> #include <qscrollbar.h>
#include <qrubberband.h> #include <qrubberband.h>
#include <qdebug.h> #include <qdebug.h>
#include <iostream>
#include "layerlistmodel.hpp" #include "layerlistmodel.hpp"
#include "layer_info_dialog.hpp" #include "layer_info_dialog.hpp"
LayerTab::LayerTab(QWidget* parent) using namespace std;
: QListView(parent)
{}
void LayerTab::paintEvent(QPaintEvent* e) LayerTab::LayerTab(QWidget* parent)
: QListView(parent) {}
void LayerTab::paintEvent(QPaintEvent *e)
{ {
QListView::paintEvent(e); QListView::paintEvent(e);
} }
void LayerTab::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles) void LayerTab::dataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight)
{ {
emit update_mapwidget(); QListView::dataChanged(topLeft, bottomRight);
QListView::dataChanged(topLeft, bottomRight, roles); qDebug("FIXME : update map view!");
emit update_mapwidget();
} }
void LayerTab::selectionChanged(const QItemSelection& selected, const QItemSelection&) void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &)
{ {
QModelIndexList list = selected.indexes(); QModelIndexList list = selected.indexes();
if (list.size() != 0) if (list.size() != 0)
{ {
qDebug("SELECTED LAYER -> %d", list[0].row()); std::cout << "SELECTED LAYER ->" << list[0].row() << "\n";
emit layerSelected(list[0].row()); emit layerSelected(list[0].row());
} }
} }
void LayerTab::layerInfo() void LayerTab::layerInfo()
{ {
qDebug("Layer info"); qDebug("Layer info");
QModelIndexList indexes = selectedIndexes(); QModelIndexList indexes = selectedIndexes();
if (indexes.size() > 0) if (indexes.size() > 0)
{ {
qDebug("id = %d", indexes[0].row()); qDebug("id = %d",indexes[0].row());
}
}
} }
void LayerTab::layerInfo2(QModelIndex const& index) void LayerTab::layerInfo2(QModelIndex const& index)
{ {
qDebug("LayerInfo id = %d", index.row()); qDebug("LayerInfo id = %d",index.row());
QVector<QPair<QString, QString>> params; QVector<QPair<QString,QString> > params;
QVector<QString> style_names; QVector<QString> style_names;
unsigned i = index.row(); unsigned i = index.row();
LayerListModel* model = static_cast<LayerListModel*>(this->model()); LayerListModel * model = static_cast<LayerListModel*>(this->model());
boost::optional<mapnik::layer&> layer = model->map_layer(i); boost::optional<mapnik::layer&> layer = model->map_layer(i);
if (layer) if (layer)
{ {
layer_info_dialog dlg(*layer, this); layer_info_dialog dlg(*layer,this);
dlg.exec(); dlg.exec();
} }
} }
StyleTab::StyleTab(QWidget*) {} StyleTab::StyleTab(QWidget*)
void StyleTab::contextMenuEvent(QContextMenuEvent* event)
{ {
qDebug("test");
}
void StyleTab::contextMenuEvent(QContextMenuEvent * event )
{
qDebug("test");
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef LAYERWIDGET_HPP #ifndef LAYERWIDGET_HPP
#define LAYERWIDGET_HPP #define LAYERWIDGET_HPP
@ -26,29 +27,28 @@
class LayerTab : public QListView class LayerTab : public QListView
{ {
Q_OBJECT Q_OBJECT
public: public:
LayerTab(QWidget* parent = 0); LayerTab(QWidget* parent=0);
void paintEvent(QPaintEvent* e); void paintEvent(QPaintEvent *e);
signals: signals:
void update_mapwidget(); void update_mapwidget();
void layerSelected(int) const; void layerSelected(int) const;
public slots: public slots:
void layerInfo(); void layerInfo();
void layerInfo2(QModelIndex const&); void layerInfo2(QModelIndex const&);
protected slots: protected slots:
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles); void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
void selectionChanged(const QItemSelection& selected, const QItemSelection&); void selectionChanged(const QItemSelection & selected, const QItemSelection &);
}; };
class StyleTab : public QTreeView class StyleTab : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public: public:
StyleTab(QWidget* parent = 0); StyleTab(QWidget* parent=0);
protected:
protected: void contextMenuEvent(QContextMenuEvent * event );
void contextMenuEvent(QContextMenuEvent* event);
}; };
#endif #endif

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,20 +17,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
// qt // qt
#include <QApplication> #include <QApplication>
#include <QStringList> #include <QStringList>
#include <QSettings> #include <QSettings>
#include <mapnik/datasource_cache.hpp> #include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp> #include <mapnik/font_engine_freetype.hpp>
#include <mapnik/mapnik.hpp>
#include "mainwindow.hpp" #include "mainwindow.hpp"
int main(int argc, char** argv) int main( int argc, char **argv )
{ {
using mapnik::datasource_cache; using mapnik::datasource_cache;
using mapnik::freetype_engine; using mapnik::freetype_engine;
mapnik::setup();
try try
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
@ -39,14 +38,15 @@ int main(int argc, char** argv)
QCoreApplication::setOrganizationName("Mapnik"); QCoreApplication::setOrganizationName("Mapnik");
QCoreApplication::setOrganizationDomain("mapnik.org"); QCoreApplication::setOrganizationDomain("mapnik.org");
QCoreApplication::setApplicationName("Viewer"); QCoreApplication::setApplicationName("Viewer");
QSettings settings("viewer.ini", QSettings::IniFormat); QSettings settings("viewer.ini",QSettings::IniFormat);
// register input plug-ins // register input plug-ins
QString plugins_dir = settings.value("mapnik/plugins_dir", QVariant("/usr/local/lib/mapnik/input/")).toString(); QString plugins_dir = settings.value("mapnik/plugins_dir",
QVariant("/usr/local/lib/mapnik/input/")).toString();
datasource_cache::instance().register_datasources(plugins_dir.toStdString()); datasource_cache::instance().register_datasources(plugins_dir.toStdString());
// register fonts // register fonts
int count = settings.beginReadArray("mapnik/fonts"); int count = settings.beginReadArray("mapnik/fonts");
for (int index = 0; index < count; ++index) for (int index=0; index < count; ++index)
{ {
settings.setArrayIndex(index); settings.setArrayIndex(index);
QString font_dir = settings.value("dir").toString(); QString font_dir = settings.value("dir").toString();
@ -54,37 +54,33 @@ int main(int argc, char** argv)
} }
settings.endArray(); settings.endArray();
QApplication app(argc, argv); QApplication app( argc, argv );
MainWindow window; MainWindow window;
window.show(); window.show();
if (argc > 1) if (argc > 1) window.open(argv[1]);
window.open(argv[1]);
if (argc >= 3) if (argc >= 3)
{ {
QStringList list = QString(argv[2]).split(","); QStringList list = QString(argv[2]).split(",");
if (list.size() == 4) if (list.size()==4)
{ {
bool ok; bool ok;
double x0 = list[0].toDouble(&ok); double x0 = list[0].toDouble(&ok);
double y0 = list[1].toDouble(&ok); double y0 = list[1].toDouble(&ok);
double x1 = list[2].toDouble(&ok); double x1 = list[2].toDouble(&ok);
double y1 = list[3].toDouble(&ok); double y1 = list[3].toDouble(&ok);
if (ok) if (ok) window.set_default_extent(x0,y0,x1,y1);
window.set_default_extent(x0, y0, x1, y1);
} }
} }
else else
{ {
std::shared_ptr<mapnik::Map> map = window.get_map(); std::shared_ptr<mapnik::Map> map = window.get_map();
if (map) if (map) map->zoom_all();
map->zoom_all();
} }
if (argc == 4) if (argc == 4)
{ {
bool ok; bool ok;
double scaling_factor = QString(argv[3]).toDouble(&ok); double scaling_factor = QString(argv[3]).toDouble(&ok);
if (ok) if (ok) window.set_scaling_factor(scaling_factor);
window.set_scaling_factor(scaling_factor);
} }
return app.exec(); return app.exec();
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
// stl // stl
#include <iostream> #include <iostream>
@ -38,7 +39,7 @@
// mapnik // mapnik
#ifndef Q_MOC_RUN // QT moc chokes on BOOST_JOIN #ifndef Q_MOC_RUN // QT moc chokes on BOOST_JOIN
// #include <mapnik/config_error.hpp> //#include <mapnik/config_error.hpp>
#include <mapnik/load_map.hpp> #include <mapnik/load_map.hpp>
#include <mapnik/save_map.hpp> #include <mapnik/save_map.hpp>
#include <mapnik/projection.hpp> #include <mapnik/projection.hpp>
@ -57,27 +58,27 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
MainWindow::MainWindow() MainWindow::MainWindow()
: filename_() : filename_(),
, default_extent_(-20037508.3428, -20037508.3428, 20037508.3428, 20037508.3428) default_extent_(-20037508.3428,-20037508.3428,20037508.3428,20037508.3428)
{ {
mapWidget_ = new MapWidget(this); mapWidget_ = new MapWidget(this);
QSplitter* splitter = new QSplitter(this); QSplitter *splitter = new QSplitter(this);
QTabWidget* tabWidget = new QTabWidget; QTabWidget *tabWidget=new QTabWidget;
layerTab_ = new LayerTab; layerTab_ = new LayerTab;
layerTab_->setFocusPolicy(Qt::NoFocus); layerTab_->setFocusPolicy(Qt::NoFocus);
layerTab_->setIconSize(QSize(16, 16)); layerTab_->setIconSize(QSize(16,16));
// LayerDelegate *delegate = new LayerDelegate(this); //LayerDelegate *delegate = new LayerDelegate(this);
// layerTab_->setItemDelegate(delegate); //layerTab_->setItemDelegate(delegate);
// layerTab_->setItemDelegate(new QItemDelegate(this)); //layerTab_->setItemDelegate(new QItemDelegate(this));
// layerTab_->setViewMode(QListView::IconMode); //layerTab_->setViewMode(QListView::IconMode);
layerTab_->setFlow(QListView::TopToBottom); layerTab_->setFlow(QListView::TopToBottom);
tabWidget->addTab(layerTab_, tr("Layers")); tabWidget->addTab(layerTab_,tr("Layers"));
// Styles tab // Styles tab
styleTab_ = new StyleTab; styleTab_ = new StyleTab;
tabWidget->addTab(styleTab_, tr("Styles")); tabWidget->addTab(styleTab_,tr("Styles"));
splitter->addWidget(tabWidget); splitter->addWidget(tabWidget);
splitter->addWidget(mapWidget_); splitter->addWidget(mapWidget_);
QList<int> list; QList<int> list;
@ -88,7 +89,7 @@ MainWindow::MainWindow()
mapWidget_->setFocusPolicy(Qt::StrongFocus); mapWidget_->setFocusPolicy(Qt::StrongFocus);
mapWidget_->setFocus(); mapWidget_->setFocus();
// setCentralWidget(mapWidget_); //setCentralWidget(mapWidget_);
setCentralWidget(splitter); setCentralWidget(splitter);
createActions(); createActions();
createMenus(); createMenus();
@ -96,25 +97,29 @@ MainWindow::MainWindow()
createContextMenu(); createContextMenu();
setWindowTitle(tr("Mapnik Viewer")); setWindowTitle(tr("Mapnik Viewer"));
status = new QStatusBar(this); status=new QStatusBar(this);
status->showMessage(tr("")); status->showMessage(tr(""));
setStatusBar(status); setStatusBar(status);
resize(800, 600); resize(800,600);
// connect mapview to layerlist //connect mapview to layerlist
connect(mapWidget_, SIGNAL(mapViewChanged()), layerTab_, SLOT(update())); connect(mapWidget_, SIGNAL(mapViewChanged()),layerTab_, SLOT(update()));
// slider // slider
connect(slider_, SIGNAL(valueChanged(int)), mapWidget_, SLOT(zoomToLevel(int))); connect(slider_,SIGNAL(valueChanged(int)),mapWidget_,SLOT(zoomToLevel(int)));
// renderer selector // renderer selector
connect(renderer_selector_, SIGNAL(currentIndexChanged(int)), mapWidget_, SLOT(updateRenderer(int))); connect(renderer_selector_,SIGNAL(currentIndexChanged(QString const&)),
mapWidget_, SLOT(updateRenderer(QString const&)));
// scale factor // scale factor
connect(scale_factor_, SIGNAL(valueChanged(double)), mapWidget_, SLOT(updateScaleFactor(double))); connect(scale_factor_,SIGNAL(valueChanged(double)),
mapWidget_, SLOT(updateScaleFactor(double)));
// //
connect(layerTab_, SIGNAL(update_mapwidget()), mapWidget_, SLOT(updateMap())); connect(layerTab_,SIGNAL(update_mapwidget()),mapWidget_,SLOT(updateMap()));
connect(layerTab_, SIGNAL(layerSelected(int)), mapWidget_, SLOT(layerSelected(int))); connect(layerTab_,SIGNAL(layerSelected(int)),
mapWidget_,SLOT(layerSelected(int)));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete mapWidget_; delete mapWidget_;
@ -136,7 +141,8 @@ void MainWindow::open(QString const& path)
{ {
if (path.isNull()) if (path.isNull())
{ {
filename_ = QFileDialog::getOpenFileName(this, tr("Open Mapnik file"), currentPath, "*.xml"); filename_ = QFileDialog::getOpenFileName(this,tr("Open Mapnik file"),
currentPath,"*.xml");
} }
else else
{ {
@ -145,15 +151,18 @@ void MainWindow::open(QString const& path)
if (!filename_.isEmpty()) if (!filename_.isEmpty())
{ {
load_map_file(filename_); load_map_file(filename_);
setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_)); setWindowTitle(tr("%1 - Mapnik Viewer").arg(filename_));
} }
} }
void MainWindow::reload() void MainWindow::reload()
{ {
if (!filename_.isEmpty()) if (!filename_.isEmpty())
{ {
mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent(); mapnik::box2d<double> bbox = mapWidget_->getMap()->get_current_extent();
load_map_file(filename_); load_map_file(filename_);
mapWidget_->zoomToBox(bbox); mapWidget_->zoomToBox(bbox);
@ -164,28 +173,28 @@ void MainWindow::reload()
void MainWindow::save() void MainWindow::save()
{ {
QString initialPath = QDir::currentPath() + "/untitled.xml"; QString initialPath = QDir::currentPath() + "/untitled.xml";
QString filename = QFileDialog::getSaveFileName(this, QString filename = QFileDialog::getSaveFileName(this, tr("Save"),
tr("Save"),
initialPath, initialPath,
tr("%1 Files (*.xml)").arg(QString("Mapnik definition"))); tr("%1 Files (*.xml)")
.arg(QString("Mapnik definition")));
if (!filename.isEmpty()) if (!filename.isEmpty())
{ {
std::cout << "saving " << filename.toStdString() << std::endl; std::cout<<"saving "<< filename.toStdString() << std::endl;
mapnik::save_map(*mapWidget_->getMap(), filename.toStdString()); mapnik::save_map(*mapWidget_->getMap(),filename.toStdString());
} }
} }
void MainWindow::load_map_file(QString const& filename) void MainWindow::load_map_file(QString const& filename)
{ {
std::cout << "loading " << filename.toStdString() << std::endl; std::cout << "loading "<< filename.toStdString() << std::endl;
unsigned width = mapWidget_->width(); unsigned width = mapWidget_->width();
unsigned height = mapWidget_->height(); unsigned height = mapWidget_->height();
std::shared_ptr<mapnik::Map> map(new mapnik::Map(width, height)); std::shared_ptr<mapnik::Map> map(new mapnik::Map(width,height));
mapWidget_->setMap(map); mapWidget_->setMap(map);
try try
{ {
mapnik::auto_cpu_timer t(std::clog, "loading map took: "); mapnik::auto_cpu_timer t(std::clog, "loading map took: ");
mapnik::load_map(*map, filename.toStdString()); mapnik::load_map(*map,filename.toStdString());
} }
catch (std::exception const& ex) catch (std::exception const& ex)
{ {
@ -195,8 +204,8 @@ void MainWindow::load_map_file(QString const& filename)
{ {
std::cerr << "Exception caught in load_map\n"; std::cerr << "Exception caught in load_map\n";
} }
layerTab_->setModel(new LayerListModel(map, this)); layerTab_->setModel(new LayerListModel(map,this));
styleTab_->setModel(new StyleModel(map, this)); styleTab_->setModel(new StyleModel(map,this));
zoom_all(); zoom_all();
} }
@ -243,15 +252,15 @@ void MainWindow::about()
void MainWindow::export_as() void MainWindow::export_as()
{ {
QAction* action = qobject_cast<QAction*>(sender()); QAction *action = qobject_cast<QAction *>(sender());
QByteArray fileFormat = action->data().toByteArray(); QByteArray fileFormat = action->data().toByteArray();
QString initialPath = QDir::currentPath() + "/map." + fileFormat; QString initialPath = QDir::currentPath() + "/map." + fileFormat;
QString fileName = QFileDialog::getSaveFileName( QString fileName = QFileDialog::getSaveFileName(this, tr("Export As"),
this, initialPath,
tr("Export As"), tr("%1 Files (*.%2);;All Files (*)")
initialPath, .arg(QString(fileFormat.toUpper()))
tr("%1 Files (*.%2);;All Files (*)").arg(QString(fileFormat.toUpper())).arg(QString(fileFormat))); .arg(QString(fileFormat)));
if (!fileName.isEmpty()) if (!fileName.isEmpty())
{ {
QPixmap const& pix = mapWidget_->pixmap(); QPixmap const& pix = mapWidget_->pixmap();
@ -261,76 +270,77 @@ void MainWindow::export_as()
void MainWindow::print() void MainWindow::print()
{ {
// Q_ASSERT(mapWidget_->pixmap());
// QPrintDialog dialog(&printer, this); //Q_ASSERT(mapWidget_->pixmap());
// if (dialog.exec()) { //QPrintDialog dialog(&printer, this);
// QPainter painter(&printer); //if (dialog.exec()) {
// QRect rect = painter.viewport(); // QPainter painter(&printer);
// QSize size = mapWidget_->pixmap()->size(); // QRect rect = painter.viewport();
// size.scale(rect.size(), Qt::KeepAspectRatio); // QSize size = mapWidget_->pixmap()->size();
// painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); // size.scale(rect.size(), Qt::KeepAspectRatio);
// painter.setWindow(mapWidget_->pixmap()->rect()); // painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
// painter.drawPixmap(0, 0, *mapWidget_->pixmap()); // painter.setWindow(mapWidget_->pixmap()->rect());
// } // painter.drawPixmap(0, 0, *mapWidget_->pixmap());
//}
} }
void MainWindow::createActions() void MainWindow::createActions()
{ {
// exportAct = new QAction(tr("&Export as ..."),this); //exportAct = new QAction(tr("&Export as ..."),this);
// exportAct->setShortcut(tr("Ctrl+E")); //exportAct->setShortcut(tr("Ctrl+E"));
// connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as())); //connect(exportAct, SIGNAL(triggered()), this, SLOT(export_as()));
zoomAllAct = new QAction(QIcon(":/images/home.png"), tr("Zoom All"), this); zoomAllAct = new QAction(QIcon(":/images/home.png"),tr("Zoom All"),this);
connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all())); connect(zoomAllAct, SIGNAL(triggered()), this, SLOT(zoom_all()));
zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"), tr("Zoom To Box"), this); zoomBoxAct = new QAction(QIcon(":/images/zoombox.png"),tr("Zoom To Box"),this);
zoomBoxAct->setCheckable(true); zoomBoxAct->setCheckable(true);
connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box())); connect(zoomBoxAct, SIGNAL(triggered()), this, SLOT(zoom_to_box()));
panAct = new QAction(QIcon(":/images/pan.png"), tr("Pan"), this); panAct = new QAction(QIcon(":/images/pan.png"),tr("Pan"),this);
panAct->setCheckable(true); panAct->setCheckable(true);
connect(panAct, SIGNAL(triggered()), this, SLOT(pan())); connect(panAct, SIGNAL(triggered()), this, SLOT(pan()));
infoAct = new QAction(QIcon(":/images/info.png"), tr("Info"), this); infoAct = new QAction(QIcon(":/images/info.png"),tr("Info"),this);
infoAct->setCheckable(true); infoAct->setCheckable(true);
connect(infoAct, SIGNAL(triggered()), this, SLOT(info())); connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
toolsGroup = new QActionGroup(this); toolsGroup=new QActionGroup(this);
toolsGroup->addAction(zoomBoxAct); toolsGroup->addAction(zoomBoxAct);
toolsGroup->addAction(panAct); toolsGroup->addAction(panAct);
toolsGroup->addAction(infoAct); toolsGroup->addAction(infoAct);
zoomBoxAct->setChecked(true); zoomBoxAct->setChecked(true);
openAct = new QAction(tr("Open Map definition"), this); openAct=new QAction(tr("Open Map definition"),this);
connect(openAct, SIGNAL(triggered()), this, SLOT(open())); connect(openAct,SIGNAL(triggered()),this,SLOT(open()));
saveAct = new QAction(tr("Save Map definition"), this); saveAct=new QAction(tr("Save Map definition"),this);
connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); connect(saveAct,SIGNAL(triggered()),this,SLOT(save()));
panLeftAct = new QAction(QIcon(":/images/left.png"), tr("&Pan Left"), this); panLeftAct = new QAction(QIcon(":/images/left.png"),tr("&Pan Left"),this);
connect(panLeftAct, SIGNAL(triggered()), this, SLOT(pan_left())); connect(panLeftAct, SIGNAL(triggered()), this, SLOT(pan_left()));
panRightAct = new QAction(QIcon(":/images/right.png"), tr("&Pan Right"), this); panRightAct = new QAction(QIcon(":/images/right.png"),tr("&Pan Right"),this);
connect(panRightAct, SIGNAL(triggered()), this, SLOT(pan_right())); connect(panRightAct, SIGNAL(triggered()), this, SLOT(pan_right()));
panUpAct = new QAction(QIcon(":/images/up.png"), tr("&Pan Up"), this); panUpAct = new QAction(QIcon(":/images/up.png"),tr("&Pan Up"),this);
connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up())); connect(panUpAct, SIGNAL(triggered()), this, SLOT(pan_up()));
panDownAct = new QAction(QIcon(":/images/down.png"), tr("&Pan Down"), this); panDownAct = new QAction(QIcon(":/images/down.png"),tr("&Pan Down"),this);
connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down())); connect(panDownAct, SIGNAL(triggered()), this, SLOT(pan_down()));
reloadAct = new QAction(QIcon(":/images/reload.png"), tr("Reload"), this); reloadAct = new QAction(QIcon(":/images/reload.png"),tr("Reload"),this);
connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload())); connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
layerInfo = new QAction(QIcon(":/images/info.png"), tr("&Layer info"), layerTab_); layerInfo = new QAction(QIcon(":/images/info.png"),tr("&Layer info"),layerTab_);
connect(layerInfo, SIGNAL(triggered()), layerTab_, SLOT(layerInfo())); connect(layerInfo, SIGNAL(triggered()), layerTab_,SLOT(layerInfo()));
connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_, SLOT(layerInfo2(QModelIndex const&))); connect(layerTab_, SIGNAL(doubleClicked(QModelIndex const&)), layerTab_,SLOT(layerInfo2(QModelIndex const&)));
foreach (QByteArray format, QImageWriter::supportedImageFormats()) foreach (QByteArray format, QImageWriter::supportedImageFormats())
{ {
QString text = tr("%1...").arg(QString(format).toUpper()); QString text = tr("%1...").arg(QString(format).toUpper());
QAction* action = new QAction(text, this); QAction *action = new QAction(text, this);
action->setData(format); action->setData(format);
connect(action, SIGNAL(triggered()), this, SLOT(export_as())); connect(action, SIGNAL(triggered()), this, SLOT(export_as()));
exportAsActs.append(action); exportAsActs.append(action);
} }
printAct = new QAction(QIcon(":/images/print.png"), tr("&Print ..."), this); printAct = new QAction(QIcon(":/images/print.png"),tr("&Print ..."),this);
printAct->setShortcut(tr("Ctrl+E")); printAct->setShortcut(tr("Ctrl+E"));
connect(printAct, SIGNAL(triggered()), this, SLOT(print())); connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
@ -338,17 +348,17 @@ void MainWindow::createActions()
exitAct->setShortcut(tr("Ctrl+Q")); exitAct->setShortcut(tr("Ctrl+Q"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
aboutAct = new QAction(QIcon(":/images/about.png"), tr("&About"), this); aboutAct = new QAction(QIcon(":/images/about.png"),tr("&About"), this);
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
} }
void MainWindow::createMenus() void MainWindow::createMenus()
{ {
exportMenu = new QMenu(tr("&Export As"), this); exportMenu = new QMenu(tr("&Export As"), this);
foreach (QAction* action, exportAsActs) foreach (QAction *action, exportAsActs)
exportMenu->addAction(action); exportMenu->addAction(action);
fileMenu = new QMenu(tr("&File"), this); fileMenu = new QMenu(tr("&File"),this);
fileMenu->addAction(openAct); fileMenu->addAction(openAct);
fileMenu->addAction(saveAct); fileMenu->addAction(saveAct);
fileMenu->addMenu(exportMenu); fileMenu->addMenu(exportMenu);
@ -387,13 +397,13 @@ void MainWindow::createToolBars()
scale_factor_ = new QDoubleSpinBox(fileToolBar); scale_factor_ = new QDoubleSpinBox(fileToolBar);
scale_factor_->setMinimum(0.1); scale_factor_->setMinimum(0.1);
scale_factor_->setMaximum(10.0); scale_factor_->setMaximum(5.0);
scale_factor_->setSingleStep(0.1); scale_factor_->setSingleStep(0.1);
scale_factor_->setValue(1.0); scale_factor_->setValue(1.0);
fileToolBar->addWidget(scale_factor_); fileToolBar->addWidget(scale_factor_);
slider_ = new QSlider(Qt::Horizontal, fileToolBar); slider_ = new QSlider(Qt::Horizontal,fileToolBar);
slider_->setRange(1, 18); slider_->setRange(1,18);
slider_->setTickPosition(QSlider::TicksBelow); slider_->setTickPosition(QSlider::TicksBelow);
slider_->setTickInterval(1); slider_->setTickInterval(1);
slider_->setTracking(false); slider_->setTracking(false);
@ -401,7 +411,9 @@ void MainWindow::createToolBars()
fileToolBar->addAction(aboutAct); fileToolBar->addAction(aboutAct);
} }
void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
void MainWindow::set_default_extent(double x0,double y0, double x1, double y1)
{ {
try try
{ {
@ -409,15 +421,14 @@ void MainWindow::set_default_extent(double x0, double y0, double x1, double y1)
if (map_ptr) if (map_ptr)
{ {
mapnik::projection prj(map_ptr->srs()); mapnik::projection prj(map_ptr->srs());
prj.forward(x0, y0); prj.forward(x0,y0);
prj.forward(x1, y1); prj.forward(x1,y1);
default_extent_ = mapnik::box2d<double>(x0, y0, x1, y1); default_extent_=mapnik::box2d<double>(x0,y0,x1,y1);
mapWidget_->zoomToBox(default_extent_); mapWidget_->zoomToBox(default_extent_);
std::cout << "SET DEFAULT EXT:" << default_extent_ << std::endl; std::cout << "SET DEFAULT EXT\n";
} }
} }
catch (...) catch (...) {}
{}
} }
void MainWindow::set_scaling_factor(double scaling_factor) void MainWindow::set_scaling_factor(double scaling_factor)

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef MAINWINDOW_HPP #ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP #define MAINWINDOW_HPP
@ -29,7 +30,7 @@
#include "mapwidget.hpp" #include "mapwidget.hpp"
// using namespace mapnik; //using namespace mapnik;
class LayerTab; class LayerTab;
class StyleTab; class StyleTab;
@ -40,24 +41,22 @@ class QDoubleSpinBox;
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
MainWindow(); MainWindow();
virtual ~MainWindow(); virtual ~MainWindow();
void set_default_extent(double x0, double y0, double x1, double y1); void set_default_extent(double x0,double y0,double x1, double y1);
void set_scaling_factor(double scaling_factor); void set_scaling_factor(double scaling_factor);
public :
public:
std::shared_ptr<mapnik::Map> get_map(); std::shared_ptr<mapnik::Map> get_map();
protected:
protected:
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);
public slots: public slots:
void zoom_all(); void zoom_all();
void zoom_to_box(); void zoom_to_box();
void pan(); void pan();
void info(); void info();
void export_as(); void export_as();
void open(QString const& path = QString()); void open(QString const& path = QString());
void reload(); void reload();
void save(); void save();
void print(); void print();
@ -66,8 +65,7 @@ class MainWindow : public QMainWindow
void pan_right(); void pan_right();
void pan_up(); void pan_up();
void pan_down(); void pan_down();
private:
private:
void createActions(); void createActions();
void createMenus(); void createMenus();
void createToolBars(); void createToolBars();
@ -76,42 +74,43 @@ class MainWindow : public QMainWindow
QString currentPath; QString currentPath;
QString filename_; QString filename_;
QAbstractItemModel* model; QAbstractItemModel *model;
LayerTab* layerTab_; LayerTab *layerTab_;
StyleTab* styleTab_; StyleTab * styleTab_;
MapWidget* mapWidget_; MapWidget * mapWidget_;
// actions //actions
QList<QAction*> exportAsActs; QList<QAction *> exportAsActs;
QActionGroup* toolsGroup; QActionGroup *toolsGroup;
QAction* zoomAllAct; QAction *zoomAllAct;
QAction* zoomBoxAct; QAction *zoomBoxAct;
QAction* panAct; QAction *panAct;
QAction* infoAct; QAction *infoAct;
QAction* openAct; QAction *openAct;
QAction* saveAct; QAction *saveAct;
QAction* printAct; QAction *printAct;
QAction* exitAct; QAction *exitAct;
QAction* aboutAct; QAction *aboutAct;
QAction* panLeftAct; QAction *panLeftAct;
QAction* panRightAct; QAction *panRightAct;
QAction* panUpAct; QAction *panUpAct;
QAction* panDownAct; QAction *panDownAct;
QAction* reloadAct; QAction *reloadAct;
QAction* layerInfo; QAction *layerInfo;
// toolbars //toolbars
QToolBar* fileToolBar; QToolBar *fileToolBar;
QToolBar* editToolBar; QToolBar *editToolBar;
// menus //menus
QMenu* exportMenu; QMenu *exportMenu;
QMenu* fileMenu; QMenu *fileMenu;
QMenu* helpMenu; QMenu *helpMenu;
// status bar //status bar
QStatusBar* status; QStatusBar *status;
QSlider* slider_; QSlider * slider_;
QComboBox* renderer_selector_; QComboBox * renderer_selector_;
QDoubleSpinBox* scale_factor_; QDoubleSpinBox * scale_factor_;
mapnik::box2d<double> default_extent_; mapnik::box2d<double> default_extent_;
}; };
#endif // MAINWINDOW_HPP
#endif //MAINWINDOW_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,12 +17,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <QtGui> #include <QtGui>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <mapnik/agg_renderer.hpp> #include <mapnik/agg_renderer.hpp>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
#include <mapnik/proj_transform.hpp> #include <mapnik/projection.hpp>
#include <mapnik/scale_denominator.hpp> #include <mapnik/scale_denominator.hpp>
#include <mapnik/view_transform.hpp> #include <mapnik/view_transform.hpp>
#include <mapnik/transform_path_adapter.hpp> #include <mapnik/transform_path_adapter.hpp>
@ -40,139 +41,153 @@
#include "mapwidget.hpp" #include "mapwidget.hpp"
#include "info_dialog.hpp" #include "info_dialog.hpp"
using mapnik::image_rgba8;
using mapnik::Map;
using mapnik::layer;
using mapnik::box2d; using mapnik::box2d;
using mapnik::coord2d; using mapnik::coord2d;
using mapnik::feature_kv_iterator;
using mapnik::feature_ptr; using mapnik::feature_ptr;
using mapnik::image_rgba8; using mapnik::view_transform;
using mapnik::layer;
using mapnik::Map;
using mapnik::projection; using mapnik::projection;
using mapnik::scale_denominator; using mapnik::scale_denominator;
using mapnik::view_transform; using mapnik::feature_kv_iterator;
double scales[] = {279541132.014, 139770566.007, 69885283.0036, 34942641.5018, 17471320.7509, double scales [] = {279541132.014,
8735660.37545, 4367830.18772, 2183915.09386, 1091957.54693, 545978.773466, 139770566.007,
272989.386733, 136494.693366, 68247.3466832, 34123.6733416, 17061.8366708, 69885283.0036,
8530.9183354, 4265.4591677, 2132.72958385, 1066.36479192, 533.182395962}; 34942641.5018,
17471320.7509,
8735660.37545,
4367830.18772,
2183915.09386,
1091957.54693,
545978.773466,
272989.386733,
136494.693366,
68247.3466832,
34123.6733416,
17061.8366708,
8530.9183354,
4265.4591677,
2132.72958385,
1066.36479192,
533.182395962};
MapWidget::MapWidget(QWidget* parent) MapWidget::MapWidget(QWidget *parent)
: QWidget(parent) : QWidget(parent),
, map_() map_(),
, selected_(1) selected_(1),
, extent_() extent_(),
, cur_tool_(ZoomToBox) cur_tool_(ZoomToBox),
, start_x_(0) start_x_(0),
, start_y_(0) start_y_(0),
, end_x_(0) end_x_(0),
, end_y_(0) end_y_(0),
, drag_(false) drag_(false),
, first_(true) first_(true),
, pen_(QColor(0, 0, 255, 96)) pen_(QColor(0,0,255,96)),
, selectedLayer_(-1) selectedLayer_(-1),
, scaling_factor_(1.0) scaling_factor_(1.0),
, cur_renderer_(AGG) cur_renderer_(AGG)
{ {
pen_.setWidth(3); pen_.setWidth(3);
pen_.setCapStyle(Qt::RoundCap); pen_.setCapStyle(Qt::RoundCap);
pen_.setJoinStyle(Qt::RoundJoin); pen_.setJoinStyle(Qt::RoundJoin);
} }
void MapWidget::setTool(eTool tool) void MapWidget::setTool(eTool tool)
{ {
cur_tool_ = tool; cur_tool_=tool;
} }
void MapWidget::paintEvent(QPaintEvent*) void MapWidget::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
if (drag_) if (drag_)
{ {
if (cur_tool_ == ZoomToBox) if (cur_tool_ == ZoomToBox)
{ {
unsigned width = end_x_ - start_x_; unsigned width = end_x_-start_x_;
unsigned height = end_y_ - start_y_; unsigned height = end_y_-start_y_;
painter.drawPixmap(QPoint(0, 0), pix_); painter.drawPixmap(QPoint(0, 0),pix_);
painter.setPen(pen_); painter.setPen(pen_);
painter.setBrush(QColor(200, 200, 255, 128)); painter.setBrush(QColor(200,200,255,128));
painter.drawRect(start_x_, start_y_, width, height); painter.drawRect(start_x_,start_y_,width,height);
} }
else if (cur_tool_ == Pan) else if (cur_tool_ == Pan)
{ {
int dx = end_x_ - start_x_; int dx = end_x_-start_x_;
int dy = end_y_ - start_y_; int dy = end_y_-start_y_;
painter.setBrush(QColor(200, 200, 200, 128)); painter.setBrush(QColor(200,200,200,128));
painter.drawRect(0, 0, width(), height()); painter.drawRect(0,0,width(),height());
painter.drawPixmap(QPoint(dx, dy), pix_); painter.drawPixmap(QPoint(dx,dy),pix_);
} }
} }
else else
{ {
painter.drawPixmap(QPoint(0, 0), pix_); painter.drawPixmap(QPoint(0, 0),pix_);
} }
painter.end(); painter.end();
} }
void MapWidget::resizeEvent(QResizeEvent* ev) void MapWidget::resizeEvent(QResizeEvent * ev)
{ {
if (map_) if (map_)
{ {
map_->resize(ev->size().width(), ev->size().height()); map_->resize(ev->size().width(),ev->size().height());
updateMap(); updateMap();
} }
} }
void MapWidget::mousePressEvent(QMouseEvent* e) void MapWidget::mousePressEvent(QMouseEvent* e)
{ {
if (e->button() == Qt::LeftButton) if (e->button()==Qt::LeftButton)
{ {
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan) if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
{ {
start_x_ = e->x(); start_x_ = e->x();
start_y_ = e->y(); start_y_ = e->y();
drag_ = true; drag_=true;
} }
else if (cur_tool_ == Info) else if (cur_tool_==Info)
{ {
if (map_) if (map_)
{
QVector<QPair<QString,QString> > info;
projection map_proj(map_->srs()); // map projection
double scale_denom = scale_denominator(map_->scale(),map_proj.is_geographic());
view_transform t(map_->width(),map_->height(),map_->get_current_extent());
for (unsigned index = 0; index < map_->layer_count();++index)
{ {
QVector<QPair<QString, QString>> info; if (int(index) != selectedLayer_) continue;
projection map_proj(map_->srs(), true); // map projection layer & layer = map_->layers()[index];
double scale_denom = scale_denominator(map_->scale(), map_proj.is_geographic()); if (!layer.visible(scale_denom)) continue;
view_transform t(map_->width(), map_->height(), map_->get_current_extent()); std::string name = layer.name();
double x = e->x();
double y = e->y();
std::cout << "query at " << x << "," << y << "\n";
projection layer_proj(layer.srs());
mapnik::proj_transform prj_trans(map_proj,layer_proj);
//std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
mapnik::featureset_ptr fs = map_->query_map_point(index,x,y);
for (unsigned index = 0; index < map_->layer_count(); ++index) if (fs)
{ {
if (int(index) != selectedLayer_) feature_ptr feat = fs->next();
continue; if (feat)
{
feature_kv_iterator itr(*feat,true);
feature_kv_iterator end(*feat);
layer& layer = map_->layers()[index]; for ( ;itr!=end; ++itr)
if (!layer.visible(scale_denom)) {
continue; info.push_back(QPair<QString,QString>(QString(std::get<0>(*itr).c_str()),
std::string name = layer.name(); std::get<1>(*itr).to_string().c_str()));
double x = e->x(); }
double y = e->y();
std::cout << "query at " << x << "," << y << "\n";
projection layer_proj(layer.srs(), true);
mapnik::proj_transform prj_trans(map_proj, layer_proj);
// std::auto_ptr<mapnik::memory_datasource> data(new mapnik::memory_datasource);
mapnik::featureset_ptr fs = map_->query_map_point(index, x, y);
if (fs)
{
feature_ptr feat = fs->next();
if (feat)
{
feature_kv_iterator itr(*feat, true);
feature_kv_iterator end(*feat);
for (; itr != end; ++itr)
{
info.push_back(QPair<QString, QString>(QString(std::get<0>(*itr).c_str()),
std::get<1>(*itr).to_string().c_str()));
}
#if 0 // #if 0 //
using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>; using path_type = mapnik::transform_path_adapter<mapnik::view_transform,mapnik::vertex_adapter>;
@ -204,285 +219,271 @@ void MapWidget::mousePressEvent(QMouseEvent* e)
} }
} }
#endif #endif
} }
} }
if (info.size() > 0) if (info.size() > 0)
{ {
info_dialog info_dlg(info, this); info_dialog info_dlg(info,this);
info_dlg.exec(); info_dlg.exec();
break; break;
} }
}
// remove annotation layer
map_->layers().erase(
remove_if(map_->layers().begin(), map_->layers().end(), bind(&layer::name, _1) == "*annotations*"),
map_->layers().end());
} }
}
} // remove annotation layer
else if (e->button() == Qt::RightButton) map_->layers().erase(remove_if(map_->layers().begin(),
{ map_->layers().end(),
// updateMap(); bind(&layer::name,_1) == "*annotations*")
} , map_->layers().end());
}
}
}
else if (e->button()==Qt::RightButton)
{
//updateMap();
}
} }
void MapWidget::mouseMoveEvent(QMouseEvent* e) void MapWidget::mouseMoveEvent(QMouseEvent* e)
{ {
if (cur_tool_ == ZoomToBox || cur_tool_ == Pan) if (cur_tool_ == ZoomToBox || cur_tool_==Pan)
{ {
end_x_ = e->x(); end_x_ = e->x();
end_y_ = e->y(); end_y_ = e->y();
update(); update();
} }
} }
void MapWidget::mouseReleaseEvent(QMouseEvent* e) void MapWidget::mouseReleaseEvent(QMouseEvent* e)
{ {
if (e->button() == Qt::LeftButton) if (e->button()==Qt::LeftButton)
{ {
end_x_ = e->x(); end_x_ = e->x();
end_y_ = e->y(); end_y_ = e->y();
if (cur_tool_ == ZoomToBox) if (cur_tool_ == ZoomToBox)
{ {
drag_ = false; drag_=false;
if (map_) if (map_)
{ {
view_transform t(map_->width(), map_->height(), map_->get_current_extent()); view_transform t(map_->width(),map_->height(),map_->get_current_extent());
box2d<double> box = t.backward(box2d<double>(start_x_, start_y_, end_x_, end_y_)); box2d<double> box = t.backward(box2d<double>(start_x_,start_y_,end_x_,end_y_));
map_->zoom_to_box(box); map_->zoom_to_box(box);
updateMap(); updateMap();
} }
} }
else if (cur_tool_ == Pan) else if (cur_tool_==Pan)
{ {
drag_ = false; drag_=false;
if (map_) if (map_)
{ {
int cx = int(0.5 * map_->width()); int cx = int(0.5 * map_->width());
int cy = int(0.5 * map_->height()); int cy = int(0.5 * map_->height());
int dx = end_x_ - start_x_; int dx = end_x_ - start_x_;
int dy = end_y_ - start_y_; int dy = end_y_ - start_y_;
map_->pan(cx - dx, cy - dy); map_->pan(cx - dx ,cy - dy);
updateMap(); updateMap();
} }
} }
} }
} }
void MapWidget::wheelEvent(QWheelEvent* e) void MapWidget::wheelEvent(QWheelEvent* e)
{ {
if (!map_) if (!map_)
{ {
return; return;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QPointF corner(map_->width(), map_->height());
QPointF zoomCoords;
double zoom;
if (e->angleDelta().y() > 0)
{
zoom = 0.5;
QPointF center = corner / 2;
QPointF delta = e->position() - center;
zoomCoords = zoom * delta + center;
}
else
{
zoom = 2.0;
zoomCoords = corner - e->position();
}
#else
QPoint corner(map_->width(), map_->height());
QPoint zoomCoords;
double zoom;
if (e->delta() > 0)
{
zoom = 0.5;
QPoint center = corner / 2;
QPoint delta = e->pos() - center;
zoomCoords = zoom * delta + center;
}
else
{
zoom = 2.0;
zoomCoords = corner - e->pos();
}
#endif
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom); QPoint corner(map_->width(), map_->height());
updateMap(); QPoint zoomCoords;
double zoom;
if (e->delta() > 0)
{
zoom = 0.5;
QPoint center = corner / 2;
QPoint delta = e->pos() - center;
zoomCoords = zoom * delta + center;
}
else
{
zoom = 2.0;
zoomCoords = corner - e->pos();
}
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
updateMap();
} }
void MapWidget::keyPressEvent(QKeyEvent* e) void MapWidget::keyPressEvent(QKeyEvent *e)
{ {
std::cout << "key pressed:" << e->key() << "\n"; std::cout << "key pressed:"<< e->key()<<"\n";
switch (e->key()) switch (e->key()) {
{ case Qt::Key_Minus:
case Qt::Key_Minus: zoomOut();
zoomOut(); break;
break; case Qt::Key_Plus:
case Qt::Key_Plus: case 61:
case 61: zoomIn();
zoomIn(); break;
break; case 65:
case 65: defaultView();
defaultView(); break;
break; case Qt::Key_Up:
case Qt::Key_Up: panUp();
panUp(); break;
break; case Qt::Key_Down:
case Qt::Key_Down: panDown();
panDown(); break;
break; case Qt::Key_Left:
case Qt::Key_Left: panLeft();
panLeft(); break;
break; case Qt::Key_Right:
case Qt::Key_Right: panRight();
panRight(); break;
break; case 49:
case 49: zoomToLevel(10);
zoomToLevel(10); break;
break; case 50:
case 50: zoomToLevel(11);
zoomToLevel(11); break;
break; case 51:
case 51: zoomToLevel(12);
zoomToLevel(12); break;
break; case 52:
case 52: zoomToLevel(13);
zoomToLevel(13); break;
break; case 53:
case 53: zoomToLevel(14);
zoomToLevel(14); break;
break; case 54:
case 54: zoomToLevel(15);
zoomToLevel(15); break;
break; case 55:
case 55: zoomToLevel(16);
zoomToLevel(16); break;
break; case 56:
case 56: zoomToLevel(17);
zoomToLevel(17); break;
break; case 57:
case 57: zoomToLevel(18);
zoomToLevel(18); break;
break; default:
default: QWidget::keyPressEvent(e);
QWidget::keyPressEvent(e); }
}
} }
void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox) void MapWidget::zoomToBox(mapnik::box2d<double> const& bbox)
{ {
if (map_) if (map_)
{ {
map_->zoom_to_box(bbox); map_->zoom_to_box(bbox);
updateMap(); updateMap();
} }
} }
void MapWidget::defaultView() void MapWidget::defaultView()
{ {
if (map_) if (map_)
{ {
map_->resize(width(), height()); map_->resize(width(),height());
map_->zoom_all(); map_->zoom_all();
updateMap(); updateMap();
} }
} }
void MapWidget::zoomIn() void MapWidget::zoomIn()
{ {
if (map_) if (map_)
{ {
map_->zoom(0.5); map_->zoom(0.5);
updateMap(); updateMap();
} }
} }
void MapWidget::zoomOut() void MapWidget::zoomOut()
{ {
if (map_) if (map_)
{ {
map_->zoom(2.0); map_->zoom(2.0);
updateMap(); updateMap();
} }
} }
void MapWidget::panUp() void MapWidget::panUp()
{ {
if (map_) if (map_)
{ {
double cx = 0.5 * map_->width(); double cx = 0.5*map_->width();
double cy = 0.5 * map_->height(); double cy = 0.5*map_->height();
map_->pan(int(cx), int(cy - cy * 0.25)); map_->pan(int(cx),int(cy - cy*0.25));
updateMap(); updateMap();
} }
} }
void MapWidget::panDown() void MapWidget::panDown()
{ {
if (map_) if (map_)
{ {
double cx = 0.5 * map_->width(); double cx = 0.5*map_->width();
double cy = 0.5 * map_->height(); double cy = 0.5*map_->height();
map_->pan(int(cx), int(cy + cy * 0.25)); map_->pan(int(cx),int(cy + cy*0.25));
updateMap(); updateMap();
} }
} }
void MapWidget::panLeft() void MapWidget::panLeft()
{ {
if (map_) if (map_)
{ {
double cx = 0.5 * map_->width(); double cx = 0.5*map_->width();
double cy = 0.5 * map_->height(); double cy = 0.5*map_->height();
map_->pan(int(cx - cx * 0.25), int(cy)); map_->pan(int(cx - cx * 0.25),int(cy));
updateMap(); updateMap();
} }
} }
void MapWidget::panRight() void MapWidget::panRight()
{ {
if (map_) if (map_)
{ {
double cx = 0.5 * map_->width(); double cx = 0.5*map_->width();
double cy = 0.5 * map_->height(); double cy = 0.5*map_->height();
map_->pan(int(cx + cx * 0.25), int(cy)); map_->pan(int(cx + cx * 0.25),int(cy));
updateMap(); updateMap();
} }
} }
void MapWidget::zoomToLevel(int level) void MapWidget::zoomToLevel(int level)
{ {
if (map_ && level >= 0 && level < 19) if ( map_ && level >= 0 && level < 19 )
{ {
double scale_denom = scales[level]; double scale_denom = scales[level];
std::cerr << "scale denominator = " << scale_denom << "\n"; std::cerr << "scale denominator = " << scale_denom << "\n";
mapnik::box2d<double> ext = map_->get_current_extent(); mapnik::box2d<double> ext = map_->get_current_extent();
double width = static_cast<double>(map_->width()); double width = static_cast<double>(map_->width());
double height = static_cast<double>(map_->height()); double height= static_cast<double>(map_->height());
mapnik::coord2d pt = ext.center(); mapnik::coord2d pt = ext.center();
double res = scale_denom * 0.00028; double res = scale_denom * 0.00028;
mapnik::box2d<double> box(pt.x - 0.5 * width * res, mapnik::box2d<double> box(pt.x - 0.5 * width * res,
pt.y - 0.5 * height * res, pt.y - 0.5 * height*res,
pt.x + 0.5 * width * res, pt.x + 0.5 * width * res,
pt.y + 0.5 * height * res); pt.y + 0.5 * height*res);
map_->zoom_to_box(box); map_->zoom_to_box(box);
updateMap(); updateMap();
} }
} }
void MapWidget::export_to_file(unsigned, unsigned, std::string const&, std::string const&) void MapWidget::export_to_file(unsigned ,unsigned ,std::string const&,std::string const&)
{ {
// image_rgba8 image(width,height); //image_rgba8 image(width,height);
// agg_renderer renderer(map,image); //agg_renderer renderer(map,image);
// renderer.apply(); //renderer.apply();
// image.saveToFile(filename,type); //image.saveToFile(filename,type);
std::cout << "Export to file .." << std::endl; std::cout << "Export to file .." << std::endl;
} }
@ -491,25 +492,25 @@ void MapWidget::set_scaling_factor(double scaling_factor)
scaling_factor_ = scaling_factor; scaling_factor_ = scaling_factor;
} }
void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap& pix) void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{ {
unsigned width = map.width(); unsigned width=map.width();
unsigned height = map.height(); unsigned height=map.height();
image_rgba8 buf(width, height); image_rgba8 buf(width,height);
mapnik::agg_renderer<image_rgba8> ren(map, buf, scaling_factor); mapnik::agg_renderer<image_rgba8> ren(map,buf,scaling_factor);
try try
{ {
mapnik::auto_cpu_timer t(std::clog, "rendering took: "); mapnik::auto_cpu_timer t(std::clog, "rendering took: ");
ren.apply(); ren.apply();
QImage image((uchar*)buf.data(), width, height, QImage::Format_ARGB32); QImage image((uchar*)buf.data(),width,height,QImage::Format_ARGB32);
pix = QPixmap::fromImage(image.rgbSwapped()); pix = QPixmap::fromImage(image.rgbSwapped());
} }
// catch (mapnik::config_error & ex) //catch (mapnik::config_error & ex)
//{ //{
// std::cerr << ex.what() << std::endl; // std::cerr << ex.what() << std::endl;
// } //}
catch (std::exception const& ex) catch (std::exception const& ex)
{ {
std::cerr << "exception: " << ex.what() << std::endl; std::cerr << "exception: " << ex.what() << std::endl;
@ -520,16 +521,18 @@ void render_agg(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
} }
} }
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
void render_grid(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{ {
std::cerr << "Not supported" << std::endl; std::cerr << "Not supported" << std::endl;
} }
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap & pix)
{ {
// FIXME // FIXME
#ifdef HAVE_CAIRO #ifdef HAVE_CAIRO
mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, map.width(), map.height()), mapnik::cairo_surface_ptr image_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,map.width(),map.height()),
mapnik::cairo_surface_closer()); mapnik::cairo_surface_closer());
mapnik::cairo_ptr cairo = mapnik::create_context(image_surface); mapnik::cairo_ptr cairo = mapnik::create_context(image_surface);
if (cairo) if (cairo)
@ -540,20 +543,17 @@ void render_cairo(mapnik::Map const& map, double scaling_factor, QPixmap& pix)
} }
mapnik::image_rgba8 data(map.width(), map.height()); mapnik::image_rgba8 data(map.width(), map.height());
mapnik::cairo_image_to_rgba8(data, image_surface); mapnik::cairo_image_to_rgba8(data, image_surface);
QImage image((uchar*)data.bytes(), data.width(), data.height(), QImage::Format_ARGB32); QImage image((uchar*)data.bytes(),data.width(),data.height(),QImage::Format_ARGB32);
pix = QPixmap::fromImage(image.rgbSwapped()); pix = QPixmap::fromImage(image.rgbSwapped());
#endif #endif
} }
void MapWidget::updateRenderer(int index) void MapWidget::updateRenderer(QString const& txt)
{ {
std::cerr << "updateRenderer:" << index << std::endl; if (txt == "AGG") cur_renderer_ = AGG;
if (index == 0) else if (txt == "Cairo") cur_renderer_ = Cairo;
cur_renderer_ = AGG; else if (txt == "Grid") cur_renderer_ = Grid;
else if (index == 1) std::cerr << "Update renderer called" << std::endl;
cur_renderer_ = Cairo;
else if (index == 2)
cur_renderer_ = Grid;
updateMap(); updateMap();
} }
@ -565,63 +565,59 @@ void MapWidget::updateScaleFactor(double scale_factor)
void MapWidget::updateMap() void MapWidget::updateMap()
{ {
if (map_) if (map_)
{ {
if (cur_renderer_ == AGG) if (cur_renderer_== AGG)
{ {
render_agg(*map_, scaling_factor_, pix_); render_agg(*map_, scaling_factor_, pix_);
} }
else if (cur_renderer_ == Cairo) else if (cur_renderer_ == Cairo)
{ {
render_cairo(*map_, scaling_factor_, pix_); render_cairo(*map_, scaling_factor_, pix_);
} }
else if (cur_renderer_ == Grid) else if (cur_renderer_ == Grid)
{ {
render_grid(*map_, scaling_factor_, pix_); render_grid(*map_, scaling_factor_, pix_);
} }
else else
{ {
std::cerr << "Unknown renderer..." << std::endl; std::cerr << "Unknown renderer..." << std::endl;
} }
try try
{ {
projection prj(map_->srs(), true); // map projection projection prj(map_->srs()); // map projection
box2d<double> ext = map_->get_current_extent(); box2d<double> ext = map_->get_current_extent();
double x0 = ext.minx(); double x0 = ext.minx();
double y0 = ext.miny(); double y0 = ext.miny();
double x1 = ext.maxx(); double x1 = ext.maxx();
double y1 = ext.maxy(); double y1 = ext.maxy();
double z = 0; prj.inverse(x0,y0);
std::string dest_srs = {"epsg:4326"}; prj.inverse(x1,y1);
mapnik::proj_transform proj_tr(map_->srs(), dest_srs); std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n";
update();
proj_tr.forward(x0, y0, z); // emit signal to interested widgets
proj_tr.forward(x1, y1, z); emit mapViewChanged();
std::cout << "MAP SIZE:" << map_->width() << "," << map_->height() << std::endl; }
std::cout << "BBOX (WGS84): " << x0 << "," << y0 << "," << x1 << "," << y1 << "\n"; catch (...)
update(); {
// emit signal to interested widgets std::cerr << "Unknown exception caught!\n";
emit mapViewChanged(); }
} }
catch (...)
{
std::cerr << "Unknown exception caught!\n";
}
}
} }
std::shared_ptr<Map> MapWidget::getMap() std::shared_ptr<Map> MapWidget::getMap()
{ {
return map_; return map_;
} }
void MapWidget::setMap(std::shared_ptr<Map> map) void MapWidget::setMap(std::shared_ptr<Map> map)
{ {
map_ = map; map_ = map;
} }
void MapWidget::layerSelected(int index) void MapWidget::layerSelected(int index)
{ {
selectedLayer_ = index; selectedLayer_ = index;
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef MAP_WIDGET_HPP #ifndef MAP_WIDGET_HPP
#define MAP_WIDGET_HPP #define MAP_WIDGET_HPP
@ -29,6 +30,7 @@
#include <string> #include <string>
#include <memory> #include <memory>
#ifndef Q_MOC_RUN #ifndef Q_MOC_RUN
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#endif #endif
@ -37,16 +39,22 @@ class MapWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
enum eTool { enum eTool
{
ZoomToBox = 1, ZoomToBox = 1,
Pan, Pan,
Info, Info,
}; };
enum eRenderer { AGG, Cairo, Grid }; enum eRenderer
{
AGG,
Cairo,
Grid
};
private: private:
std::shared_ptr<mapnik::Map> map_; std::shared_ptr<mapnik::Map> map_;
int selected_; int selected_;
QPixmap pix_; QPixmap pix_;
@ -62,12 +70,11 @@ class MapWidget : public QWidget
int selectedLayer_; int selectedLayer_;
double scaling_factor_; double scaling_factor_;
eRenderer cur_renderer_; eRenderer cur_renderer_;
public:
public: MapWidget(QWidget *parent=0);
MapWidget(QWidget* parent = 0);
void setTool(eTool tool); void setTool(eTool tool);
std::shared_ptr<mapnik::Map> getMap(); std::shared_ptr<mapnik::Map> getMap();
inline QPixmap const& pixmap() const { return pix_; } inline QPixmap const& pixmap() const { return pix_;}
void setMap(std::shared_ptr<mapnik::Map> map); void setMap(std::shared_ptr<mapnik::Map> map);
void defaultView(); void defaultView();
void zoomToBox(mapnik::box2d<double> const& box); void zoomToBox(mapnik::box2d<double> const& box);
@ -78,24 +85,26 @@ class MapWidget : public QWidget
void panUp(); void panUp();
void panDown(); void panDown();
void set_scaling_factor(double); void set_scaling_factor(double);
public slots: public slots:
void zoomToLevel(int level); void zoomToLevel(int level);
void updateMap(); void updateMap();
void layerSelected(int); void layerSelected(int);
void updateRenderer(int); void updateRenderer(QString const& txt);
void updateScaleFactor(double scale_factor); void updateScaleFactor(double scale_factor);
signals: signals:
void mapViewChanged(); void mapViewChanged();
protected:
protected:
void paintEvent(QPaintEvent* ev); void paintEvent(QPaintEvent* ev);
void resizeEvent(QResizeEvent* ev); void resizeEvent(QResizeEvent* ev);
void mousePressEvent(QMouseEvent* e); void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e); void mouseMoveEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent* e); void mouseReleaseEvent(QMouseEvent* e);
void wheelEvent(QWheelEvent* e); void wheelEvent(QWheelEvent* e);
void keyPressEvent(QKeyEvent* e); void keyPressEvent(QKeyEvent *e);
void export_to_file(unsigned width, unsigned height, std::string const& filename, std::string const& type); void export_to_file(unsigned width,
unsigned height,
std::string const& filename,
std::string const& type);
}; };
#endif // MAP_WIDGET_HPP #endif // MAP_WIDGET_HPP

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "styles_model.hpp" #include "styles_model.hpp"
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/util/variant.hpp> #include <mapnik/util/variant.hpp>
@ -38,50 +39,70 @@ class node : private mapnik::util::noncopyable
{ {
struct node_base struct node_base
{ {
virtual QString name() const = 0; virtual QString name() const=0;
virtual QIcon icon() const = 0; virtual QIcon icon() const=0;
virtual ~node_base() {} virtual ~node_base() {}
}; };
template<typename T> template <typename T>
struct wrap : public node_base struct wrap : public node_base
{ {
wrap(T const& obj) wrap(T const& obj)
: obj_(obj) : obj_(obj) {}
{}
~wrap() {} ~wrap() {}
QString name() const { return obj_.name(); } QString name () const
{
return obj_.name();
}
QIcon icon() const { return obj_.icon(); } QIcon icon() const
{
return obj_.icon();
}
T obj_; T obj_;
}; };
public: public:
template<typename T> template <typename T>
node(T const& obj, node* parent = 0) node ( T const& obj, node * parent=0)
: impl_(new wrap<T>(obj)) : impl_(new wrap<T>(obj)),
, parent_(parent) parent_(parent)
{} {}
QString name() const { return impl_->name(); } QString name() const
{
return impl_->name();
}
QIcon icon() const { return impl_->icon(); } QIcon icon() const
{
return impl_->icon();
}
unsigned num_children() const { return children_.count(); } unsigned num_children() const
{
return children_.count();
}
node* child(unsigned row) const { return children_.value(row); } node * child(unsigned row) const
{
return children_.value(row);
}
node* parent() const { return parent_; } node * parent() const
{
return parent_;
}
node* add_child(node* child) node * add_child(node * child)
{ {
children_.push_back(child); children_.push_back(child);
return child; return child;
} }
int row() const int row () const
{ {
if (parent_) if (parent_)
return parent_->children_.indexOf(const_cast<node*>(this)); return parent_->children_.indexOf(const_cast<node*>(this));
@ -89,90 +110,94 @@ class node : private mapnik::util::noncopyable
return 0; return 0;
} }
~node() { qDeleteAll(children_); } ~node()
{
qDeleteAll(children_);
}
private: private:
const std::unique_ptr<node_base> impl_; const std::unique_ptr<node_base> impl_;
QList<node*> children_; QList<node*> children_;
node* parent_; node * parent_;
}; };
struct symbolizer_info struct symbolizer_info
{ {
QString operator()(mapnik::point_symbolizer const& sym) const QString operator() (mapnik::point_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("PointSymbolizer"); return QString("PointSymbolizer");
} }
QString operator()(mapnik::line_symbolizer const& sym) const QString operator() (mapnik::line_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("LineSymbolizer"); return QString("LineSymbolizer");
} }
QString operator()(mapnik::line_pattern_symbolizer const& sym) const QString operator() (mapnik::line_pattern_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("LinePatternSymbolizer"); return QString("LinePatternSymbolizer");
} }
QString operator()(mapnik::polygon_symbolizer const& sym) const QString operator() (mapnik::polygon_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("PolygonSymbolizer"); return QString("PolygonSymbolizer");
} }
QString operator()(mapnik::polygon_pattern_symbolizer const& sym) const QString operator() (mapnik::polygon_pattern_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("PolygonSymbolizer"); return QString("PolygonSymbolizer");
} }
QString operator()(mapnik::text_symbolizer const& sym) const QString operator() (mapnik::text_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("TextSymbolizer"); return QString("TextSymbolizer");
} }
QString operator()(mapnik::shield_symbolizer const& sym) const QString operator() (mapnik::shield_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("ShieldSymbolizer"); return QString("ShieldSymbolizer");
} }
QString operator()(mapnik::markers_symbolizer const& sym) const QString operator() (mapnik::markers_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("MarkersSymbolizer"); return QString("MarkersSymbolizer");
} }
QString operator()(mapnik::building_symbolizer const& sym) const QString operator() (mapnik::building_symbolizer const& sym) const
{ {
boost::ignore_unused_variable_warning(sym); boost::ignore_unused_variable_warning(sym);
return QString("BuildingSymbolizer"); return QString("BuildingSymbolizer");
} }
template<typename T> template <typename T>
QString operator()(T const&) const QString operator() (T const& ) const
{ {
return QString("FIXME"); return QString ("FIXME");
} }
}; };
struct symbolizer_icon struct symbolizer_icon
{ {
QIcon operator()(mapnik::polygon_symbolizer const& sym) const QIcon operator() (mapnik::polygon_symbolizer const& sym) const
{ {
QPixmap pix(16, 16); QPixmap pix(16,16);
QPainter painter(&pix); QPainter painter(&pix);
mapnik::color const& fill = mapnik::get<mapnik::color>(sym, mapnik::keys::fill); mapnik::color const& fill = mapnik::get<mapnik::color>(sym, mapnik::keys::fill);
QBrush brush(QColor(fill.red(), fill.green(), fill.blue(), fill.alpha())); QBrush brush(QColor(fill.red(),fill.green(),fill.blue(),fill.alpha()));
painter.fillRect(0, 0, 16, 16, brush); painter.fillRect(0, 0, 16, 16, brush);
return QIcon(pix); return QIcon(pix);
} }
QIcon operator()(mapnik::point_symbolizer const& sym) const QIcon operator() (mapnik::point_symbolizer const& sym) const
{ {
// FIXME! // FIXME!
/* /*
@ -187,57 +212,55 @@ struct symbolizer_icon
*/ */
return QIcon(); return QIcon();
} }
QIcon operator()(mapnik::line_symbolizer const& sym) const QIcon operator() (mapnik::line_symbolizer const& sym) const
{ {
QPixmap pix(48, 16); QPixmap pix(48,16);
pix.fill(); pix.fill();
QPainter painter(&pix); QPainter painter(&pix);
// mapnik::stroke const& strk = sym.get_stroke(); //mapnik::stroke const& strk = sym.get_stroke();
mapnik::color const& col = mapnik::get<mapnik::color>(sym, mapnik::keys::stroke); mapnik::color const& col = mapnik::get<mapnik::color>(sym, mapnik::keys::stroke);
QPen pen(QColor(col.red(), col.green(), col.blue(), col.alpha())); QPen pen(QColor(col.red(),col.green(),col.blue(),col.alpha()));
pen.setWidth(mapnik::get<double>(sym, mapnik::keys::width)); pen.setWidth(mapnik::get<double>(sym, mapnik::keys::width));
painter.setPen(pen); painter.setPen(pen);
painter.drawLine(0, 7, 47, 7); painter.drawLine(0,7,47,7);
// painter.drawLine(7,15,12,0); //painter.drawLine(7,15,12,0);
// painter.drawLine(12,0,8,15); //painter.drawLine(12,0,8,15);
return QIcon(pix); return QIcon(pix);
} }
template<typename T> template <typename T>
QIcon operator()(T const&) const QIcon operator() (T const& ) const
{ {
return QIcon(":/images/filter.png"); return QIcon (":/images/filter.png");
} }
}; };
class symbolizer_node class symbolizer_node
{ {
public: public:
symbolizer_node(mapnik::symbolizer const& sym) symbolizer_node(mapnik::symbolizer const & sym)
: sym_(sym) : sym_(sym) {}
{} ~symbolizer_node(){}
~symbolizer_node() {}
QString name() const QString name() const
{ {
// return QString("Symbolizer:fixme"); //return QString("Symbolizer:fixme");
return mapnik::util::apply_visitor(symbolizer_info(), sym_); return mapnik::util::apply_visitor(symbolizer_info(),sym_);
} }
QIcon icon() const QIcon icon() const
{ {
return mapnik::util::apply_visitor(symbolizer_icon(), sym_); // QIcon(":/images/filter.png"); return mapnik::util::apply_visitor(symbolizer_icon(),sym_);//QIcon(":/images/filter.png");
} }
mapnik::symbolizer const& sym_; mapnik::symbolizer const& sym_;
}; };
class rule_node class rule_node
{ {
public: public:
rule_node(QString name, mapnik::rule const& r) rule_node(QString name,mapnik::rule const & r)
: name_(name) : name_(name),
, rule_(r) rule_(r) {}
{}
~rule_node() {} ~rule_node() {}
QString name() const QString name() const
{ {
@ -245,68 +268,81 @@ class rule_node
return QString(mapnik::to_expression_string(*filter).c_str()); return QString(mapnik::to_expression_string(*filter).c_str());
} }
QIcon icon() const { return QIcon(":/images/filter.png"); } QIcon icon() const
{
return QIcon(":/images/filter.png");
}
private: private:
QString name_; QString name_;
mapnik::rule const& rule_; mapnik::rule const& rule_;
}; };
class style_node class style_node
{ {
public: public:
style_node(QString name, mapnik::feature_type_style const& style) style_node(QString name, mapnik::feature_type_style const& style)
: name_(name) : name_(name),
, style_(style) style_(style) {}
{}
~style_node() {} ~style_node() {}
QString name() const { return name_; } QString name() const
{
return name_;
}
QIcon icon() const { return QIcon(":/images/style.png"); } QIcon icon() const
{
return QIcon(":/images/style.png");
}
private: private:
QString name_; QString name_;
mapnik::feature_type_style const& style_; mapnik::feature_type_style const& style_;
}; };
class map_node class map_node
{ {
public: public:
explicit map_node(std::shared_ptr<mapnik::Map> map) explicit map_node(std::shared_ptr<mapnik::Map> map)
: map_(map) : map_(map) {}
{}
~map_node() {} ~map_node() {}
QString name() const { return QString("Map"); } QString name() const
{
return QString("Map");
}
QIcon icon() const { return QIcon(":/images/map.png"); } QIcon icon() const
{
return QIcon(":/images/map.png");
}
private: private:
std::shared_ptr<mapnik::Map> map_; std::shared_ptr<mapnik::Map> map_;
}; };
StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent) StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent),
, root_(new node(map_node(map))) root_(new node(map_node(map)))
{ {
using style_type = std::map<std::string, mapnik::feature_type_style>; using style_type = std::map<std::string,mapnik::feature_type_style>;
style_type const& styles = map->styles(); style_type const & styles = map->styles();
style_type::const_iterator itr = styles.begin(); style_type::const_iterator itr = styles.begin();
style_type::const_iterator end = styles.end(); style_type::const_iterator end = styles.end();
for (; itr != end; ++itr) for (; itr != end; ++itr)
{ {
node* style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()), itr->second), root_.get())); node * style_n = root_->add_child(new node(style_node(QString(itr->first.c_str()),itr->second),root_.get()));
mapnik::rules const& rules = itr->second.get_rules(); mapnik::rules const& rules = itr->second.get_rules();
mapnik::rules::const_iterator itr2 = rules.begin(); mapnik::rules::const_iterator itr2 = rules.begin();
for (; itr2 != rules.end(); ++itr2) for ( ; itr2 != rules.end();++itr2)
{ {
node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"), *itr2), style_n)); node* rule_n = style_n->add_child(new node(rule_node(QString("Rule"),*itr2),style_n));
mapnik::rule::symbolizers::const_iterator itr3 = (*itr2).begin(); mapnik::rule::symbolizers::const_iterator itr3 = (*itr2).begin();
for (; itr3 != itr2->end(); ++itr3) for ( ; itr3 !=itr2->end();++itr3)
{ {
rule_n->add_child(new node(symbolizer_node(*itr3), rule_n)); rule_n->add_child(new node(symbolizer_node(*itr3),rule_n));
} }
} }
} }
@ -315,39 +351,38 @@ StyleModel::StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent)
StyleModel::~StyleModel() {} StyleModel::~StyleModel() {}
// interface // interface
QModelIndex StyleModel::index(int row, int col, QModelIndex const& parent) const QModelIndex StyleModel::index (int row, int col, QModelIndex const& parent) const
{ {
// qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId()); // qDebug("index() row=%d col=%d parent::internalId() = %lld", row,col,parent.internalId());
node* parent_node; node * parent_node;
if (!parent.isValid()) if (!parent.isValid())
parent_node = root_.get(); parent_node = root_.get();
else else
parent_node = static_cast<node*>(parent.internalPointer()); parent_node = static_cast<node*>(parent.internalPointer());
node* child_node = parent_node->child(row); node * child_node = parent_node->child(row);
if (child_node) if (child_node)
return createIndex(row, col, child_node); return createIndex(row,col,child_node);
else else
return QModelIndex(); return QModelIndex();
} }
QModelIndex StyleModel::parent(QModelIndex const& index) const QModelIndex StyleModel::parent (QModelIndex const& index) const
{ {
node* child_node = static_cast<node*>(index.internalPointer()); node * child_node = static_cast<node*>(index.internalPointer());
node* parent_node = child_node->parent(); node * parent_node = child_node->parent();
if (parent_node == root_.get()) if (parent_node == root_.get())
return QModelIndex(); return QModelIndex();
return createIndex(parent_node->row(), 0, parent_node); return createIndex(parent_node->row(),0,parent_node);
} }
int StyleModel::rowCount(QModelIndex const& parent) const int StyleModel::rowCount(QModelIndex const& parent) const
{ {
// qDebug("rowCount"); //qDebug("rowCount");
node* parent_node; node * parent_node;
if (parent.column() > 0) if (parent.column() > 0) return 0;
return 0;
if (!parent.isValid()) if (!parent.isValid())
parent_node = root_.get(); parent_node = root_.get();
else else
@ -355,24 +390,25 @@ int StyleModel::rowCount(QModelIndex const& parent) const
return parent_node->num_children(); return parent_node->num_children();
} }
int StyleModel::columnCount(QModelIndex const&) const int StyleModel::columnCount( QModelIndex const&) const
{ {
return 1; return 1;
} }
QVariant StyleModel::data(const QModelIndex& index, int role) const QVariant StyleModel::data(const QModelIndex & index, int role) const
{ {
// qDebug("data index::internalId() = %lld", index.internalId()); //qDebug("data index::internalId() = %lld", index.internalId());
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
node* cur_node = static_cast<node*>(index.internalPointer()); node * cur_node = static_cast<node*>(index.internalPointer());
if (cur_node) if (cur_node)
{ {
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
{ {
return QVariant(cur_node->name()); return QVariant(cur_node->name());
} }
else if (role == Qt::DecorationRole) else if ( role == Qt::DecorationRole)
{ {
return cur_node->icon(); return cur_node->icon();
} }

View file

@ -1,6 +1,6 @@
/* This file is part of Mapnik (c++ mapping toolkit) /* This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2024 Artem Pavlenko * Copyright (C) 2017 Artem Pavlenko
* *
* Mapnik is free software; you can redistribute it and/or * Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#ifndef STYLE_MODEL_HPP #ifndef STYLE_MODEL_HPP
#define STYLE_MODEL_HPP #define STYLE_MODEL_HPP
@ -26,23 +27,24 @@
#include <mapnik/map.hpp> #include <mapnik/map.hpp>
#endif #endif
class node; class node;
class StyleModel : public QAbstractItemModel class StyleModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
StyleModel(std::shared_ptr<mapnik::Map> map, QObject* parent = 0); StyleModel(std::shared_ptr<mapnik::Map> map, QObject * parent=0);
~StyleModel(); ~StyleModel();
// interface // interface
QModelIndex index(int row, int col, QModelIndex const& parent = QModelIndex()) const; QModelIndex index (int row, int col, QModelIndex const& parent = QModelIndex()) const;
QModelIndex parent(QModelIndex const& child) const; QModelIndex parent (QModelIndex const& child) const;
int rowCount(QModelIndex const& parent = QModelIndex()) const; int rowCount( QModelIndex const& parent = QModelIndex()) const;
int columnCount(QModelIndex const& parent = QModelIndex()) const; int columnCount( QModelIndex const& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
private:
private: //std::shared_ptr<mapnik::Map> map_;
// std::shared_ptr<mapnik::Map> map_; const std::unique_ptr<node> root_;
const std::unique_ptr<node> root_;
}; };
#endif // STYLE_MODEL_HPP #endif // STYLE_MODEL_HPP

1
deps/CMakeLists.txt vendored
View file

@ -1 +0,0 @@
add_subdirectory(agg)

View file

@ -1 +0,0 @@
DisableFormat: true

View file

@ -1,19 +0,0 @@
project(agg)
add_library(agg INTERFACE)
add_library(mapnik::agg ALIAS agg)
target_include_directories(agg INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(agg INTERFACE mapnik::core)
install(TARGETS agg
EXPORT MapnikTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include
)
# agg headers would be installed in the top level CMakeLists.txt

View file

@ -365,7 +365,7 @@ namespace agg
inline bool is_close(unsigned c) inline bool is_close(unsigned c)
{ {
return (c & ~(path_flags_cw | path_flags_ccw)) == return (c & ~(path_flags_cw | path_flags_ccw)) ==
(path_cmd_end_poly | static_cast<path_commands_e>(path_flags_close)); (path_cmd_end_poly | path_flags_close);
} }
//------------------------------------------------------------is_next_poly //------------------------------------------------------------is_next_poly

View file

@ -436,8 +436,7 @@ struct gray16
static value_type luminance(const rgba& c) static value_type luminance(const rgba& c)
{ {
// Calculate grayscale value as per ITU-R BT.709. // Calculate grayscale value as per ITU-R BT.709.
return value_type(uround((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) return value_type(uround((0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b) * base_mask));
* static_cast<double>(base_mask)));
} }
static value_type luminance(const rgba16& c) static value_type luminance(const rgba16& c)
@ -538,13 +537,13 @@ struct gray16
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a) static AGG_INLINE double to_double(value_type a)
{ {
return static_cast<double>(a) / static_cast<double>(base_mask); return double(a) / base_mask;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a) static AGG_INLINE value_type from_double(double a)
{ {
return value_type(uround(a * static_cast<double>(base_mask))); return value_type(uround(a * base_mask));
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -699,7 +698,7 @@ struct gray16
self_type gradient(self_type c, double k) const self_type gradient(self_type c, double k) const
{ {
self_type ret; self_type ret;
calc_type ik = uround(k * static_cast<double>(base_scale)); calc_type ik = uround(k * base_scale);
ret.v = lerp(v, c.v, ik); ret.v = lerp(v, c.v, ik);
ret.a = lerp(a, c.a, ik); ret.a = lerp(a, c.a, ik);
return ret; return ret;
@ -950,7 +949,7 @@ struct gray32
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE value_type mult_cover(value_type a, cover_type b) static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{ {
return value_type(a * b / static_cast<double>(cover_mask)); return value_type(a * b / cover_mask);
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------

View file

@ -281,10 +281,10 @@ struct rgba8T
static void convert(rgba8T<linear>& dst, const rgba& src) static void convert(rgba8T<linear>& dst, const rgba& src)
{ {
dst.r = value_type(uround(src.r * static_cast<double>(base_mask))); dst.r = value_type(uround(src.r * base_mask));
dst.g = value_type(uround(src.g * static_cast<double>(base_mask))); dst.g = value_type(uround(src.g * base_mask));
dst.b = value_type(uround(src.b * static_cast<double>(base_mask))); dst.b = value_type(uround(src.b * base_mask));
dst.a = value_type(uround(src.a * static_cast<double>(base_mask))); dst.a = value_type(uround(src.a * base_mask));
} }
static void convert(rgba8T<sRGB>& dst, const rgba& src) static void convert(rgba8T<sRGB>& dst, const rgba& src)
@ -761,13 +761,13 @@ struct rgba16
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE double to_double(value_type a) static AGG_INLINE double to_double(value_type a)
{ {
return static_cast<double>(a) / static_cast<double>(base_mask); return double(a) / base_mask;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE value_type from_double(double a) static AGG_INLINE value_type from_double(double a)
{ {
return value_type(uround(a * static_cast<double>(base_mask))); return value_type(uround(a * base_mask));
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -955,7 +955,7 @@ struct rgba16
AGG_INLINE self_type gradient(const self_type& c, double k) const AGG_INLINE self_type gradient(const self_type& c, double k) const
{ {
self_type ret; self_type ret;
calc_type ik = uround(k * static_cast<double>(base_mask)); calc_type ik = uround(k * base_mask);
ret.r = lerp(r, c.r, ik); ret.r = lerp(r, c.r, ik);
ret.g = lerp(g, c.g, ik); ret.g = lerp(g, c.g, ik);
ret.b = lerp(b, c.b, ik); ret.b = lerp(b, c.b, ik);
@ -1194,7 +1194,7 @@ struct rgba32
//-------------------------------------------------------------------- //--------------------------------------------------------------------
static AGG_INLINE value_type mult_cover(value_type a, cover_type b) static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
{ {
return value_type(a * b / static_cast<float>(cover_mask)); return value_type(a * b / cover_mask);
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------

View file

@ -103,8 +103,7 @@ namespace agg
if(m_vpgen.auto_close() && m_vertices > 2) if(m_vpgen.auto_close() && m_vertices > 2)
{ {
m_vpgen.line_to(m_start_x, m_start_y); m_vpgen.line_to(m_start_x, m_start_y);
m_poly_flags = path_cmd_end_poly m_poly_flags = path_cmd_end_poly | path_flags_close;
| static_cast<path_commands_e>(path_flags_close);
m_start_x = tx; m_start_x = tx;
m_start_y = ty; m_start_y = ty;
m_vertices = -1; m_vertices = -1;
@ -142,8 +141,7 @@ namespace agg
if(m_vpgen.auto_close() && m_vertices > 2) if(m_vpgen.auto_close() && m_vertices > 2)
{ {
m_vpgen.line_to(m_start_x, m_start_y); m_vpgen.line_to(m_start_x, m_start_y);
m_poly_flags = path_cmd_end_poly m_poly_flags = path_cmd_end_poly | path_flags_close;
| static_cast<path_commands_e>(path_flags_close);
m_vertices = -2; m_vertices = -2;
continue; continue;
} }
@ -159,3 +157,4 @@ namespace agg
#endif #endif

View file

@ -22,7 +22,6 @@
#include "agg_array.h" #include "agg_array.h"
#include "agg_math.h" #include "agg_math.h"
#include <cstdint>
namespace agg namespace agg
{ {
@ -60,8 +59,7 @@ namespace agg
double x = double(i) / double(image_subpixel_scale); double x = double(i) / double(image_subpixel_scale);
double y = filter.calc_weight(x); double y = filter.calc_weight(x);
m_weight_array[pivot + i] = m_weight_array[pivot + i] =
m_weight_array[pivot - i] = m_weight_array[pivot - i] = (int16)iround(y * image_filter_scale);
static_cast<std::int16_t>(iround(y * static_cast<double>(image_filter_scale)));
} }
unsigned end = (diameter() << image_subpixel_shift) - 1; unsigned end = (diameter() << image_subpixel_shift) - 1;
m_weight_array[0] = m_weight_array[end]; m_weight_array[0] = m_weight_array[end];
@ -82,7 +80,7 @@ namespace agg
double radius() const { return m_radius; } double radius() const { return m_radius; }
unsigned diameter() const { return m_diameter; } unsigned diameter() const { return m_diameter; }
int start() const { return m_start; } int start() const { return m_start; }
std::int16_t const* weight_array() const { return &m_weight_array[0]; } const int16* weight_array() const { return &m_weight_array[0]; }
void normalize(); void normalize();
private: private:
@ -93,7 +91,7 @@ namespace agg
double m_radius; double m_radius;
unsigned m_diameter; unsigned m_diameter;
int m_start; int m_start;
pod_array<std::int16_t> m_weight_array; pod_array<int16> m_weight_array;
}; };

View file

@ -44,13 +44,13 @@ namespace agg
//------------------------------------------------------------------line_mr //------------------------------------------------------------------line_mr
AGG_INLINE int line_mr(int x) AGG_INLINE int line_mr(int x)
{ {
return x >> (line_subpixel_shift - static_cast<line_subpixel_scale_e>(line_mr_subpixel_shift)); return x >> (line_subpixel_shift - line_mr_subpixel_shift);
} }
//-------------------------------------------------------------------line_hr //-------------------------------------------------------------------line_hr
AGG_INLINE int line_hr(int x) AGG_INLINE int line_hr(int x)
{ {
return x << (line_subpixel_shift - static_cast<line_subpixel_scale_e>(line_mr_subpixel_shift)); return x << (line_subpixel_shift - line_mr_subpixel_shift);
} }
//---------------------------------------------------------------line_dbl_hr //---------------------------------------------------------------line_dbl_hr
@ -64,7 +64,7 @@ namespace agg
{ {
AGG_INLINE static int conv(double x) AGG_INLINE static int conv(double x)
{ {
return iround(x * static_cast<double>(line_subpixel_scale)); return iround(x * line_subpixel_scale);
} }
}; };
@ -73,7 +73,7 @@ namespace agg
{ {
AGG_INLINE static int conv(double x) AGG_INLINE static int conv(double x)
{ {
return saturation<line_max_coord>::iround(x * static_cast<double>(line_subpixel_scale)); return saturation<line_max_coord>::iround(x * line_subpixel_scale);
} }
}; };

View file

@ -398,8 +398,7 @@ namespace agg
if(m_closed && !m_stop) if(m_closed && !m_stop)
{ {
m_stop = true; m_stop = true;
return path_cmd_end_poly return path_cmd_end_poly | path_flags_close;
| static_cast<agg::path_commands_e>(path_flags_close);
} }
return path_cmd_stop; return path_cmd_stop;
} }
@ -464,8 +463,7 @@ namespace agg
if(m_closed && !m_stop) if(m_closed && !m_stop)
{ {
m_stop = true; m_stop = true;
return path_cmd_end_poly return path_cmd_end_poly | path_flags_close;
| static_cast<agg::path_commands_e>(path_flags_close);
} }
return path_cmd_stop; return path_cmd_stop;
} }
@ -527,8 +525,7 @@ namespace agg
if(m_closed && !m_stop) if(m_closed && !m_stop)
{ {
m_stop = true; m_stop = true;
return path_cmd_end_poly return path_cmd_end_poly | path_flags_close;
| static_cast<agg::path_commands_e>(path_flags_close);
} }
return path_cmd_stop; return path_cmd_stop;
} }
@ -981,11 +978,10 @@ namespace agg
{ {
join_path(a); join_path(a);
} }
// We are adding an explicit line_to, even if we've already add the else
// bezier arc to the current path. This is to prevent subsequent smooth {
// bezier curves from accidentally assuming that the previous command line_to(x, y);
// was a bezier curve as well when calculating reflection points. }
line_to(x, y);
} }
else else
{ {

View file

@ -54,7 +54,7 @@ namespace agg
if (cover < cover_full) if (cover < cover_full)
{ {
double x = static_cast<double>(cover) / static_cast<double>(cover_full); double x = double(cover) / cover_full;
c.r *= x; c.r *= x;
c.g *= x; c.g *= x;
c.b *= x; c.b *= x;

View file

@ -24,7 +24,6 @@
#ifndef AGG_PIXFMT_RGBA_INCLUDED #ifndef AGG_PIXFMT_RGBA_INCLUDED
#define AGG_PIXFMT_RGBA_INCLUDED #define AGG_PIXFMT_RGBA_INCLUDED
#include <mapnik/config.hpp>
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
#include "agg_basics.h" #include "agg_basics.h"
@ -3167,10 +3166,6 @@ private:
extern template struct MAPNIK_DECL comp_op_rgba_hue<agg::rgba8, agg::order_rgba>;
extern template struct MAPNIK_DECL comp_op_rgba_saturation<agg::rgba8, agg::order_rgba>;
extern template struct MAPNIK_DECL comp_op_rgba_color<agg::rgba8, agg::order_rgba>;
extern template struct MAPNIK_DECL comp_op_rgba_value<agg::rgba8, agg::order_rgba>;
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
typedef blender_rgba<rgba8, order_rgba> blender_rgba32; //----blender_rgba32 typedef blender_rgba<rgba8, order_rgba> blender_rgba32; //----blender_rgba32

View file

@ -35,7 +35,7 @@ namespace agg
} }
static int xi(int v) { return v; } static int xi(int v) { return v; }
static int yi(int v) { return v; } static int yi(int v) { return v; }
static int upscale(double v) { return iround(v * static_cast<double>(poly_subpixel_scale)); } static int upscale(double v) { return iround(v * poly_subpixel_scale); }
static int downscale(int v) { return v; } static int downscale(int v) { return v; }
}; };
@ -51,7 +51,7 @@ namespace agg
static int yi(int v) { return v; } static int yi(int v) { return v; }
static int upscale(double v) static int upscale(double v)
{ {
return saturation<poly_max_coord>::iround(v * static_cast<double>(poly_subpixel_scale)); return saturation<poly_max_coord>::iround(v * poly_subpixel_scale);
} }
static int downscale(int v) { return v; } static int downscale(int v) { return v; }
}; };
@ -66,7 +66,7 @@ namespace agg
} }
static int xi(int v) { return v * 3; } static int xi(int v) { return v * 3; }
static int yi(int v) { return v; } static int yi(int v) { return v; }
static int upscale(double v) { return iround(v * static_cast<double>(poly_subpixel_scale)); } static int upscale(double v) { return iround(v * poly_subpixel_scale); }
static int downscale(int v) { return v; } static int downscale(int v) { return v; }
}; };
@ -78,10 +78,10 @@ namespace agg
{ {
return a * b / c; return a * b / c;
} }
static int xi(double v) { return iround(v * static_cast<double>(poly_subpixel_scale)); } static int xi(double v) { return iround(v * poly_subpixel_scale); }
static int yi(double v) { return iround(v * static_cast<double>(poly_subpixel_scale)); } static int yi(double v) { return iround(v * poly_subpixel_scale); }
static double upscale(double v) { return v; } static double upscale(double v) { return v; }
static double downscale(int v) { return v / static_cast<double>(poly_subpixel_scale); } static double downscale(int v) { return v / double(poly_subpixel_scale); }
}; };
//--------------------------------------------------------ras_conv_dbl_3x //--------------------------------------------------------ras_conv_dbl_3x
@ -92,10 +92,10 @@ namespace agg
{ {
return a * b / c; return a * b / c;
} }
static int xi(double v) { return iround(v * static_cast<double>(poly_subpixel_scale) * 3); } static int xi(double v) { return iround(v * poly_subpixel_scale * 3); }
static int yi(double v) { return iround(v * static_cast<double>(poly_subpixel_scale)); } static int yi(double v) { return iround(v * poly_subpixel_scale); }
static double upscale(double v) { return v; } static double upscale(double v) { return v; }
static double downscale(int v) { return v / static_cast<double>(poly_subpixel_scale); } static double downscale(int v) { return v / double(poly_subpixel_scale); }
}; };

View file

@ -1305,7 +1305,7 @@ namespace agg
for(i = 0; i < aa_scale; i++) for(i = 0; i < aa_scale; i++)
{ {
m_gamma[i] = value_type( m_gamma[i] = value_type(
uround(gamma_function(static_cast<double>(i) / static_cast<double>(aa_mask)) * aa_mask)); uround(gamma_function(double(i) / aa_mask) * aa_mask));
} }
} }

View file

@ -66,9 +66,7 @@ void arrowhead::rewind(unsigned path_id)
m_cmd[3] = path_cmd_line_to; m_cmd[3] = path_cmd_line_to;
m_cmd[4] = path_cmd_line_to; m_cmd[4] = path_cmd_line_to;
m_cmd[5] = path_cmd_line_to; m_cmd[5] = path_cmd_line_to;
m_cmd[7] = path_cmd_end_poly m_cmd[7] = path_cmd_end_poly | path_flags_close | path_flags_ccw;
| static_cast<path_commands_e>(path_flags_close)
| static_cast<path_commands_e>(path_flags_ccw);
m_cmd[6] = path_cmd_stop; m_cmd[6] = path_cmd_stop;
return; return;
} }
@ -89,9 +87,7 @@ void arrowhead::rewind(unsigned path_id)
m_cmd[1] = path_cmd_line_to; m_cmd[1] = path_cmd_line_to;
m_cmd[2] = path_cmd_line_to; m_cmd[2] = path_cmd_line_to;
m_cmd[3] = path_cmd_line_to; m_cmd[3] = path_cmd_line_to;
m_cmd[4] = path_cmd_end_poly m_cmd[4] = path_cmd_end_poly | path_flags_close | path_flags_ccw;
| static_cast<path_commands_e>(path_flags_close)
| static_cast<path_commands_e>(path_flags_ccw);
m_cmd[5] = path_cmd_stop; m_cmd[5] = path_cmd_stop;
return; return;
} }

Some files were not shown because too many files have changed in this diff Show more