2009-01-28 21:16:31 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
//$Id$
|
|
|
|
|
|
|
|
#include <mapnik/global.hpp>
|
|
|
|
#include <mapnik/datasource.hpp>
|
2009-12-16 21:02:06 +01:00
|
|
|
#include <mapnik/box2d.hpp>
|
2009-01-29 05:20:34 +01:00
|
|
|
#include <mapnik/geometry.hpp>
|
2009-01-28 21:16:31 +01:00
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/feature_layer_desc.hpp>
|
|
|
|
#include <mapnik/wkb.hpp>
|
|
|
|
#include <mapnik/unicode.hpp>
|
|
|
|
|
2009-01-29 05:20:34 +01:00
|
|
|
// ogr
|
2009-01-28 21:16:31 +01:00
|
|
|
#include "ogr_featureset.hpp"
|
2009-05-12 00:06:48 +02:00
|
|
|
#include "ogr_converter.hpp"
|
|
|
|
#include "ogr_feature_ptr.hpp"
|
2009-01-29 05:20:34 +01:00
|
|
|
|
2009-01-28 21:16:31 +01:00
|
|
|
using std::clog;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
using mapnik::query;
|
2009-12-16 21:02:06 +01:00
|
|
|
using mapnik::box2d;
|
2009-01-29 05:20:34 +01:00
|
|
|
using mapnik::CoordTransform;
|
2009-01-28 21:16:31 +01:00
|
|
|
using mapnik::Feature;
|
|
|
|
using mapnik::feature_ptr;
|
|
|
|
using mapnik::geometry_utils;
|
2009-01-29 17:20:30 +01:00
|
|
|
using mapnik::transcoder;
|
2009-01-28 21:16:31 +01:00
|
|
|
|
2009-02-03 19:30:06 +01:00
|
|
|
|
2009-05-12 00:06:48 +02:00
|
|
|
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
|
|
|
OGRLayer & layer,
|
|
|
|
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)
|
2009-02-03 19:30:06 +01:00
|
|
|
{
|
2009-05-12 00:06:48 +02:00
|
|
|
layer_.SetSpatialFilter (&extent);
|
|
|
|
}
|
2009-02-03 19:30:06 +01:00
|
|
|
|
2009-01-28 21:16:31 +01:00
|
|
|
ogr_featureset::ogr_featureset(OGRDataSource & dataset,
|
|
|
|
OGRLayer & layer,
|
2009-12-16 21:02:06 +01:00
|
|
|
const mapnik::box2d<double> & extent,
|
2009-05-12 00:06:48 +02:00
|
|
|
const std::string& encoding,
|
|
|
|
const bool multiple_geometries)
|
2009-01-28 21:16:31 +01:00
|
|
|
: dataset_(dataset),
|
|
|
|
layer_(layer),
|
2009-02-05 17:47:07 +01:00
|
|
|
layerdef_(layer.GetLayerDefn()),
|
2009-01-29 17:20:30 +01:00
|
|
|
tr_(new transcoder(encoding)),
|
2009-01-28 21:16:31 +01:00
|
|
|
fidcolumn_(layer_.GetFIDColumn ()),
|
2009-05-12 00:06:48 +02:00
|
|
|
multiple_geometries_(multiple_geometries),
|
|
|
|
count_(0)
|
2009-01-28 21:16:31 +01:00
|
|
|
{
|
2009-05-12 00:06:48 +02:00
|
|
|
layer_.SetSpatialFilterRect (extent.minx(),
|
|
|
|
extent.miny(),
|
|
|
|
extent.maxx(),
|
|
|
|
extent.maxy());
|
2009-01-28 21:16:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ogr_featureset::~ogr_featureset() {}
|
|
|
|
|
|
|
|
feature_ptr ogr_featureset::next()
|
|
|
|
{
|
2009-02-03 19:30:06 +01:00
|
|
|
ogr_feature_ptr feat (layer_.GetNextFeature());
|
|
|
|
if ((*feat) != NULL)
|
2009-01-28 21:16:31 +01:00
|
|
|
{
|
2009-02-03 19:30:06 +01:00
|
|
|
OGRGeometry* geom=(*feat)->GetGeometryRef();
|
2010-08-20 23:14:14 +02:00
|
|
|
if (geom && !geom->IsEmpty())
|
2009-01-28 21:16:31 +01:00
|
|
|
{
|
2009-02-03 19:30:06 +01:00
|
|
|
feature_ptr feature(new Feature((*feat)->GetFID()));
|
2009-01-28 21:16:31 +01:00
|
|
|
|
2009-05-12 00:06:48 +02:00
|
|
|
ogr_converter::convert_geometry (geom, feature, multiple_geometries_);
|
|
|
|
++count_;
|
2009-01-28 21:16:31 +01:00
|
|
|
|
2009-02-05 17:47:07 +01:00
|
|
|
int fld_count = layerdef_->GetFieldCount();
|
2009-01-29 17:20:30 +01:00
|
|
|
for (int i = 0; i < fld_count; i++)
|
2009-01-28 21:16:31 +01:00
|
|
|
{
|
2009-02-05 17:47:07 +01:00
|
|
|
OGRFieldDefn* fld = layerdef_->GetFieldDefn (i);
|
2009-01-28 21:16:31 +01:00
|
|
|
OGRFieldType type_oid = fld->GetType ();
|
2009-02-18 23:50:12 +01:00
|
|
|
std::string fld_name = fld->GetNameRef ();
|
2009-01-28 21:16:31 +01:00
|
|
|
|
|
|
|
switch (type_oid)
|
|
|
|
{
|
|
|
|
case OFTInteger:
|
2009-01-29 17:20:30 +01:00
|
|
|
{
|
2009-02-05 17:47:07 +01:00
|
|
|
boost::put(*feature,fld_name,(*feat)->GetFieldAsInteger (i));
|
2009-01-28 21:16:31 +01:00
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
2009-01-28 21:16:31 +01:00
|
|
|
|
|
|
|
case OFTReal:
|
2009-01-29 17:20:30 +01:00
|
|
|
{
|
2009-02-05 17:47:07 +01:00
|
|
|
boost::put(*feature,fld_name,(*feat)->GetFieldAsDouble (i));
|
2009-01-28 21:16:31 +01:00
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
2009-01-28 21:16:31 +01:00
|
|
|
|
|
|
|
case OFTString:
|
2009-01-29 17:20:30 +01:00
|
|
|
case OFTWideString: // deprecated !
|
|
|
|
{
|
2009-02-03 19:30:06 +01:00
|
|
|
UnicodeString ustr = tr_->transcode((*feat)->GetFieldAsString (i));
|
2009-02-05 17:47:07 +01:00
|
|
|
boost::put(*feature,fld_name,ustr);
|
2009-01-29 17:20:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OFTIntegerList:
|
|
|
|
case OFTRealList:
|
|
|
|
case OFTStringList:
|
2009-02-05 17:47:07 +01:00
|
|
|
case OFTWideStringList: // deprecated !
|
2009-01-29 17:20:30 +01:00
|
|
|
{
|
2009-01-29 05:20:34 +01:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2009-01-29 17:20:30 +01:00
|
|
|
clog << "unhandled type_oid=" << type_oid << endl;
|
2009-01-29 05:20:34 +01:00
|
|
|
#endif
|
2009-01-28 21:16:31 +01:00
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 21:16:31 +01:00
|
|
|
case OFTBinary:
|
2009-01-29 17:20:30 +01:00
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
|
|
|
clog << "unhandled type_oid=" << type_oid << endl;
|
2009-01-28 21:16:31 +01:00
|
|
|
#endif
|
2009-01-29 17:20:30 +01:00
|
|
|
//boost::put(*feature,name,feat->GetFieldAsBinary (i, size));
|
2009-01-28 21:16:31 +01:00
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
2009-01-28 21:16:31 +01:00
|
|
|
|
|
|
|
case OFTDate:
|
|
|
|
case OFTTime:
|
2009-01-29 17:20:30 +01:00
|
|
|
case OFTDateTime: // unhandled !
|
|
|
|
{
|
2009-01-28 21:16:31 +01:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2009-01-29 05:20:34 +01:00
|
|
|
clog << "unhandled type_oid=" << type_oid << endl;
|
2009-01-28 21:16:31 +01:00
|
|
|
#endif
|
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
2009-01-28 21:16:31 +01:00
|
|
|
|
|
|
|
default: // unknown
|
2009-01-29 17:20:30 +01:00
|
|
|
{
|
2009-01-28 21:16:31 +01:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2009-01-29 05:20:34 +01:00
|
|
|
clog << "unknown type_oid=" << type_oid << endl;
|
2009-01-28 21:16:31 +01:00
|
|
|
#endif
|
|
|
|
break;
|
2009-01-29 17:20:30 +01:00
|
|
|
}
|
2009-01-28 21:16:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-29 05:20:34 +01:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2009-05-12 00:06:48 +02:00
|
|
|
clog << count_ << " features" << endl;
|
2009-01-29 05:20:34 +01:00
|
|
|
#endif
|
2009-05-12 00:06:48 +02:00
|
|
|
return feature_ptr();
|
2009-01-29 05:20:34 +01:00
|
|
|
}
|
|
|
|
|