2011-12-02 17:34:22 +01:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:37:58 +01:00
|
|
|
*
|
2011-12-02 17:34:22 +01:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2024-07-22 11:20:47 +02:00
|
|
|
* Copyright (C) 2024 Artem Pavlenko
|
2011-12-02 17:34:22 +01:00
|
|
|
*
|
|
|
|
* 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 <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2022-02-02 17:20:29 +01:00
|
|
|
#include <mapnik/mapnik.hpp>
|
2015-03-24 13:32:05 +01:00
|
|
|
#include <mapnik/geometry.hpp>
|
2011-12-02 17:34:22 +01:00
|
|
|
#include <mapnik/feature.hpp>
|
2015-03-16 16:14:54 +01:00
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
2011-12-02 17:34:22 +01:00
|
|
|
#include <mapnik/datasource_cache.hpp>
|
|
|
|
#include <mapnik/util/geometry_to_wkb.hpp>
|
|
|
|
|
2022-01-26 20:41:37 +01:00
|
|
|
int main(int argc, char** argv)
|
2011-12-02 17:34:22 +01:00
|
|
|
{
|
2022-01-26 20:41:37 +01:00
|
|
|
if (argc != 2)
|
2011-12-02 17:34:22 +01:00
|
|
|
{
|
|
|
|
std::cerr << "Usage: " << argv[0] << " <path-to-shapefile>\n";
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
std::cerr << "Geometry to WKB converter\n";
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2022-02-02 17:20:29 +01:00
|
|
|
mapnik::setup();
|
2012-09-07 17:23:03 +02:00
|
|
|
mapnik::datasource_cache::instance().register_datasources("/opt/mapnik/lib/mapnik/input/");
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
std::string filename(argv[1]);
|
|
|
|
std::cerr << filename << std::endl;
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
mapnik::parameters p;
|
|
|
|
p["type"] = "shape";
|
|
|
|
p["file"] = filename;
|
|
|
|
|
|
|
|
mapnik::datasource_ptr ds;
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
try
|
|
|
|
{
|
2012-09-07 17:23:03 +02:00
|
|
|
ds = mapnik::datasource_cache::instance().create(p);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (...)
|
2011-12-02 17:34:22 +01:00
|
|
|
{
|
|
|
|
std::cerr << "Can't create datasource!\n";
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
if (ds)
|
2012-02-02 02:37:58 +01:00
|
|
|
{
|
|
|
|
std::cerr << ds->envelope() << std::endl;
|
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
mapnik::query q(ds->envelope());
|
2011-12-02 18:18:28 +01:00
|
|
|
mapnik::layer_descriptor layer_desc = ds->get_descriptor();
|
2013-09-20 05:19:01 +02:00
|
|
|
for (mapnik::attribute_descriptor const& attr_desc : layer_desc.get_descriptors())
|
2011-12-02 18:18:28 +01:00
|
|
|
{
|
|
|
|
q.add_property_name(attr_desc.get_name());
|
|
|
|
}
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
mapnik::featureset_ptr fs = ds->features(q);
|
|
|
|
mapnik::feature_ptr f = fs->next();
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2022-01-26 20:41:37 +01:00
|
|
|
while (f)
|
2011-12-02 17:34:22 +01:00
|
|
|
{
|
|
|
|
std::cerr << *f << std::endl;
|
2015-04-09 22:22:51 +02:00
|
|
|
mapnik::geometry::geometry<double> const& geom = f->get_geometry();
|
2015-03-16 16:14:54 +01:00
|
|
|
// NDR
|
2011-12-02 17:34:22 +01:00
|
|
|
{
|
2022-01-26 20:41:37 +01:00
|
|
|
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom, mapnik::wkbNDR);
|
|
|
|
std::cerr << mapnik::util::detail::to_hex(wkb->buffer(), wkb->size()) << std::endl;
|
2015-03-16 16:14:54 +01:00
|
|
|
}
|
|
|
|
// XDR
|
|
|
|
{
|
2022-01-26 20:41:37 +01:00
|
|
|
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom, mapnik::wkbXDR);
|
|
|
|
std::cerr << mapnik::util::detail::to_hex(wkb->buffer(), wkb->size()) << std::endl;
|
2011-12-02 17:34:22 +01:00
|
|
|
}
|
|
|
|
f = fs->next();
|
|
|
|
}
|
|
|
|
}
|
2012-02-02 02:37:58 +01:00
|
|
|
|
2011-12-02 17:34:22 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|