plugin code formatting based on emacs format in utils/format_source_files
This commit is contained in:
parent
3fd56f82f5
commit
ce9e44b5f2
88 changed files with 1873 additions and 1873 deletions
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -74,9 +74,9 @@ inline GDALDataset* gdal_datasource::open_dataset() const
|
|||
|
||||
|
||||
gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
desc_(*params.get<std::string>("type"), "utf-8"),
|
||||
filter_factor_(*params_.get<double>("filter_factor", 0.0))
|
||||
: datasource(params),
|
||||
desc_(*params.get<std::string>("type"), "utf-8"),
|
||||
filter_factor_(*params_.get<double>("filter_factor", 0.0))
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Initializing..." << std::endl;
|
||||
|
@ -96,7 +96,7 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
|||
{
|
||||
dataset_name_ = *file;
|
||||
}
|
||||
|
||||
|
||||
if (bind)
|
||||
{
|
||||
this->bind();
|
||||
|
@ -106,12 +106,12 @@ gdal_datasource::gdal_datasource(parameters const& params, bool bind)
|
|||
void gdal_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
shared_dataset_ = *params_.get<mapnik::boolean>("shared", false);
|
||||
band_ = *params_.get<int>("band", -1);
|
||||
|
||||
GDALDataset *dataset = open_dataset();
|
||||
|
||||
|
||||
nbands_ = dataset->GetRasterCount();
|
||||
width_ = dataset->GetRasterXSize();
|
||||
height_ = dataset->GetRasterYSize();
|
||||
|
@ -131,7 +131,7 @@ void gdal_datasource::bind() const
|
|||
throw datasource_exception("GDAL Plugin: bbox parameter '" + *bbox_s + "' invalid");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (bbox_override)
|
||||
{
|
||||
tr[0] = extent_.minx();
|
||||
|
@ -145,13 +145,13 @@ void gdal_datasource::bind() const
|
|||
{
|
||||
dataset->GetGeoTransform(tr);
|
||||
}
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: geotransform=" << tr[0] << "," << tr[1] << ","
|
||||
<< tr[2] << "," << tr[3] << ","
|
||||
<< tr[4] << "," << tr[5] << std::endl;
|
||||
<< tr[2] << "," << tr[3] << ","
|
||||
<< tr[4] << "," << tr[5] << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
if (tr[2] != 0 || tr[4] != 0)
|
||||
{
|
||||
throw datasource_exception("GDAL Plugin: only 'north up' images are supported");
|
||||
|
@ -159,27 +159,27 @@ void gdal_datasource::bind() const
|
|||
|
||||
dx_ = tr[1];
|
||||
dy_ = tr[5];
|
||||
|
||||
|
||||
if (! bbox_override)
|
||||
{
|
||||
double x0 = tr[0];
|
||||
double y0 = tr[3];
|
||||
double x1 = tr[0] + width_ * dx_ + height_ *tr[2];
|
||||
double y1 = tr[3] + width_ *tr[4] + height_ * dy_;
|
||||
|
||||
|
||||
/*
|
||||
double x0 = tr[0] + (height_) * tr[2]; // minx
|
||||
double y0 = tr[3] + (height_) * tr[5]; // miny
|
||||
|
||||
double x1 = tr[0] + (width_) * tr[1]; // maxx
|
||||
double y1 = tr[3] + (width_) * tr[4]; // maxy
|
||||
double x0 = tr[0] + (height_) * tr[2]; // minx
|
||||
double y0 = tr[3] + (height_) * tr[5]; // miny
|
||||
|
||||
double x1 = tr[0] + (width_) * tr[1]; // maxx
|
||||
double y1 = tr[3] + (width_) * tr[4]; // maxy
|
||||
*/
|
||||
|
||||
|
||||
extent_.init(x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
GDALClose(dataset);
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Raster Size=" << width_ << "," << height_ << std::endl;
|
||||
std::clog << "GDAL Plugin: Raster Extent=" << extent_ << std::endl;
|
||||
|
@ -205,7 +205,7 @@ std::string gdal_datasource::name()
|
|||
box2d<double> gdal_datasource::envelope() const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -32,7 +32,7 @@
|
|||
// gdal
|
||||
#include <gdal_priv.h>
|
||||
|
||||
class gdal_datasource : public mapnik::datasource
|
||||
class gdal_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
gdal_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -40,9 +40,9 @@ using mapnik::geometry_type;
|
|||
using mapnik::datasource_exception;
|
||||
using mapnik::feature_factory;
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#ifdef _WINDOWS
|
||||
using mapnik::rint;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
||||
int band,
|
||||
|
@ -54,17 +54,17 @@ gdal_featureset::gdal_featureset(GDALDataset& dataset,
|
|||
double dx,
|
||||
double dy,
|
||||
double filter_factor)
|
||||
: dataset_(dataset),
|
||||
band_(band),
|
||||
gquery_(q),
|
||||
raster_extent_(extent),
|
||||
raster_width_(width),
|
||||
raster_height_(height),
|
||||
dx_(dx),
|
||||
dy_(dy),
|
||||
nbands_(nbands),
|
||||
filter_factor_(filter_factor),
|
||||
first_(true)
|
||||
: dataset_(dataset),
|
||||
band_(band),
|
||||
gquery_(q),
|
||||
raster_extent_(extent),
|
||||
raster_width_(width),
|
||||
raster_height_(height),
|
||||
dx_(dx),
|
||||
dy_(dy),
|
||||
nbands_(nbands),
|
||||
filter_factor_(filter_factor),
|
||||
first_(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -112,17 +112,17 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
GDALRasterBand * green = 0;
|
||||
GDALRasterBand * blue = 0;
|
||||
GDALRasterBand * alpha = 0;
|
||||
GDALRasterBand * grey = 0;
|
||||
|
||||
GDALRasterBand * grey = 0;
|
||||
|
||||
/*
|
||||
double tr[6];
|
||||
dataset_.GetGeoTransform(tr);
|
||||
|
||||
double dx = tr[1];
|
||||
double dy = tr[5];
|
||||
std::clog << "dx_: " << dx_ << " dx: " << dx << " dy_: " << dy_ << "dy: " << dy << "\n";
|
||||
double tr[6];
|
||||
dataset_.GetGeoTransform(tr);
|
||||
|
||||
double dx = tr[1];
|
||||
double dy = tr[5];
|
||||
std::clog << "dx_: " << dx_ << " dx: " << dx << " dy_: " << dy_ << "dy: " << dy << "\n";
|
||||
*/
|
||||
|
||||
|
||||
CoordTransform t(raster_width_, raster_height_, raster_extent_, 0, 0);
|
||||
box2d<double> intersect = raster_extent_.intersect(q.get_bbox());
|
||||
box2d<double> box = t.forward(intersect);
|
||||
|
@ -178,21 +178,21 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
//calculate actual box2d of returned raster
|
||||
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
|
||||
intersect = t.backward(feature_raster_extent);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Raster extent=" << raster_extent_ << std::endl;
|
||||
std::clog << "GDAL Plugin: View extent=" << intersect << std::endl;
|
||||
std::clog << "GDAL Plugin: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution()) << std::endl;
|
||||
std::clog << boost::format("GDAL Plugin: StartX=%d StartY=%d Width=%d Height=%d") % x_off % y_off % width % height << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
double width_res = boost::get<0>(q.resolution());
|
||||
double height_res = boost::get<1>(q.resolution());
|
||||
int im_width = int(width_res * intersect.width() + 0.5);
|
||||
int im_height = int(height_res * intersect.height() + 0.5);
|
||||
|
||||
|
||||
// if layer-level filter_factor is set, apply it
|
||||
if (filter_factor_)
|
||||
{
|
||||
|
@ -211,7 +211,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
}
|
||||
|
||||
// case where we need to avoid upsampling so that the
|
||||
// image can be later scaled within raster_symbolizer
|
||||
// image can be later scaled within raster_symbolizer
|
||||
if (im_width >= width || im_height >= height)
|
||||
{
|
||||
im_width = width;
|
||||
|
@ -221,14 +221,14 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
if (im_width > 0 && im_height > 0)
|
||||
{
|
||||
mapnik::image_data_32 image(im_width, im_height);
|
||||
image.set(0xffffffff);
|
||||
|
||||
image.set(0xffffffff);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Image Size=(" << im_width << "," << im_height << ")" << std::endl;
|
||||
std::clog << "GDAL Plugin: Reading band " << band_ << std::endl;
|
||||
#endif
|
||||
typedef std::vector<int,int> pallete;
|
||||
|
||||
|
||||
if (band_ > 0) // we are querying a single band
|
||||
{
|
||||
if (band_ > nbands_)
|
||||
|
@ -243,7 +243,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
band->RasterIO(GF_Read, x_off, y_off, width, height,
|
||||
imageData, image.width(), image.height(),
|
||||
GDT_Float32, 0, 0);
|
||||
|
||||
|
||||
feature->set_raster(mapnik::raster_ptr(boost::make_shared<mapnik::raster>(intersect,image)));
|
||||
if (hasNoData)
|
||||
{
|
||||
|
@ -255,11 +255,11 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
for (int i = 0; i < nbands_; ++i)
|
||||
{
|
||||
GDALRasterBand * band = dataset_.GetRasterBand(i + 1);
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
get_overview_meta(band);
|
||||
#endif
|
||||
|
||||
|
||||
GDALColorInterp color_interp = band->GetColorInterpretation();
|
||||
switch (color_interp)
|
||||
{
|
||||
|
@ -300,19 +300,19 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
std::clog << "GDAL Plugin: Found gray band, and colortable..." << std::endl;
|
||||
#endif
|
||||
GDALColorTable *color_table = band->GetColorTable();
|
||||
|
||||
|
||||
if (color_table)
|
||||
{
|
||||
int count = color_table->GetColorEntryCount();
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Color Table count = " << count << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
const GDALColorEntry *ce = color_table->GetColorEntry (j);
|
||||
if (! ce) continue;
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <<ce->c2 << "," << ce->c3 << ")" << std::endl;
|
||||
std::clog << "GDAL Plugin: Color entry RGB (" << ce->c1 << "," <<ce->c2 << "," << ce->c3 << ")" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (red && green && blue)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
@ -435,7 +435,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (alpha)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
@ -444,7 +444,7 @@ feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
|
|||
alpha->RasterIO(GF_Read, x_off, y_off, width, height, image.getBytes() + 3,
|
||||
image.width(), image.height(), GDT_Byte, 4, 4 * image.width());
|
||||
}
|
||||
|
||||
|
||||
feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersect, image)));
|
||||
}
|
||||
return feature;
|
||||
|
@ -503,7 +503,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
|
|||
#ifdef MAPNIK_DEBUG
|
||||
void gdal_featureset::get_overview_meta(GDALRasterBand* band)
|
||||
{
|
||||
int band_overviews = band->GetOverviewCount();
|
||||
int band_overviews = band->GetOverviewCount();
|
||||
if (band_overviews > 0)
|
||||
{
|
||||
std::clog << "GDAL Plugin: "<< band_overviews << " overviews found!" << std::endl;
|
||||
|
@ -517,9 +517,9 @@ void gdal_featureset::get_overview_meta(GDALRasterBand* band)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::clog << "GDAL Plugin: No overviews found!" << std::endl;
|
||||
std::clog << "GDAL Plugin: No overviews found!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int bsx,bsy;
|
||||
double scale;
|
||||
band->GetBlockSize(&bsx, &bsy);
|
||||
|
@ -527,6 +527,6 @@ void gdal_featureset::get_overview_meta(GDALRasterBand* band)
|
|||
|
||||
std::clog << boost::format("GDAL Plugin: Block=%dx%d Scale=%f Type=%s Color=%s") % bsx % bsy % scale
|
||||
% GDALGetDataTypeName(band->GetRasterDataType())
|
||||
% GDALGetColorInterpretationName(band->GetColorInterpretation()) << std::endl;
|
||||
% GDALGetColorInterpretationName(band->GetColorInterpretation()) << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -65,7 +65,7 @@ void geos_notice(const char* fmt, ...)
|
|||
{
|
||||
va_list ap;
|
||||
fprintf( stdout, "GEOS Plugin: (GEOS NOTICE) ");
|
||||
|
||||
|
||||
va_start (ap, fmt);
|
||||
vfprintf( stdout, fmt, ap);
|
||||
va_end(ap);
|
||||
|
@ -85,14 +85,14 @@ void geos_error(const char* fmt, ...)
|
|||
|
||||
|
||||
geos_datasource::geos_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
|
||||
geometry_data_(""),
|
||||
geometry_data_name_("name"),
|
||||
geometry_id_(1)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
|
||||
geometry_data_(""),
|
||||
geometry_data_name_("name"),
|
||||
geometry_id_(1)
|
||||
{
|
||||
boost::optional<std::string> geometry = params.get<std::string>("wkt");
|
||||
if (! geometry) throw datasource_exception("missing <wkt> parameter");
|
||||
|
@ -122,7 +122,7 @@ geos_datasource::geos_datasource(parameters const& params, bool bind)
|
|||
|
||||
geos_datasource::~geos_datasource()
|
||||
{
|
||||
if (is_bound_)
|
||||
if (is_bound_)
|
||||
{
|
||||
geometry_.set_feature(0);
|
||||
|
||||
|
@ -132,7 +132,7 @@ geos_datasource::~geos_datasource()
|
|||
|
||||
void geos_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
if (is_bound_) return;
|
||||
|
||||
// open geos driver
|
||||
initGEOS(geos_notice, geos_error);
|
||||
|
@ -161,7 +161,7 @@ void geos_datasource::bind() const
|
|||
GEOSCoordSeq_getSize(cs, &size);
|
||||
GEOSCoordSeq_getX(cs, 0, &x);
|
||||
GEOSCoordSeq_getY(cs, 0, &y);
|
||||
|
||||
|
||||
extent_.init(x, y, x, y);
|
||||
extent_initialized_ = true;
|
||||
}
|
||||
|
@ -188,9 +188,9 @@ void geos_datasource::bind() const
|
|||
|
||||
double x, y;
|
||||
double minx = std::numeric_limits<float>::max(),
|
||||
miny = std::numeric_limits<float>::max(),
|
||||
maxx = -std::numeric_limits<float>::max(),
|
||||
maxy = -std::numeric_limits<float>::max();
|
||||
miny = std::numeric_limits<float>::max(),
|
||||
maxx = -std::numeric_limits<float>::max(),
|
||||
maxy = -std::numeric_limits<float>::max();
|
||||
|
||||
unsigned int num_points;
|
||||
GEOSCoordSeq_getSize(cs, &num_points);
|
||||
|
@ -199,7 +199,7 @@ void geos_datasource::bind() const
|
|||
{
|
||||
GEOSCoordSeq_getX(cs, i, &x);
|
||||
GEOSCoordSeq_getY(cs, i, &y);
|
||||
|
||||
|
||||
if (x < minx) minx = x;
|
||||
if (x > maxx) maxx = x;
|
||||
if (y < miny) miny = y;
|
||||
|
@ -218,7 +218,7 @@ void geos_datasource::bind() const
|
|||
{
|
||||
throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry");
|
||||
}
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
|
@ -235,14 +235,14 @@ int geos_datasource::type() const
|
|||
box2d<double> geos_datasource::envelope() const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
||||
layer_descriptor geos_datasource::get_descriptor() const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
return desc_;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "geos_feature_ptr.hpp"
|
||||
|
||||
class geos_datasource : public mapnik::datasource
|
||||
class geos_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
geos_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
: feat_ (feat)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~geos_feature_ptr ()
|
||||
{
|
||||
if (feat_ != NULL)
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
{
|
||||
if (feat_ != NULL)
|
||||
GEOSGeom_destroy(feat_);
|
||||
|
||||
|
||||
feat_ = feat;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -55,18 +55,18 @@ geos_featureset::geos_featureset(GEOSGeometry* geometry,
|
|||
const std::string& field_name,
|
||||
const std::string& encoding,
|
||||
bool multiple_geometries)
|
||||
: geometry_(geometry),
|
||||
tr_(new transcoder(encoding)),
|
||||
extent_(extent),
|
||||
identifier_(identifier),
|
||||
field_(field),
|
||||
field_name_(field_name),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
already_rendered_(false)
|
||||
: geometry_(geometry),
|
||||
tr_(new transcoder(encoding)),
|
||||
extent_(extent),
|
||||
identifier_(identifier),
|
||||
field_(field),
|
||||
field_name_(field_name),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
already_rendered_(false)
|
||||
{
|
||||
}
|
||||
|
||||
geos_featureset::~geos_featureset()
|
||||
geos_featureset::~geos_featureset()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -75,11 +75,11 @@ feature_ptr geos_featureset::next()
|
|||
if (! already_rendered_)
|
||||
{
|
||||
already_rendered_ = true;
|
||||
|
||||
|
||||
if (GEOSisValid(geometry_) && ! GEOSisEmpty(geometry_))
|
||||
{
|
||||
bool render_geometry = true;
|
||||
|
||||
|
||||
if (*extent_ != NULL && GEOSisValid(*extent_) && ! GEOSisEmpty(*extent_))
|
||||
{
|
||||
const int type = GEOSGeomTypeId(*extent_);
|
||||
|
@ -108,7 +108,7 @@ feature_ptr geos_featureset::next()
|
|||
std::clog << "GEOS Plugin: unknown extent geometry_type=" << type << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (render_geometry)
|
||||
|
@ -127,7 +127,7 @@ feature_ptr geos_featureset::next()
|
|||
{
|
||||
boost::put(*feature, field_name_, tr_->transcode(field_.c_str()));
|
||||
}
|
||||
|
||||
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/geom_util.hpp>
|
||||
|
||||
// boost
|
||||
|
@ -35,7 +35,7 @@
|
|||
#include <geos_c.h>
|
||||
|
||||
#include "geos_feature_ptr.hpp"
|
||||
|
||||
|
||||
class geos_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -72,12 +72,12 @@ std::list<kismet_network_data> knd_list;
|
|||
const unsigned int queue_size = 20;
|
||||
|
||||
kismet_datasource::kismet_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
srs_("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
|
||||
{
|
||||
boost::optional<std::string> host = params_.get<std::string>("host");
|
||||
if (host)
|
||||
|
@ -88,7 +88,7 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
|
|||
{
|
||||
throw datasource_exception("Kismet Plugin: missing <host> parameter");
|
||||
}
|
||||
|
||||
|
||||
boost::optional<unsigned int> port = params_.get<unsigned int>("port", 2501);
|
||||
if (port)
|
||||
{
|
||||
|
@ -118,7 +118,7 @@ kismet_datasource::kismet_datasource(parameters const& params, bool bind)
|
|||
void kismet_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
|
@ -150,9 +150,9 @@ layer_descriptor kismet_datasource::get_descriptor() const
|
|||
featureset_ptr kismet_datasource::features(query const& q) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
// std::clog << "kismet_datasource::features()" << endl;
|
||||
|
||||
|
||||
// TODO: use box2d to filter bbox before adding to featureset_ptr
|
||||
// mapnik::box2d<double> const& e = q.get_bbox();
|
||||
|
||||
|
@ -168,7 +168,7 @@ featureset_ptr kismet_datasource::features(query const& q) const
|
|||
featureset_ptr kismet_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
// std::clog << "kismet_datasource::features_at_point()" << endl;
|
||||
|
||||
return featureset_ptr();
|
||||
|
@ -179,7 +179,7 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
|
|||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Kismet Plugin: enter run" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
int sockfd, n;
|
||||
struct sockaddr_in sock_addr;
|
||||
struct in_addr inadr;
|
||||
|
@ -190,7 +190,7 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
|
|||
if (inet_aton(ip_host.c_str(), &inadr))
|
||||
{
|
||||
host = gethostbyaddr((char*)&inadr, sizeof(inadr), AF_INET);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
host = gethostbyname(ip_host.c_str());
|
||||
|
@ -233,24 +233,24 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
|
|||
double bestlat = 0;
|
||||
double bestlon = 0;
|
||||
int crypt = crypt_none;
|
||||
|
||||
// BUG: if kismet_server is active sending after mapnik was killed and then restarted the
|
||||
|
||||
// BUG: if kismet_server is active sending after mapnik was killed and then restarted the
|
||||
// assert is called. Needs to be analyzed!
|
||||
while ((n = read(sockfd, buffer, sizeof(buffer))) > 0)
|
||||
{
|
||||
assert(n < MAX_TCP_BUFFER);
|
||||
|
||||
|
||||
buffer[n] = '\0';
|
||||
std::string bufferObj(buffer); // TCP data send from kismet_server as STL string
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Kismet Plugin: buffer_obj=" << bufferObj << "[END]" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
std::string::size_type found = 0;
|
||||
std::string::size_type search_start = 0;
|
||||
std::string kismet_line; // contains a line from kismet_server
|
||||
do
|
||||
do
|
||||
{
|
||||
found = bufferObj.find('\n', search_start);
|
||||
if (found != std::string::npos)
|
||||
|
@ -260,9 +260,9 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
|
|||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Kismet Plugin: line=" << kismet_line << " [ENDL]" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
int param_number = 5; // the number of parameters to parse
|
||||
|
||||
|
||||
// Attention: string length specified to the constant!
|
||||
if (sscanf (kismet_line.c_str(),
|
||||
KISMET_COMMAND,
|
||||
|
@ -278,23 +278,23 @@ void kismet_datasource::run(const std::string& ip_host, const unsigned int port)
|
|||
#endif
|
||||
|
||||
kismet_network_data knd(ssid, bssid, bestlat, bestlon, crypt);
|
||||
|
||||
|
||||
boost::mutex::scoped_lock lock(knd_list_mutex);
|
||||
|
||||
|
||||
// the queue only grows to a max size
|
||||
if (knd_list.size () >= queue_size)
|
||||
{
|
||||
knd_list.pop_front();
|
||||
}
|
||||
|
||||
|
||||
knd_list.push_back(knd);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// do nothing if not matched!
|
||||
}
|
||||
|
||||
search_start = found + 1;
|
||||
search_start = found + 1;
|
||||
}
|
||||
}
|
||||
while (found != std::string::npos);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -30,7 +30,7 @@
|
|||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/feature_layer_desc.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -40,7 +40,7 @@
|
|||
// sqlite
|
||||
#include "kismet_types.hpp"
|
||||
|
||||
class kismet_datasource : public mapnik::datasource
|
||||
class kismet_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
kismet_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -78,17 +78,17 @@ feature_ptr kismet_featureset::next()
|
|||
|
||||
feature_ptr feature(feature_factory::create(feature_id_));
|
||||
++feature_id_;
|
||||
|
||||
|
||||
geometry_type* pt = new geometry_type(mapnik::Point);
|
||||
pt->move_to(knd.bestlon(), knd.bestlat());
|
||||
feature->add_geometry(pt);
|
||||
|
||||
|
||||
boost::put(*feature, key, tr_->transcode(value.c_str()));
|
||||
|
||||
|
||||
++knd_list_it;
|
||||
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
return feature_ptr();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -25,8 +25,8 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
@ -36,7 +36,7 @@
|
|||
#include <list>
|
||||
|
||||
#include "kismet_types.hpp"
|
||||
|
||||
|
||||
class kismet_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -30,7 +30,7 @@
|
|||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// this is a copy from packet.h from kismet 2007.10.R1
|
||||
enum crypt_type
|
||||
enum crypt_type
|
||||
{
|
||||
crypt_none = 0,
|
||||
crypt_unknown = 1,
|
||||
|
@ -58,7 +58,7 @@ class kismet_network_data
|
|||
{
|
||||
public:
|
||||
kismet_network_data()
|
||||
: bestlat_(0), bestlon_(0), crypt_(crypt_none)
|
||||
: bestlat_(0), bestlon_(0), crypt_(crypt_none)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,11 @@ public:
|
|||
double bestlat,
|
||||
double bestlon,
|
||||
int crypt)
|
||||
: ssid_(ssid),
|
||||
bssid_(bssid),
|
||||
bestlat_(bestlat),
|
||||
bestlon_(bestlon),
|
||||
crypt_(crypt)
|
||||
: ssid_(ssid),
|
||||
bssid_(bssid),
|
||||
bestlat_(bestlat),
|
||||
bestlon_(bestlon),
|
||||
crypt_(crypt)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -68,7 +68,7 @@ const std::string occi_datasource::METADATA_TABLE = "USER_SDO_GEOM_METADATA";
|
|||
DATASOURCE_PLUGIN(occi_datasource)
|
||||
|
||||
occi_datasource::occi_datasource(parameters const& params, bool bind)
|
||||
: datasource (params),
|
||||
: datasource (params),
|
||||
type_(datasource::Vector),
|
||||
fields_(*params_.get<std::string>("fields", "*")),
|
||||
geometry_field_(*params_.get<std::string>("geometry_field", "")),
|
||||
|
@ -93,11 +93,11 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
|
|||
{
|
||||
table_ = *table;
|
||||
}
|
||||
|
||||
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
|
||||
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true);
|
||||
use_connection_pool_ = *params_.get<mapnik::boolean>("use_connection_pool",true);
|
||||
|
||||
|
||||
boost::optional<std::string> ext = params_.get<std::string>("extent");
|
||||
if (ext) extent_initialized_ = extent_.from_string(*ext);
|
||||
|
||||
|
@ -149,13 +149,13 @@ void occi_datasource::bind() const
|
|||
Environment* env = occi_environment::get_environment();
|
||||
|
||||
pool_ = env->createStatelessConnectionPool(
|
||||
*params_.get<std::string>("user"),
|
||||
*params_.get<std::string>("password"),
|
||||
*params_.get<std::string>("host"),
|
||||
*params_.get<int>("max_size", 10),
|
||||
*params_.get<int>("initial_size", 1),
|
||||
1,
|
||||
StatelessConnectionPool::HOMOGENEOUS);
|
||||
*params_.get<std::string>("user"),
|
||||
*params_.get<std::string>("password"),
|
||||
*params_.get<std::string>("host"),
|
||||
*params_.get<int>("max_size", 10),
|
||||
*params_.get<int>("initial_size", 1),
|
||||
1,
|
||||
StatelessConnectionPool::HOMOGENEOUS);
|
||||
}
|
||||
catch (SQLException& ex)
|
||||
{
|
||||
|
@ -167,11 +167,11 @@ void occi_datasource::bind() const
|
|||
try
|
||||
{
|
||||
Environment* env = occi_environment::get_environment();
|
||||
|
||||
|
||||
conn_ = env->createConnection(
|
||||
*params_.get<std::string>("user"),
|
||||
*params_.get<std::string>("password"),
|
||||
*params_.get<std::string>("host"));
|
||||
*params_.get<std::string>("user"),
|
||||
*params_.get<std::string>("password"),
|
||||
*params_.get<std::string>("host"));
|
||||
}
|
||||
catch (SQLException& ex)
|
||||
{
|
||||
|
@ -187,7 +187,7 @@ void occi_datasource::bind() const
|
|||
std::ostringstream s;
|
||||
s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE";
|
||||
s << " LOWER(table_name) = LOWER('" << table_name << "')";
|
||||
|
||||
|
||||
if (geometry_field_ != "")
|
||||
{
|
||||
s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";
|
||||
|
@ -211,7 +211,7 @@ void occi_datasource::bind() const
|
|||
srid_ = rs->getInt(1);
|
||||
srid_initialized_ = true;
|
||||
}
|
||||
|
||||
|
||||
if (geometry_field_ == "")
|
||||
{
|
||||
geometry_field_ = rs->getString(2);
|
||||
|
@ -252,12 +252,12 @@ void occi_datasource::bind() const
|
|||
int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);
|
||||
|
||||
/*
|
||||
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
|
||||
if (type_code == OCCI_TYPECODE_OBJECT)
|
||||
{
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
|
||||
continue;
|
||||
}
|
||||
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
|
||||
if (type_code == OCCI_TYPECODE_OBJECT)
|
||||
{
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
switch (type_oid)
|
||||
|
@ -444,7 +444,7 @@ box2d<double> occi_datasource::envelope() const
|
|||
std::clog << "OCCI Plugin: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (rs->next())
|
||||
{
|
||||
try
|
||||
|
@ -479,7 +479,7 @@ box2d<double> occi_datasource::envelope() const
|
|||
layer_descriptor occi_datasource::get_descriptor() const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
return desc_;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -35,7 +35,7 @@
|
|||
// oci
|
||||
#include "occi_types.hpp"
|
||||
|
||||
class occi_datasource : public mapnik::datasource
|
||||
class occi_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
occi_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -63,10 +63,10 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
|
|||
bool use_connection_pool,
|
||||
unsigned prefetch_rows,
|
||||
unsigned num_attrs)
|
||||
: tr_(new transcoder(encoding)),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
num_attrs_(num_attrs),
|
||||
feature_id_(1)
|
||||
: tr_(new transcoder(encoding)),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
num_attrs_(num_attrs),
|
||||
feature_id_(1)
|
||||
{
|
||||
if (use_connection_pool)
|
||||
{
|
||||
|
@ -113,12 +113,12 @@ feature_ptr occi_featureset::next()
|
|||
std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
|
||||
int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);
|
||||
|
||||
/*
|
||||
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
|
||||
if (type_code == OCCI_TYPECODE_OBJECT)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
|
||||
if (type_code == OCCI_TYPECODE_OBJECT)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
switch (type_oid)
|
||||
|
@ -194,9 +194,9 @@ feature_ptr occi_featureset::next()
|
|||
<< "(type_oid=" << type_oid << ")" << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
|
|||
int gtype = (int)geom->getSdo_gtype();
|
||||
int dimensions = gtype / 1000;
|
||||
int lrsvalue = (gtype - dimensions * 1000) / 100;
|
||||
int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100);
|
||||
int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100);
|
||||
|
||||
#if 0
|
||||
std::clog << "-----------Geometry Object ------------" << std::endl;
|
||||
|
@ -232,131 +232,131 @@ void occi_featureset::convert_geometry(SDOGeometry* geom, feature_ptr feature, b
|
|||
switch (geomtype)
|
||||
{
|
||||
case SDO_GTYPE_POINT:
|
||||
{
|
||||
SDOPointType* sdopoint = geom->getSdo_point();
|
||||
if (sdopoint && ! sdopoint->isNull())
|
||||
{
|
||||
SDOPointType* sdopoint = geom->getSdo_point();
|
||||
if (sdopoint && ! sdopoint->isNull())
|
||||
{
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(sdopoint->getX(), sdopoint->getY());
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(sdopoint->getX(), sdopoint->getY());
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_LINE:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = true;
|
||||
const bool is_point_type = false;
|
||||
const bool multiple_geoms = false;
|
||||
const bool is_single_geom = true;
|
||||
const bool is_point_type = false;
|
||||
const bool multiple_geoms = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::LineString,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
convert_ordinates(feature,
|
||||
mapnik::LineString,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_POLYGON:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = true;
|
||||
const bool is_point_type = false;
|
||||
const bool multiple_geoms = false;
|
||||
const bool is_single_geom = true;
|
||||
const bool is_point_type = false;
|
||||
const bool multiple_geoms = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_MULTIPOINT:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = true;
|
||||
const bool multiple_geoms = true;
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = true;
|
||||
const bool multiple_geoms = true;
|
||||
|
||||
// Todo - force using true as multiple_geometries until we have proper multipoint handling
|
||||
// http://trac.mapnik.org/ticket/458
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Point,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
// Todo - force using true as multiple_geometries until we have proper multipoint handling
|
||||
// http://trac.mapnik.org/ticket/458
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Point,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geoms);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_MULTILINE:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::LineString,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
convert_ordinates(feature,
|
||||
mapnik::LineString,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_MULTIPOLYGON:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_COLLECTION:
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
if (ordinates_size >= dimensions)
|
||||
{
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
const bool is_single_geom = false;
|
||||
const bool is_point_type = false;
|
||||
|
||||
convert_ordinates(feature,
|
||||
mapnik::Polygon,
|
||||
elem_info,
|
||||
ordinates,
|
||||
dimensions,
|
||||
is_single_geom,
|
||||
is_point_type,
|
||||
multiple_geometries);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDO_GTYPE_UNKNOWN:
|
||||
default:
|
||||
#ifdef MAPNIK_DEBUG
|
||||
|
@ -379,7 +379,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
{
|
||||
const int elem_size = elem_info.size();
|
||||
const int ord_size = ordinates.size();
|
||||
|
||||
|
||||
if (elem_size >= 0)
|
||||
{
|
||||
int offset = elem_info[0];
|
||||
|
@ -390,7 +390,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
{
|
||||
geometry_type* geom = multiple_geometries ? 0 : new geometry_type(geom_type);
|
||||
if (geom) geom->set_capacity(ord_size);
|
||||
|
||||
|
||||
for (int i = SDO_ELEM_INFO_SIZE; i < elem_size; i+=3)
|
||||
{
|
||||
int next_offset = elem_info[i];
|
||||
|
@ -407,7 +407,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
if (interp > SDO_INTERPRETATION_POINT) {}
|
||||
gtype = mapnik::Point;
|
||||
break;
|
||||
|
||||
|
||||
case SDO_ETYPE_LINESTRING:
|
||||
if (interp == SDO_INTERPRETATION_STRAIGHT) {}
|
||||
if (interp == SDO_INTERPRETATION_CIRCULAR) {}
|
||||
|
@ -450,7 +450,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
{
|
||||
feature->add_geometry(geom);
|
||||
}
|
||||
|
||||
|
||||
geom = new geometry_type(gtype);
|
||||
geom->set_capacity((next_offset - 1) - (offset - 1 - dimensions));
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
etype = next_etype;
|
||||
interp = next_interp;
|
||||
}
|
||||
|
||||
|
||||
if (geom)
|
||||
{
|
||||
feature->add_geometry(geom);
|
||||
|
@ -478,7 +478,7 @@ void occi_featureset::convert_ordinates(mapnik::feature_ptr feature,
|
|||
{
|
||||
geometry_type * geom = new geometry_type(geom_type);
|
||||
geom->set_capacity(ord_size);
|
||||
|
||||
|
||||
fill_geometry_type(geom,
|
||||
offset - 1,
|
||||
ord_size,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -26,7 +26,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
// oci
|
||||
#include "occi_types.hpp"
|
||||
|
||||
|
||||
class occi_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -35,9 +35,9 @@
|
|||
|
||||
// check for oracle support
|
||||
#if OCCI_MAJOR_VERSION >= 10 && OCCI_MINOR_VERSION >= 1
|
||||
// We have at least ORACLE 10g >= 10.2.0.X
|
||||
// We have at least ORACLE 10g >= 10.2.0.X
|
||||
#else
|
||||
#error Only ORACLE 10g >= 10.2.0.X is supported !
|
||||
#error Only ORACLE 10g >= 10.2.0.X is supported !
|
||||
#endif
|
||||
|
||||
// geometry types definitions
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
#endif
|
||||
|
||||
const int mode = oracle::occi::Environment::OBJECT
|
||||
| oracle::occi::Environment::THREADED_MUTEXED;
|
||||
| oracle::occi::Environment::THREADED_MUTEXED;
|
||||
|
||||
env_ = oracle::occi::Environment::createEnvironment((oracle::occi::Environment::Mode) mode);
|
||||
RegisterClasses(env_);
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
void set_pool(oracle::occi::StatelessConnectionPool* pool)
|
||||
{
|
||||
close_query(true);
|
||||
|
||||
|
||||
pool_ = pool;
|
||||
conn_ = pool_->getConnection();
|
||||
owns_connection_ = true;
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
void set_connection(oracle::occi::Connection* conn, bool owns_connection)
|
||||
{
|
||||
close_query(true);
|
||||
|
||||
|
||||
pool_ = 0;
|
||||
conn_ = conn;
|
||||
owns_connection_ = owns_connection;
|
||||
|
@ -172,7 +172,7 @@ public:
|
|||
}
|
||||
|
||||
rs_ = stmt_->executeQuery();
|
||||
|
||||
|
||||
return rs_;
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ private:
|
|||
if (stmt_)
|
||||
{
|
||||
if (rs_)
|
||||
{
|
||||
{
|
||||
stmt_->closeResultSet(rs_);
|
||||
rs_ = 0;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ private:
|
|||
conn_->terminateStatement(stmt_);
|
||||
stmt_ = 0;
|
||||
}
|
||||
|
||||
|
||||
if (release_connection)
|
||||
{
|
||||
if (pool_)
|
||||
|
@ -211,7 +211,7 @@ private:
|
|||
env_->terminateConnection(conn_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
conn_ = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
void RegisterClasses(oracle::occi::Environment* envOCCI_)
|
||||
{
|
||||
oracle::occi::Map *mapOCCI_ = envOCCI_->getMap();
|
||||
mapOCCI_->put("MDSYS.SDO_POINT_TYPE", &SDOPointType::readSQL, &SDOPointType::writeSQL);
|
||||
mapOCCI_->put("MDSYS.SDO_GEOMETRY", &SDOGeometry::readSQL, &SDOGeometry::writeSQL);
|
||||
oracle::occi::Map *mapOCCI_ = envOCCI_->getMap();
|
||||
mapOCCI_->put("MDSYS.SDO_POINT_TYPE", &SDOPointType::readSQL, &SDOPointType::writeSQL);
|
||||
mapOCCI_->put("MDSYS.SDO_GEOMETRY", &SDOGeometry::readSQL, &SDOGeometry::writeSQL);
|
||||
}
|
||||
|
|
|
@ -9,72 +9,72 @@
|
|||
|
||||
oracle::occi::Number SDOPointType::getX() const
|
||||
{
|
||||
return X;
|
||||
return X;
|
||||
}
|
||||
|
||||
void SDOPointType::setX(const oracle::occi::Number &value)
|
||||
{
|
||||
X = value;
|
||||
X = value;
|
||||
}
|
||||
|
||||
oracle::occi::Number SDOPointType::getY() const
|
||||
{
|
||||
return Y;
|
||||
return Y;
|
||||
}
|
||||
|
||||
void SDOPointType::setY(const oracle::occi::Number &value)
|
||||
{
|
||||
Y = value;
|
||||
Y = value;
|
||||
}
|
||||
|
||||
oracle::occi::Number SDOPointType::getZ() const
|
||||
{
|
||||
return Z;
|
||||
return Z;
|
||||
}
|
||||
|
||||
void SDOPointType::setZ(const oracle::occi::Number &value)
|
||||
{
|
||||
Z = value;
|
||||
Z = value;
|
||||
}
|
||||
|
||||
void *SDOPointType::operator new(size_t size)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size);
|
||||
return oracle::occi::PObject::operator new(size);
|
||||
}
|
||||
|
||||
void *SDOPointType::operator new(size_t size, const oracle::occi::Connection * sess,
|
||||
const OCCI_STD_NAMESPACE::string& table)
|
||||
const OCCI_STD_NAMESPACE::string& table)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, sess, table,
|
||||
(char *) "MDSYS.SDO_POINT_TYPE");
|
||||
return oracle::occi::PObject::operator new(size, sess, table,
|
||||
(char *) "MDSYS.SDO_POINT_TYPE");
|
||||
}
|
||||
|
||||
void *SDOPointType::operator new(size_t size, void *ctxOCCI_)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, ctxOCCI_);
|
||||
return oracle::occi::PObject::operator new(size, ctxOCCI_);
|
||||
}
|
||||
|
||||
void *SDOPointType::operator new(size_t size,
|
||||
const oracle::occi::Connection *sess,
|
||||
const OCCI_STD_NAMESPACE::string &tableName,
|
||||
const OCCI_STD_NAMESPACE::string &typeName,
|
||||
const OCCI_STD_NAMESPACE::string &tableSchema,
|
||||
const OCCI_STD_NAMESPACE::string &typeSchema)
|
||||
const oracle::occi::Connection *sess,
|
||||
const OCCI_STD_NAMESPACE::string &tableName,
|
||||
const OCCI_STD_NAMESPACE::string &typeName,
|
||||
const OCCI_STD_NAMESPACE::string &tableSchema,
|
||||
const OCCI_STD_NAMESPACE::string &typeSchema)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, sess, tableName,
|
||||
typeName, tableSchema, typeSchema);
|
||||
return oracle::occi::PObject::operator new(size, sess, tableName,
|
||||
typeName, tableSchema, typeSchema);
|
||||
}
|
||||
|
||||
OCCI_STD_NAMESPACE::string SDOPointType::getSQLTypeName() const
|
||||
{
|
||||
return OCCI_STD_NAMESPACE::string("MDSYS.SDO_POINT_TYPE");
|
||||
return OCCI_STD_NAMESPACE::string("MDSYS.SDO_POINT_TYPE");
|
||||
}
|
||||
|
||||
void SDOPointType::getSQLTypeName(oracle::occi::Environment *env, void **schemaName,
|
||||
unsigned int &schemaNameLen, void **typeName, unsigned int &typeNameLen) const
|
||||
unsigned int &schemaNameLen, void **typeName, unsigned int &typeNameLen) const
|
||||
{
|
||||
PObject::getSQLTypeName(env, &SDOPointType::readSQL, schemaName,
|
||||
schemaNameLen, typeName, typeNameLen);
|
||||
PObject::getSQLTypeName(env, &SDOPointType::readSQL, schemaName,
|
||||
schemaNameLen, typeName, typeNameLen);
|
||||
}
|
||||
|
||||
SDOPointType::SDOPointType()
|
||||
|
@ -83,61 +83,61 @@ SDOPointType::SDOPointType()
|
|||
|
||||
void *SDOPointType::readSQL(void *ctxOCCI_)
|
||||
{
|
||||
SDOPointType *objOCCI_ = new(ctxOCCI_) SDOPointType(ctxOCCI_);
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
SDOPointType *objOCCI_ = new(ctxOCCI_) SDOPointType(ctxOCCI_);
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
|
||||
try
|
||||
{
|
||||
if (streamOCCI_.isNull())
|
||||
objOCCI_->setNull();
|
||||
else
|
||||
objOCCI_->readSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
delete objOCCI_;
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
return (void *)NULL;
|
||||
}
|
||||
return (void *)objOCCI_;
|
||||
try
|
||||
{
|
||||
if (streamOCCI_.isNull())
|
||||
objOCCI_->setNull();
|
||||
else
|
||||
objOCCI_->readSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
delete objOCCI_;
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
return (void *)NULL;
|
||||
}
|
||||
return (void *)objOCCI_;
|
||||
}
|
||||
|
||||
void SDOPointType::readSQL(oracle::occi::AnyData& streamOCCI_)
|
||||
{
|
||||
X = streamOCCI_.getNumber();
|
||||
Y = streamOCCI_.getNumber();
|
||||
Z = streamOCCI_.getNumber();
|
||||
X = streamOCCI_.getNumber();
|
||||
Y = streamOCCI_.getNumber();
|
||||
Z = streamOCCI_.getNumber();
|
||||
}
|
||||
|
||||
void SDOPointType::writeSQL(void *objectOCCI_, void *ctxOCCI_)
|
||||
{
|
||||
SDOPointType *objOCCI_ = (SDOPointType *) objectOCCI_;
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
SDOPointType *objOCCI_ = (SDOPointType *) objectOCCI_;
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
|
||||
try
|
||||
{
|
||||
if (objOCCI_->isNull())
|
||||
streamOCCI_.setNull();
|
||||
else
|
||||
objOCCI_->writeSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
}
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (objOCCI_->isNull())
|
||||
streamOCCI_.setNull();
|
||||
else
|
||||
objOCCI_->writeSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void SDOPointType::writeSQL(oracle::occi::AnyData& streamOCCI_)
|
||||
{
|
||||
streamOCCI_.setNumber(X);
|
||||
streamOCCI_.setNumber(Y);
|
||||
streamOCCI_.setNumber(Z);
|
||||
streamOCCI_.setNumber(X);
|
||||
streamOCCI_.setNumber(Y);
|
||||
streamOCCI_.setNumber(Z);
|
||||
}
|
||||
|
||||
SDOPointType::~SDOPointType()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
}
|
||||
|
||||
/*****************************************************************/
|
||||
|
@ -146,169 +146,169 @@ SDOPointType::~SDOPointType()
|
|||
|
||||
oracle::occi::Number SDOGeometry::getSdo_gtype() const
|
||||
{
|
||||
return SDO_GTYPE;
|
||||
return SDO_GTYPE;
|
||||
}
|
||||
|
||||
void SDOGeometry::setSdo_gtype(const oracle::occi::Number &value)
|
||||
{
|
||||
SDO_GTYPE = value;
|
||||
SDO_GTYPE = value;
|
||||
}
|
||||
|
||||
oracle::occi::Number SDOGeometry::getSdo_srid() const
|
||||
{
|
||||
return SDO_SRID;
|
||||
return SDO_SRID;
|
||||
}
|
||||
|
||||
void SDOGeometry::setSdo_srid(const oracle::occi::Number &value)
|
||||
{
|
||||
SDO_SRID = value;
|
||||
SDO_SRID = value;
|
||||
}
|
||||
|
||||
SDOPointType * SDOGeometry::getSdo_point() const
|
||||
{
|
||||
return SDO_POINT;
|
||||
return SDO_POINT;
|
||||
}
|
||||
|
||||
void SDOGeometry::setSdo_point(SDOPointType * value)
|
||||
{
|
||||
SDO_POINT = value;
|
||||
SDO_POINT = value;
|
||||
}
|
||||
|
||||
OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_elem_info()
|
||||
OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_elem_info()
|
||||
{
|
||||
return SDO_ELEM_INFO;
|
||||
return SDO_ELEM_INFO;
|
||||
}
|
||||
|
||||
const OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_elem_info() const
|
||||
{
|
||||
return SDO_ELEM_INFO;
|
||||
return SDO_ELEM_INFO;
|
||||
}
|
||||
|
||||
void SDOGeometry::setSdo_elem_info(const OCCI_STD_NAMESPACE::vector< oracle::occi::Number > &value)
|
||||
{
|
||||
SDO_ELEM_INFO = value;
|
||||
SDO_ELEM_INFO = value;
|
||||
}
|
||||
|
||||
OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_ordinates()
|
||||
OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_ordinates()
|
||||
{
|
||||
return SDO_ORDINATES;
|
||||
return SDO_ORDINATES;
|
||||
}
|
||||
|
||||
const OCCI_STD_NAMESPACE::vector< oracle::occi::Number >& SDOGeometry::getSdo_ordinates() const
|
||||
{
|
||||
return SDO_ORDINATES;
|
||||
return SDO_ORDINATES;
|
||||
}
|
||||
|
||||
void SDOGeometry::setSdo_ordinates(const OCCI_STD_NAMESPACE::vector< oracle::occi::Number > &value)
|
||||
{
|
||||
SDO_ORDINATES = value;
|
||||
SDO_ORDINATES = value;
|
||||
}
|
||||
|
||||
void *SDOGeometry::operator new(size_t size)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size);
|
||||
return oracle::occi::PObject::operator new(size);
|
||||
}
|
||||
|
||||
void *SDOGeometry::operator new(size_t size, const oracle::occi::Connection * sess,
|
||||
const OCCI_STD_NAMESPACE::string& table)
|
||||
const OCCI_STD_NAMESPACE::string& table)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, sess, table,
|
||||
(char *) "MDSYS.SDO_GEOMETRY");
|
||||
return oracle::occi::PObject::operator new(size, sess, table,
|
||||
(char *) "MDSYS.SDO_GEOMETRY");
|
||||
}
|
||||
|
||||
void *SDOGeometry::operator new(size_t size, void *ctxOCCI_)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, ctxOCCI_);
|
||||
return oracle::occi::PObject::operator new(size, ctxOCCI_);
|
||||
}
|
||||
|
||||
void *SDOGeometry::operator new(size_t size,
|
||||
const oracle::occi::Connection *sess,
|
||||
const OCCI_STD_NAMESPACE::string &tableName,
|
||||
const OCCI_STD_NAMESPACE::string &typeName,
|
||||
const OCCI_STD_NAMESPACE::string &tableSchema,
|
||||
const OCCI_STD_NAMESPACE::string &typeSchema)
|
||||
const oracle::occi::Connection *sess,
|
||||
const OCCI_STD_NAMESPACE::string &tableName,
|
||||
const OCCI_STD_NAMESPACE::string &typeName,
|
||||
const OCCI_STD_NAMESPACE::string &tableSchema,
|
||||
const OCCI_STD_NAMESPACE::string &typeSchema)
|
||||
{
|
||||
return oracle::occi::PObject::operator new(size, sess, tableName,
|
||||
typeName, tableSchema, typeSchema);
|
||||
return oracle::occi::PObject::operator new(size, sess, tableName,
|
||||
typeName, tableSchema, typeSchema);
|
||||
}
|
||||
|
||||
OCCI_STD_NAMESPACE::string SDOGeometry::getSQLTypeName() const
|
||||
{
|
||||
return OCCI_STD_NAMESPACE::string("MDSYS.SDO_GEOMETRY");
|
||||
return OCCI_STD_NAMESPACE::string("MDSYS.SDO_GEOMETRY");
|
||||
}
|
||||
|
||||
void SDOGeometry::getSQLTypeName(oracle::occi::Environment *env, void **schemaName,
|
||||
unsigned int &schemaNameLen, void **typeName, unsigned int &typeNameLen) const
|
||||
unsigned int &schemaNameLen, void **typeName, unsigned int &typeNameLen) const
|
||||
{
|
||||
PObject::getSQLTypeName(env, &SDOGeometry::readSQL, schemaName,
|
||||
schemaNameLen, typeName, typeNameLen);
|
||||
PObject::getSQLTypeName(env, &SDOGeometry::readSQL, schemaName,
|
||||
schemaNameLen, typeName, typeNameLen);
|
||||
}
|
||||
|
||||
SDOGeometry::SDOGeometry()
|
||||
{
|
||||
SDO_POINT = (SDOPointType *) 0;
|
||||
SDO_POINT = (SDOPointType *) 0;
|
||||
}
|
||||
|
||||
void *SDOGeometry::readSQL(void *ctxOCCI_)
|
||||
{
|
||||
SDOGeometry *objOCCI_ = new(ctxOCCI_) SDOGeometry(ctxOCCI_);
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
SDOGeometry *objOCCI_ = new(ctxOCCI_) SDOGeometry(ctxOCCI_);
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
|
||||
try
|
||||
{
|
||||
if (streamOCCI_.isNull())
|
||||
objOCCI_->setNull();
|
||||
else
|
||||
objOCCI_->readSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
delete objOCCI_;
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
return (void *)NULL;
|
||||
}
|
||||
return (void *)objOCCI_;
|
||||
try
|
||||
{
|
||||
if (streamOCCI_.isNull())
|
||||
objOCCI_->setNull();
|
||||
else
|
||||
objOCCI_->readSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
delete objOCCI_;
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
return (void *)NULL;
|
||||
}
|
||||
return (void *)objOCCI_;
|
||||
}
|
||||
|
||||
void SDOGeometry::readSQL(oracle::occi::AnyData& streamOCCI_)
|
||||
{
|
||||
SDO_GTYPE = streamOCCI_.getNumber();
|
||||
SDO_SRID = streamOCCI_.getNumber();
|
||||
SDO_POINT = (SDOPointType *) streamOCCI_.getObject(&SDOPointType::readSQL);
|
||||
oracle::occi::getVector(streamOCCI_, SDO_ELEM_INFO);
|
||||
oracle::occi::getVector(streamOCCI_, SDO_ORDINATES);
|
||||
SDO_GTYPE = streamOCCI_.getNumber();
|
||||
SDO_SRID = streamOCCI_.getNumber();
|
||||
SDO_POINT = (SDOPointType *) streamOCCI_.getObject(&SDOPointType::readSQL);
|
||||
oracle::occi::getVector(streamOCCI_, SDO_ELEM_INFO);
|
||||
oracle::occi::getVector(streamOCCI_, SDO_ORDINATES);
|
||||
}
|
||||
|
||||
void SDOGeometry::writeSQL(void *objectOCCI_, void *ctxOCCI_)
|
||||
{
|
||||
SDOGeometry *objOCCI_ = (SDOGeometry *) objectOCCI_;
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
SDOGeometry *objOCCI_ = (SDOGeometry *) objectOCCI_;
|
||||
oracle::occi::AnyData streamOCCI_(ctxOCCI_);
|
||||
|
||||
try
|
||||
{
|
||||
if (objOCCI_->isNull())
|
||||
streamOCCI_.setNull();
|
||||
else
|
||||
objOCCI_->writeSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
}
|
||||
return;
|
||||
try
|
||||
{
|
||||
if (objOCCI_->isNull())
|
||||
streamOCCI_.setNull();
|
||||
else
|
||||
objOCCI_->writeSQL(streamOCCI_);
|
||||
}
|
||||
catch (oracle::occi::SQLException& excep)
|
||||
{
|
||||
excep.setErrorCtx(ctxOCCI_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void SDOGeometry::writeSQL(oracle::occi::AnyData& streamOCCI_)
|
||||
{
|
||||
streamOCCI_.setNumber(SDO_GTYPE);
|
||||
streamOCCI_.setNumber(SDO_SRID);
|
||||
streamOCCI_.setObject(SDO_POINT);
|
||||
oracle::occi::setVector(streamOCCI_, SDO_ELEM_INFO);
|
||||
oracle::occi::setVector(streamOCCI_, SDO_ORDINATES);
|
||||
streamOCCI_.setNumber(SDO_GTYPE);
|
||||
streamOCCI_.setNumber(SDO_SRID);
|
||||
streamOCCI_.setObject(SDO_POINT);
|
||||
oracle::occi::setVector(streamOCCI_, SDO_ELEM_INFO);
|
||||
oracle::occi::setVector(streamOCCI_, SDO_ORDINATES);
|
||||
}
|
||||
|
||||
SDOGeometry::~SDOGeometry()
|
||||
{
|
||||
int i;
|
||||
delete SDO_POINT;
|
||||
int i;
|
||||
delete SDO_POINT;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -129,7 +129,7 @@ void ogr_converter::convert_polygon(OGRPolygon* geom, feature_ptr feature)
|
|||
{
|
||||
OGRLinearRing* interior = geom->getInteriorRing(r);
|
||||
capacity += interior->getNumPoints();
|
||||
}
|
||||
}
|
||||
geometry_type* poly = new geometry_type(mapnik::Polygon);
|
||||
poly->set_capacity(num_points + capacity);
|
||||
poly->move_to(exterior->getX(0), exterior->getY(0));
|
||||
|
@ -154,14 +154,14 @@ void ogr_converter::convert_multipoint(OGRMultiPoint* geom, feature_ptr feature)
|
|||
{
|
||||
int num_geometries = geom->getNumGeometries();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
|
||||
|
||||
for (int i = 0; i < num_geometries; i++)
|
||||
{
|
||||
OGRPoint* ogrpoint = static_cast<OGRPoint*>(geom->getGeometryRef(i));
|
||||
point->move_to(ogrpoint->getX(), ogrpoint->getY());
|
||||
//Todo - need to accept multiple points per mapnik::Point
|
||||
}
|
||||
|
||||
|
||||
// Todo - this only gets last point
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ void ogr_converter::convert_multilinestring(OGRMultiLineString* geom, feature_pt
|
|||
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
line->set_capacity(num_points);
|
||||
|
||||
|
||||
for (int i = 0; i < num_geometries; i++)
|
||||
{
|
||||
OGRLineString* ls = static_cast<OGRLineString*>(geom->getGeometryRef(i));
|
||||
|
@ -226,7 +226,7 @@ void ogr_converter::convert_multipolygon(OGRMultiPolygon* geom, feature_ptr feat
|
|||
{
|
||||
OGRLinearRing* interior = p->getInteriorRing(r);
|
||||
capacity += interior->getNumPoints();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
geometry_type* poly = new geometry_type(mapnik::Polygon);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
// ogr
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
|
||||
class ogr_converter
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -53,11 +53,11 @@ using mapnik::filter_at_point;
|
|||
|
||||
|
||||
ogr_datasource::ogr_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
|
||||
indexed_(false)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8")),
|
||||
indexed_(false)
|
||||
{
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
boost::optional<std::string> string = params.get<std::string>("string");
|
||||
|
@ -70,7 +70,7 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
|
|||
|
||||
if (string)
|
||||
{
|
||||
dataset_name_ = *string;
|
||||
dataset_name_ = *string;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -93,7 +93,7 @@ ogr_datasource::ogr_datasource(parameters const& params, bool bind)
|
|||
|
||||
ogr_datasource::~ogr_datasource()
|
||||
{
|
||||
if (is_bound_)
|
||||
if (is_bound_)
|
||||
{
|
||||
// free layer before destroying the datasource
|
||||
layer_.free_layer();
|
||||
|
@ -108,7 +108,7 @@ void ogr_datasource::bind() const
|
|||
|
||||
// initialize ogr formats
|
||||
OGRRegisterAll();
|
||||
|
||||
|
||||
std::string driver = *params_.get<std::string>("driver","");
|
||||
|
||||
if (! driver.empty())
|
||||
|
@ -118,7 +118,7 @@ void ogr_datasource::bind() const
|
|||
{
|
||||
dataset_ = ogr_driver->Open((dataset_name_).c_str(), FALSE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -261,9 +261,9 @@ void ogr_datasource::bind() const
|
|||
// TODO - enable this warning once the ogrindex tool is a bit more stable/mature
|
||||
else
|
||||
{
|
||||
std::clog << "### Notice: no ogrindex file found for " << dataset_name_
|
||||
<< ", use the 'ogrindex' program to build an index for faster rendering"
|
||||
<< std::endl;
|
||||
std::clog << "### Notice: no ogrindex file found for " << dataset_name_
|
||||
<< ", use the 'ogrindex' program to build an index for faster rendering"
|
||||
<< std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -353,7 +353,7 @@ layer_descriptor ogr_datasource::get_descriptor() const
|
|||
featureset_ptr ogr_datasource::features(query const& q) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
if (dataset_ && layer_.is_valid())
|
||||
{
|
||||
OGRLayer* layer = layer_.layer();
|
||||
|
@ -361,7 +361,7 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
if (indexed_)
|
||||
{
|
||||
filter_in_box filter(q.get_bbox());
|
||||
|
||||
|
||||
return featureset_ptr(new ogr_index_featureset<filter_in_box>(*dataset_,
|
||||
*layer,
|
||||
filter,
|
||||
|
@ -385,7 +385,7 @@ featureset_ptr ogr_datasource::features(query const& q) const
|
|||
featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
if (dataset_ && layer_.is_valid())
|
||||
{
|
||||
OGRLayer* layer = layer_.layer();
|
||||
|
@ -393,7 +393,7 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt) const
|
|||
if (indexed_)
|
||||
{
|
||||
filter_at_point filter(pt);
|
||||
|
||||
|
||||
return featureset_ptr(new ogr_index_featureset<filter_at_point> (*dataset_,
|
||||
*layer,
|
||||
filter,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "ogr_layer_ptr.hpp"
|
||||
|
||||
class ogr_datasource : public mapnik::datasource
|
||||
class ogr_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
ogr_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
// ogr
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
|
||||
class ogr_feature_ptr
|
||||
{
|
||||
public:
|
||||
|
@ -33,7 +33,7 @@ public:
|
|||
: feat_(feat)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
~ogr_feature_ptr()
|
||||
{
|
||||
if (feat_ != NULL)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -51,13 +51,13 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
|||
OGRGeometry & extent,
|
||||
const std::string& encoding,
|
||||
const bool multiple_geometries)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn ()),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
count_(0)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn ()),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
count_(0)
|
||||
{
|
||||
layer_.SetSpatialFilter (&extent);
|
||||
}
|
||||
|
@ -67,13 +67,13 @@ ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
|||
const mapnik::box2d<double> & extent,
|
||||
const std::string& encoding,
|
||||
const bool multiple_geometries)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn()),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
count_(0)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn()),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
count_(0)
|
||||
{
|
||||
layer_.SetSpatialFilterRect (extent.minx(),
|
||||
extent.miny(),
|
||||
|
@ -95,7 +95,7 @@ feature_ptr ogr_featureset::next()
|
|||
// consistent with other mapnik datasources that start at 1
|
||||
const int feature_id = ((*feat)->GetFID() + 1);
|
||||
feature_ptr feature(feature_factory::create(feature_id));
|
||||
|
||||
|
||||
OGRGeometry* geom = (*feat)->GetGeometryRef();
|
||||
if (geom && ! geom->IsEmpty())
|
||||
{
|
||||
|
@ -109,80 +109,80 @@ feature_ptr ogr_featureset::next()
|
|||
}
|
||||
#endif
|
||||
++count_;
|
||||
|
||||
|
||||
int fld_count = layerdef_->GetFieldCount();
|
||||
for (int i = 0; i < fld_count; i++)
|
||||
{
|
||||
OGRFieldDefn* fld = layerdef_->GetFieldDefn(i);
|
||||
const OGRFieldType type_oid = fld->GetType();
|
||||
const std::string fld_name = fld->GetNameRef();
|
||||
|
||||
|
||||
switch (type_oid)
|
||||
{
|
||||
case OFTInteger:
|
||||
{
|
||||
boost::put(*feature, fld_name, (*feat)->GetFieldAsInteger(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTReal:
|
||||
{
|
||||
boost::put(*feature, fld_name, (*feat)->GetFieldAsDouble(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTString:
|
||||
case OFTWideString: // deprecated !
|
||||
{
|
||||
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString(i));
|
||||
boost::put(*feature, fld_name, ustr);
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
case OFTWideStringList: // deprecated !
|
||||
{
|
||||
case OFTInteger:
|
||||
{
|
||||
boost::put(*feature, fld_name, (*feat)->GetFieldAsInteger(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTReal:
|
||||
{
|
||||
boost::put(*feature, fld_name, (*feat)->GetFieldAsDouble(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTString:
|
||||
case OFTWideString: // deprecated !
|
||||
{
|
||||
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString(i));
|
||||
boost::put(*feature, fld_name, ustr);
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
case OFTWideStringList: // deprecated !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTBinary:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTBinary:
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
{
|
||||
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: // unknown
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default: // unknown
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: " << count_ << " features" << std::endl;
|
||||
std::clog << "OGR Plugin: " << count_ << " features" << std::endl;
|
||||
#endif
|
||||
return feature_ptr();
|
||||
return feature_ptr();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/geom_util.hpp>
|
||||
|
||||
// boost
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
// ogr
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
|
||||
class ogr_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -70,7 +70,7 @@ void ogr_index<filterT,IStream>::query_node(const filterT& filter, IStream& file
|
|||
file.seekg(offset + num_shapes * 4 + 4, std::ios::cur);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < num_shapes; ++i)
|
||||
{
|
||||
const int id = read_ndr_integer(file);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -58,31 +58,31 @@ ogr_index_featureset<filterT>::ogr_index_featureset(OGRDataSource & dataset,
|
|||
const std::string& index_file,
|
||||
const std::string& encoding,
|
||||
const bool multiple_geometries)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
filter_(filter),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn()),
|
||||
multiple_geometries_(multiple_geometries)
|
||||
: dataset_(dataset),
|
||||
layer_(layer),
|
||||
layerdef_(layer.GetLayerDefn()),
|
||||
filter_(filter),
|
||||
tr_(new transcoder(encoding)),
|
||||
fidcolumn_(layer_.GetFIDColumn()),
|
||||
multiple_geometries_(multiple_geometries)
|
||||
{
|
||||
|
||||
|
||||
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::find(index_file.c_str(),true);
|
||||
if (memory)
|
||||
{
|
||||
boost::interprocess::ibufferstream file(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
|
||||
boost::interprocess::ibufferstream file(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
|
||||
ogr_index<filterT,boost::interprocess::ibufferstream >::query(filter,file,ids_);
|
||||
}
|
||||
|
||||
std::sort(ids_.begin(),ids_.end());
|
||||
|
||||
|
||||
std::sort(ids_.begin(),ids_.end());
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: query size=" << ids_.size() << std::endl;
|
||||
#endif
|
||||
|
||||
itr_ = ids_.begin();
|
||||
|
||||
// reset reading
|
||||
// reset reading
|
||||
layer_.ResetReading();
|
||||
}
|
||||
|
||||
|
@ -104,91 +104,91 @@ feature_ptr ogr_index_featureset<filterT>::next()
|
|||
// consistent with other mapnik datasources that start at 1
|
||||
int feature_id = ((*feat)->GetFID() + 1);
|
||||
feature_ptr feature(feature_factory::create(feature_id));
|
||||
|
||||
|
||||
OGRGeometry* geom=(*feat)->GetGeometryRef();
|
||||
if (geom && !geom->IsEmpty())
|
||||
{
|
||||
ogr_converter::convert_geometry (geom, feature, multiple_geometries_);
|
||||
}
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
else
|
||||
{
|
||||
std::clog << "### Warning: feature with null geometry: " << (*feat)->GetFID() << "\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
int fld_count = layerdef_->GetFieldCount();
|
||||
for (int i = 0; i < fld_count; i++)
|
||||
{
|
||||
OGRFieldDefn* fld = layerdef_->GetFieldDefn (i);
|
||||
OGRFieldType type_oid = fld->GetType ();
|
||||
std::string fld_name = fld->GetNameRef ();
|
||||
|
||||
|
||||
switch (type_oid)
|
||||
{
|
||||
case OFTInteger:
|
||||
{
|
||||
boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTReal:
|
||||
{
|
||||
boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTString:
|
||||
case OFTWideString: // deprecated !
|
||||
{
|
||||
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i));
|
||||
boost::put(*feature,fld_name,ustr);
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
case OFTWideStringList: // deprecated !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTBinary:
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: // unknown
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case OFTInteger:
|
||||
{
|
||||
boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTReal:
|
||||
{
|
||||
boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTString:
|
||||
case OFTWideString: // deprecated !
|
||||
{
|
||||
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i));
|
||||
boost::put(*feature,fld_name,ustr);
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTIntegerList:
|
||||
case OFTRealList:
|
||||
case OFTStringList:
|
||||
case OFTWideStringList: // deprecated !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTBinary:
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
||||
break;
|
||||
}
|
||||
|
||||
case OFTDate:
|
||||
case OFTTime:
|
||||
case OFTDateTime: // unhandled !
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
default: // unknown
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "OGR Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -30,15 +30,15 @@
|
|||
|
||||
// ogr
|
||||
#include <ogrsf_frmts.h>
|
||||
|
||||
|
||||
class ogr_layer_ptr
|
||||
{
|
||||
public:
|
||||
ogr_layer_ptr()
|
||||
: datasource_(NULL),
|
||||
layer_(NULL),
|
||||
owns_layer_(false),
|
||||
is_valid_(false)
|
||||
: datasource_(NULL),
|
||||
layer_(NULL),
|
||||
owns_layer_(false),
|
||||
is_valid_(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ CURL_LOAD_DATA* do_grab(CURL* curl,const char* url)
|
|||
CURL_LOAD_DATA* data = (CURL_LOAD_DATA*)malloc(sizeof(CURL_LOAD_DATA));
|
||||
data->data = NULL;
|
||||
data->nbytes = 0;
|
||||
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, response_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
|
||||
|
|
|
@ -65,7 +65,7 @@ osm_dataset* dataset_deliverer::load_from_url(const string& url, const string& b
|
|||
}
|
||||
|
||||
atexit(dataset_deliverer::release);
|
||||
last_bbox = bbox;
|
||||
last_bbox = bbox;
|
||||
}
|
||||
else if (bbox != last_bbox)
|
||||
{
|
||||
|
|
|
@ -19,70 +19,70 @@ void MapSource::process_cmd_line_args(int argc,char *argv[])
|
|||
{
|
||||
switch(argv[0][1])
|
||||
{
|
||||
case 's': setSource(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 's': setSource(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'w': width=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'h': height=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'w': width=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'x': xmlfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'h': height=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'i': osmfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'x': xmlfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'b': bbox=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'i': osmfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'z': zoom_start=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'b': bbox=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'Z': zoom_end=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'z': zoom_start=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 't': tiled=true;
|
||||
argv+=1;
|
||||
argc-=1;
|
||||
break;
|
||||
case 'Z': zoom_end=atoi(argv[1]);
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'm': multirqst=true;
|
||||
argv+=1;
|
||||
argc-=1;
|
||||
break;
|
||||
case 't': tiled=true;
|
||||
argv+=1;
|
||||
argc-=1;
|
||||
break;
|
||||
|
||||
case 'u': url=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'o': outfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
case 'm': multirqst=true;
|
||||
argv+=1;
|
||||
argc-=1;
|
||||
break;
|
||||
|
||||
case 'r': srtm=true;
|
||||
argv++;
|
||||
argc--;
|
||||
break;
|
||||
case 'u': url=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'o': outfile=argv[1];
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
break;
|
||||
|
||||
case 'r': srtm=true;
|
||||
argv++;
|
||||
argc--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -90,7 +90,7 @@ void MapSource::process_cmd_line_args(int argc,char *argv[])
|
|||
argv++;
|
||||
argc--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(bbox!="")
|
||||
|
@ -125,30 +125,30 @@ void MapSource::generateMaps()
|
|||
if(tiled)
|
||||
{
|
||||
ScreenPos topLeft = (proj.fromLLToPixel(w,n,zoom_start)) ,
|
||||
bottomRight = (proj.fromLLToPixel(e,s,zoom_start)) ;
|
||||
bottomRight = (proj.fromLLToPixel(e,s,zoom_start)) ;
|
||||
|
||||
topLeft.x /= 256;
|
||||
topLeft.y /= 256;
|
||||
bottomRight.x /= 256;
|
||||
bottomRight.y /= 256;
|
||||
|
||||
int x_fetch_freq, y_fetch_freq, x_fetches, y_fetches;
|
||||
int x_fetch_freq, y_fetch_freq, x_fetches, y_fetches;
|
||||
|
||||
if(multirqst)
|
||||
{
|
||||
// Gives a value approx equal to 0.1 lat/lon in southern UK
|
||||
x_fetch_freq = (int)(pow(2.0,zoom_start-11));
|
||||
y_fetch_freq = (int)(pow(2.0,zoom_start-11));
|
||||
x_fetches = ((bottomRight.x-topLeft.x) / x_fetch_freq)+1,
|
||||
y_fetches = ((bottomRight.y-topLeft.y) / y_fetch_freq)+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_fetch_freq = bottomRight.x - topLeft.x;
|
||||
y_fetch_freq = bottomRight.y - topLeft.y;
|
||||
x_fetches = 1;
|
||||
y_fetches = 1;
|
||||
}
|
||||
if(multirqst)
|
||||
{
|
||||
// Gives a value approx equal to 0.1 lat/lon in southern UK
|
||||
x_fetch_freq = (int)(pow(2.0,zoom_start-11));
|
||||
y_fetch_freq = (int)(pow(2.0,zoom_start-11));
|
||||
x_fetches = ((bottomRight.x-topLeft.x) / x_fetch_freq)+1,
|
||||
y_fetches = ((bottomRight.y-topLeft.y) / y_fetch_freq)+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_fetch_freq = bottomRight.x - topLeft.x;
|
||||
y_fetch_freq = bottomRight.y - topLeft.y;
|
||||
x_fetches = 1;
|
||||
y_fetches = 1;
|
||||
}
|
||||
|
||||
fprintf(stderr,"topLeft: %d %d\n",topLeft.x,topLeft.y);
|
||||
fprintf(stderr,"bottomRight: %d %d\n",bottomRight.x,bottomRight.y);
|
||||
|
@ -156,33 +156,33 @@ void MapSource::generateMaps()
|
|||
|
||||
for(int xfetch=0; xfetch<x_fetches; xfetch++)
|
||||
{
|
||||
for (int yfetch=0; yfetch<y_fetches; yfetch++)
|
||||
for (int yfetch=0; yfetch<y_fetches; yfetch++)
|
||||
{
|
||||
cerr<<"XFETCH="<<xfetch<<" YFETCH="<<yfetch<<endl;
|
||||
EarthPoint bottomL_LL =
|
||||
proj.fromPixelToLL( (topLeft.x+xfetch*x_fetch_freq)*256,
|
||||
((topLeft.y+yfetch*y_fetch_freq)
|
||||
+y_fetch_freq)*256, zoom_start),
|
||||
topR_LL =
|
||||
((topLeft.y+yfetch*y_fetch_freq)
|
||||
+y_fetch_freq)*256, zoom_start),
|
||||
topR_LL =
|
||||
proj.fromPixelToLL( (
|
||||
(topLeft.x+xfetch*x_fetch_freq)+x_fetch_freq)*256,
|
||||
(topLeft.x+xfetch*x_fetch_freq)+x_fetch_freq)*256,
|
||||
(topLeft.y+yfetch*y_fetch_freq)
|
||||
*256, zoom_start),
|
||||
bottomR_LL =
|
||||
*256, zoom_start),
|
||||
bottomR_LL =
|
||||
proj.fromPixelToLL( ((topLeft.x+xfetch*x_fetch_freq)+
|
||||
x_fetch_freq)*256,
|
||||
((topLeft.y+yfetch*y_fetch_freq)
|
||||
+y_fetch_freq)*256, zoom_start),
|
||||
topL_LL =
|
||||
proj.fromPixelToLL(
|
||||
(topLeft.x+xfetch*x_fetch_freq)*256,
|
||||
(topLeft.y+yfetch*y_fetch_freq)
|
||||
*256, zoom_start);
|
||||
x_fetch_freq)*256,
|
||||
((topLeft.y+yfetch*y_fetch_freq)
|
||||
+y_fetch_freq)*256, zoom_start),
|
||||
topL_LL =
|
||||
proj.fromPixelToLL(
|
||||
(topLeft.x+xfetch*x_fetch_freq)*256,
|
||||
(topLeft.y+yfetch*y_fetch_freq)
|
||||
*256, zoom_start);
|
||||
|
||||
double w1 = min(bottomL_LL.x-0.01,topL_LL.x-0.01),
|
||||
s1 = min(bottomL_LL.y-0.01,bottomR_LL.y-0.01),
|
||||
e1 = max(bottomR_LL.x+0.01,topR_LL.x+0.01),
|
||||
n1 = max(topL_LL.y+0.01,topR_LL.y+0.01);
|
||||
double w1 = min(bottomL_LL.x-0.01,topL_LL.x-0.01),
|
||||
s1 = min(bottomL_LL.y-0.01,bottomR_LL.y-0.01),
|
||||
e1 = max(bottomR_LL.x+0.01,topR_LL.x+0.01),
|
||||
n1 = max(topL_LL.y+0.01,topR_LL.y+0.01);
|
||||
|
||||
parameters p;
|
||||
if(getSource()=="api")
|
||||
|
@ -199,7 +199,7 @@ void MapSource::generateMaps()
|
|||
{
|
||||
p["file"] = osmfile;
|
||||
}
|
||||
|
||||
|
||||
Map m (width, height);
|
||||
p["type"] ="osm";
|
||||
load_map(m,xmlfile);
|
||||
|
@ -211,14 +211,14 @@ void MapSource::generateMaps()
|
|||
|
||||
// lonToX() and latToY() give *pixel* coordinates
|
||||
|
||||
// See email Chris Schmidt 12/02/09
|
||||
// See email Chris Schmidt 12/02/09
|
||||
double metres_per_pixel = (20037508.34/pow(2.0,
|
||||
7+zoom_start));
|
||||
7+zoom_start));
|
||||
|
||||
for(int z=zoom_start; z<=zoom_end; z++)
|
||||
{
|
||||
EarthPoint bl,tr;
|
||||
|
||||
|
||||
int ZOOM_FCTR = (int)(pow(2.0,z-zoom_start));
|
||||
for(int tileX=
|
||||
(topLeft.x+xfetch*x_fetch_freq)*ZOOM_FCTR;
|
||||
|
@ -228,39 +228,39 @@ void MapSource::generateMaps()
|
|||
tileX++)
|
||||
{
|
||||
for(int tileY=(topLeft.y+yfetch*y_fetch_freq)
|
||||
*ZOOM_FCTR;
|
||||
*ZOOM_FCTR;
|
||||
tileY<(topLeft.y+yfetch*y_fetch_freq+y_fetch_freq)
|
||||
*ZOOM_FCTR;
|
||||
*ZOOM_FCTR;
|
||||
tileY++)
|
||||
{
|
||||
cerr<<"x: " << tileX << " y: " << tileY
|
||||
<<" z: " << z << endl;
|
||||
|
||||
image_32 buf(m.width(),m.height());
|
||||
double metres_w =( (tileX*256.0) *
|
||||
metres_per_pixel ) -
|
||||
image_32 buf(m.width(),m.height());
|
||||
double metres_w =( (tileX*256.0) *
|
||||
metres_per_pixel ) -
|
||||
20037814.088;
|
||||
double metres_s = 20034756.658 -
|
||||
((tileY*256.0) * metres_per_pixel );
|
||||
|
||||
double metres_e = metres_w + (metres_per_pixel*256);
|
||||
double metres_n = metres_s + (metres_per_pixel*256);
|
||||
|
||||
box2d<double> bb
|
||||
(metres_w-32*metres_per_pixel,
|
||||
metres_s-32*metres_per_pixel,
|
||||
metres_e+32*metres_per_pixel,
|
||||
metres_n+32*metres_per_pixel);
|
||||
double metres_s = 20034756.658 -
|
||||
((tileY*256.0) * metres_per_pixel );
|
||||
|
||||
m.zoom_to_box(bb);
|
||||
agg_renderer<image_32> r(m,buf);
|
||||
r.apply();
|
||||
|
||||
string filename="";
|
||||
std::ostringstream str;
|
||||
str<< z<< "."<<tileX<<"." << tileY << ".png";
|
||||
save_to_file<image_data_32>(buf.data(),
|
||||
"tmp.png","png");
|
||||
double metres_e = metres_w + (metres_per_pixel*256);
|
||||
double metres_n = metres_s + (metres_per_pixel*256);
|
||||
|
||||
box2d<double> bb
|
||||
(metres_w-32*metres_per_pixel,
|
||||
metres_s-32*metres_per_pixel,
|
||||
metres_e+32*metres_per_pixel,
|
||||
metres_n+32*metres_per_pixel);
|
||||
|
||||
m.zoom_to_box(bb);
|
||||
agg_renderer<image_32> r(m,buf);
|
||||
r.apply();
|
||||
|
||||
string filename="";
|
||||
std::ostringstream str;
|
||||
str<< z<< "."<<tileX<<"." << tileY << ".png";
|
||||
save_to_file<image_data_32>(buf.data(),
|
||||
"tmp.png","png");
|
||||
FILE *in=fopen("tmp.png","r");
|
||||
FILE *out=fopen(str.str().c_str(),"w");
|
||||
|
||||
|
@ -291,17 +291,17 @@ void MapSource::generateMaps()
|
|||
setOSMLayers(m,p);
|
||||
|
||||
box2d<double> latlon=
|
||||
(hasBbox()) ?
|
||||
(hasBbox()) ?
|
||||
box2d<double>(w,s,e,n):
|
||||
m.getLayer(0).envelope();
|
||||
|
||||
EarthPoint bottomL_LL =
|
||||
|
||||
EarthPoint bottomL_LL =
|
||||
GoogleProjection::fromLLToGoog(latlon.minx(),latlon.miny()),
|
||||
topR_LL =
|
||||
topR_LL =
|
||||
GoogleProjection::fromLLToGoog(latlon.maxx(),latlon.maxy());
|
||||
box2d<double> bb =
|
||||
box2d<double>(bottomL_LL.x,bottomL_LL.y,
|
||||
topR_LL.x,topR_LL.y);
|
||||
box2d<double>(bottomL_LL.x,bottomL_LL.y,
|
||||
topR_LL.x,topR_LL.y);
|
||||
m.zoom_to_box(bb);
|
||||
image_32 buf (m.width(), m.height());
|
||||
agg_renderer<image_32> r(m,buf);
|
||||
|
@ -320,7 +320,7 @@ void MapSource::setOSMLayers(Map& m, const parameters &p)
|
|||
if(boost::get<std::string>(q["type"])=="osm")
|
||||
{
|
||||
m.getLayer(count).set_datasource
|
||||
(datasource_cache::instance()->create(p));
|
||||
(datasource_cache::instance()->create(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -343,14 +343,14 @@ void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n)
|
|||
|
||||
// Set the specific latlon shapefile for the first SRTM layer
|
||||
|
||||
parameters p;
|
||||
parameters p;
|
||||
p["type"] = "shape";
|
||||
std::stringstream str;
|
||||
int lon=floor(w),lat=floor(s);
|
||||
str<<(lat<0 ? "S":"N")<<setw(2)<<setfill('0')<<
|
||||
(lat<0 ? -lat:lat)<<
|
||||
(lon>=0 ? "E":"W") << setw(3)<<setfill('0')
|
||||
<<(lon>=0 ? lon:-lon)<<"c10";
|
||||
(lat<0 ? -lat:lat)<<
|
||||
(lon>=0 ? "E":"W") << setw(3)<<setfill('0')
|
||||
<<(lon>=0 ? lon:-lon)<<"c10";
|
||||
p["file"] = str.str();
|
||||
cerr<<"ADDING SRTM LAYER: " << p["file"] << endl;
|
||||
m.getLayer(i).set_datasource(datasource_cache::instance()->create(p));
|
||||
|
@ -372,13 +372,13 @@ void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n)
|
|||
// SRTM layer for it
|
||||
if(lon!=floor(w) || lat!=floor(s))
|
||||
{
|
||||
parameters p;
|
||||
parameters p;
|
||||
p["type"] = "shape";
|
||||
std::stringstream str;
|
||||
str<<(lat<0 ? "S":"N")<<setw(2)<<setfill('0')<<
|
||||
(lat<0 ? -lat:lat)<<
|
||||
(lon>=0 ? "E":"W") << setw(3)<<setfill('0')
|
||||
<<(lon>=0 ? lon:-lon)<<"c10";
|
||||
<<(lon>=0 ? lon:-lon)<<"c10";
|
||||
p["file"] = str.str();
|
||||
cerr<<"ADDING SRTM LAYER: " << p["file"] << endl;
|
||||
layer lyr("srtm_" + str.str());
|
||||
|
|
|
@ -22,7 +22,7 @@ int main(int argc,char *argv[])
|
|||
}
|
||||
|
||||
|
||||
MapSource s ;
|
||||
MapSource s ;
|
||||
s.process_cmd_line_args(argc,argv);
|
||||
|
||||
if(!s.isValid())
|
||||
|
@ -49,25 +49,25 @@ void usage()
|
|||
{
|
||||
cerr << "Usage: easymapnik -s source [-w width] [-h height] -x xmlfile "
|
||||
<< endl <<
|
||||
"[-i InOSMFile] [-o OutPNGFile] [-t] [-z startzoom] [-Z endzoom] "
|
||||
"[-i InOSMFile] [-o OutPNGFile] [-t] [-z startzoom] [-Z endzoom] "
|
||||
<< endl <<
|
||||
"[-b bbox] [-u serverURL] [-m]" << endl << endl;
|
||||
"[-b bbox] [-u serverURL] [-m]" << endl << endl;
|
||||
}
|
||||
|
||||
|
||||
void help()
|
||||
{
|
||||
cerr << "Source should be 'osm' or 'api', indicating OSM files and "
|
||||
<< endl << "retrieval direct from a server (e.g. OSMXAPI) respectively."
|
||||
<< endl <<
|
||||
cerr << "Source should be 'osm' or 'api', indicating OSM files and "
|
||||
<< endl << "retrieval direct from a server (e.g. OSMXAPI) respectively."
|
||||
<< endl <<
|
||||
"-t indicates tiled mode (generate 'Google' style tiles); you must "
|
||||
<< endl <<
|
||||
"supply at least a start zoom, and a bounding box, for this."
|
||||
<< endl <<
|
||||
"-m means 'multirequest'; if you're requesting a relatively large "
|
||||
<< endl <<
|
||||
"area from the server (e.g. OSMXAPI), it will fetch it in "
|
||||
<< "0.1x0.1 degree tiles. "
|
||||
<< endl << "This speeds up processing considerably." << endl;
|
||||
<< endl <<
|
||||
"supply at least a start zoom, and a bounding box, for this."
|
||||
<< endl <<
|
||||
"-m means 'multirequest'; if you're requesting a relatively large "
|
||||
<< endl <<
|
||||
"area from the server (e.g. OSMXAPI), it will fetch it in "
|
||||
<< "0.1x0.1 degree tiles. "
|
||||
<< endl << "This speeds up processing considerably." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ bool osm_dataset::load(const char* filename,const std::string& parser)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool osm_dataset::load_from_url(const std::string& url,
|
||||
bool osm_dataset::load_from_url(const std::string& url,
|
||||
const std::string& bbox,
|
||||
const std::string& parser)
|
||||
{
|
||||
|
@ -168,7 +168,7 @@ osm_way* osm_dataset::next_way()
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
osm_item* osm_dataset::next_item()
|
||||
{
|
||||
osm_item* item = NULL;
|
||||
|
@ -188,7 +188,7 @@ osm_item* osm_dataset::next_item()
|
|||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
std::set<std::string> osm_dataset::get_keys()
|
||||
{
|
||||
std::set<std::string> keys;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -50,7 +50,7 @@ using mapnik::attribute_descriptor;
|
|||
DATASOURCE_PLUGIN(osm_datasource)
|
||||
|
||||
osm_datasource::osm_datasource(const parameters& params, bool bind)
|
||||
: datasource (params),
|
||||
: datasource (params),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding", "utf-8"))
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ void osm_datasource::bind() const
|
|||
std::string parser = *params_.get<std::string>("parser", "libxml2");
|
||||
std::string url = *params_.get<std::string>("url", "");
|
||||
std::string bbox = *params_.get<std::string>("bbox", "");
|
||||
|
||||
|
||||
bool do_process = false;
|
||||
|
||||
// load the data
|
||||
|
@ -119,14 +119,14 @@ void osm_datasource::bind() const
|
|||
bounds b = osm_data_->get_bounds();
|
||||
extent_ = box2d<double>(b.w, b.s, b.e, b.n);
|
||||
}
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
osm_datasource::~osm_datasource()
|
||||
{
|
||||
osm_datasource::~osm_datasource()
|
||||
{
|
||||
// Do not do as is now static variable and cleaned up at exit
|
||||
//delete osm_data_;
|
||||
//delete osm_data_;
|
||||
}
|
||||
|
||||
std::string osm_datasource::name()
|
||||
|
@ -147,10 +147,10 @@ layer_descriptor osm_datasource::get_descriptor() const
|
|||
featureset_ptr osm_datasource::features(const query& q) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
filter_in_box filter(q.get_bbox());
|
||||
// so we need to filter osm features by bbox here...
|
||||
|
||||
|
||||
return boost::make_shared<osm_featureset<filter_in_box> >(filter,
|
||||
osm_data_,
|
||||
q.property_names(),
|
||||
|
@ -160,20 +160,20 @@ featureset_ptr osm_datasource::features(const query& q) const
|
|||
featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
filter_at_point filter(pt);
|
||||
// collect all attribute names
|
||||
std::vector<attribute_descriptor> const& desc_vector = desc_.get_descriptors();
|
||||
std::vector<attribute_descriptor>::const_iterator itr = desc_vector.begin();
|
||||
std::vector<attribute_descriptor>::const_iterator end = desc_vector.end();
|
||||
std::set<std::string> names;
|
||||
|
||||
|
||||
while (itr != end)
|
||||
{
|
||||
names.insert(itr->get_name());
|
||||
++itr;
|
||||
}
|
||||
|
||||
|
||||
return boost::make_shared<osm_featureset<filter_at_point> >(filter,
|
||||
osm_data_,
|
||||
names,
|
||||
|
@ -182,7 +182,7 @@ featureset_ptr osm_datasource::features_at_point(coord2d const& pt) const
|
|||
|
||||
box2d<double> osm_datasource::envelope() const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
return extent_;
|
||||
if (! is_bound_) bind();
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -36,17 +36,17 @@ using mapnik::geometry_type;
|
|||
using mapnik::feature_factory;
|
||||
|
||||
template <typename filterT>
|
||||
osm_featureset<filterT>::osm_featureset(const filterT& filter,
|
||||
osm_featureset<filterT>::osm_featureset(const filterT& filter,
|
||||
osm_dataset* dataset,
|
||||
const std::set<std::string>&
|
||||
const std::set<std::string>&
|
||||
attribute_names,
|
||||
std::string const& encoding)
|
||||
: filter_(filter),
|
||||
query_ext_(),
|
||||
tr_(new transcoder(encoding)),
|
||||
feature_id_(1),
|
||||
dataset_ (dataset),
|
||||
attribute_names_ (attribute_names)
|
||||
: filter_(filter),
|
||||
query_ext_(),
|
||||
tr_(new transcoder(encoding)),
|
||||
feature_id_(1),
|
||||
dataset_ (dataset),
|
||||
attribute_names_ (attribute_names)
|
||||
{
|
||||
dataset_->rewind();
|
||||
}
|
||||
|
@ -70,11 +70,11 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
point->move_to(lon, lat);
|
||||
feature->add_geometry(point);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
else if (dataset_->current_item_is_way())
|
||||
{
|
||||
bounds b = static_cast<osm_way*>(cur_item)->get_bounds();
|
||||
|
||||
|
||||
// Loop until we find a feature which passes the filter
|
||||
while (cur_item != NULL &&
|
||||
! filter_.pass(box2d<double>(b.w, b.s, b.e, b.n)))
|
||||
|
@ -84,8 +84,8 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
{
|
||||
b = static_cast<osm_way*>(cur_item)->get_bounds();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (cur_item != NULL)
|
||||
{
|
||||
if (static_cast<osm_way*>(cur_item)->nodes.size())
|
||||
|
@ -101,11 +101,11 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
{
|
||||
geom = new geometry_type(mapnik::LineString);
|
||||
}
|
||||
|
||||
|
||||
geom->set_capacity(static_cast<osm_way*>(cur_item)->nodes.size());
|
||||
geom->move_to(static_cast<osm_way*>(cur_item)->nodes[0]->lon,
|
||||
static_cast<osm_way*>(cur_item)->nodes[0]->lat);
|
||||
|
||||
|
||||
for (unsigned int count = 1;
|
||||
count < static_cast<osm_way*>(cur_item)->nodes.size();
|
||||
count++)
|
||||
|
@ -118,8 +118,8 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// can feature_ptr be compared to NULL? - no
|
||||
|
||||
// can feature_ptr be compared to NULL? - no
|
||||
if (success)
|
||||
{
|
||||
std::map<std::string,std::string>::iterator i = cur_item->keyvals.begin();
|
||||
|
@ -127,7 +127,7 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
// add the keyvals to the feature. the feature seems to be a map
|
||||
// of some sort so this should work - see dbf_file::add_attribute()
|
||||
while (i != cur_item->keyvals.end())
|
||||
{
|
||||
{
|
||||
// only add if in the specified set of attribute names
|
||||
if (attribute_names_.find(i->first) != attribute_names_.end())
|
||||
{
|
||||
|
@ -139,7 +139,7 @@ feature_ptr osm_featureset<filterT>::next()
|
|||
|
||||
return feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -9,149 +9,149 @@ using std::cerr;
|
|||
using std::endl;
|
||||
|
||||
|
||||
osm_item* osmparser::cur_item=NULL;
|
||||
long osmparser::curID=0;
|
||||
bool osmparser::in_node=false, osmparser::in_way=false;
|
||||
osm_dataset* osmparser::components=NULL;
|
||||
std::string osmparser::error="";
|
||||
std::map<long,osm_node*> osmparser::tmp_node_store=std::map<long,osm_node*>();
|
||||
osm_item* osmparser::cur_item=NULL;
|
||||
long osmparser::curID=0;
|
||||
bool osmparser::in_node=false, osmparser::in_way=false;
|
||||
osm_dataset* osmparser::components=NULL;
|
||||
std::string osmparser::error="";
|
||||
std::map<long,osm_node*> osmparser::tmp_node_store=std::map<long,osm_node*>();
|
||||
|
||||
void osmparser::processNode(xmlTextReaderPtr reader)
|
||||
{
|
||||
xmlChar *name = xmlTextReaderName(reader);
|
||||
if(name==NULL)
|
||||
name=xmlStrdup(BAD_CAST "--");
|
||||
xmlChar *name = xmlTextReaderName(reader);
|
||||
if(name==NULL)
|
||||
name=xmlStrdup(BAD_CAST "--");
|
||||
|
||||
switch(xmlTextReaderNodeType(reader))
|
||||
{
|
||||
switch(xmlTextReaderNodeType(reader))
|
||||
{
|
||||
case XML_READER_TYPE_ELEMENT:
|
||||
startElement(reader,name);
|
||||
break;
|
||||
startElement(reader,name);
|
||||
break;
|
||||
|
||||
case XML_READER_TYPE_END_ELEMENT:
|
||||
endElement(name);
|
||||
}
|
||||
xmlFree(name);
|
||||
endElement(name);
|
||||
}
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
void osmparser::startElement(xmlTextReaderPtr reader, const xmlChar *name)
|
||||
{
|
||||
std::string tags;
|
||||
xmlChar *xid, *xlat, *xlon, *xk, *xv;
|
||||
std::string tags;
|
||||
xmlChar *xid, *xlat, *xlon, *xk, *xv;
|
||||
|
||||
if(xmlStrEqual(name,BAD_CAST "node"))
|
||||
{
|
||||
curID = 0;
|
||||
in_node = true;
|
||||
osm_node *node=new osm_node;
|
||||
xlat=xmlTextReaderGetAttribute(reader,BAD_CAST "lat");
|
||||
xlon=xmlTextReaderGetAttribute(reader,BAD_CAST "lon");
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id");
|
||||
assert(xlat);
|
||||
assert(xlon);
|
||||
assert(xid);
|
||||
node->lat=atof((char*)xlat);
|
||||
node->lon=atof((char*)xlon);
|
||||
node->id = atol((char*)xid);
|
||||
cur_item = node;
|
||||
tmp_node_store[node->id] = node;
|
||||
xmlFree(xid);
|
||||
xmlFree(xlon);
|
||||
xmlFree(xlat);
|
||||
curID = 0;
|
||||
in_node = true;
|
||||
osm_node *node=new osm_node;
|
||||
xlat=xmlTextReaderGetAttribute(reader,BAD_CAST "lat");
|
||||
xlon=xmlTextReaderGetAttribute(reader,BAD_CAST "lon");
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id");
|
||||
assert(xlat);
|
||||
assert(xlon);
|
||||
assert(xid);
|
||||
node->lat=atof((char*)xlat);
|
||||
node->lon=atof((char*)xlon);
|
||||
node->id = atol((char*)xid);
|
||||
cur_item = node;
|
||||
tmp_node_store[node->id] = node;
|
||||
xmlFree(xid);
|
||||
xmlFree(xlon);
|
||||
xmlFree(xlat);
|
||||
}
|
||||
else if (xmlStrEqual(name,BAD_CAST "way"))
|
||||
else if (xmlStrEqual(name,BAD_CAST "way"))
|
||||
{
|
||||
curID=0;
|
||||
in_way = true;
|
||||
osm_way *way=new osm_way;
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id");
|
||||
assert(xid);
|
||||
way->id = atol((char*)xid);
|
||||
cur_item = way;
|
||||
// Prevent ways with no name being assigned a name of "0"
|
||||
cur_item->keyvals["name"] = "";
|
||||
curID=0;
|
||||
in_way = true;
|
||||
osm_way *way=new osm_way;
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "id");
|
||||
assert(xid);
|
||||
way->id = atol((char*)xid);
|
||||
cur_item = way;
|
||||
// Prevent ways with no name being assigned a name of "0"
|
||||
cur_item->keyvals["name"] = "";
|
||||
|
||||
// HACK: allows comparison with "" in the XML file. Otherwise it
|
||||
// doesn't work. Only do for the most crucial tags for Freemap's
|
||||
// purposes. TODO investigate why this is
|
||||
cur_item->keyvals["width"] = "";
|
||||
cur_item->keyvals["horse"] = "";
|
||||
cur_item->keyvals["foot"] = "";
|
||||
cur_item->keyvals["bicycle"] = "";
|
||||
xmlFree(xid);
|
||||
// HACK: allows comparison with "" in the XML file. Otherwise it
|
||||
// doesn't work. Only do for the most crucial tags for Freemap's
|
||||
// purposes. TODO investigate why this is
|
||||
cur_item->keyvals["width"] = "";
|
||||
cur_item->keyvals["horse"] = "";
|
||||
cur_item->keyvals["foot"] = "";
|
||||
cur_item->keyvals["bicycle"] = "";
|
||||
xmlFree(xid);
|
||||
}
|
||||
else if (xmlStrEqual(name,BAD_CAST "nd"))
|
||||
{
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "ref");
|
||||
assert(xid);
|
||||
long ndid = atol((char*)xid);
|
||||
if(tmp_node_store.find(ndid)!=tmp_node_store.end())
|
||||
{
|
||||
(static_cast<osm_way*>(cur_item))->nodes.push_back
|
||||
(tmp_node_store[ndid]);
|
||||
}
|
||||
xmlFree(xid);
|
||||
xid=xmlTextReaderGetAttribute(reader,BAD_CAST "ref");
|
||||
assert(xid);
|
||||
long ndid = atol((char*)xid);
|
||||
if(tmp_node_store.find(ndid)!=tmp_node_store.end())
|
||||
{
|
||||
(static_cast<osm_way*>(cur_item))->nodes.push_back
|
||||
(tmp_node_store[ndid]);
|
||||
}
|
||||
xmlFree(xid);
|
||||
}
|
||||
else if (xmlStrEqual(name,BAD_CAST "tag"))
|
||||
{
|
||||
std::string key="", value="";
|
||||
xk = xmlTextReaderGetAttribute(reader,BAD_CAST "k");
|
||||
xv = xmlTextReaderGetAttribute(reader,BAD_CAST "v");
|
||||
assert(xk);
|
||||
assert(xv);
|
||||
cur_item->keyvals[(char*)xk] = (char*)xv;
|
||||
xmlFree(xk);
|
||||
xmlFree(xv);
|
||||
std::string key="", value="";
|
||||
xk = xmlTextReaderGetAttribute(reader,BAD_CAST "k");
|
||||
xv = xmlTextReaderGetAttribute(reader,BAD_CAST "v");
|
||||
assert(xk);
|
||||
assert(xv);
|
||||
cur_item->keyvals[(char*)xk] = (char*)xv;
|
||||
xmlFree(xk);
|
||||
xmlFree(xv);
|
||||
}
|
||||
}
|
||||
|
||||
void osmparser::endElement(const xmlChar* name)
|
||||
{
|
||||
if(xmlStrEqual(name,BAD_CAST "node"))
|
||||
{
|
||||
in_node = false;
|
||||
components->add_node(static_cast<osm_node*>(cur_item));
|
||||
}
|
||||
else if(xmlStrEqual(name,BAD_CAST "way"))
|
||||
{
|
||||
in_way = false;
|
||||
components->add_way(static_cast<osm_way*>(cur_item));
|
||||
}
|
||||
if(xmlStrEqual(name,BAD_CAST "node"))
|
||||
{
|
||||
in_node = false;
|
||||
components->add_node(static_cast<osm_node*>(cur_item));
|
||||
}
|
||||
else if(xmlStrEqual(name,BAD_CAST "way"))
|
||||
{
|
||||
in_way = false;
|
||||
components->add_way(static_cast<osm_way*>(cur_item));
|
||||
}
|
||||
}
|
||||
|
||||
bool osmparser::parse(osm_dataset *ds, const char* filename)
|
||||
{
|
||||
components=ds;
|
||||
xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename);
|
||||
int ret=do_parse(reader);
|
||||
xmlFreeTextReader(reader);
|
||||
return (ret==0) ? true:false;
|
||||
components=ds;
|
||||
xmlTextReaderPtr reader = xmlNewTextReaderFilename(filename);
|
||||
int ret=do_parse(reader);
|
||||
xmlFreeTextReader(reader);
|
||||
return (ret==0) ? true:false;
|
||||
}
|
||||
|
||||
bool osmparser::parse(osm_dataset *ds,char* data, int nbytes)
|
||||
{
|
||||
// from cocoasamurai.blogspot.com/2008/10/getting-some-xml-love-with-
|
||||
// libxml2.html, converted from Objective-C to straight C
|
||||
// from cocoasamurai.blogspot.com/2008/10/getting-some-xml-love-with-
|
||||
// libxml2.html, converted from Objective-C to straight C
|
||||
|
||||
components=ds;
|
||||
xmlTextReaderPtr reader = xmlReaderForMemory(data,nbytes,NULL,NULL,0);
|
||||
int ret=do_parse(reader);
|
||||
xmlFreeTextReader(reader);
|
||||
return (ret==0) ? true:false;
|
||||
components=ds;
|
||||
xmlTextReaderPtr reader = xmlReaderForMemory(data,nbytes,NULL,NULL,0);
|
||||
int ret=do_parse(reader);
|
||||
xmlFreeTextReader(reader);
|
||||
return (ret==0) ? true:false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int osmparser::do_parse(xmlTextReaderPtr reader)
|
||||
{
|
||||
int ret=-1;
|
||||
if(reader!=NULL)
|
||||
{
|
||||
ret = xmlTextReaderRead(reader);
|
||||
while(ret==1)
|
||||
int ret=-1;
|
||||
if(reader!=NULL)
|
||||
{
|
||||
processNode(reader);
|
||||
ret=xmlTextReaderRead(reader);
|
||||
ret = xmlTextReaderRead(reader);
|
||||
while(ret==1)
|
||||
{
|
||||
processNode(reader);
|
||||
ret=xmlTextReaderRead(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int main(int argc,char *argv[])
|
|||
|
||||
mapnik::Map m(800, 800);
|
||||
mapnik::load_map(m, argv[1]);
|
||||
|
||||
|
||||
if (argc > 6)
|
||||
{
|
||||
mapnik::parameters p;
|
||||
|
@ -62,7 +62,7 @@ int main(int argc,char *argv[])
|
|||
}
|
||||
|
||||
mapnik::box2d<double> bbox (atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]));
|
||||
|
||||
|
||||
m.zoom_to_box(bbox);
|
||||
|
||||
mapnik::image_32 buf (m.width(), m.height());
|
||||
|
|
|
@ -5,21 +5,21 @@ using std::endl;
|
|||
|
||||
int main(int argc,char* argv[])
|
||||
{
|
||||
if(argc>=2)
|
||||
{
|
||||
osm_dataset dataset(argv[1]);
|
||||
bounds b = dataset.get_bounds();
|
||||
osm_item *item;
|
||||
dataset.rewind();
|
||||
while((item=dataset.next_item())!=NULL)
|
||||
if(argc>=2)
|
||||
{
|
||||
std::cerr << item->to_string() << endl;
|
||||
osm_dataset dataset(argv[1]);
|
||||
bounds b = dataset.get_bounds();
|
||||
osm_item *item;
|
||||
dataset.rewind();
|
||||
while((item=dataset.next_item())!=NULL)
|
||||
{
|
||||
std::cerr << item->to_string() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr<<"Usage: test OSMfile"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
std::cerr<<"Usage: test OSMfile"<<std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -27,118 +27,118 @@
|
|||
#include <boost/make_shared.hpp>
|
||||
|
||||
extern "C" {
|
||||
#include "libpq-fe.h"
|
||||
#include "libpq-fe.h"
|
||||
}
|
||||
|
||||
#include "resultset.hpp"
|
||||
|
||||
class Connection
|
||||
{
|
||||
private:
|
||||
PGconn *conn_;
|
||||
int cursorId;
|
||||
bool closed_;
|
||||
public:
|
||||
Connection(std::string const& connection_str)
|
||||
:cursorId(0),
|
||||
private:
|
||||
PGconn *conn_;
|
||||
int cursorId;
|
||||
bool closed_;
|
||||
public:
|
||||
Connection(std::string const& connection_str)
|
||||
:cursorId(0),
|
||||
closed_(false)
|
||||
{
|
||||
conn_=PQconnectdb(connection_str.c_str());
|
||||
if (PQstatus(conn_) != CONNECTION_OK)
|
||||
{
|
||||
std::ostringstream s("Postgis Plugin: PSQL error");
|
||||
if (conn_ )
|
||||
{
|
||||
std::string msg = PQerrorMessage( conn_ );
|
||||
if ( ! msg.empty() )
|
||||
{
|
||||
s << ":\n" << msg.substr( 0, msg.size() - 1 );
|
||||
}
|
||||
}
|
||||
throw mapnik::datasource_exception( s.str() );
|
||||
}
|
||||
}
|
||||
|
||||
bool execute(const std::string& sql) const
|
||||
{
|
||||
PGresult *result=PQexec(conn_,sql.c_str());
|
||||
bool ok=(result && PQresultStatus(result)==PGRES_COMMAND_OK);
|
||||
PQclear(result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const
|
||||
{
|
||||
PGresult *result=0;
|
||||
if (type==1)
|
||||
{
|
||||
result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
result=PQexec(conn_,sql.c_str());
|
||||
}
|
||||
if(!result || PQresultStatus(result) != PGRES_TUPLES_OK)
|
||||
{
|
||||
std::ostringstream s("Postgis Plugin: PSQL error");
|
||||
if (conn_ )
|
||||
{
|
||||
std::string msg = PQerrorMessage( conn_ );
|
||||
if ( ! msg.empty() )
|
||||
{
|
||||
s << ":\n" << msg.substr( 0, msg.size() - 1 );
|
||||
}
|
||||
|
||||
s << "\nFull sql was: '" << sql << "'\n";
|
||||
}
|
||||
if (result)
|
||||
PQclear(result);
|
||||
throw mapnik::datasource_exception( s.str() );
|
||||
}
|
||||
{
|
||||
conn_=PQconnectdb(connection_str.c_str());
|
||||
if (PQstatus(conn_) != CONNECTION_OK)
|
||||
{
|
||||
std::ostringstream s("Postgis Plugin: PSQL error");
|
||||
if (conn_ )
|
||||
{
|
||||
std::string msg = PQerrorMessage( conn_ );
|
||||
if ( ! msg.empty() )
|
||||
{
|
||||
s << ":\n" << msg.substr( 0, msg.size() - 1 );
|
||||
}
|
||||
}
|
||||
throw mapnik::datasource_exception( s.str() );
|
||||
}
|
||||
}
|
||||
|
||||
return boost::make_shared<ResultSet>(result);
|
||||
}
|
||||
|
||||
std::string client_encoding() const
|
||||
{
|
||||
return PQparameterStatus(conn_,"client_encoding");
|
||||
}
|
||||
|
||||
bool isOK() const
|
||||
{
|
||||
return (PQstatus(conn_)!=CONNECTION_BAD);
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
if (!closed_)
|
||||
{
|
||||
PQfinish(conn_);
|
||||
bool execute(const std::string& sql) const
|
||||
{
|
||||
PGresult *result=PQexec(conn_,sql.c_str());
|
||||
bool ok=(result && PQresultStatus(result)==PGRES_COMMAND_OK);
|
||||
PQclear(result);
|
||||
return ok;
|
||||
}
|
||||
|
||||
boost::shared_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const
|
||||
{
|
||||
PGresult *result=0;
|
||||
if (type==1)
|
||||
{
|
||||
result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
result=PQexec(conn_,sql.c_str());
|
||||
}
|
||||
if(!result || PQresultStatus(result) != PGRES_TUPLES_OK)
|
||||
{
|
||||
std::ostringstream s("Postgis Plugin: PSQL error");
|
||||
if (conn_ )
|
||||
{
|
||||
std::string msg = PQerrorMessage( conn_ );
|
||||
if ( ! msg.empty() )
|
||||
{
|
||||
s << ":\n" << msg.substr( 0, msg.size() - 1 );
|
||||
}
|
||||
|
||||
s << "\nFull sql was: '" << sql << "'\n";
|
||||
}
|
||||
if (result)
|
||||
PQclear(result);
|
||||
throw mapnik::datasource_exception( s.str() );
|
||||
}
|
||||
|
||||
return boost::make_shared<ResultSet>(result);
|
||||
}
|
||||
|
||||
std::string client_encoding() const
|
||||
{
|
||||
return PQparameterStatus(conn_,"client_encoding");
|
||||
}
|
||||
|
||||
bool isOK() const
|
||||
{
|
||||
return (PQstatus(conn_)!=CONNECTION_BAD);
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
if (!closed_)
|
||||
{
|
||||
PQfinish(conn_);
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "PostGIS: datasource closed, also closing connection - " << conn_ << std::endl;
|
||||
std::clog << "PostGIS: datasource closed, also closing connection - " << conn_ << std::endl;
|
||||
#endif
|
||||
closed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string new_cursor_name()
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "mapnik_" << (cursorId++);
|
||||
return s.str();
|
||||
}
|
||||
|
||||
~Connection()
|
||||
{
|
||||
if (!closed_)
|
||||
{
|
||||
PQfinish(conn_);
|
||||
closed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string new_cursor_name()
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "mapnik_" << (cursorId++);
|
||||
return s.str();
|
||||
}
|
||||
|
||||
~Connection()
|
||||
{
|
||||
if (!closed_)
|
||||
{
|
||||
PQfinish(conn_);
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "PostGIS: postgresql connection closed - " << conn_ << std::endl;
|
||||
std::clog << "PostGIS: postgresql connection closed - " << conn_ << std::endl;
|
||||
#endif
|
||||
closed_ = true;
|
||||
}
|
||||
}
|
||||
closed_ = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //CONNECTION_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -58,17 +58,17 @@ public:
|
|||
user_(user),
|
||||
pass_(pass),
|
||||
connect_timeout_(connect_timeout) {}
|
||||
|
||||
|
||||
T* operator()() const
|
||||
{
|
||||
return new T(connection_string());
|
||||
}
|
||||
|
||||
inline std::string id() const
|
||||
|
||||
inline std::string id() const
|
||||
{
|
||||
return connection_string();
|
||||
}
|
||||
|
||||
|
||||
inline std::string connection_string() const
|
||||
{
|
||||
std::string connect_str;
|
||||
|
@ -77,11 +77,11 @@ public:
|
|||
if (dbname_ && (*dbname_).size()) connect_str += " dbname=" + *dbname_;
|
||||
if (user_ && (*user_).size()) connect_str += " user=" + *user_;
|
||||
if (pass_ && (*pass_).size()) connect_str += " password=" + *pass_;
|
||||
if (connect_timeout_ && (*connect_timeout_).size())
|
||||
if (connect_timeout_ && (*connect_timeout_).size())
|
||||
connect_str +=" connect_timeout=" + *connect_timeout_;
|
||||
return connect_str;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
boost::optional<string> host_;
|
||||
boost::optional<string> port_;
|
||||
|
@ -97,13 +97,13 @@ class ConnectionManager : public singleton <ConnectionManager,CreateStatic>
|
|||
friend class CreateStatic<ConnectionManager>;
|
||||
typedef Pool<Connection,ConnectionCreator> PoolType;
|
||||
typedef std::map<std::string,boost::shared_ptr<PoolType> > ContType;
|
||||
typedef boost::shared_ptr<Connection> HolderType;
|
||||
typedef boost::shared_ptr<Connection> HolderType;
|
||||
ContType pools_;
|
||||
|
||||
public:
|
||||
|
||||
bool registerPool(const ConnectionCreator<Connection>& creator,unsigned initialSize,unsigned maxSize)
|
||||
{
|
||||
|
||||
bool registerPool(const ConnectionCreator<Connection>& creator,unsigned initialSize,unsigned maxSize)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
//mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
|
@ -114,14 +114,14 @@ public:
|
|||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
boost::shared_ptr<PoolType> getPool(std::string const& key)
|
||||
|
||||
boost::shared_ptr<PoolType> getPool(std::string const& key)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
//mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
#endif
|
||||
ContType::const_iterator itr=pools_.find(key);
|
||||
if (itr!=pools_.end())
|
||||
{
|
||||
|
@ -130,14 +130,14 @@ public:
|
|||
static const boost::shared_ptr<PoolType> emptyPool;
|
||||
return emptyPool;
|
||||
}
|
||||
|
||||
|
||||
HolderType get(std::string const& key)
|
||||
{
|
||||
#ifdef MAPNIK_THREADSAFE
|
||||
//mutex::scoped_lock lock(mutex_);
|
||||
#endif
|
||||
#endif
|
||||
ContType::const_iterator itr=pools_.find(key);
|
||||
if (itr!=pools_.end())
|
||||
if (itr!=pools_.end())
|
||||
{
|
||||
boost::shared_ptr<PoolType> pool=itr->second;
|
||||
return pool->borrowObject();
|
||||
|
@ -148,6 +148,6 @@ public:
|
|||
private:
|
||||
ConnectionManager(const ConnectionManager&);
|
||||
ConnectionManager& operator=(const ConnectionManager);
|
||||
};
|
||||
};
|
||||
|
||||
#endif //CONNECTION_MANAGER_HPP
|
||||
|
|
|
@ -13,7 +13,7 @@ private:
|
|||
int fetch_size_;
|
||||
bool is_closed_;
|
||||
int *refCount_;
|
||||
|
||||
|
||||
void getNextResultSet()
|
||||
{
|
||||
std::ostringstream s;
|
||||
|
@ -27,7 +27,7 @@ private:
|
|||
std::clog << "Postgis Plugin: FETCH result (" << cursorName_ << "): " << rs_->size() << " rows" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
CursorResultSet(boost::shared_ptr<Connection> const &conn, std::string cursorName, int fetch_count)
|
||||
: conn_(conn),
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
{
|
||||
return rs_->isNull(index);
|
||||
}
|
||||
|
||||
|
||||
virtual const char* getValue(int index) const
|
||||
{
|
||||
return rs_->getValue(index);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -86,11 +86,11 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
|
|||
intersect_min_scale_(*params_.get<int>("intersect_min_scale",0)),
|
||||
intersect_max_scale_(*params_.get<int>("intersect_max_scale",0))
|
||||
//show_queries_(*params_.get<mapnik::boolean>("show_queries",false))
|
||||
{
|
||||
{
|
||||
if (table_.empty()) throw mapnik::datasource_exception("Postgis Plugin: missing <table> parameter");
|
||||
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
|
||||
|
||||
|
||||
boost::optional<std::string> ext = params_.get<std::string>("extent");
|
||||
if (ext) extent_initialized_ = extent_.from_string(*ext);
|
||||
|
||||
|
@ -103,16 +103,16 @@ postgis_datasource::postgis_datasource(parameters const& params, bool bind)
|
|||
void postgis_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
boost::optional<int> initial_size = params_.get<int>("initial_size",1);
|
||||
boost::optional<int> max_size = params_.get<int>("max_size",10);
|
||||
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
mgr->registerPool(creator_, *initial_size, *max_size);
|
||||
|
||||
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
|
||||
if (pool)
|
||||
{
|
||||
{
|
||||
shared_ptr<Connection> conn = pool->borrowObject();
|
||||
if (conn && conn->isOK())
|
||||
{
|
||||
|
@ -120,8 +120,8 @@ void postgis_datasource::bind() const
|
|||
is_bound_ = true;
|
||||
|
||||
PoolGuard<shared_ptr<Connection>,
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
|
||||
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
|
||||
|
||||
desc_.set_encoding(conn->client_encoding());
|
||||
|
||||
if(geometry_table_.empty())
|
||||
|
@ -151,20 +151,20 @@ void postgis_datasource::bind() const
|
|||
std::ostringstream s;
|
||||
s << "SELECT f_geometry_column, srid FROM ";
|
||||
s << GEOMETRY_COLUMNS <<" WHERE f_table_name='" << mapnik::sql_utils::unquote_double(geometry_table_) <<"'";
|
||||
|
||||
if (schema_.length() > 0)
|
||||
|
||||
if (schema_.length() > 0)
|
||||
s << " AND f_table_schema='" << mapnik::sql_utils::unquote_double(schema_) << "'";
|
||||
|
||||
|
||||
if (geometry_field_.length() > 0)
|
||||
s << " AND f_geometry_column='" << mapnik::sql_utils::unquote_double(geometry_field_) << "'";
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
|
||||
if (rs->next())
|
||||
{
|
||||
|
@ -172,7 +172,7 @@ void postgis_datasource::bind() const
|
|||
|
||||
if (srid_ == 0)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
srid_ = lexical_cast<int>(rs->getValue("srid"));
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ void postgis_datasource::bind() const
|
|||
}
|
||||
}
|
||||
rs->close();
|
||||
|
||||
|
||||
// If we still do not know the srid then we can try to fetch
|
||||
// it from the 'table_' parameter, which should work even if it is
|
||||
// a subselect as long as we know the geometry_field to query
|
||||
|
@ -194,10 +194,10 @@ void postgis_datasource::bind() const
|
|||
s << populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;";
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
|
||||
|
@ -215,7 +215,7 @@ void postgis_datasource::bind() const
|
|||
rs->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (srid_ == 0)
|
||||
{
|
||||
srid_ = -1;
|
||||
|
@ -223,24 +223,24 @@ void postgis_datasource::bind() const
|
|||
}
|
||||
|
||||
// At this point the geometry_field may still not be known
|
||||
// but we'll catch that where more useful...
|
||||
// but we'll catch that where more useful...
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Postgis Plugin: using SRID=" << srid_ << std::endl;
|
||||
std::clog << "Postgis Plugin: using geometry_column=" << geometryColumn_ << std::endl;
|
||||
#endif
|
||||
|
||||
// collect attribute desc
|
||||
// collect attribute desc
|
||||
std::ostringstream s;
|
||||
s << "SELECT * FROM " << populate_tokens(table_) << " LIMIT 0";
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
|
||||
int count = rs->getNumFields();
|
||||
|
@ -268,15 +268,15 @@ void postgis_datasource::bind() const
|
|||
if (rs_oid->next())
|
||||
{
|
||||
error_s << rs_oid->getValue("typname")
|
||||
<< "' (oid:" << rs_oid->getValue("oid") << ")";
|
||||
<< "' (oid:" << rs_oid->getValue("oid") << ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
error_s << "oid:" << type_oid << "'";
|
||||
error_s << "oid:" << type_oid << "'";
|
||||
}
|
||||
rs_oid->close();
|
||||
error_s << " for key_field '" << fld_name << "' - "
|
||||
<< "must be an integer primary key";
|
||||
<< "must be an integer primary key";
|
||||
rs->close();
|
||||
throw mapnik::datasource_exception( error_s.str() );
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ void postgis_datasource::bind() const
|
|||
case 23: // int4
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
|
||||
break;
|
||||
case 700: // float4
|
||||
case 700: // float4
|
||||
case 701: // float8
|
||||
case 1700: // numeric ??
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
|
||||
|
@ -303,29 +303,29 @@ void postgis_datasource::bind() const
|
|||
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
|
||||
break;
|
||||
default: // should not get here
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
s.str("");
|
||||
s << "SELECT oid, typname FROM pg_type WHERE oid = " << type_oid;
|
||||
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
shared_ptr<ResultSet> rs_oid = conn->executeQuery(s.str());
|
||||
if (rs_oid->next())
|
||||
{
|
||||
std::clog << "Postgis Plugin: unknown type = " << rs_oid->getValue("typname")
|
||||
<< " (oid:" << rs_oid->getValue("oid") << ")" << std::endl;
|
||||
<< " (oid:" << rs_oid->getValue("oid") << ")" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::clog << "Postgis Plugin: unknown oid type =" << type_oid << std::endl;
|
||||
std::clog << "Postgis Plugin: unknown oid type =" << type_oid << std::endl;
|
||||
}
|
||||
rs_oid->close();
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ layer_descriptor postgis_datasource::get_descriptor() const
|
|||
|
||||
|
||||
std::string postgis_datasource::sql_bbox(box2d<double> const& env) const
|
||||
{
|
||||
{
|
||||
std::ostringstream b;
|
||||
if (srid_ > 0)
|
||||
b << "SetSRID(";
|
||||
|
@ -369,13 +369,13 @@ std::string postgis_datasource::sql_bbox(box2d<double> const& env) const
|
|||
std::string postgis_datasource::populate_tokens(const std::string& sql) const
|
||||
{
|
||||
std::string populated_sql = sql;
|
||||
|
||||
|
||||
if ( boost::algorithm::icontains(sql,bbox_token_) )
|
||||
{
|
||||
box2d<double> max_env(-1 * FMAX,-1 * FMAX,FMAX,FMAX);
|
||||
std::string max_box = sql_bbox(max_env);
|
||||
boost::algorithm::replace_all(populated_sql,bbox_token_,max_box);
|
||||
}
|
||||
}
|
||||
if ( boost::algorithm::icontains(sql,scale_denom_token_) )
|
||||
{
|
||||
std::string max_denom = lexical_cast<std::string>(FMAX);
|
||||
|
@ -388,13 +388,13 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double c
|
|||
{
|
||||
std::string populated_sql = sql;
|
||||
std::string box = sql_bbox(env);
|
||||
|
||||
|
||||
if ( boost::algorithm::icontains(populated_sql,scale_denom_token_) )
|
||||
{
|
||||
std::string max_denom = lexical_cast<std::string>(scale_denom);
|
||||
boost::algorithm::replace_all(populated_sql,scale_denom_token_,max_denom);
|
||||
}
|
||||
|
||||
|
||||
if ( boost::algorithm::icontains(populated_sql,bbox_token_) )
|
||||
{
|
||||
boost::algorithm::replace_all(populated_sql,bbox_token_,box);
|
||||
|
@ -405,17 +405,17 @@ std::string postgis_datasource::populate_tokens(const std::string& sql, double c
|
|||
std::ostringstream s;
|
||||
if (intersect_min_scale_ > 0 && (scale_denom <= intersect_min_scale_ ))
|
||||
{
|
||||
s << " WHERE ST_Intersects(\"" << geometryColumn_ << "\"," << box << ")";
|
||||
s << " WHERE ST_Intersects(\"" << geometryColumn_ << "\"," << box << ")";
|
||||
}
|
||||
else if (intersect_max_scale_ > 0 && (scale_denom >= intersect_max_scale_ ))
|
||||
{
|
||||
// do no bbox restriction
|
||||
// do no bbox restriction
|
||||
}
|
||||
else
|
||||
{
|
||||
s << " WHERE \"" << geometryColumn_ << "\" && " << box;
|
||||
}
|
||||
return populated_sql + s.str();
|
||||
return populated_sql + s.str();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,10 +431,10 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
|
|||
csql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << sql << " FOR READ ONLY";
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % csql.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % csql.str();
|
||||
}
|
||||
*/
|
||||
|
||||
if (!conn->execute(csql.str()))
|
||||
|
@ -448,10 +448,10 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
|
|||
// no cursor
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % sql;
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % sql;
|
||||
}
|
||||
*/
|
||||
|
||||
return conn->executeQuery(sql,1);
|
||||
|
@ -461,7 +461,7 @@ boost::shared_ptr<IResultSet> postgis_datasource::get_resultset(boost::shared_pt
|
|||
featureset_ptr postgis_datasource::features(const query& q) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
box2d<double> const& box = q.get_bbox();
|
||||
double scale_denom = q.scale_denominator();
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
|
@ -470,7 +470,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
{
|
||||
shared_ptr<Connection> conn = pool->borrowObject();
|
||||
if (conn && conn->isOK())
|
||||
{
|
||||
{
|
||||
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
|
||||
|
||||
if (!geometryColumn_.length() > 0)
|
||||
|
@ -501,7 +501,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
else
|
||||
s << "AsBinary(\"" << geometryColumn_ << "\") AS geom";
|
||||
|
||||
if (!key_field_.empty())
|
||||
if (!key_field_.empty())
|
||||
mapnik::sql_utils::quote_attr(s,key_field_);
|
||||
|
||||
std::set<std::string> const& props=q.property_names();
|
||||
|
@ -511,7 +511,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
{
|
||||
mapnik::sql_utils::quote_attr(s,*pos);
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
|
||||
std::string table_with_bbox = populate_tokens(table_,scale_denom,box);
|
||||
|
||||
|
@ -520,14 +520,14 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
if (row_limit_ > 0) {
|
||||
s << " LIMIT " << row_limit_;
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr<IResultSet> rs = get_resultset(conn, s.str());
|
||||
unsigned num_attr = props.size();
|
||||
if (!key_field_.empty())
|
||||
++num_attr;
|
||||
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(),multiple_geometries_,!key_field_.empty(),num_attr);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
throw mapnik::datasource_exception("Postgis Plugin: bad connection");
|
||||
}
|
||||
|
@ -538,14 +538,14 @@ featureset_ptr postgis_datasource::features(const query& q) const
|
|||
featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
|
||||
if (pool)
|
||||
{
|
||||
shared_ptr<Connection> conn = pool->borrowObject();
|
||||
if (conn && conn->isOK())
|
||||
{
|
||||
{
|
||||
PoolGuard<shared_ptr<Connection>,shared_ptr<Pool<Connection,ConnectionCreator> > > guard(conn,pool);
|
||||
std::ostringstream s;
|
||||
|
||||
|
@ -567,7 +567,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
|||
s_error << geometry_table_ << "'.";
|
||||
throw mapnik::datasource_exception(s_error.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
s << "SELECT ";
|
||||
if (st_)
|
||||
|
@ -576,7 +576,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
|||
s << "AsBinary(ST_Force_2D(\"" << geometryColumn_ << "\")) AS geom";
|
||||
else
|
||||
s << "AsBinary(\"" << geometryColumn_ << "\") AS geom";
|
||||
|
||||
|
||||
if (!key_field_.empty())
|
||||
mapnik::sql_utils::quote_attr(s,key_field_);
|
||||
|
||||
|
@ -594,11 +594,11 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
|
|||
std::string table_with_bbox = populate_tokens(table_,FMAX,box);
|
||||
|
||||
s << " from " << table_with_bbox;
|
||||
|
||||
|
||||
if (row_limit_ > 0) {
|
||||
s << " LIMIT " << row_limit_;
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr<IResultSet> rs = get_resultset(conn, s.str());
|
||||
return boost::make_shared<postgis_featureset>(rs,desc_.get_encoding(),multiple_geometries_,!key_field_.empty(),size);
|
||||
}
|
||||
|
@ -610,7 +610,7 @@ box2d<double> postgis_datasource::envelope() const
|
|||
{
|
||||
if (extent_initialized_) return extent_;
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
ConnectionManager *mgr=ConnectionManager::instance();
|
||||
shared_ptr<Pool<Connection,ConnectionCreator> > pool=mgr->getPool(creator_.id());
|
||||
if (pool)
|
||||
|
@ -674,16 +674,16 @@ box2d<double> postgis_datasource::envelope() const
|
|||
}
|
||||
|
||||
/*
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
if (show_queries_)
|
||||
{
|
||||
std::clog << boost::format("PostGIS: sending query: %s\n") % s.str();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
shared_ptr<ResultSet> rs=conn->executeQuery(s.str());
|
||||
if (rs->next())
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
double lox=lexical_cast<double>(rs->getValue(0));
|
||||
double loy=lexical_cast<double>(rs->getValue(1));
|
||||
|
@ -703,7 +703,7 @@ box2d<double> postgis_datasource::envelope() const
|
|||
return extent_;
|
||||
}
|
||||
|
||||
postgis_datasource::~postgis_datasource()
|
||||
postgis_datasource::~postgis_datasource()
|
||||
{
|
||||
if (is_bound_ && !persist_connection_)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -50,54 +50,54 @@ using mapnik::coord2d;
|
|||
|
||||
class postgis_datasource : public datasource
|
||||
{
|
||||
static const std::string GEOMETRY_COLUMNS;
|
||||
static const std::string SPATIAL_REF_SYS;
|
||||
const std::string uri_;
|
||||
const std::string username_;
|
||||
const std::string password_;
|
||||
const std::string table_;
|
||||
mutable std::string schema_;
|
||||
mutable std::string geometry_table_;
|
||||
const std::string geometry_field_;
|
||||
const std::string key_field_;
|
||||
const int cursor_fetch_size_;
|
||||
const int row_limit_;
|
||||
mutable std::string geometryColumn_;
|
||||
int type_;
|
||||
mutable int srid_;
|
||||
mutable bool extent_initialized_;
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
mutable layer_descriptor desc_;
|
||||
ConnectionCreator<Connection> creator_;
|
||||
bool multiple_geometries_;
|
||||
const std::string bbox_token_;
|
||||
const std::string scale_denom_token_;
|
||||
bool persist_connection_;
|
||||
bool extent_from_subquery_;
|
||||
// params below are for testing purposes only (will likely be removed at any time)
|
||||
bool force2d_;
|
||||
bool st_;
|
||||
int intersect_min_scale_;
|
||||
int intersect_max_scale_;
|
||||
//bool show_queries_;
|
||||
public:
|
||||
static std::string name();
|
||||
int type() const;
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
postgis_datasource(const parameters ¶ms, bool bind=true);
|
||||
~postgis_datasource();
|
||||
void bind() const;
|
||||
private:
|
||||
std::string sql_bbox(box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql, double const& scale_denom, box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql) const;
|
||||
static std::string unquote(const std::string& sql);
|
||||
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const;
|
||||
postgis_datasource(const postgis_datasource&);
|
||||
postgis_datasource& operator=(const postgis_datasource&);
|
||||
static const std::string GEOMETRY_COLUMNS;
|
||||
static const std::string SPATIAL_REF_SYS;
|
||||
const std::string uri_;
|
||||
const std::string username_;
|
||||
const std::string password_;
|
||||
const std::string table_;
|
||||
mutable std::string schema_;
|
||||
mutable std::string geometry_table_;
|
||||
const std::string geometry_field_;
|
||||
const std::string key_field_;
|
||||
const int cursor_fetch_size_;
|
||||
const int row_limit_;
|
||||
mutable std::string geometryColumn_;
|
||||
int type_;
|
||||
mutable int srid_;
|
||||
mutable bool extent_initialized_;
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
mutable layer_descriptor desc_;
|
||||
ConnectionCreator<Connection> creator_;
|
||||
bool multiple_geometries_;
|
||||
const std::string bbox_token_;
|
||||
const std::string scale_denom_token_;
|
||||
bool persist_connection_;
|
||||
bool extent_from_subquery_;
|
||||
// params below are for testing purposes only (will likely be removed at any time)
|
||||
bool force2d_;
|
||||
bool st_;
|
||||
int intersect_min_scale_;
|
||||
int intersect_max_scale_;
|
||||
//bool show_queries_;
|
||||
public:
|
||||
static std::string name();
|
||||
int type() const;
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
postgis_datasource(const parameters ¶ms, bool bind=true);
|
||||
~postgis_datasource();
|
||||
void bind() const;
|
||||
private:
|
||||
std::string sql_bbox(box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql, double const& scale_denom, box2d<double> const& env) const;
|
||||
std::string populate_tokens(const std::string& sql) const;
|
||||
static std::string unquote(const std::string& sql);
|
||||
boost::shared_ptr<IResultSet> get_resultset(boost::shared_ptr<Connection> const &conn, const std::string &sql) const;
|
||||
postgis_datasource(const postgis_datasource&);
|
||||
postgis_datasource& operator=(const postgis_datasource&);
|
||||
};
|
||||
|
||||
#endif //POSTGIS_DATASOURCE_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -63,7 +63,7 @@ postgis_featureset::postgis_featureset(boost::shared_ptr<IResultSet> const& rs,
|
|||
feature_ptr postgis_featureset::next()
|
||||
{
|
||||
if (rs_->next())
|
||||
{
|
||||
{
|
||||
// new feature
|
||||
feature_ptr feature;
|
||||
|
||||
|
@ -105,7 +105,7 @@ feature_ptr postgis_featureset::next()
|
|||
const char *data = rs_->getValue(0);
|
||||
geometry_utils::from_wkb(feature->paths(),data,size,multiple_geometries_);
|
||||
totalGeomSize_+=size;
|
||||
|
||||
|
||||
for ( ;pos<num_attrs_+1;++pos)
|
||||
{
|
||||
std::string name = rs_->getFieldName(pos);
|
||||
|
@ -118,7 +118,7 @@ feature_ptr postgis_featureset::next()
|
|||
{
|
||||
const char* buf = rs_->getValue(pos);
|
||||
int oid = rs_->getTypeOID(pos);
|
||||
|
||||
|
||||
if (oid==16) //bool
|
||||
{
|
||||
boost::put(*feature,name,buf[0] != 0);
|
||||
|
@ -163,17 +163,17 @@ feature_ptr postgis_featureset::next()
|
|||
else if (oid == 1700) // numeric
|
||||
{
|
||||
std::string str = mapnik::sql_utils::numeric2string(buf);
|
||||
try
|
||||
try
|
||||
{
|
||||
double val = boost::lexical_cast<double>(str);
|
||||
boost::put(*feature,name,val);
|
||||
}
|
||||
catch (boost::bad_lexical_cast & ex)
|
||||
{
|
||||
std::clog << ex.what() << "\n";
|
||||
std::clog << ex.what() << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Postgis Plugin: uknown OID = " << oid << " FIXME " << std::endl;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -24,7 +24,7 @@
|
|||
#define RESULTSET_HPP
|
||||
|
||||
extern "C" {
|
||||
#include "libpq-fe.h"
|
||||
#include "libpq-fe.h"
|
||||
}
|
||||
|
||||
class IResultSet
|
||||
|
@ -151,12 +151,12 @@ public:
|
|||
return PQftype(res_,col);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
virtual bool isNull(int index) const
|
||||
{
|
||||
return PQgetisnull(res_,pos_,index);
|
||||
}
|
||||
|
||||
|
||||
virtual const char* getValue(int index) const
|
||||
{
|
||||
return PQgetvalue(res_,pos_,index);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -46,7 +46,7 @@ using mapnik::image_reader;
|
|||
DATASOURCE_PLUGIN(raster_datasource)
|
||||
|
||||
raster_datasource::raster_datasource(const parameters& params, bool bind)
|
||||
: datasource(params),
|
||||
: datasource(params),
|
||||
desc_(*params.get<std::string>("type"), "utf-8"),
|
||||
extent_initialized_(false)
|
||||
{
|
||||
|
@ -56,19 +56,19 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
|
|||
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
if (! file) throw datasource_exception("Raster Plugin: missing <file> parameter ");
|
||||
|
||||
|
||||
boost::optional<std::string> base = params.get<std::string>("base");
|
||||
if (base)
|
||||
filename_ = *base + "/" + *file;
|
||||
filename_ = *base + "/" + *file;
|
||||
else
|
||||
filename_ = *file;
|
||||
filename_ = *file;
|
||||
|
||||
multi_tiles_ = *params_.get<bool>("multi", false);
|
||||
tile_size_ = *params_.get<unsigned>("tile_size", 256);
|
||||
tile_stride_ = *params_.get<unsigned>("tile_stride", 1);
|
||||
|
||||
format_ = *params_.get<std::string>("format","tiff");
|
||||
|
||||
|
||||
boost::optional<double> lox = params_.get<double>("lox");
|
||||
boost::optional<double> loy = params_.get<double>("loy");
|
||||
boost::optional<double> hix = params_.get<double>("hix");
|
||||
|
@ -90,7 +90,7 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
|
|||
throw datasource_exception("Raster Plugin: valid <extent> or <lox> <loy> <hix> <hiy> are required");
|
||||
}
|
||||
|
||||
if (bind)
|
||||
if (bind)
|
||||
{
|
||||
this->bind();
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ raster_datasource::raster_datasource(const parameters& params, bool bind)
|
|||
void raster_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
if (multi_tiles_)
|
||||
{
|
||||
boost::optional<unsigned> x_width = params_.get<unsigned>("x_width");
|
||||
|
@ -124,7 +124,7 @@ void raster_datasource::bind() const
|
|||
{
|
||||
throw datasource_exception("Raster Plugin: " + filename_ + " does not exist");
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(filename_, format_));
|
||||
|
@ -147,7 +147,7 @@ void raster_datasource::bind() const
|
|||
throw datasource_exception("Raster Plugin: image reader unknown exception caught");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: RASTER SIZE(" << width_ << "," << height_ << ")" << std::endl;
|
||||
#endif
|
||||
|
@ -182,11 +182,11 @@ layer_descriptor raster_datasource::get_descriptor() const
|
|||
featureset_ptr raster_datasource::features(query const& q) const
|
||||
{
|
||||
if (! is_bound_) bind();
|
||||
|
||||
|
||||
mapnik::CoordTransform t(width_, height_, extent_, 0, 0);
|
||||
mapnik::box2d<double> intersect = extent_.intersect(q.get_bbox());
|
||||
mapnik::box2d<double> ext = t.forward(intersect);
|
||||
|
||||
|
||||
const int width = int(ext.maxx() + 0.5) - int(ext.minx() + 0.5);
|
||||
const int height = int(ext.maxy() + 0.5) - int(ext.miny() + 0.5);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -43,12 +43,12 @@ template <typename LookupPolicy>
|
|||
raster_featureset<LookupPolicy>::raster_featureset(LookupPolicy const& policy,
|
||||
box2d<double> const& extent,
|
||||
query const& q)
|
||||
: policy_(policy),
|
||||
feature_id_(1),
|
||||
extent_(extent),
|
||||
bbox_(q.get_bbox()),
|
||||
curIter_(policy_.begin()),
|
||||
endIter_(policy_.end())
|
||||
: policy_(policy),
|
||||
feature_id_(1),
|
||||
extent_(extent),
|
||||
bbox_(q.get_bbox()),
|
||||
curIter_(policy_.begin()),
|
||||
endIter_(policy_.end())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ feature_ptr raster_featureset<LookupPolicy>::next()
|
|||
{
|
||||
std::auto_ptr<image_reader> reader(mapnik::get_image_reader(curIter_->file(),curIter_->format()));
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: READER = " << curIter_->format() << " " << curIter_->file()
|
||||
<< " size(" << curIter_->width() << "," << curIter_->height() << ")" << std::endl;
|
||||
#endif
|
||||
|
@ -78,7 +78,7 @@ feature_ptr raster_featureset<LookupPolicy>::next()
|
|||
{
|
||||
int image_width = policy_.img_width(reader->width());
|
||||
int image_height = policy_.img_height(reader->height());
|
||||
|
||||
|
||||
if (image_width > 0 && image_height > 0)
|
||||
{
|
||||
CoordTransform t(image_width, image_height, extent_, 0, 0);
|
||||
|
@ -131,7 +131,7 @@ feature_ptr raster_featureset<LookupPolicy>::next()
|
|||
{
|
||||
std::cerr << "Raster Plugin: exception caught" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
++curIter_;
|
||||
return feature;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -117,9 +117,9 @@ public:
|
|||
class tiled_file_policy
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef std::vector<raster_info>::const_iterator const_iterator;
|
||||
|
||||
|
||||
tiled_file_policy(std::string const& file,
|
||||
std::string const& format,
|
||||
unsigned tile_size,
|
||||
|
@ -130,19 +130,19 @@ public:
|
|||
{
|
||||
double lox = extent.minx();
|
||||
double loy = extent.miny();
|
||||
|
||||
|
||||
int max_x = int(std::ceil(double(width) / double(tile_size)));
|
||||
int max_y = int(std::ceil(double(height) / double(tile_size)));
|
||||
|
||||
double pixel_x = extent.width() / double(width);
|
||||
double pixel_y = extent.height() / double(height);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
box2d<double> e = bbox.intersect(extent);
|
||||
|
||||
|
||||
for (int x = 0; x < max_x; ++x)
|
||||
{
|
||||
for (int y = 0; y < max_y; ++y)
|
||||
|
@ -151,7 +151,7 @@ public:
|
|||
double y0 = loy + y * tile_size * pixel_y;
|
||||
double x1 = x0 + tile_size * pixel_x;
|
||||
double y1 = y0 + tile_size * pixel_y;
|
||||
|
||||
|
||||
if (e.intersects(box2d<double>(x0, y0, x1, y1)))
|
||||
{
|
||||
box2d<double> tile_box = e.intersect(box2d<double>(x0,y0,x1,y1));
|
||||
|
@ -160,21 +160,21 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
const_iterator begin()
|
||||
{
|
||||
return infos_.begin();
|
||||
}
|
||||
|
||||
|
||||
const_iterator end()
|
||||
{
|
||||
return infos_.end();
|
||||
}
|
||||
|
||||
|
||||
inline int img_width(int reader_width) const
|
||||
{
|
||||
return reader_width;
|
||||
|
@ -198,9 +198,9 @@ private:
|
|||
class tiled_multi_file_policy
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef std::vector<raster_info>::const_iterator const_iterator;
|
||||
|
||||
|
||||
tiled_multi_file_policy(std::string const& file_pattern,
|
||||
std::string const& format,
|
||||
unsigned tile_size,
|
||||
|
@ -209,27 +209,27 @@ public:
|
|||
unsigned width,
|
||||
unsigned height,
|
||||
unsigned tile_stride)
|
||||
: image_width_(width),
|
||||
image_height_(height),
|
||||
tile_size_(tile_size),
|
||||
tile_stride_(tile_stride)
|
||||
: image_width_(width),
|
||||
image_height_(height),
|
||||
tile_size_(tile_size),
|
||||
tile_stride_(tile_stride)
|
||||
{
|
||||
double lox = extent.minx();
|
||||
double loy = extent.miny();
|
||||
|
||||
|
||||
//int max_x = int(std::ceil(double(width) / double(tile_size)));
|
||||
//int max_y = int(std::ceil(double(height) / double(tile_size)));
|
||||
|
||||
double pixel_x = extent.width() / double(width);
|
||||
double pixel_y = extent.height() / double(height);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: PIXEL SIZE("<< pixel_x << "," << pixel_y << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
// intersection of query with extent => new query
|
||||
box2d<double> e = bbox.intersect(extent);
|
||||
|
||||
|
||||
const int x_min = int(std::floor((e.minx() - lox) / (tile_size * pixel_x)));
|
||||
const int y_min = int(std::floor((e.miny() - loy) / (tile_size * pixel_y)));
|
||||
const int x_max = int(std::ceil((e.maxx() - lox) / (tile_size * pixel_x)));
|
||||
|
@ -244,7 +244,7 @@ public:
|
|||
double y0 = loy + y*tile_size*pixel_y;
|
||||
double x1 = x0 + tile_size*pixel_x;
|
||||
double y1 = y0 + tile_size*pixel_y;
|
||||
|
||||
|
||||
// check if it intersects the query
|
||||
if (e.intersects(box2d<double>(x0,y0,x1,y1)))
|
||||
{
|
||||
|
@ -256,11 +256,11 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Raster Plugin: INFO SIZE=" << infos_.size() << " " << file_pattern << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
const_iterator begin()
|
||||
{
|
||||
return infos_.begin();
|
||||
|
@ -270,7 +270,7 @@ public:
|
|||
{
|
||||
return infos_.end();
|
||||
}
|
||||
|
||||
|
||||
inline int img_width(int) const
|
||||
{
|
||||
return image_width_;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -27,20 +27,20 @@ raster_info::raster_info(std::string const& file,
|
|||
mapnik::box2d<double> const& extent,
|
||||
unsigned width,
|
||||
unsigned height)
|
||||
: file_(file),
|
||||
format_(format),
|
||||
extent_(extent),
|
||||
width_(width),
|
||||
height_(height)
|
||||
: file_(file),
|
||||
format_(format),
|
||||
extent_(extent),
|
||||
width_(width),
|
||||
height_(height)
|
||||
{
|
||||
}
|
||||
|
||||
raster_info::raster_info(const raster_info& rhs)
|
||||
: file_(rhs.file_),
|
||||
format_(rhs.format_),
|
||||
extent_(rhs.extent_),
|
||||
width_(rhs.width_),
|
||||
height_(rhs.height_)
|
||||
: file_(rhs.file_),
|
||||
format_(rhs.format_),
|
||||
extent_(rhs.extent_),
|
||||
width_(rhs.width_),
|
||||
height_(rhs.height_)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -33,27 +33,27 @@ using mapnik::box2d;
|
|||
class raster_info
|
||||
{
|
||||
public:
|
||||
raster_info(const std::string& file,
|
||||
const std::string& format,
|
||||
const box2d<double>& extent,
|
||||
unsigned width,
|
||||
unsigned height);
|
||||
raster_info(const raster_info& rhs);
|
||||
raster_info& operator=(const raster_info& rhs);
|
||||
inline box2d<double> const& envelope() const {return extent_;}
|
||||
inline std::string const& file() const { return file_;}
|
||||
inline std::string const& format() const {return format_;}
|
||||
inline unsigned width() const { return width_;}
|
||||
inline unsigned height() const { return height_;}
|
||||
|
||||
private:
|
||||
void swap(raster_info& other) throw();
|
||||
raster_info(const std::string& file,
|
||||
const std::string& format,
|
||||
const box2d<double>& extent,
|
||||
unsigned width,
|
||||
unsigned height);
|
||||
raster_info(const raster_info& rhs);
|
||||
raster_info& operator=(const raster_info& rhs);
|
||||
inline box2d<double> const& envelope() const {return extent_;}
|
||||
inline std::string const& file() const { return file_;}
|
||||
inline std::string const& format() const {return format_;}
|
||||
inline unsigned width() const { return width_;}
|
||||
inline unsigned height() const { return height_;}
|
||||
|
||||
std::string file_;
|
||||
std::string format_;
|
||||
box2d<double> extent_;
|
||||
unsigned width_;
|
||||
unsigned height_;
|
||||
private:
|
||||
void swap(raster_info& other) throw();
|
||||
|
||||
std::string file_;
|
||||
std::string format_;
|
||||
box2d<double> extent_;
|
||||
unsigned width_;
|
||||
unsigned height_;
|
||||
};
|
||||
|
||||
#endif // RASTER_INFO_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -53,7 +53,7 @@ using mapnik::datasource_exception;
|
|||
inline void *rasterlite_datasource::open_dataset() const
|
||||
{
|
||||
void *dataset = rasterliteOpen (dataset_name_.c_str(), table_name_.c_str());
|
||||
|
||||
|
||||
if (! dataset) throw datasource_exception("Rasterlite Plugin: Error opening dataset");
|
||||
|
||||
if (rasterliteIsError (dataset))
|
||||
|
@ -61,7 +61,7 @@ inline void *rasterlite_datasource::open_dataset() const
|
|||
std::string error (rasterliteGetLastError(dataset));
|
||||
|
||||
rasterliteClose (dataset);
|
||||
|
||||
|
||||
throw datasource_exception(error);
|
||||
}
|
||||
|
||||
|
@ -100,24 +100,24 @@ rasterlite_datasource::rasterlite_datasource(parameters const& params, bool bind
|
|||
|
||||
void rasterlite_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
if (is_bound_) return;
|
||||
|
||||
if (!boost::filesystem::exists(dataset_name_)) throw datasource_exception(dataset_name_ + " does not exist");
|
||||
|
||||
void *dataset = open_dataset();
|
||||
|
||||
|
||||
double x0, y0, x1, y1;
|
||||
if (rasterliteGetExtent (dataset, &x0, &y0, &x1, &y1) != RASTERLITE_OK)
|
||||
{
|
||||
std::string error (rasterliteGetLastError(dataset));
|
||||
|
||||
rasterliteClose (dataset);
|
||||
|
||||
|
||||
throw datasource_exception(error);
|
||||
}
|
||||
|
||||
extent_.init(x0,y0,x1,y1);
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
int srid, auth_srid;
|
||||
const char *auth_name;
|
||||
|
@ -129,11 +129,11 @@ void rasterlite_datasource::bind() const
|
|||
int levels = rasterliteGetLevels (dataset);
|
||||
|
||||
if (rasterliteGetSrid(dataset, &srid, &auth_name, &auth_srid, &ref_sys_name, &proj4text) != RASTERLITE_OK)
|
||||
{
|
||||
{
|
||||
std::string error (rasterliteGetLastError(dataset));
|
||||
|
||||
rasterliteClose (dataset);
|
||||
|
||||
|
||||
throw datasource_exception(error);
|
||||
}
|
||||
|
||||
|
@ -145,19 +145,19 @@ void rasterlite_datasource::bind() const
|
|||
std::clog << "Rasterlite Plugin: Proj4Text=" << proj4text << std::endl;
|
||||
std::clog << "Rasterlite Plugin: Extent(" << x0 << "," << y0 << " " << x1 << "," << y1 << ")" << std::endl;
|
||||
std::clog << "Rasterlite Plugin: Levels=" << levels << std::endl;
|
||||
|
||||
|
||||
for (int i = 0; i < levels; i++)
|
||||
{
|
||||
if (rasterliteGetResolution(dataset, i, &pixel_x_size, &pixel_y_size, &tile_count) == RASTERLITE_OK)
|
||||
{
|
||||
std::clog << "Rasterlite Plugin: Level=" << i
|
||||
<< " x=" << pixel_x_size << " y=" << pixel_y_size << " tiles=" << tile_count << std::endl;
|
||||
<< " x=" << pixel_x_size << " y=" << pixel_y_size << " tiles=" << tile_count << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
rasterliteClose(dataset);
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ int rasterlite_datasource::type() const
|
|||
box2d<double> rasterlite_datasource::envelope() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ featureset_ptr rasterlite_datasource::features(query const& q) const
|
|||
featureset_ptr rasterlite_datasource::features_at_point(coord2d const& pt) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
rasterlite_query gq = pt;
|
||||
return boost::make_shared<rasterlite_featureset>(open_dataset(), gq);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "rasterlite_include.hpp"
|
||||
|
||||
class rasterlite_datasource : public mapnik::datasource
|
||||
class rasterlite_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
rasterlite_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -42,9 +42,9 @@ using mapnik::feature_factory;
|
|||
|
||||
|
||||
rasterlite_featureset::rasterlite_featureset(void* dataset, rasterlite_query q)
|
||||
: dataset_(dataset),
|
||||
gquery_(q),
|
||||
first_(true)
|
||||
: dataset_(dataset),
|
||||
gquery_(q),
|
||||
first_(true)
|
||||
{
|
||||
rasterliteSetBackgroundColor(dataset_, 255, 0, 255);
|
||||
rasterliteSetTransparentColor(dataset_, 255, 0, 255);
|
||||
|
@ -103,7 +103,7 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
|
|||
const double pixel_size = (intersect.width() >= intersect.height()) ?
|
||||
(intersect.width() / (double) width) : (intersect.height() / (double) height);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Rasterlite Plugin: Raster extent=" << raster_extent << std::endl;
|
||||
std::clog << "Rasterlite Plugin: View extent=" << q.get_bbox() << std::endl;
|
||||
std::clog << "Rasterlite Plugin: Intersect extent=" << intersect << std::endl;
|
||||
|
@ -144,18 +144,18 @@ feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
|
|||
|
||||
free (raster);
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Rasterlite Plugin: done" << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Rasterlite Plugin: error=" << rasterliteGetLastError (dataset_) << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return feature;
|
||||
}
|
||||
return feature_ptr();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -24,8 +24,8 @@
|
|||
#define RASTERLITE_INCLUDE_HPP
|
||||
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
#include <rasterlite.h>
|
||||
#include <sqlite3.h>
|
||||
#include <rasterlite.h>
|
||||
}
|
||||
|
||||
#endif // RASTERLITE_INCLUDE_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -58,7 +58,7 @@ dbf_file::dbf_file(std::string const& file_name)
|
|||
{
|
||||
file_.buffer(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (file_)
|
||||
{
|
||||
read_header();
|
||||
|
@ -75,9 +75,9 @@ dbf_file::~dbf_file()
|
|||
bool dbf_file::is_open()
|
||||
{
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
return (file_.buffer().second > 0);
|
||||
return (file_.buffer().second > 0);
|
||||
#else
|
||||
return file_.is_open();
|
||||
return file_.is_open();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
|
|||
if (col>=0 && col<num_fields_)
|
||||
{
|
||||
std::string name=fields_[col].name_;
|
||||
|
||||
|
||||
switch (fields_[col].type_)
|
||||
{
|
||||
case 'C':
|
||||
|
@ -139,33 +139,33 @@ void dbf_file::add_attribute(int col, mapnik::transcoder const& tr, Feature cons
|
|||
// FIXME - avoid constructing std::string on stack
|
||||
std::string str(record_+fields_[col].offset_,fields_[col].length_);
|
||||
boost::trim(str);
|
||||
f[name] = tr.transcode(str.c_str());
|
||||
f[name] = tr.transcode(str.c_str());
|
||||
break;
|
||||
}
|
||||
case 'N':
|
||||
case 'F':
|
||||
{
|
||||
|
||||
|
||||
if (record_[fields_[col].offset_] == '*')
|
||||
{
|
||||
boost::put(f,name,0);
|
||||
break;
|
||||
}
|
||||
if ( fields_[col].dec_>0 )
|
||||
{
|
||||
{
|
||||
double val = 0.0;
|
||||
const char *itr = record_+fields_[col].offset_;
|
||||
const char *end = itr + fields_[col].length_;
|
||||
qi::phrase_parse(itr,end,double_,ascii::space,val);
|
||||
boost::put(f,name,val);
|
||||
boost::put(f,name,val);
|
||||
}
|
||||
else
|
||||
{
|
||||
int val = 0;
|
||||
int val = 0;
|
||||
const char *itr = record_+fields_[col].offset_;
|
||||
const char *end = itr + fields_[col].length_;
|
||||
qi::phrase_parse(itr,end,int_,ascii::space,val);
|
||||
boost::put(f,name,val);
|
||||
boost::put(f,name,val);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ int dbf_file::read_short()
|
|||
|
||||
|
||||
int dbf_file::read_int()
|
||||
{
|
||||
{
|
||||
char b[4];
|
||||
file_.read(b,4);
|
||||
boost::int32_t val;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -59,7 +59,7 @@ shape_datasource::shape_datasource(const parameters ¶ms, bool bind)
|
|||
{
|
||||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
if (!file) throw datasource_exception("Shape Plugin: missing <file> parameter");
|
||||
|
||||
|
||||
boost::optional<std::string> base = params.get<std::string>("base");
|
||||
if (base)
|
||||
shape_name_ = *base + "/" + *file;
|
||||
|
@ -67,7 +67,7 @@ shape_datasource::shape_datasource(const parameters ¶ms, bool bind)
|
|||
shape_name_ = *file;
|
||||
|
||||
boost::algorithm::ireplace_last(shape_name_,".shp","");
|
||||
|
||||
|
||||
if (bind)
|
||||
{
|
||||
this->bind();
|
||||
|
@ -77,7 +77,7 @@ shape_datasource::shape_datasource(const parameters ¶ms, bool bind)
|
|||
void shape_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
if (!boost::filesystem::exists(shape_name_ + ".shp"))
|
||||
{
|
||||
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist");
|
||||
|
@ -95,7 +95,7 @@ void shape_datasource::bind() const
|
|||
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
boost::shared_ptr<shape_io> shape_ref = boost::make_shared<shape_io>(shape_name_);
|
||||
init(*shape_ref);
|
||||
for (int i=0;i<shape_ref->dbf().num_fields();++i)
|
||||
|
@ -116,7 +116,7 @@ void shape_datasource::bind() const
|
|||
case 'F': // float
|
||||
{
|
||||
if (fd.dec_>0)
|
||||
{
|
||||
{
|
||||
desc_.add_descriptor(attribute_descriptor(fld_name,Double,false,8));
|
||||
}
|
||||
else
|
||||
|
@ -131,7 +131,7 @@ void shape_datasource::bind() const
|
|||
// G - ole
|
||||
// + - autoincrement
|
||||
std::clog << "Shape Plugin: unknown type " << fd.type_ << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ void shape_datasource::bind() const
|
|||
std::clog << "Shape Plugin: error processing field attributes" << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
|
@ -171,23 +171,23 @@ void shape_datasource::init(shape_io& shape) const
|
|||
//invalid file code
|
||||
throw datasource_exception("Shape Plugin: " + (boost::format("wrong file code : %d") % file_code).str());
|
||||
}
|
||||
|
||||
|
||||
shape.shp().skip(5*4);
|
||||
file_length_=shape.shp().read_xdr_integer();
|
||||
int version=shape.shp().read_ndr_integer();
|
||||
|
||||
|
||||
if (version!=1000)
|
||||
{
|
||||
//invalid version number
|
||||
throw datasource_exception("Shape Plugin: " + (boost::format("invalid version number: %d") % version).str());
|
||||
}
|
||||
|
||||
|
||||
int shape_type = shape.shp().read_ndr_integer();
|
||||
if (shape_type == shape_io::shape_multipatch)
|
||||
throw datasource_exception("Shape Plugin: shapefile multipatch type is not supported");
|
||||
|
||||
|
||||
shape.shp().read_envelope(extent_);
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
double zmin = shape.shp().read_double();
|
||||
double zmax = shape.shp().read_double();
|
||||
|
@ -201,9 +201,9 @@ void shape_datasource::init(shape_io& shape) const
|
|||
#endif
|
||||
|
||||
// check if we have an index file around
|
||||
|
||||
|
||||
indexed_ = shape.has_index();
|
||||
|
||||
|
||||
//std::string index_name(shape_name_+".index");
|
||||
//std::ifstream file(index_name.c_str(),std::ios::in | std::ios::binary);
|
||||
//if (file)
|
||||
|
@ -215,7 +215,7 @@ void shape_datasource::init(shape_io& shape) const
|
|||
//{
|
||||
// std::clog << "### Notice: no .index file found for " + shape_name_ + ".shp, use the 'shapeindex' program to build an index for faster rendering\n";
|
||||
//}
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Shape Plugin: extent=" << extent_ << std::endl;
|
||||
std::clog << "Shape Plugin: file_length=" << file_length_ << std::endl;
|
||||
|
@ -243,7 +243,7 @@ layer_descriptor shape_datasource::get_descriptor() const
|
|||
featureset_ptr shape_datasource::features(const query& q) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
filter_in_box filter(q.get_bbox());
|
||||
if (indexed_)
|
||||
{
|
||||
|
@ -260,11 +260,11 @@ featureset_ptr shape_datasource::features(const query& q) const
|
|||
else
|
||||
{
|
||||
return boost::make_shared<shape_featureset<filter_in_box> >(filter,
|
||||
shape_name_,
|
||||
q.property_names(),
|
||||
desc_.get_encoding(),
|
||||
file_length_,
|
||||
row_limit_);
|
||||
shape_name_,
|
||||
q.property_names(),
|
||||
desc_.get_encoding(),
|
||||
file_length_,
|
||||
row_limit_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,13 +278,13 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
|
|||
std::vector<attribute_descriptor>::const_iterator itr = desc_vector.begin();
|
||||
std::vector<attribute_descriptor>::const_iterator end = desc_vector.end();
|
||||
std::set<std::string> names;
|
||||
|
||||
|
||||
while (itr != end)
|
||||
{
|
||||
{
|
||||
names.insert(itr->get_name());
|
||||
++itr;
|
||||
}
|
||||
|
||||
|
||||
if (indexed_)
|
||||
{
|
||||
shape_->shp().seek(0);
|
||||
|
@ -300,17 +300,17 @@ featureset_ptr shape_datasource::features_at_point(coord2d const& pt) const
|
|||
else
|
||||
{
|
||||
return boost::make_shared<shape_featureset<filter_at_point> >(filter,
|
||||
shape_name_,
|
||||
names,
|
||||
desc_.get_encoding(),
|
||||
file_length_,
|
||||
row_limit_);
|
||||
shape_name_,
|
||||
names,
|
||||
desc_.get_encoding(),
|
||||
file_length_,
|
||||
row_limit_);
|
||||
}
|
||||
}
|
||||
|
||||
box2d<double> shape_datasource::envelope() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -44,14 +44,14 @@ class shape_datasource : public datasource
|
|||
public:
|
||||
shape_datasource(const parameters ¶ms, bool bind=true);
|
||||
virtual ~shape_datasource();
|
||||
|
||||
|
||||
int type() const;
|
||||
static std::string name();
|
||||
featureset_ptr features(const query& q) const;
|
||||
featureset_ptr features_at_point(coord2d const& pt) const;
|
||||
box2d<double> envelope() const;
|
||||
layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
void bind() const;
|
||||
private:
|
||||
shape_datasource(const shape_datasource&);
|
||||
shape_datasource& operator=(const shape_datasource&);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -36,20 +36,20 @@ using mapnik::geometry_type;
|
|||
using mapnik::feature_factory;
|
||||
|
||||
template <typename filterT>
|
||||
shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
||||
shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
||||
const std::string& shape_name,
|
||||
const std::set<std::string>& attribute_names,
|
||||
std::string const& encoding,
|
||||
long file_length,
|
||||
int row_limit)
|
||||
: filter_(filter),
|
||||
//shape_type_(shape_io::shape_null),
|
||||
shape_(shape_name, false),
|
||||
query_ext_(),
|
||||
tr_(new transcoder(encoding)),
|
||||
file_length_(file_length),
|
||||
count_(0),
|
||||
row_limit_(row_limit)
|
||||
: filter_(filter),
|
||||
//shape_type_(shape_io::shape_null),
|
||||
shape_(shape_name, false),
|
||||
query_ext_(),
|
||||
tr_(new transcoder(encoding)),
|
||||
file_length_(file_length),
|
||||
count_(0),
|
||||
row_limit_(row_limit)
|
||||
{
|
||||
shape_.shp().skip(100);
|
||||
|
||||
|
@ -81,7 +81,7 @@ shape_featureset<filterT>::shape_featureset(const filterT& filter,
|
|||
list.push_back(shape_.dbf().descriptor(i).name_);
|
||||
}
|
||||
s << boost::algorithm::join(list, ",") << ".";
|
||||
|
||||
|
||||
throw mapnik::datasource_exception("Shape Plugin: " + s.str());
|
||||
}
|
||||
++pos;
|
||||
|
@ -111,12 +111,12 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (pos < std::streampos(file_length_ * 2))
|
||||
{
|
||||
int type = shape_.type();
|
||||
feature_ptr feature(feature_factory::create(shape_.id_));
|
||||
|
||||
|
||||
if (type == shape_io::shape_point)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
|
@ -155,7 +155,7 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
}
|
||||
else
|
||||
{
|
||||
// skip shapes
|
||||
// skip shapes
|
||||
for (;;)
|
||||
{
|
||||
std::streampos pos = shape_.shp().pos();
|
||||
|
@ -186,127 +186,127 @@ feature_ptr shape_featureset<filterT>::next()
|
|||
return feature_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case shape_io::shape_multipoint:
|
||||
case shape_io::shape_multipoint:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
++count_;
|
||||
break;
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointm:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointm:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
// skip m
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointz:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
|
||||
// skip z
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
|
||||
// check if we have measure data
|
||||
if (shape_.reclength_ == (unsigned)(num_points * 16 + 36))
|
||||
{
|
||||
// skip m
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_multipointz:
|
||||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
case shape_io::shape_polyline:
|
||||
{
|
||||
geometry_type* line = shape_.read_polyline();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
// skip z
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
|
||||
// check if we have measure data
|
||||
if (shape_.reclength_ == (unsigned)(num_points * 16 + 36))
|
||||
{
|
||||
// skip m
|
||||
shape_.shp().skip(2 * 8 + 8 * num_points);
|
||||
}
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
case shape_io::shape_polylinem:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinem();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polyline:
|
||||
{
|
||||
geometry_type* line = shape_.read_polyline();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
case shape_io::shape_polylinez:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinez();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinem:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinem();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
case shape_io::shape_polygon:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygon();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polylinez:
|
||||
{
|
||||
geometry_type* line = shape_.read_polylinez();
|
||||
feature->add_geometry(line);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
case shape_io::shape_polygonm:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonm();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygon:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygon();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonm:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonm();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
||||
case shape_io::shape_polygonz:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonz();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
case shape_io::shape_polygonz:
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonz();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
feature->set_id(shape_.id_);
|
||||
if (attr_ids_.size())
|
||||
{
|
||||
shape_.dbf().move_to(shape_.id_);
|
||||
std::vector<int>::const_iterator itr = attr_ids_.begin();
|
||||
std::vector<int>::const_iterator end = attr_ids_.end();
|
||||
try
|
||||
try
|
||||
{
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
{
|
||||
shape_.dbf().add_attribute(*itr, *tr_, *feature); //TODO optimize!!!
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -40,32 +40,32 @@ using mapnik::transcoder;
|
|||
template <typename filterT>
|
||||
class shape_featureset : public Featureset
|
||||
{
|
||||
filterT filter_;
|
||||
//int shape_type_;
|
||||
shape_io shape_;
|
||||
box2d<double> query_ext_;
|
||||
boost::scoped_ptr<transcoder> tr_;
|
||||
long file_length_;
|
||||
std::vector<int> attr_ids_;
|
||||
mutable box2d<double> feature_ext_;
|
||||
mutable int total_geom_size;
|
||||
mutable int count_;
|
||||
const int row_limit_;
|
||||
filterT filter_;
|
||||
//int shape_type_;
|
||||
shape_io shape_;
|
||||
box2d<double> query_ext_;
|
||||
boost::scoped_ptr<transcoder> tr_;
|
||||
long file_length_;
|
||||
std::vector<int> attr_ids_;
|
||||
mutable box2d<double> feature_ext_;
|
||||
mutable int total_geom_size;
|
||||
mutable int count_;
|
||||
const int row_limit_;
|
||||
|
||||
public:
|
||||
shape_featureset(const filterT& filter,
|
||||
const std::string& shape_file,
|
||||
const std::set<std::string>& attribute_names,
|
||||
std::string const& encoding,
|
||||
long file_length,
|
||||
int row_limit);
|
||||
virtual ~shape_featureset();
|
||||
feature_ptr next();
|
||||
public:
|
||||
shape_featureset(const filterT& filter,
|
||||
const std::string& shape_file,
|
||||
const std::set<std::string>& attribute_names,
|
||||
std::string const& encoding,
|
||||
long file_length,
|
||||
int row_limit);
|
||||
virtual ~shape_featureset();
|
||||
feature_ptr next();
|
||||
|
||||
private:
|
||||
shape_featureset(const shape_featureset&);
|
||||
const shape_featureset& operator=(const shape_featureset&);
|
||||
|
||||
private:
|
||||
shape_featureset(const shape_featureset&);
|
||||
const shape_featureset& operator=(const shape_featureset&);
|
||||
|
||||
};
|
||||
|
||||
#endif //SHAPE_FEATURESET_HPP
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -42,12 +42,12 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
std::string const& encoding,
|
||||
std::string const& shape_name,
|
||||
int row_limit)
|
||||
: filter_(filter),
|
||||
//shape_type_(0),
|
||||
shape_(shape),
|
||||
tr_(new transcoder(encoding)),
|
||||
count_(0),
|
||||
row_limit_(row_limit)
|
||||
: filter_(filter),
|
||||
//shape_type_(0),
|
||||
shape_(shape),
|
||||
tr_(new transcoder(encoding)),
|
||||
count_(0),
|
||||
row_limit_(row_limit)
|
||||
{
|
||||
shape_.shp().skip(100);
|
||||
|
||||
|
@ -63,7 +63,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
}
|
||||
|
||||
std::sort(ids_.begin(), ids_.end());
|
||||
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Shape Plugin: query size=" << ids_.size() << std::endl;
|
||||
#endif
|
||||
|
@ -97,7 +97,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
}
|
||||
|
||||
s << boost::algorithm::join(list, ",") << ".";
|
||||
|
||||
|
||||
throw mapnik::datasource_exception("Shape Plugin: " + s.str());
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ shape_index_featureset<filterT>::shape_index_featureset(const filterT& filter,
|
|||
|
||||
template <typename filterT>
|
||||
feature_ptr shape_index_featureset<filterT>::next()
|
||||
{
|
||||
{
|
||||
if (row_limit_ && count_ > row_limit_)
|
||||
{
|
||||
return feature_ptr();
|
||||
|
@ -155,13 +155,13 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
++count_;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(! filter_.pass(shape_.current_extent()) &&
|
||||
itr_ != ids_.end())
|
||||
{
|
||||
if (shape_.type() != shape_io::shape_null)
|
||||
if (shape_.type() != shape_io::shape_null)
|
||||
{
|
||||
pos = *itr_++;
|
||||
shape_.move_to(pos);
|
||||
|
@ -171,7 +171,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
return feature_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case shape_io::shape_multipoint:
|
||||
|
@ -180,14 +180,14 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
{
|
||||
int num_points = shape_.shp().read_ndr_integer();
|
||||
for (int i = 0; i < num_points; ++i)
|
||||
{
|
||||
{
|
||||
double x = shape_.shp().read_double();
|
||||
double y = shape_.shp().read_double();
|
||||
geometry_type* point = new geometry_type(mapnik::Point);
|
||||
point->move_to(x, y);
|
||||
feature->add_geometry(point);
|
||||
}
|
||||
// ignore m and z for now
|
||||
// ignore m and z for now
|
||||
++count_;
|
||||
break;
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
}
|
||||
|
||||
case shape_io::shape_polygon:
|
||||
{
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygon();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
|
@ -225,7 +225,7 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
}
|
||||
|
||||
case shape_io::shape_polygonm:
|
||||
{
|
||||
{
|
||||
geometry_type* poly = shape_.read_polygonm();
|
||||
feature->add_geometry(poly);
|
||||
++count_;
|
||||
|
@ -241,17 +241,17 @@ feature_ptr shape_index_featureset<filterT>::next()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
feature->set_id(shape_.id_);
|
||||
if (attr_ids_.size())
|
||||
{
|
||||
shape_.dbf().move_to(shape_.id_);
|
||||
std::set<int>::const_iterator itr = attr_ids_.begin();
|
||||
std::set<int>::const_iterator end = attr_ids_.end();
|
||||
try
|
||||
try
|
||||
{
|
||||
for (; itr!=end; ++itr)
|
||||
{
|
||||
{
|
||||
shape_.dbf().add_attribute(*itr, *tr_, *feature);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -37,27 +37,27 @@ const std::string shape_io::DBF = ".dbf";
|
|||
const std::string shape_io::INDEX = ".index";
|
||||
|
||||
shape_io::shape_io(const std::string& shape_name, bool open_index)
|
||||
: type_(shape_null),
|
||||
shp_(shape_name + SHP),
|
||||
dbf_(shape_name + DBF),
|
||||
reclength_(0),
|
||||
id_(0)
|
||||
: type_(shape_null),
|
||||
shp_(shape_name + SHP),
|
||||
dbf_(shape_name + DBF),
|
||||
reclength_(0),
|
||||
id_(0)
|
||||
{
|
||||
bool ok = (shp_.is_open() && dbf_.is_open());
|
||||
if (! ok)
|
||||
{
|
||||
{
|
||||
throw datasource_exception("Shape Plugin: cannot read shape file '" + shape_name + "'");
|
||||
}
|
||||
|
||||
if (open_index)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
index_= boost::make_shared<shape_file>(shape_name + INDEX);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Shape Plugin: warning - could not open index: '" + shape_name + INDEX + "'" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void shape_io::move_to(int pos)
|
|||
id_ = shp_.read_xdr_integer();
|
||||
reclength_ = shp_.read_xdr_integer();
|
||||
type_ = shp_.read_ndr_integer();
|
||||
|
||||
|
||||
if (type_ != shape_null && type_ != shape_point && type_ != shape_pointm && type_ != shape_pointz)
|
||||
{
|
||||
shp_.read_envelope(cur_extent_);
|
||||
|
@ -107,7 +107,7 @@ dbf_file& shape_io::dbf()
|
|||
}
|
||||
|
||||
geometry_type* shape_io::read_polyline()
|
||||
{
|
||||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
|
@ -149,11 +149,11 @@ geometry_type* shape_io::read_polyline()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
|
||||
|
||||
for (int j = start + 1; j < end; ++j)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
@ -166,7 +166,7 @@ geometry_type* shape_io::read_polyline()
|
|||
}
|
||||
|
||||
geometry_type* shape_io::read_polylinem()
|
||||
{
|
||||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
|
@ -178,7 +178,7 @@ geometry_type* shape_io::read_polylinem()
|
|||
{
|
||||
record.skip(4);
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
for (int i = 1; i < num_points; ++i)
|
||||
{
|
||||
|
@ -207,11 +207,11 @@ geometry_type* shape_io::read_polylinem()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
|
||||
|
||||
for (int j = start + 1; j < end; ++j)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
@ -224,48 +224,48 @@ geometry_type* shape_io::read_polylinem()
|
|||
// m-range
|
||||
//double m0=record.read_double();
|
||||
//double m1=record.read_double();
|
||||
|
||||
|
||||
//for (int i=0;i<num_points;++i)
|
||||
//{
|
||||
// double m=record.read_double();
|
||||
//}
|
||||
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
geometry_type* shape_io::read_polylinez()
|
||||
{
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
shape_file::record_type record(reclength_ * 2 - 36);
|
||||
shp_.read_record(record);
|
||||
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
record.skip(4);
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
for (int i = 1; i < num_points; ++i)
|
||||
{
|
||||
x = record.read_double();
|
||||
y = record.read_double();
|
||||
line->line_to(x, y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<int> parts(num_parts);
|
||||
for (int i = 0; i < num_parts; ++i)
|
||||
{
|
||||
parts[i] = record.read_ndr_integer();
|
||||
}
|
||||
int num_parts = record.read_ndr_integer();
|
||||
int num_points = record.read_ndr_integer();
|
||||
geometry_type* line = new geometry_type(mapnik::LineString);
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
record.skip(4);
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
for (int i = 1; i < num_points; ++i)
|
||||
{
|
||||
x = record.read_double();
|
||||
y = record.read_double();
|
||||
line->line_to(x, y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<int> parts(num_parts);
|
||||
for (int i = 0; i < num_parts; ++i)
|
||||
{
|
||||
parts[i] = record.read_ndr_integer();
|
||||
}
|
||||
|
||||
int start, end;
|
||||
for (int k = 0; k < num_parts; ++k)
|
||||
{
|
||||
int start, end;
|
||||
for (int k = 0; k < num_parts; ++k)
|
||||
{
|
||||
start = parts[k];
|
||||
if (k == num_parts - 1)
|
||||
{
|
||||
|
@ -275,11 +275,11 @@ geometry_type* shape_io::read_polylinez()
|
|||
{
|
||||
end = parts[k + 1];
|
||||
}
|
||||
|
||||
|
||||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
line->move_to(x, y);
|
||||
|
||||
|
||||
for (int j = start + 1; j < end; ++j)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
@ -296,11 +296,11 @@ geometry_type* shape_io::read_polylinez()
|
|||
// {
|
||||
// double z=record.read_double();
|
||||
// }
|
||||
|
||||
|
||||
// m-range
|
||||
//double m0=record.read_double();
|
||||
//double m1=record.read_double();
|
||||
|
||||
|
||||
//for (int i=0;i<num_points;++i)
|
||||
//{
|
||||
// double m=record.read_double();
|
||||
|
@ -340,7 +340,7 @@ geometry_type* shape_io::read_polygon()
|
|||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
||||
|
||||
for (int j=start+1;j<end;j++)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
@ -365,7 +365,7 @@ geometry_type* shape_io::read_polygonm()
|
|||
{
|
||||
parts[i] = record.read_ndr_integer();
|
||||
}
|
||||
|
||||
|
||||
for (int k = 0; k < num_parts; k++)
|
||||
{
|
||||
int start = parts[k];
|
||||
|
@ -382,7 +382,7 @@ geometry_type* shape_io::read_polygonm()
|
|||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
||||
|
||||
for (int j = start + 1; j < end; j++)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
@ -416,7 +416,7 @@ geometry_type* shape_io::read_polygonz()
|
|||
{
|
||||
parts[i] = record.read_ndr_integer();
|
||||
}
|
||||
|
||||
|
||||
for (int k = 0; k < num_parts; k++)
|
||||
{
|
||||
int start = parts[k];
|
||||
|
@ -433,7 +433,7 @@ geometry_type* shape_io::read_polygonz()
|
|||
double x = record.read_double();
|
||||
double y = record.read_double();
|
||||
poly->move_to(x, y);
|
||||
|
||||
|
||||
for (int j = start + 1; j < end; j++)
|
||||
{
|
||||
x = record.read_double();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -58,17 +58,17 @@ public:
|
|||
shape_file& shp();
|
||||
//shape_file& shx();
|
||||
dbf_file& dbf();
|
||||
|
||||
|
||||
inline boost::shared_ptr<shape_file>& index()
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
|
||||
|
||||
inline bool has_index() const
|
||||
{
|
||||
return (index_ && index_->is_open());
|
||||
}
|
||||
|
||||
|
||||
void move_to(int id);
|
||||
int type() const;
|
||||
const box2d<double>& current_extent() const;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -51,7 +51,7 @@ struct RecordTag
|
|||
{
|
||||
return static_cast<data_type>(::operator new(sizeof(char)*size));
|
||||
}
|
||||
|
||||
|
||||
static void dealloc(data_type data)
|
||||
{
|
||||
::operator delete(data);
|
||||
|
@ -73,9 +73,9 @@ struct shape_record
|
|||
mutable size_t pos;
|
||||
|
||||
explicit shape_record(size_t size)
|
||||
: data(Tag::alloc(size)),
|
||||
size(size),
|
||||
pos(0)
|
||||
: data(Tag::alloc(size)),
|
||||
size(size),
|
||||
pos(0)
|
||||
{}
|
||||
|
||||
~shape_record()
|
||||
|
@ -88,16 +88,16 @@ struct shape_record
|
|||
data = data_;
|
||||
}
|
||||
|
||||
typename Tag::data_type get_data()
|
||||
typename Tag::data_type get_data()
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void skip(unsigned n)
|
||||
{
|
||||
pos += n;
|
||||
}
|
||||
|
||||
|
||||
int read_ndr_integer()
|
||||
{
|
||||
boost::int32_t val;
|
||||
|
@ -105,7 +105,7 @@ struct shape_record
|
|||
pos += 4;
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
int read_xdr_integer()
|
||||
{
|
||||
boost::int32_t val;
|
||||
|
@ -113,25 +113,25 @@ struct shape_record
|
|||
pos += 4;
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
double read_double()
|
||||
{
|
||||
double val;
|
||||
double val;
|
||||
read_double_ndr(&data[pos], val);
|
||||
pos += 8;
|
||||
return val;
|
||||
}
|
||||
|
||||
long remains()
|
||||
long remains()
|
||||
{
|
||||
return (size - pos);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using namespace boost::interprocess;
|
||||
|
||||
class shape_file : boost::noncopyable
|
||||
{
|
||||
{
|
||||
public:
|
||||
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
|
@ -141,15 +141,15 @@ public:
|
|||
typedef std::ifstream file_source_type;
|
||||
typedef shape_record<RecordTag> record_type;
|
||||
#endif
|
||||
|
||||
|
||||
file_source_type file_;
|
||||
|
||||
shape_file() {}
|
||||
|
||||
|
||||
shape_file(std::string const& file_name) :
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
file_()
|
||||
#else
|
||||
#else
|
||||
file_(file_name.c_str(), std::ios::in | std::ios::binary)
|
||||
#endif
|
||||
{
|
||||
|
@ -161,16 +161,16 @@ public:
|
|||
{
|
||||
file_.buffer(static_cast<char*>((*memory)->get_address()), (*memory)->get_size());
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
~shape_file() {}
|
||||
|
||||
inline file_source_type& file()
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
|
||||
|
||||
inline bool is_open()
|
||||
{
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
|
@ -179,7 +179,7 @@ public:
|
|||
return file_.is_open();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void read_record(record_type& rec)
|
||||
{
|
||||
#ifdef SHAPE_MEMORY_MAPPED_FILE
|
||||
|
@ -189,7 +189,7 @@ public:
|
|||
file_.read(rec.get_data(), rec.size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline int read_xdr_integer()
|
||||
{
|
||||
char b[4];
|
||||
|
@ -198,7 +198,7 @@ public:
|
|||
read_int32_xdr(b, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
inline int read_ndr_integer()
|
||||
{
|
||||
char b[4];
|
||||
|
@ -207,7 +207,7 @@ public:
|
|||
read_int32_ndr(b, val);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
inline double read_double()
|
||||
{
|
||||
double val;
|
||||
|
@ -220,7 +220,7 @@ public:
|
|||
#endif
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
inline void read_envelope(box2d<double>& envelope)
|
||||
{
|
||||
#ifndef MAPNIK_BIG_ENDIAN
|
||||
|
@ -234,29 +234,29 @@ public:
|
|||
read_double_ndr(data + 2 * 8, maxx);
|
||||
read_double_ndr(data + 3 * 8, maxy);
|
||||
envelope.init(minx, miny, maxx, maxy);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void skip(std::streampos bytes)
|
||||
{
|
||||
file_.seekg(bytes, std::ios::cur);
|
||||
}
|
||||
|
||||
|
||||
inline void rewind()
|
||||
{
|
||||
seek(100);
|
||||
}
|
||||
|
||||
|
||||
inline void seek(std::streampos pos)
|
||||
{
|
||||
file_.seekg(pos, std::ios::beg);
|
||||
}
|
||||
|
||||
|
||||
inline std::streampos pos()
|
||||
{
|
||||
return file_.tellg();
|
||||
}
|
||||
|
||||
|
||||
inline bool is_eof()
|
||||
{
|
||||
return file_.eof();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -71,7 +71,7 @@ void shp_index<filterT, IStream>::query_node(const filterT& filter, IStream& fil
|
|||
file.seekg(offset + num_shapes * 4 + 4, std::ios::cur);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < num_shapes; ++i)
|
||||
{
|
||||
int id = read_ndr_integer(file);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
// sqlite
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
|
||||
#include "sqlite_resultset.hpp"
|
||||
|
@ -56,13 +56,13 @@ public:
|
|||
{
|
||||
#if SQLITE_VERSION_NUMBER >= 3005000
|
||||
int mode = SQLITE_OPEN_READWRITE;
|
||||
#if SQLITE_VERSION_NUMBER >= 3006018
|
||||
// shared cache flag not available until >= 3.6.18
|
||||
mode |= SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE;
|
||||
#endif
|
||||
#if SQLITE_VERSION_NUMBER >= 3006018
|
||||
// shared cache flag not available until >= 3.6.18
|
||||
mode |= SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE;
|
||||
#endif
|
||||
const int rc = sqlite3_open_v2 (file_.c_str(), &db_, mode, 0);
|
||||
#else
|
||||
#warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..."
|
||||
#warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..."
|
||||
const int rc = sqlite3_open (file_.c_str(), &db_);
|
||||
#endif
|
||||
if (rc != SQLITE_OK)
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
throw mapnik::datasource_exception (s.str());
|
||||
}
|
||||
|
||||
|
||||
sqlite3_busy_timeout(db_,5000);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
#if SQLITE_VERSION_NUMBER >= 3005000
|
||||
const int rc = sqlite3_open_v2 (file_.c_str(), &db_, flags, 0);
|
||||
#else
|
||||
#warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..."
|
||||
#warning "Mapnik's sqlite plugin is compiling against a version of sqlite older than 3.5.x which may make rendering slow..."
|
||||
const int rc = sqlite3_open (file_.c_str(), &db_);
|
||||
#endif
|
||||
if (rc != SQLITE_OK)
|
||||
|
@ -112,12 +112,12 @@ public:
|
|||
else
|
||||
s << "unknown error, lost connection";
|
||||
s << " (" << file_ << ")"
|
||||
<< "\nFull sql was: '"
|
||||
<< "\nFull sql was: '"
|
||||
<< sql << "'";
|
||||
|
||||
throw mapnik::datasource_exception (s.str());
|
||||
}
|
||||
|
||||
|
||||
boost::shared_ptr<sqlite_resultset> execute_query(const std::string& sql)
|
||||
{
|
||||
sqlite3_stmt* stmt = 0;
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
|
||||
return boost::make_shared<sqlite_resultset>(stmt);
|
||||
}
|
||||
|
||||
|
||||
void execute(const std::string& sql)
|
||||
{
|
||||
const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0);
|
||||
|
@ -145,13 +145,13 @@ public:
|
|||
const int rc = sqlite3_exec(db_, sql.c_str(), 0, 0, 0);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
sqlite3* operator*()
|
||||
{
|
||||
return db_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
sqlite3* db_;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -49,7 +49,7 @@ using mapnik::parameters;
|
|||
DATASOURCE_PLUGIN(sqlite_datasource)
|
||||
|
||||
sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
|
@ -66,10 +66,10 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
|||
format_(mapnik::wkbAuto)
|
||||
{
|
||||
/* TODO
|
||||
- throw if no primary key but spatial index is present?
|
||||
- remove auto-indexing
|
||||
- throw if no primary key but spatial index is present?
|
||||
- remove auto-indexing
|
||||
*/
|
||||
|
||||
|
||||
boost::optional<std::string> file = params_.get<std::string>("file");
|
||||
if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
|
||||
|
||||
|
@ -77,7 +77,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
|||
{
|
||||
throw mapnik::datasource_exception("Sqlite Plugin: missing <table> parameter");
|
||||
}
|
||||
|
||||
|
||||
if (bind)
|
||||
{
|
||||
this->bind();
|
||||
|
@ -87,7 +87,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params, bool bind)
|
|||
void sqlite_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
boost::optional<std::string> file = params_.get<std::string>("file");
|
||||
if (! file) throw datasource_exception("Sqlite Plugin: missing <file> parameter");
|
||||
|
||||
|
@ -100,23 +100,23 @@ void sqlite_datasource::bind() const
|
|||
if ((dataset_name_.compare(":memory:") != 0) && (!boost::filesystem::exists(dataset_name_)))
|
||||
{
|
||||
throw datasource_exception("Sqlite Plugin: " + dataset_name_ + " does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries", false);
|
||||
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index", true);
|
||||
|
||||
|
||||
// TODO - remove this option once all datasources have an indexing api
|
||||
bool auto_index = *params_.get<mapnik::boolean>("auto_index", true);
|
||||
|
||||
boost::optional<std::string> ext = params_.get<std::string>("extent");
|
||||
if (ext) extent_initialized_ = extent_.from_string(*ext);
|
||||
|
||||
|
||||
boost::optional<std::string> wkb = params_.get<std::string>("wkb_format");
|
||||
if (wkb)
|
||||
{
|
||||
if (*wkb == "spatialite")
|
||||
{
|
||||
format_ = mapnik::wkbSpatiaLite;
|
||||
format_ = mapnik::wkbSpatiaLite;
|
||||
}
|
||||
else if (*wkb == "generic")
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ void sqlite_datasource::bind() const
|
|||
{
|
||||
parse_attachdb(*attachdb);
|
||||
}
|
||||
|
||||
|
||||
boost::optional<std::string> initdb = params_.get<std::string>("initdb");
|
||||
if (initdb)
|
||||
{
|
||||
|
@ -181,7 +181,7 @@ void sqlite_datasource::bind() const
|
|||
#endif
|
||||
dataset_->execute(*iter);
|
||||
}
|
||||
|
||||
|
||||
bool found_types_via_subquery = false;
|
||||
if (using_subquery_)
|
||||
{
|
||||
|
@ -195,13 +195,13 @@ void sqlite_datasource::bind() const
|
|||
{
|
||||
desc_.add_descriptor(attribute_descriptor("rowid", mapnik::Integer));
|
||||
}
|
||||
|
||||
|
||||
bool found_table = sqlite_utils::table_info(key_field_,
|
||||
found_types_via_subquery,
|
||||
geometry_field_,
|
||||
geometry_table_,
|
||||
desc_,
|
||||
dataset_);
|
||||
found_types_via_subquery,
|
||||
geometry_field_,
|
||||
geometry_table_,
|
||||
desc_,
|
||||
dataset_);
|
||||
|
||||
if (! found_table)
|
||||
{
|
||||
|
@ -236,7 +236,7 @@ void sqlite_datasource::bind() const
|
|||
}
|
||||
|
||||
std::string index_db = sqlite_utils::index_for_db(dataset_name_);
|
||||
|
||||
|
||||
has_spatial_index_ = false;
|
||||
if (use_spatial_index_)
|
||||
{
|
||||
|
@ -251,7 +251,7 @@ void sqlite_datasource::bind() const
|
|||
if (! key_field_.empty())
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "SELECT "
|
||||
query << "SELECT "
|
||||
<< geometry_field_
|
||||
<< "," << key_field_
|
||||
<< " FROM ("
|
||||
|
@ -270,7 +270,7 @@ void sqlite_datasource::bind() const
|
|||
else
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "Sqlite Plugin: key_field is empty for "
|
||||
s << "Sqlite Plugin: key_field is empty for "
|
||||
<< geometry_field_
|
||||
<< " and "
|
||||
<< geometry_table_;
|
||||
|
@ -294,11 +294,11 @@ void sqlite_datasource::bind() const
|
|||
table_))
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "Sqlite Plugin: extent could not be determined for table '"
|
||||
s << "Sqlite Plugin: extent could not be determined for table '"
|
||||
<< geometry_table_ << "' and geometry field '" << geometry_field_ << "'"
|
||||
<< " because an rtree spatial index is missing or empty."
|
||||
<< " - either set the table 'extent' or create an rtree spatial index";
|
||||
|
||||
|
||||
throw datasource_exception(s.str());
|
||||
}
|
||||
}
|
||||
|
@ -312,31 +312,31 @@ sqlite_datasource::~sqlite_datasource()
|
|||
#if (BOOST_FILESYSTEM_VERSION <= 2)
|
||||
namespace boost {
|
||||
namespace filesystem {
|
||||
path read_symlink(const path& p)
|
||||
{
|
||||
path read_symlink(const path& p)
|
||||
{
|
||||
path symlink_path;
|
||||
|
||||
#ifdef BOOST_POSIX_API
|
||||
for (std::size_t path_max = 64;; path_max *= 2)// loop 'til buffer is large enough
|
||||
{
|
||||
boost::scoped_array<char> buf(new char[path_max]);
|
||||
ssize_t result;
|
||||
if ((result=::readlink(p.string().c_str(), buf.get(), path_max))== -1)
|
||||
{
|
||||
throw std::runtime_error("could not read symlink");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(result != static_cast<ssize_t>(path_max))
|
||||
boost::scoped_array<char> buf(new char[path_max]);
|
||||
ssize_t result;
|
||||
if ((result=::readlink(p.string().c_str(), buf.get(), path_max))== -1)
|
||||
{
|
||||
symlink_path.assign(buf.get(), buf.get() + result);
|
||||
break;
|
||||
throw std::runtime_error("could not read symlink");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(result != static_cast<ssize_t>(path_max))
|
||||
{
|
||||
symlink_path.assign(buf.get(), buf.get() + result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return symlink_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -379,11 +379,11 @@ void sqlite_datasource::parse_attachdb(std::string const& attachdb) const
|
|||
absolute_path = boost::filesystem::read_symlink(absolute_path);
|
||||
}
|
||||
|
||||
#if (BOOST_FILESYSTEM_VERSION == 3)
|
||||
#if (BOOST_FILESYSTEM_VERSION == 3)
|
||||
filename = boost::filesystem::absolute(absolute_path.parent_path() / filename).string();
|
||||
#else
|
||||
#else
|
||||
filename = boost::filesystem::complete(absolute_path.branch_path() / filename).normalize().string();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
|||
mapnik::box2d<double> const& e = q.get_bbox();
|
||||
|
||||
std::ostringstream s;
|
||||
|
||||
|
||||
s << "SELECT " << geometry_field_;
|
||||
if (!key_field_.empty())
|
||||
s << "," << key_field_;
|
||||
|
@ -436,12 +436,12 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
|||
{
|
||||
s << ",\"" << *pos << "\"";
|
||||
++pos;
|
||||
}
|
||||
|
||||
s << " FROM ";
|
||||
|
||||
}
|
||||
|
||||
s << " FROM ";
|
||||
|
||||
std::string query (table_);
|
||||
|
||||
|
||||
if (! key_field_.empty() && has_spatial_index_)
|
||||
{
|
||||
std::ostringstream spatial_sql;
|
||||
|
@ -458,9 +458,9 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
|||
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s << query ;
|
||||
|
||||
|
||||
if (row_limit_ > 0)
|
||||
{
|
||||
s << " LIMIT " << row_limit_;
|
||||
|
@ -483,9 +483,9 @@ featureset_ptr sqlite_datasource::features(query const& q) const
|
|||
format_,
|
||||
multiple_geometries_,
|
||||
using_subquery_);
|
||||
}
|
||||
}
|
||||
|
||||
return featureset_ptr();
|
||||
return featureset_ptr();
|
||||
}
|
||||
|
||||
featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
||||
|
@ -513,11 +513,11 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
|||
|
||||
++itr;
|
||||
}
|
||||
|
||||
s << " FROM ";
|
||||
|
||||
|
||||
s << " FROM ";
|
||||
|
||||
std::string query(table_);
|
||||
|
||||
|
||||
if (! key_field_.empty() && has_spatial_index_)
|
||||
{
|
||||
std::ostringstream spatial_sql;
|
||||
|
@ -534,9 +534,9 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
|||
boost::algorithm::ireplace_first(query, table_, table_ + " " + spatial_sql.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
s << query ;
|
||||
|
||||
|
||||
if (row_limit_ > 0)
|
||||
{
|
||||
s << " LIMIT " << row_limit_;
|
||||
|
@ -558,7 +558,7 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt) const
|
|||
format_,
|
||||
multiple_geometries_,
|
||||
using_subquery_);
|
||||
}
|
||||
|
||||
return featureset_ptr();
|
||||
}
|
||||
|
||||
return featureset_ptr();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -27,7 +27,7 @@
|
|||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <mapnik/feature_layer_desc.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
@ -37,7 +37,7 @@
|
|||
#include "sqlite_connection.hpp"
|
||||
|
||||
|
||||
class sqlite_datasource : public mapnik::datasource
|
||||
class sqlite_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
sqlite_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -49,11 +49,11 @@ sqlite_featureset::sqlite_featureset(boost::shared_ptr<sqlite_resultset> rs,
|
|||
mapnik::wkbFormat format,
|
||||
bool multiple_geometries,
|
||||
bool using_subquery)
|
||||
: rs_(rs),
|
||||
tr_(new transcoder(encoding)),
|
||||
format_(format),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
using_subquery_(using_subquery)
|
||||
: rs_(rs),
|
||||
tr_(new transcoder(encoding)),
|
||||
format_(format),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
using_subquery_(using_subquery)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ feature_ptr sqlite_featureset::next()
|
|||
|
||||
feature_ptr feature(feature_factory::create(feature_id));
|
||||
geometry_utils::from_wkb(feature->paths(), data, size, multiple_geometries_, format_);
|
||||
|
||||
|
||||
for (int i = 2; i < rs_->column_count(); ++i)
|
||||
{
|
||||
const int type_oid = rs_->column_type(i);
|
||||
|
@ -96,40 +96,40 @@ feature_ptr sqlite_featureset::next()
|
|||
switch (type_oid)
|
||||
{
|
||||
case SQLITE_INTEGER:
|
||||
{
|
||||
boost::put(*feature, fld_name_str, rs_->column_integer(i));
|
||||
break;
|
||||
}
|
||||
{
|
||||
boost::put(*feature, fld_name_str, rs_->column_integer(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
{
|
||||
boost::put(*feature, fld_name_str, rs_->column_double(i));
|
||||
break;
|
||||
}
|
||||
{
|
||||
boost::put(*feature, fld_name_str, rs_->column_double(i));
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_TEXT:
|
||||
{
|
||||
int text_size;
|
||||
const char * data = rs_->column_text(i, text_size);
|
||||
UnicodeString ustr = tr_->transcode(data, text_size);
|
||||
boost::put(*feature, fld_name_str, ustr);
|
||||
break;
|
||||
}
|
||||
{
|
||||
int text_size;
|
||||
const char * data = rs_->column_text(i, text_size);
|
||||
UnicodeString ustr = tr_->transcode(data, text_size);
|
||||
boost::put(*feature, fld_name_str, ustr);
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_NULL:
|
||||
{
|
||||
boost::put(*feature, fld_name_str, mapnik::value_null());
|
||||
break;
|
||||
}
|
||||
{
|
||||
boost::put(*feature, fld_name_str, mapnik::value_null());
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_BLOB:
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Sqlite Plugin: field " << fld_name_str
|
||||
<< " unhandled type_oid=" << type_oid << std::endl;
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -25,8 +25,8 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
@ -34,7 +34,7 @@
|
|||
|
||||
// sqlite
|
||||
#include "sqlite_resultset.hpp"
|
||||
|
||||
|
||||
|
||||
class sqlite_featureset : public mapnik::Featureset
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -38,10 +38,10 @@
|
|||
|
||||
// sqlite
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
|
||||
class prepared_index_statement : boost::noncopyable
|
||||
class prepared_index_statement : boost::noncopyable
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -51,10 +51,10 @@ public:
|
|||
{
|
||||
|
||||
const int rc = sqlite3_prepare_v2(*(*ds_),
|
||||
sql.c_str(),
|
||||
-1,
|
||||
&stmt_,
|
||||
0);
|
||||
sql.c_str(),
|
||||
-1,
|
||||
&stmt_,
|
||||
0);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
throw mapnik::datasource_exception(index_error.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
~prepared_index_statement()
|
||||
{
|
||||
if (stmt_)
|
||||
|
@ -85,14 +85,14 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void bind(sqlite_int64 const pkid)
|
||||
{
|
||||
if (sqlite3_bind_int64(stmt_, 1, pkid) != SQLITE_OK)
|
||||
{
|
||||
throw mapnik::datasource_exception("SQLite Plugin: invalid value for for key field while generating index");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void bind(mapnik::box2d<double> const& bbox)
|
||||
|
@ -105,7 +105,7 @@ public:
|
|||
throw mapnik::datasource_exception("SQLite Plugin: invalid value for for extent while generating index");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool step_next ()
|
||||
{
|
||||
const int status = sqlite3_step(stmt_);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
// sqlite
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
{
|
||||
return sqlite3_column_type (stmt_, col);
|
||||
}
|
||||
|
||||
|
||||
const char* column_name (int col)
|
||||
{
|
||||
return sqlite3_column_name (stmt_, col);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 Artem Pavlenko
|
||||
|
@ -41,7 +41,7 @@
|
|||
|
||||
// sqlite
|
||||
extern "C" {
|
||||
#include <sqlite3.h>
|
||||
#include <sqlite3.h>
|
||||
}
|
||||
|
||||
#include "sqlite_resultset.hpp"
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
}
|
||||
if ((first >= '0' && first <= '9') ||
|
||||
(name.find("-") != std::string::npos)
|
||||
)
|
||||
)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
{
|
||||
boost::algorithm::trim_if(z,boost::algorithm::is_any_of("[]'\"`"));
|
||||
}
|
||||
|
||||
|
||||
static std::string index_for_table(std::string const& table, std::string const& field)
|
||||
{
|
||||
std::string table_trimmed = table;
|
||||
|
@ -103,10 +103,10 @@ public:
|
|||
//}
|
||||
//else
|
||||
//{
|
||||
return file + ".index";
|
||||
return file + ".index";
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
static void get_tables(boost::shared_ptr<sqlite_connection> ds,
|
||||
std::vector<std::string> & tables)
|
||||
{
|
||||
|
@ -131,23 +131,23 @@ public:
|
|||
boost::shared_ptr<sqlite_resultset> rs = boost::make_shared<sqlite_resultset>(stmt);
|
||||
while (rs->is_valid() && rs->step_next())
|
||||
{
|
||||
std::clog << "b\n";
|
||||
std::clog << "b\n";
|
||||
const int type_oid = rs->column_type(0);
|
||||
if (type_oid == SQLITE_TEXT)
|
||||
{
|
||||
std::clog << "c\n";
|
||||
std::clog << "c\n";
|
||||
const char * data = rs->column_text(0);
|
||||
if (data)
|
||||
{
|
||||
|
||||
std::clog << "d\n";
|
||||
std::clog << "d\n";
|
||||
tables.push_back(std::string(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void query_extent(boost::shared_ptr<sqlite_resultset> rs,
|
||||
mapnik::box2d<double>& extent)
|
||||
{
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
for (unsigned i=0; i<paths.size(); ++i)
|
||||
{
|
||||
mapnik::box2d<double> const& bbox = paths[i].envelope();
|
||||
|
||||
|
||||
if (bbox.valid())
|
||||
{
|
||||
if (first)
|
||||
|
@ -181,20 +181,20 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool create_spatial_index(std::string const& index_db,
|
||||
std::string const& index_table,
|
||||
boost::shared_ptr<sqlite_resultset> rs)
|
||||
{
|
||||
/* TODO
|
||||
- speedups
|
||||
- return early/recover from failure
|
||||
- allow either in db or in separate
|
||||
- speedups
|
||||
- return early/recover from failure
|
||||
- allow either in db or in separate
|
||||
*/
|
||||
|
||||
|
||||
if (!rs->is_valid())
|
||||
return false;
|
||||
|
||||
|
||||
#if SQLITE_VERSION_NUMBER >= 3005000
|
||||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
|
||||
#else
|
||||
|
@ -203,7 +203,7 @@ public:
|
|||
|
||||
bool existed = boost::filesystem::exists(index_db);
|
||||
boost::shared_ptr<sqlite_connection> ds = boost::make_shared<sqlite_connection>(index_db,flags);
|
||||
|
||||
|
||||
bool one_success = false;
|
||||
try
|
||||
{
|
||||
|
@ -212,31 +212,31 @@ public:
|
|||
ds->execute("BEGIN IMMEDIATE TRANSACTION");
|
||||
|
||||
/*
|
||||
ds->execute("PRAGMA journal_mode=WAL");
|
||||
ds->execute("PRAGMA fullfsync=1");
|
||||
ds->execute("PRAGMA locking_mode = EXCLUSIVE");
|
||||
ds->execute("BEGIN EXCLUSIVE TRANSACTION");
|
||||
ds->execute("PRAGMA journal_mode=WAL");
|
||||
ds->execute("PRAGMA fullfsync=1");
|
||||
ds->execute("PRAGMA locking_mode = EXCLUSIVE");
|
||||
ds->execute("BEGIN EXCLUSIVE TRANSACTION");
|
||||
*/
|
||||
|
||||
// first drop the index if it already exists
|
||||
std::ostringstream spatial_index_drop_sql;
|
||||
spatial_index_drop_sql << "DROP TABLE IF EXISTS " << index_table;
|
||||
ds->execute(spatial_index_drop_sql.str());
|
||||
|
||||
|
||||
// create the spatial index
|
||||
std::ostringstream create_idx;
|
||||
create_idx << "create virtual table "
|
||||
create_idx << "create virtual table "
|
||||
<< index_table
|
||||
<< " using rtree(pkid, xmin, xmax, ymin, ymax)";
|
||||
|
||||
|
||||
// insert for prepared statement
|
||||
std::ostringstream insert_idx;
|
||||
insert_idx << "insert into "
|
||||
<< index_table
|
||||
<< " values (?,?,?,?,?)";
|
||||
|
||||
|
||||
ds->execute(create_idx.str());
|
||||
|
||||
|
||||
prepared_index_statement ps(ds,insert_idx.str());
|
||||
|
||||
while (rs->is_valid() && rs->step_next())
|
||||
|
@ -254,9 +254,9 @@ public:
|
|||
mapnik::box2d<double> const& bbox = paths[i].envelope();
|
||||
if (bbox.valid())
|
||||
{
|
||||
|
||||
|
||||
ps.bind(bbox);
|
||||
|
||||
|
||||
const int type_oid = rs->column_type(1);
|
||||
if (type_oid != SQLITE_INTEGER)
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ public:
|
|||
<< "' type was: " << type_oid << "";
|
||||
throw mapnik::datasource_exception(error_msg.str());
|
||||
}
|
||||
|
||||
|
||||
const sqlite_int64 pkid = rs->column_integer64(1);
|
||||
ps.bind(pkid);
|
||||
}
|
||||
|
@ -274,10 +274,10 @@ public:
|
|||
{
|
||||
std::ostringstream error_msg;
|
||||
error_msg << "SQLite Plugin: encountered invalid bbox at '"
|
||||
<< rs->column_name(1) << "' == " << rs->column_integer64(1);
|
||||
<< rs->column_name(1) << "' == " << rs->column_integer64(1);
|
||||
throw mapnik::datasource_exception(error_msg.str());
|
||||
}
|
||||
|
||||
|
||||
ps.step_next();
|
||||
one_success = true;
|
||||
}
|
||||
|
@ -322,20 +322,20 @@ public:
|
|||
std::string const& geometry_table,
|
||||
std::string const& key_field,
|
||||
std::string const& table
|
||||
)
|
||||
)
|
||||
{
|
||||
if (has_spatial_index)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "SELECT MIN(xmin), MIN(ymin), MAX(xmax), MAX(ymax) FROM "
|
||||
<< index_table;
|
||||
|
||||
s << "SELECT MIN(xmin), MIN(ymin), MAX(xmax), MAX(ymax) FROM "
|
||||
<< index_table;
|
||||
|
||||
boost::shared_ptr<sqlite_resultset> rs(ds->execute_query(s.str()));
|
||||
if (rs->is_valid() && rs->step_next())
|
||||
{
|
||||
if (! rs->column_isnull(0))
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
double xmin = boost::lexical_cast<double>(rs->column_double(0));
|
||||
double ymin = boost::lexical_cast<double>(rs->column_double(1));
|
||||
|
@ -403,9 +403,9 @@ public:
|
|||
}
|
||||
|
||||
static bool detect_types_from_subquery(std::string const& query,
|
||||
std::string & geometry_field,
|
||||
mapnik::layer_descriptor & desc,
|
||||
boost::shared_ptr<sqlite_connection> ds)
|
||||
std::string & geometry_field,
|
||||
mapnik::layer_descriptor & desc,
|
||||
boost::shared_ptr<sqlite_connection> ds)
|
||||
{
|
||||
bool found = false;
|
||||
boost::shared_ptr<sqlite_resultset> rs(ds->execute_query(query));
|
||||
|
@ -421,15 +421,15 @@ public:
|
|||
case SQLITE_INTEGER:
|
||||
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Integer));
|
||||
break;
|
||||
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::Double));
|
||||
break;
|
||||
|
||||
|
||||
case SQLITE_TEXT:
|
||||
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
|
||||
break;
|
||||
|
||||
|
||||
case SQLITE_NULL:
|
||||
// sqlite reports based on value, not actual column type unless
|
||||
// PRAGMA table_info is used so here we assume the column is a string
|
||||
|
@ -446,7 +446,7 @@ public:
|
|||
geometry_field = std::string(fld_name);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
#ifdef MAPNIK_DEBUG
|
||||
std::clog << "Sqlite Plugin: unknown type_oid=" << type_oid << std::endl;
|
||||
|
@ -455,21 +455,21 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool table_info(std::string & key_field,
|
||||
bool detected_types,
|
||||
std::string & field,
|
||||
std::string & table,
|
||||
mapnik::layer_descriptor & desc,
|
||||
boost::shared_ptr<sqlite_connection> ds)
|
||||
bool detected_types,
|
||||
std::string & field,
|
||||
std::string & table,
|
||||
mapnik::layer_descriptor & desc,
|
||||
boost::shared_ptr<sqlite_connection> ds)
|
||||
{
|
||||
|
||||
// http://www.sqlite.org/pragma.html#pragma_table_info
|
||||
// use pragma table_info to detect primary key
|
||||
// and to detect types if no subquery is used or
|
||||
// and to detect types if no subquery is used or
|
||||
// if the subquery-based type detection failed
|
||||
std::ostringstream s;
|
||||
s << "PRAGMA table_info(" << table << ")";
|
||||
|
@ -483,7 +483,7 @@ public:
|
|||
std::string fld_type(rs->column_text(2));
|
||||
int fld_pk = rs->column_integer(5);
|
||||
boost::algorithm::to_lower(fld_type);
|
||||
|
||||
|
||||
// TODO - how to handle primary keys on multiple columns ?
|
||||
if (key_field.empty() && ! found_pk && fld_pk != 0)
|
||||
{
|
||||
|
@ -499,12 +499,12 @@ public:
|
|||
boost::algorithm::contains(fld_type, "point") ||
|
||||
boost::algorithm::contains(fld_type, "linestring") ||
|
||||
boost::algorithm::contains(fld_type, "polygon"))
|
||||
||
|
||||
||
|
||||
(boost::algorithm::icontains(fld_name, "geom") ||
|
||||
boost::algorithm::icontains(fld_name, "point") ||
|
||||
boost::algorithm::icontains(fld_name, "linestring") ||
|
||||
boost::algorithm::icontains(fld_name, "polygon")))
|
||||
)
|
||||
)
|
||||
{
|
||||
field = std::string(fld_name);
|
||||
}
|
||||
|
@ -531,23 +531,23 @@ public:
|
|||
desc.add_descriptor(mapnik::attribute_descriptor(fld_name, mapnik::String));
|
||||
}
|
||||
}
|
||||
#ifdef MAPNIK_DEBUG
|
||||
#ifdef MAPNIK_DEBUG
|
||||
else
|
||||
{
|
||||
// "Column Affinity" says default to "Numeric" but for now we pass..
|
||||
//desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
|
||||
|
||||
|
||||
// TODO - this should not fail when we specify geometry_field in XML file
|
||||
|
||||
|
||||
std::clog << "Sqlite Plugin: column '"
|
||||
<< std::string(fld_name)
|
||||
<< "' unhandled due to unknown type: "
|
||||
<< fld_type << std::endl;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return found_table;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,10 +12,10 @@ using mapnik::parameters;
|
|||
DATASOURCE_PLUGIN(hello_datasource)
|
||||
|
||||
hello_datasource::hello_datasource(parameters const& params, bool bind)
|
||||
: datasource(params),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")),
|
||||
extent_()
|
||||
: datasource(params),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")),
|
||||
extent_()
|
||||
{
|
||||
if (bind)
|
||||
{
|
||||
|
@ -26,14 +26,14 @@ hello_datasource::hello_datasource(parameters const& params, bool bind)
|
|||
void hello_datasource::bind() const
|
||||
{
|
||||
if (is_bound_) return;
|
||||
|
||||
|
||||
// every datasource must have some way of reporting its extent
|
||||
// in this case we are not actually reading from any data so for fun
|
||||
// let's just create a world extent in Mapnik's default srs:
|
||||
// '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326)
|
||||
// see http://spatialreference.org/ref/epsg/4326/ for more details
|
||||
extent_.init(-180,-90,180,90);
|
||||
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,14 @@ mapnik::box2d<double> hello_datasource::envelope() const
|
|||
mapnik::layer_descriptor hello_datasource::get_descriptor() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
return desc_;
|
||||
}
|
||||
|
||||
mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
|
||||
|
||||
// if the query box intersects our world extent then query for features
|
||||
if (extent_.intersects(q.get_bbox()))
|
||||
{
|
||||
|
|
|
@ -4,47 +4,47 @@
|
|||
// mapnik
|
||||
#include <mapnik/datasource.hpp>
|
||||
|
||||
class hello_datasource : public mapnik::datasource
|
||||
class hello_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
// arguments must not change
|
||||
hello_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
|
||||
// destructor
|
||||
virtual ~hello_datasource ();
|
||||
|
||||
// mandatory: type of the plugin, used to match at runtime
|
||||
int type() const;
|
||||
public:
|
||||
// constructor
|
||||
// arguments must not change
|
||||
hello_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
|
||||
// mandatory: name of the plugin
|
||||
static std::string name();
|
||||
// destructor
|
||||
virtual ~hello_datasource ();
|
||||
|
||||
// mandatory: function to query features by box2d
|
||||
// this is called when rendering, specifically in feature_style_processor.hpp
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
// mandatory: type of the plugin, used to match at runtime
|
||||
int type() const;
|
||||
|
||||
// mandatory: function to query features by point (coord2d)
|
||||
// not used by rendering, but available to calling applications
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
// mandatory: name of the plugin
|
||||
static std::string name();
|
||||
|
||||
// mandatory: return the box2d of the datasource
|
||||
// called during rendering to determine if the layer should be processed
|
||||
mapnik::box2d<double> envelope() const;
|
||||
|
||||
// mandatory: return the layer descriptor
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
||||
// mandatory: will bind the datasource given params
|
||||
void bind() const;
|
||||
// mandatory: function to query features by box2d
|
||||
// this is called when rendering, specifically in feature_style_processor.hpp
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
|
||||
private:
|
||||
// recommended naming convention of datasource members:
|
||||
// name_, type_, extent_, and desc_
|
||||
static const std::string name_;
|
||||
int type_;
|
||||
mutable mapnik::layer_descriptor desc_;
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
// mandatory: function to query features by point (coord2d)
|
||||
// not used by rendering, but available to calling applications
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
|
||||
// mandatory: return the box2d of the datasource
|
||||
// called during rendering to determine if the layer should be processed
|
||||
mapnik::box2d<double> envelope() const;
|
||||
|
||||
// mandatory: return the layer descriptor
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
|
||||
// mandatory: will bind the datasource given params
|
||||
void bind() const;
|
||||
|
||||
private:
|
||||
// recommended naming convention of datasource members:
|
||||
// name_, type_, extent_, and desc_
|
||||
static const std::string name_;
|
||||
int type_;
|
||||
mutable mapnik::layer_descriptor desc_;
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#include "hello_featureset.hpp"
|
||||
|
||||
hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding)
|
||||
: box_(box),
|
||||
feature_id_(1),
|
||||
tr_(new mapnik::transcoder(encoding)) { }
|
||||
: box_(box),
|
||||
feature_id_(1),
|
||||
tr_(new mapnik::transcoder(encoding)) { }
|
||||
|
||||
hello_featureset::~hello_featureset() { }
|
||||
|
||||
|
@ -29,17 +29,17 @@ mapnik::feature_ptr hello_featureset::next()
|
|||
// we take the center of the bbox that was used to query
|
||||
// since we don't actually have any data to pull from...
|
||||
mapnik::coord2d center = box_.center();
|
||||
|
||||
|
||||
// create a new point geometry
|
||||
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
|
||||
|
||||
|
||||
// we use path type geometries in Mapnik to fit nicely with AGG and Cairo
|
||||
// here we stick an x,y pair into the geometry using move_to()
|
||||
pt->move_to(center.x,center.y);
|
||||
|
||||
|
||||
// add the geometry to the feature
|
||||
feature->add_geometry(pt);
|
||||
|
||||
|
||||
// A feature usually will have just one geometry of a given type
|
||||
// but mapnik does support many geometries per feature of any type
|
||||
// so here we draw a line around the point
|
||||
|
@ -50,11 +50,11 @@ mapnik::feature_ptr hello_featureset::next()
|
|||
line->line_to(box_.maxx(),box_.miny());
|
||||
line->line_to(box_.minx(),box_.miny());
|
||||
feature->add_geometry(line);
|
||||
|
||||
|
||||
// return the feature!
|
||||
return feature;
|
||||
}
|
||||
|
||||
|
||||
// otherwise return an empty feature
|
||||
return mapnik::feature_ptr();
|
||||
}
|
||||
|
|
|
@ -10,21 +10,21 @@
|
|||
// extend the mapnik::Featureset defined in include/mapnik/datasource.hpp
|
||||
class hello_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
// this constructor can have any arguments you need
|
||||
hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding);
|
||||
|
||||
// desctructor
|
||||
virtual ~hello_featureset();
|
||||
|
||||
// mandatory: you must expose a next() method, called when rendering
|
||||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
// members are up to you, but these are recommended
|
||||
mapnik::box2d<double> const& box_;
|
||||
mutable int feature_id_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
public:
|
||||
// this constructor can have any arguments you need
|
||||
hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding);
|
||||
|
||||
// desctructor
|
||||
virtual ~hello_featureset();
|
||||
|
||||
// mandatory: you must expose a next() method, called when rendering
|
||||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
// members are up to you, but these are recommended
|
||||
mapnik::box2d<double> const& box_;
|
||||
mutable int feature_id_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
};
|
||||
|
||||
#endif // HELLO_FEATURESET_HPP
|
||||
|
|
Loading…
Reference in a new issue