Merge branch 'master' into svg-group-render
This commit is contained in:
commit
45f954c578
12 changed files with 229 additions and 7 deletions
18
configure
vendored
18
configure
vendored
|
@ -1,18 +1,32 @@
|
|||
#! /bin/sh
|
||||
#! /usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
: ${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
|
||||
# environment variables that should be used before
|
||||
# running tests like PROJ_LIB, GDAL_DATA, and ICU_DATA
|
||||
# These do not normally need to be set except when
|
||||
# building against binary versions of dependencies like
|
||||
# done via bootstrap.sh
|
||||
VARS=()
|
||||
if [ -f mapnik-settings.env ]; then
|
||||
echo "Inheriting from mapnik-settings.env"
|
||||
. ./mapnik-settings.env
|
||||
VARS=( $(cat mapnik-settings.env) )
|
||||
fi
|
||||
|
||||
$PYTHON scons/scons.py --implicit-deps-changed configure "$@"
|
||||
$PYTHON scons/scons.py --implicit-deps-changed configure ${VARS[*]} "$@"
|
||||
|
|
|
@ -4,6 +4,7 @@ add_plugin_target(input-ogr "ogr")
|
|||
target_sources(input-ogr ${_plugin_visibility}
|
||||
ogr_converter.cpp
|
||||
ogr_datasource.cpp
|
||||
ogr_utils.cpp
|
||||
ogr_featureset.cpp
|
||||
ogr_index_featureset.cpp
|
||||
)
|
||||
|
|
|
@ -31,6 +31,7 @@ plugin_sources = Split(
|
|||
"""
|
||||
%(PLUGIN_NAME)s_converter.cpp
|
||||
%(PLUGIN_NAME)s_datasource.cpp
|
||||
%(PLUGIN_NAME)s_utils.cpp
|
||||
%(PLUGIN_NAME)s_featureset.cpp
|
||||
%(PLUGIN_NAME)s_index_featureset.cpp
|
||||
""" % locals()
|
||||
|
|
|
@ -127,16 +127,24 @@ void ogr_datasource::init(mapnik::parameters const& params)
|
|||
}
|
||||
|
||||
std::string driver = *params.get<std::string>("driver", "");
|
||||
std::vector<ogr_utils::option_ptr> open_options_map =
|
||||
ogr_utils::split_open_options(*params.get<std::string>("open_options", ""));
|
||||
char** open_options = ogr_utils::open_options_for_ogr(open_options_map);
|
||||
|
||||
if (!driver.empty())
|
||||
{
|
||||
unsigned int nOpenFlags = GDAL_OF_READONLY | GDAL_OF_VECTOR;
|
||||
const char* papszAllowedDrivers[] = {driver.c_str(), nullptr};
|
||||
|
||||
dataset_ = reinterpret_cast<gdal_dataset_type>(
|
||||
GDALOpenEx(dataset_name_.c_str(), nOpenFlags, papszAllowedDrivers, nullptr, nullptr));
|
||||
GDALOpenEx(dataset_name_.c_str(), nOpenFlags, papszAllowedDrivers, open_options, nullptr));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (open_options[0] != nullptr)
|
||||
{
|
||||
throw datasource_exception("<open_options> parameter provided but <driver> is missing");
|
||||
}
|
||||
// open ogr driver
|
||||
dataset_ = reinterpret_cast<gdal_dataset_type>(OGROpen(dataset_name_.c_str(), false, nullptr));
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ MAPNIK_DISABLE_WARNING_PUSH
|
|||
#include <ogrsf_frmts.h>
|
||||
MAPNIK_DISABLE_WARNING_POP
|
||||
#include "ogr_layer_ptr.hpp"
|
||||
#include "ogr_utils.hpp"
|
||||
|
||||
DATASOURCE_PLUGIN_DEF(ogr_datasource_plugin, ogr);
|
||||
|
||||
|
|
85
plugins/input/ogr/ogr_utils.cpp
Normal file
85
plugins/input/ogr/ogr_utils.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2023 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "ogr_utils.hpp"
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
std::vector<ogr_utils::option_ptr> ogr_utils::split_open_options(const std::string& options)
|
||||
{
|
||||
size_t i;
|
||||
bool escaped = false; // if previous character was a backslash to escape a backslash or space
|
||||
std::vector<ogr_utils::option_ptr> opts;
|
||||
std::string unescaped_str; // copy of input string but unescaped
|
||||
for (i = 0; i < options.size(); ++i)
|
||||
{
|
||||
char current = options.at(i);
|
||||
if (current == '\\')
|
||||
{
|
||||
if (escaped)
|
||||
{
|
||||
unescaped_str.push_back(current);
|
||||
}
|
||||
escaped = !escaped;
|
||||
}
|
||||
else if (current != ' ')
|
||||
{
|
||||
unescaped_str.push_back(current);
|
||||
}
|
||||
if (current == ' ' || i + 1 == options.size())
|
||||
{
|
||||
if (!escaped)
|
||||
{
|
||||
size_t count = unescaped_str.size();
|
||||
if (count > 0)
|
||||
{
|
||||
option_ptr opt(new char[count + 1], [](char* arr) { delete[] arr; });
|
||||
unescaped_str.copy(opt.get(), count);
|
||||
opt[count] = '\0';
|
||||
opts.push_back(std::move(opt));
|
||||
}
|
||||
unescaped_str = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
escaped = false;
|
||||
unescaped_str.push_back(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (escaped)
|
||||
{
|
||||
throw mapnik::datasource_exception("<open_options> parameter ends with single backslash");
|
||||
}
|
||||
opts.emplace_back(nullptr);
|
||||
return opts;
|
||||
}
|
||||
|
||||
char** ogr_utils::open_options_for_ogr(std::vector<ogr_utils::option_ptr>& options)
|
||||
{
|
||||
char** for_ogr = new char*[options.size() + 1];
|
||||
for (size_t i = 0; i < options.size(); ++i)
|
||||
{
|
||||
for_ogr[i] = options.at(i).get();
|
||||
}
|
||||
for_ogr[options.size()] = nullptr;
|
||||
return for_ogr;
|
||||
}
|
41
plugins/input/ogr/ogr_utils.hpp
Normal file
41
plugins/input/ogr/ogr_utils.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2023 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef PLUGINS_INPUT_OGR_OGR_UTILS_HPP_
|
||||
#define PLUGINS_INPUT_OGR_OGR_UTILS_HPP_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ogr_utils {
|
||||
|
||||
using option_ptr = std::unique_ptr<char[], std::function<void(char*)>>;
|
||||
|
||||
std::vector<option_ptr> split_open_options(const std::string& options);
|
||||
|
||||
char** open_options_for_ogr(std::vector<ogr_utils::option_ptr>& options);
|
||||
|
||||
} // namespace ogr_utils
|
||||
|
||||
#endif /* PLUGINS_INPUT_OGR_OGR_UTILS_HPP_ */
|
|
@ -70,8 +70,8 @@ gradient& gradient::operator=(gradient rhs)
|
|||
bool gradient::operator==(gradient const& other) const
|
||||
{
|
||||
return transform_ == other.transform_ && x1_ == other.x1_ && y1_ == other.y1_ && x2_ == other.x2_ &&
|
||||
y2_ == other.y2_ && r_ == other.r_ && std::equal(stops_.begin(), stops_.end(), other.stops_.begin()),
|
||||
units_ == other.units_ && gradient_type_ == other.gradient_type_;
|
||||
y2_ == other.y2_ && r_ == other.r_ && std::equal(stops_.begin(), stops_.end(), other.stops_.begin()) &&
|
||||
units_ == other.units_ && gradient_type_ == other.gradient_type_;
|
||||
}
|
||||
|
||||
void gradient::set_gradient_type(gradient_e grad)
|
||||
|
|
|
@ -88,7 +88,7 @@ class libxml2_loader : util::noncopyable
|
|||
|
||||
if (!doc)
|
||||
{
|
||||
xmlError* error = xmlCtxtGetLastError(ctx_);
|
||||
const xmlError* error = xmlCtxtGetLastError(ctx_);
|
||||
if (error)
|
||||
{
|
||||
std::string msg("XML document not well formed:\n");
|
||||
|
@ -128,7 +128,7 @@ class libxml2_loader : util::noncopyable
|
|||
if (!doc)
|
||||
{
|
||||
std::string msg("XML document not well formed");
|
||||
xmlError* error = xmlCtxtGetLastError(ctx_);
|
||||
const xmlError* error = xmlCtxtGetLastError(ctx_);
|
||||
if (error)
|
||||
{
|
||||
msg += ":\n";
|
||||
|
|
|
@ -34,6 +34,7 @@ add_executable(mapnik-test-unit
|
|||
unit/datasource/geobuf.cpp
|
||||
unit/datasource/geojson.cpp
|
||||
unit/datasource/memory.cpp
|
||||
../plugins/input/ogr/ogr_utils.cpp
|
||||
unit/datasource/ogr.cpp
|
||||
unit/datasource/postgis.cpp
|
||||
unit/datasource/shapeindex.cpp
|
||||
|
|
|
@ -35,6 +35,7 @@ else:
|
|||
# unit tests
|
||||
sources = glob.glob('./unit/*/*.cpp')
|
||||
sources.extend(glob.glob('./unit/*.cpp'))
|
||||
sources.append('../plugins/input/ogr/ogr_utils.cpp')
|
||||
test_program = test_env_local.Program("./unit/run", source=sources)
|
||||
Depends(test_program, env.subst('../src/%s' % env['MAPNIK_LIB_NAME']))
|
||||
Depends(test_program, env.subst('../src/json/libmapnik-json${LIBSUFFIX}'))
|
||||
|
|
|
@ -29,6 +29,19 @@
|
|||
#include <mapnik/image_reader.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/datasource_cache.hpp>
|
||||
#include "../../../plugins/input/ogr/ogr_utils.hpp"
|
||||
|
||||
inline std::vector<ogr_utils::option_ptr> split_options(std::string const& options)
|
||||
{
|
||||
return ogr_utils::split_open_options(options);
|
||||
}
|
||||
|
||||
void assert_option(std::vector<ogr_utils::option_ptr> const& options, size_t const& index, std::string const expected)
|
||||
{
|
||||
auto const* opt = options.at(index).get();
|
||||
REQUIRE(opt != nullptr);
|
||||
REQUIRE_FALSE(strcmp(opt, expected.c_str()));
|
||||
}
|
||||
|
||||
TEST_CASE("ogr")
|
||||
{
|
||||
|
@ -57,3 +70,59 @@ TEST_CASE("ogr")
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ogr open_options")
|
||||
{
|
||||
const bool have_ogr_plugin = mapnik::datasource_cache::instance().plugin_registered("ogr");
|
||||
if (have_ogr_plugin)
|
||||
{
|
||||
SECTION("splitting open_options string")
|
||||
{
|
||||
std::string opts = "ZOOM=5";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, opts);
|
||||
}
|
||||
SECTION("splitting open_options string with multiple components")
|
||||
{
|
||||
std::string opts = "ZOOM=8 USE_BOUNDS=YES";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "ZOOM=8");
|
||||
assert_option(v, 1, "USE_BOUNDS=YES");
|
||||
}
|
||||
SECTION("open_options string with escaped character")
|
||||
{
|
||||
std::string opts = "MY_KEY=THIS\\ VALUE OTHER_KEY=SOMETHING";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "MY_KEY=THIS VALUE");
|
||||
assert_option(v, 1, "OTHER_KEY=SOMETHING");
|
||||
}
|
||||
SECTION("splitting open_options string with escaping")
|
||||
{
|
||||
std::string opts = "ZOOM=14 FANCY_OPTION=WITH\\ SPACE_VALUE";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "ZOOM=14");
|
||||
assert_option(v, 1, "FANCY_OPTION=WITH SPACE_VALUE");
|
||||
}
|
||||
SECTION("splitting open_options string, starts with space")
|
||||
{
|
||||
std::string opts = " ZOOM=14 K23=V45";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "ZOOM=14");
|
||||
assert_option(v, 1, "K23=V45");
|
||||
}
|
||||
SECTION("splitting open_options string, ends with space")
|
||||
{
|
||||
std::string opts = "ZOOM=14 K23=V46 ";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "ZOOM=14");
|
||||
assert_option(v, 1, "K23=V46");
|
||||
}
|
||||
SECTION("splitting open_options string, doubled space")
|
||||
{
|
||||
std::string opts = "ZOOM=14 K23=V47";
|
||||
std::vector<ogr_utils::option_ptr> v = split_options(opts);
|
||||
assert_option(v, 0, "ZOOM=14");
|
||||
assert_option(v, 1, "K23=V47");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue