mapnik-index: add initial support for processing GeoJSON
This commit is contained in:
parent
0bca3afa4e
commit
da1247fa1e
5 changed files with 133 additions and 6 deletions
|
@ -31,6 +31,7 @@ source = Split(
|
||||||
"""
|
"""
|
||||||
mapnik-index.cpp
|
mapnik-index.cpp
|
||||||
process_csv_file.cpp
|
process_csv_file.cpp
|
||||||
|
process_geojson_file.cpp
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <mapnik/quad_tree.hpp>
|
#include <mapnik/quad_tree.hpp>
|
||||||
|
|
||||||
#include "process_csv_file.hpp"
|
#include "process_csv_file.hpp"
|
||||||
|
#include "process_geojson_file.hpp"
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
|
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
|
||||||
|
@ -143,7 +143,7 @@ int main (int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
using box_type = mapnik::box2d<double>;
|
using box_type = mapnik::box2d<double>;
|
||||||
using item_type = std::pair<box_type, std::pair<unsigned, unsigned>>;
|
using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;
|
||||||
|
|
||||||
for (auto const& filename : files)
|
for (auto const& filename : files)
|
||||||
{
|
{
|
||||||
|
@ -164,7 +164,9 @@ int main (int argc, char** argv)
|
||||||
}
|
}
|
||||||
else if (mapnik::detail::is_geojson(filename))
|
else if (mapnik::detail::is_geojson(filename))
|
||||||
{
|
{
|
||||||
std::clog << "TODO: support GeoJSON" << std::endl;
|
auto result = mapnik::detail::process_geojson_file(boxes, filename);
|
||||||
|
if (!result.first) continue;
|
||||||
|
extent = result.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extent.valid())
|
if (extent.valid())
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#include <boost/interprocess/streams/bufferstream.hpp>
|
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#include <mapnik/mapped_memory_cache.hpp>
|
#include <mapnik/mapped_memory_cache.hpp>
|
||||||
#include <boost/version.hpp>
|
|
||||||
|
|
||||||
namespace mapnik { namespace detail {
|
namespace mapnik { namespace detail {
|
||||||
|
|
||||||
|
@ -209,8 +208,8 @@ std::pair<bool,box2d<double>> process_csv_file(T & boxes, std::string const& fil
|
||||||
}
|
}
|
||||||
|
|
||||||
using box_type = mapnik::box2d<double>;
|
using box_type = mapnik::box2d<double>;
|
||||||
using item_type = std::pair<box_type, std::pair<unsigned, unsigned>>;
|
using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;
|
||||||
using boxes_type = std::vector<item_type>;
|
using boxes_type = std::vector<item_type>;
|
||||||
template std::pair<bool,box2d<double>> process_csv_file(boxes_type&, std::string const&e, std::string const&, char, char);
|
template std::pair<bool,box2d<double>> process_csv_file(boxes_type&, std::string const&, std::string const&, char, char);
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
89
utils/mapnik-index/process_geojson_file.cpp
Normal file
89
utils/mapnik-index/process_geojson_file.cpp
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 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 "process_geojson_file.hpp"
|
||||||
|
#include <mapnik/geometry.hpp>
|
||||||
|
#include <mapnik/geometry_envelope.hpp>
|
||||||
|
#include <mapnik/geometry_adapters.hpp>
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wshadow"
|
||||||
|
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||||
|
#include <boost/interprocess/mapped_region.hpp>
|
||||||
|
#include <boost/interprocess/streams/bufferstream.hpp>
|
||||||
|
#include <boost/spirit/include/qi.hpp>
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#include <mapnik/mapped_memory_cache.hpp>
|
||||||
|
#include <mapnik/json/positions_grammar.hpp>
|
||||||
|
#include <mapnik/json/extract_bounding_box_grammar_impl.hpp>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using base_iterator_type = char const*;
|
||||||
|
const mapnik::json::extract_bounding_box_grammar<base_iterator_type> geojson_datasource_static_bbox_grammar;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace mapnik { namespace detail {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::pair<bool,box2d<double>> process_geojson_file(T & boxes, std::string const& filename)
|
||||||
|
{
|
||||||
|
mapnik::box2d<double> extent;
|
||||||
|
mapnik::mapped_region_ptr mapped_region;
|
||||||
|
boost::optional<mapnik::mapped_region_ptr> memory =
|
||||||
|
mapnik::mapped_memory_cache::instance().find(filename, true);
|
||||||
|
if (!memory)
|
||||||
|
{
|
||||||
|
std::clog << "Error : cannot mmap " << filename << std::endl;
|
||||||
|
return std::make_pair(false, extent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mapped_region = *memory;
|
||||||
|
}
|
||||||
|
char const* start = reinterpret_cast<char const*>(mapped_region->get_address());
|
||||||
|
char const* end = start + mapped_region->get_size();
|
||||||
|
boost::spirit::standard::space_type space;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!boost::spirit::qi::phrase_parse(start, end, (geojson_datasource_static_bbox_grammar)(boost::phoenix::ref(boxes)) , space))
|
||||||
|
{
|
||||||
|
std::clog << "mapnik-index (GeoJSON) : could not parse: '" << filename << "'";
|
||||||
|
return std::make_pair(false, extent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception const& ex)
|
||||||
|
{
|
||||||
|
std::clog << "mapnik-index:" << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
for (auto const& item : boxes)
|
||||||
|
{
|
||||||
|
if (!extent.valid()) extent = item.first;
|
||||||
|
else extent.expand_to_include(item.first);
|
||||||
|
}
|
||||||
|
return std::make_pair(true, extent);
|
||||||
|
}
|
||||||
|
|
||||||
|
using box_type = mapnik::box2d<double>;
|
||||||
|
using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;
|
||||||
|
using boxes_type = std::vector<item_type>;
|
||||||
|
template std::pair<bool,box2d<double>> process_geojson_file(boxes_type&, std::string const&);
|
||||||
|
|
||||||
|
}}
|
36
utils/mapnik-index/process_geojson_file.hpp
Normal file
36
utils/mapnik-index/process_geojson_file.hpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
*
|
||||||
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 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 MAPNIK_UTILS_PROCESS_GEOJSON_FILE_HPP
|
||||||
|
#define MAPNIK_UTILS_PROCESS_GEOJSON_FILE_HPP
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <mapnik/box2d.hpp>
|
||||||
|
|
||||||
|
namespace mapnik { namespace detail {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::pair<bool, box2d<double>> process_geojson_file(T & boxes, std::string const& filename);
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif // MAPNIK_UTILS_PROCESS_GEOJSON_FILE_HPP
|
Loading…
Reference in a new issue