From 55f5fed310ad03258255dd8d014d1246a2d12335 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Fri, 2 Dec 2011 16:34:22 +0000 Subject: [PATCH] add geometry_to_wkb test utililty --- utils/geometry_to_wkb/Jamroot | 19 ++++++ utils/geometry_to_wkb/main.cpp | 103 +++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 utils/geometry_to_wkb/Jamroot create mode 100644 utils/geometry_to_wkb/main.cpp diff --git a/utils/geometry_to_wkb/Jamroot b/utils/geometry_to_wkb/Jamroot new file mode 100644 index 000000000..92c6686a7 --- /dev/null +++ b/utils/geometry_to_wkb/Jamroot @@ -0,0 +1,19 @@ +###################################################################### + +MAPNIK_INCLUDE_DIR = "/opt/mapnik/include" ; +MAPNIK_LIB_DIR = "/opt/mapnik/lib" ; +BOOST_INCLUDE_DIR = "/opt/boost_1_48_0/include" ; + + +lib mapnik : : mapnik $(MAPNIK_LIB_DIR) ; +lib icu : : icuuc /usr/local/lib ; + +exe to_wkb : + main.cpp + .//mapnik + .//icu + : + $(MAPNIK_INCLUDE_DIR) + $(BOOST_INCLUDE_DIR) + ; + diff --git a/utils/geometry_to_wkb/main.cpp b/utils/geometry_to_wkb/main.cpp new file mode 100644 index 000000000..64ad5db64 --- /dev/null +++ b/utils/geometry_to_wkb/main.cpp @@ -0,0 +1,103 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2011 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 + * + *****************************************************************************/ + +//$Id$ + +#include +#include + +#include +#include +#include +#include + +#include + + +int main (int argc, char ** argv ) +{ + + if ( argc !=2) + { + std::cerr << "Usage: " << argv[0] << " \n"; + return EXIT_SUCCESS; + } + + std::cerr << "Geometry to WKB converter\n"; + + mapnik::datasource_cache::instance()->register_datasources("/opt/mapnik/lib/mapnik/input/"); + + std::string filename(argv[1]); + std::cerr << filename << std::endl; + + mapnik::parameters p; + p["type"] = "shape"; + p["file"] = filename; + + mapnik::datasource_ptr ds; + + try + { + ds = mapnik::datasource_cache::instance()->create(p); + } + catch ( ... ) + { + std::cerr << "Can't create datasource!\n"; + return EXIT_FAILURE; + } + + if (ds) + { + std::cerr << ds->envelope() << std::endl; + + mapnik::query q(ds->envelope()); + mapnik::featureset_ptr fs = ds->features(q); + mapnik::feature_ptr f = fs->next(); + + while(f) + { + std::cerr << *f << std::endl; + boost::ptr_vector & paths = f->paths(); + BOOST_FOREACH ( mapnik::geometry_type const& geom, paths) + { + // NDR + { + mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::util::wkbNDR); + std::cerr << mapnik::util::to_hex(wkb->buffer(),wkb->size()) << std::endl; + } + // XDR + { + mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::util::wkbXDR); + std::cerr << mapnik::util::to_hex(wkb->buffer(),wkb->size()) << std::endl; + } + } + + f = fs->next(); + } + } + + + + return EXIT_SUCCESS; +} + +