+ improved and cleaned up occi plugin

This commit is contained in:
Lucio Asnaghi 2010-11-22 11:40:08 +00:00
parent 6713df5937
commit 1d7acffadb
5 changed files with 286 additions and 342 deletions

View file

@ -40,10 +40,6 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
using std::clog;
using std::endl;
using std::vector;
using boost::lexical_cast; using boost::lexical_cast;
using boost::bad_lexical_cast; using boost::bad_lexical_cast;
@ -66,13 +62,14 @@ using oracle::occi::SQLException;
using oracle::occi::Type; using oracle::occi::Type;
using oracle::occi::StatelessConnectionPool; using oracle::occi::StatelessConnectionPool;
const std::string occi_datasource::METADATA_TABLE="USER_SDO_GEOM_METADATA";
DATASOURCE_PLUGIN(occi_datasource) DATASOURCE_PLUGIN(occi_datasource)
occi_datasource::occi_datasource(parameters const& params, bool bind) occi_datasource::occi_datasource(parameters const& params, bool bind)
: datasource (params), : datasource (params),
type_(datasource::Vector), type_(datasource::Vector),
table_(*params_.get<std::string>("table","")),
fields_(*params_.get<std::string>("fields","*")), fields_(*params_.get<std::string>("fields","*")),
geometry_field_(*params_.get<std::string>("geometry_field","")), geometry_field_(*params_.get<std::string>("geometry_field","")),
srid_initialized_(false), srid_initialized_(false),
@ -80,12 +77,22 @@ occi_datasource::occi_datasource(parameters const& params, bool bind)
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")), desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")),
row_limit_(*params_.get<int>("row_limit",0)), row_limit_(*params_.get<int>("row_limit",0)),
row_prefetch_(*params_.get<int>("row_prefetch",100)), row_prefetch_(*params_.get<int>("row_prefetch",100)),
pool_(NULL), pool_(0),
conn_(NULL) conn_(0)
{ {
if (! params_.get<std::string>("user")) throw datasource_exception("No <user> specified"); if (! params_.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified");
if (! params_.get<std::string>("password")) throw datasource_exception("No <password> specified"); if (! params_.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified");
if (! params_.get<std::string>("host")) throw datasource_exception("No <host> string specified"); if (! params_.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified");
boost::optional<std::string> table = params_.get<std::string>("table");
if (!table)
{
throw datasource_exception("OCCI Plugin: no <table> parameter specified");
}
else
{
table_ = *table;
}
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false); multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true); use_spatial_index_ = *params_.get<mapnik::boolean>("use_spatial_index",true);
@ -115,12 +122,12 @@ occi_datasource::~occi_datasource()
if (use_connection_pool_) if (use_connection_pool_)
{ {
if (pool_ != NULL) if (pool_ != 0)
env->terminateStatelessConnectionPool (pool_); env->terminateStatelessConnectionPool (pool_, StatelessConnectionPool::SPD_FORCE);
} }
else else
{ {
if (conn_ != NULL) if (conn_ != 0)
env->terminateConnection(conn_); env->terminateConnection(conn_);
} }
} }
@ -148,7 +155,7 @@ void occi_datasource::bind() const
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
else else
@ -164,7 +171,7 @@ void occi_datasource::bind() const
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
@ -174,12 +181,16 @@ void occi_datasource::bind() const
if (! srid_initialized_ || geometry_field_ == "") if (! srid_initialized_ || geometry_field_ == "")
{ {
std::ostringstream s; std::ostringstream s;
s << "SELECT srid, column_name FROM " << SDO_GEOMETRY_METADATA_TABLE << " WHERE"; s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE";
s << " LOWER(table_name) = LOWER('" << table_name << "')"; s << " LOWER(table_name) = LOWER('" << table_name << "')";
if (geometry_field_ != "") if (geometry_field_ != "")
s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";
#ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif
try try
{ {
occi_connection_ptr conn; occi_connection_ptr conn;
@ -203,7 +214,7 @@ void occi_datasource::bind() const
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
@ -212,6 +223,10 @@ void occi_datasource::bind() const
std::ostringstream s; std::ostringstream s;
s << "SELECT " << fields_ << " FROM (" << table_name << ") WHERE rownum < 1"; s << "SELECT " << fields_ << " FROM (" << table_name << ") WHERE rownum < 1";
#ifdef MAPNIK_DEBUG
std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif
try try
{ {
occi_connection_ptr conn; occi_connection_ptr conn;
@ -230,14 +245,14 @@ void occi_datasource::bind() const
std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);
#if 0 /*
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
if (type_code == OCCI_TYPECODE_OBJECT) if (type_code == OCCI_TYPECODE_OBJECT)
{ {
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
continue; continue;
} }
#endif */
switch (type_oid) switch (type_oid)
{ {
@ -301,14 +316,13 @@ void occi_datasource::bind() const
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "unsupported datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")" << endl; << " (type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
default: default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "unknown datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl;
<< " (type_oid=" << type_oid << ")" << endl;
#endif #endif
break; break;
} }
@ -351,7 +365,7 @@ box2d<double> occi_datasource::envelope() const
s << " TABLE(SDO_UTIL.GETVERTICES(a.shape)) c"; s << " TABLE(SDO_UTIL.GETVERTICES(a.shape)) c";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif #endif
try try
@ -374,13 +388,13 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast &ex)
{ {
clog << ex.what() << endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
else if (use_spatial_index_) else if (use_spatial_index_)
@ -389,15 +403,15 @@ box2d<double> occi_datasource::envelope() const
std::ostringstream s; std::ostringstream s;
s << "SELECT dim.sdo_lb, dim.sdo_ub FROM "; s << "SELECT dim.sdo_lb, dim.sdo_ub FROM ";
s << SDO_GEOMETRY_METADATA_TABLE << " m, TABLE(m.diminfo) dim "; s << METADATA_TABLE << " m, TABLE(m.diminfo) dim ";
s << " WHERE LOWER(m.table_name) = LOWER('" << table_name << "') AND dim.sdo_dimname = 'X'"; s << " WHERE LOWER(m.table_name) = LOWER('" << table_name << "') AND dim.sdo_dimname = 'X'";
s << " UNION "; s << " UNION ";
s << "SELECT dim.sdo_lb, dim.sdo_ub FROM "; s << "SELECT dim.sdo_lb, dim.sdo_ub FROM ";
s << SDO_GEOMETRY_METADATA_TABLE << " m, TABLE(m.diminfo) dim "; s << METADATA_TABLE << " m, TABLE(m.diminfo) dim ";
s << " WHERE LOWER(m.table_name) = LOWER('" << table_name << "') AND dim.sdo_dimname = 'Y'"; s << " WHERE LOWER(m.table_name) = LOWER('" << table_name << "') AND dim.sdo_dimname = 'Y'";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif #endif
try try
@ -418,7 +432,7 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast &ex)
{ {
clog << ex.what() << endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
@ -431,7 +445,7 @@ box2d<double> occi_datasource::envelope() const
} }
catch (bad_lexical_cast &ex) catch (bad_lexical_cast &ex)
{ {
clog << ex.what() << endl; std::clog << "OCCI Plugin: " << ex.what() << std::endl;
} }
} }
@ -441,12 +455,12 @@ box2d<double> occi_datasource::envelope() const
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); throw datasource_exception("OCCI Plugin: " + ex.getMessage());
} }
} }
if (! extent_initialized_) if (! extent_initialized_)
throw datasource_exception("Unable to determine the extent of a <occi> table"); throw datasource_exception("OCCI Plugin: unable to determine the extent of a <occi> table");
return extent_; return extent_;
} }
@ -465,13 +479,13 @@ featureset_ptr occi_datasource::features(query const& q) const
box2d<double> const& box=q.get_bbox(); box2d<double> const& box=q.get_bbox();
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_ << " AS geom"; s << "SELECT " << geometry_field_;
std::set<std::string> const& props = q.property_names(); std::set<std::string> const& props = q.property_names();
std::set<std::string>::const_iterator pos = props.begin(); std::set<std::string>::const_iterator pos = props.begin();
std::set<std::string>::const_iterator end = props.end(); std::set<std::string>::const_iterator end = props.end();
while (pos != end) while (pos != end)
{ {
s << ",\"" << *pos << "\""; s << ", " << *pos;
++pos; ++pos;
} }
@ -502,7 +516,7 @@ featureset_ptr occi_datasource::features(query const& q) const
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "Cannot determine where to add the spatial filter declaration" << endl; std::clog << "OCCI Plugin: cannot determine where to add the spatial filter declaration" << std::endl;
#endif #endif
} }
} }
@ -522,7 +536,7 @@ featureset_ptr occi_datasource::features(query const& q) const
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "Cannot determine where to add the row limit declaration" << endl; std::clog << "OCCI Plugin: cannot determine where to add the row limit declaration" << std::endl;
#endif #endif
} }
} }
@ -530,7 +544,7 @@ featureset_ptr occi_datasource::features(query const& q) const
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif #endif
return featureset_ptr (new occi_featureset (pool_, return featureset_ptr (new occi_featureset (pool_,
@ -548,13 +562,13 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
if (!is_bound_) bind(); if (!is_bound_) bind();
std::ostringstream s; std::ostringstream s;
s << "SELECT " << geometry_field_ << " AS geom"; s << "SELECT " << geometry_field_;
std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin(); std::vector<attribute_descriptor>::const_iterator itr = desc_.get_descriptors().begin();
std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end(); std::vector<attribute_descriptor>::const_iterator end = desc_.get_descriptors().end();
unsigned size=0; unsigned size=0;
while (itr != end) while (itr != end)
{ {
s << ",\"" << itr->get_name() << "\""; s << ", " << itr->get_name();
++itr; ++itr;
++size; ++size;
} }
@ -585,7 +599,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "Cannot determine where to add the spatial filter declaration" << endl; std::clog << "OCCI Plugin: cannot determine where to add the spatial filter declaration" << std::endl;
#endif #endif
} }
} }
@ -605,7 +619,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
else else
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "Cannot determine where to add the row limit declaration" << endl; std::clog << "OCCI Plugin: cannot determine where to add the row limit declaration" << std::endl;
#endif #endif
} }
} }
@ -613,7 +627,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
s << query; s << query;
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << s.str() << endl; std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif #endif
return featureset_ptr (new occi_featureset (pool_, return featureset_ptr (new occi_featureset (pool_,
@ -625,3 +639,4 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const
row_prefetch_, row_prefetch_,
size)); size));
} }

View file

@ -65,6 +65,7 @@ class occi_datasource : public mapnik::datasource
bool use_connection_pool_; bool use_connection_pool_;
bool multiple_geometries_; bool multiple_geometries_;
bool use_spatial_index_; bool use_spatial_index_;
static const std::string METADATA_TABLE;
}; };

View file

@ -21,6 +21,7 @@
*****************************************************************************/ *****************************************************************************/
//$Id$ //$Id$
// mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/datasource.hpp> #include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
@ -30,12 +31,12 @@
#include <mapnik/wkb.hpp> #include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
// boost
#include <boost/shared_array.hpp>
// ogr // ogr
#include "occi_featureset.hpp" #include "occi_featureset.hpp"
using std::clog;
using std::endl;
using mapnik::query; using mapnik::query;
using mapnik::box2d; using mapnik::box2d;
using mapnik::CoordTransform; using mapnik::CoordTransform;
@ -54,6 +55,7 @@ using oracle::occi::MetaData;
using oracle::occi::SQLException; using oracle::occi::SQLException;
using oracle::occi::Type; using oracle::occi::Type;
using oracle::occi::Number; using oracle::occi::Number;
using oracle::occi::Blob;
occi_featureset::occi_featureset(StatelessConnectionPool* pool, occi_featureset::occi_featureset(StatelessConnectionPool* pool,
Connection* conn, Connection* conn,
@ -79,7 +81,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool,
} }
catch (SQLException &ex) catch (SQLException &ex)
{ {
throw datasource_exception(ex.getMessage()); std::clog << "OCCI Plugin: error processing " << sqlstring << " : " << ex.getMessage() << std::endl;
} }
} }
@ -108,13 +110,13 @@ feature_ptr occi_featureset::next()
std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);
#if 0 /*
int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
if (type_code == OCCI_TYPECODE_OBJECT) if (type_code == OCCI_TYPECODE_OBJECT)
{ {
continue; continue;
} }
#endif */
switch (type_oid) switch (type_oid)
{ {
@ -122,22 +124,16 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCIINT: case oracle::occi::OCCIINT:
case oracle::occi::OCCIUNSIGNED_INT: case oracle::occi::OCCIUNSIGNED_INT:
case oracle::occi::OCCIROWID: case oracle::occi::OCCIROWID:
{
boost::put(*feature,fld_name,rs_->getInt (i + 1)); boost::put(*feature,fld_name,rs_->getInt (i + 1));
break; break;
}
case oracle::occi::OCCIFLOAT: case oracle::occi::OCCIFLOAT:
case oracle::occi::OCCIBFLOAT: case oracle::occi::OCCIBFLOAT:
case oracle::occi::OCCIDOUBLE: case oracle::occi::OCCIDOUBLE:
case oracle::occi::OCCIBDOUBLE: case oracle::occi::OCCIBDOUBLE:
case oracle::occi::OCCINUMBER: case oracle::occi::OCCINUMBER:
case oracle::occi::OCCI_SQLT_NUM: case oracle::occi::OCCI_SQLT_NUM:
{
boost::put(*feature,fld_name,rs_->getDouble (i + 1)); boost::put(*feature,fld_name,rs_->getDouble (i + 1));
break; break;
}
case oracle::occi::OCCICHAR: case oracle::occi::OCCICHAR:
case oracle::occi::OCCISTRING: case oracle::occi::OCCISTRING:
case oracle::occi::OCCI_SQLT_AFC: case oracle::occi::OCCI_SQLT_AFC:
@ -150,12 +146,8 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCI_SQLT_VNU: case oracle::occi::OCCI_SQLT_VNU:
case oracle::occi::OCCI_SQLT_VBI: case oracle::occi::OCCI_SQLT_VBI:
case oracle::occi::OCCI_SQLT_VST: case oracle::occi::OCCI_SQLT_VST:
{ boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str()));
UnicodeString ustr = tr_->transcode (rs_->getString (i + 1).c_str());
boost::put(*feature,fld_name,ustr);
break; break;
}
case oracle::occi::OCCIDATE: case oracle::occi::OCCIDATE:
case oracle::occi::OCCITIMESTAMP: case oracle::occi::OCCITIMESTAMP:
case oracle::occi::OCCIINTERVALDS: case oracle::occi::OCCIINTERVALDS:
@ -187,24 +179,18 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCI_SQLT_CLOB: case oracle::occi::OCCI_SQLT_CLOB:
case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_BLOB:
case oracle::occi::OCCI_SQLT_RSET: case oracle::occi::OCCI_SQLT_RSET:
{
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "unsupported datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid)
<< " (type_oid=" << type_oid << ")" << endl; << " (type_oid=" << type_oid << ")" << std::endl;
#endif #endif
break; break;
}
default: // shouldn't get here default: // shouldn't get here
{
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "unknown datatype " << occi_enums::resolve_datatype(type_oid) std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl;
<< " (type_oid=" << type_oid << ")" << endl;
#endif #endif
break; break;
} }
} }
}
++count_; ++count_;
return feature; return feature;
@ -235,148 +221,109 @@ void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature,
clog << "SDO SRID = " << (int) sdo_srid << endl; clog << "SDO SRID = " << (int) sdo_srid << endl;
#endif #endif
const std::vector<Number>& elem_info = geom->getSdo_elem_info();
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
const int ordinates_size = (int) ordinates.size();
switch (geomtype) switch (geomtype)
{ {
case SDO_GTYPE_POINT: case SDO_GTYPE_POINT:
convert_point (geom, feature, dimensions);
break;
case SDO_GTYPE_LINE:
convert_linestring (geom, feature, dimensions);
break;
case SDO_GTYPE_POLYGON:
convert_polygon (geom, feature, dimensions);
break;
case SDO_GTYPE_MULTIPOINT:
// Todo - using convert_multipoint_2 until we have proper multipoint handling in convert_multipoint
// http://trac.mapnik.org/ticket/458
//convert_multipoint (geom, feature, dimensions, multiple_geometries);
convert_multipoint (geom, feature, dimensions, true);
break;
case SDO_GTYPE_MULTILINE:
convert_multilinestring (geom, feature, dimensions, multiple_geometries);
break;
case SDO_GTYPE_MULTIPOLYGON:
convert_multipolygon (geom, feature, dimensions, multiple_geometries);
break;
case SDO_GTYPE_COLLECTION:
convert_collection (geom, feature, dimensions, multiple_geometries);
break;
case SDO_GTYPE_UNKNOWN:
default:
#ifdef MAPNIK_DEBUG
clog << "unknown <occi> " << occi_enums::resolve_gtype(geomtype)
<< "(gtype=" << gtype << ")" << endl;
#endif
break;
}
}
void occi_featureset::convert_point (SDOGeometry* geom, feature_ptr feature, int dimensions)
{ {
SDOPointType* sdopoint = geom->getSdo_point(); SDOPointType* sdopoint = geom->getSdo_point();
if (sdopoint && ! sdopoint->isNull()) if (sdopoint && ! sdopoint->isNull())
{ {
geometry_type* point = new geometry_type(mapnik::Point); geometry_type* point = new geometry_type(mapnik::Point);
point->move_to (sdopoint->getX(), sdopoint->getY()); point->move_to (sdopoint->getX(), sdopoint->getY());
feature->add_geometry (point); feature->add_geometry (point);
} }
} }
break;
void occi_featureset::convert_linestring (SDOGeometry* geom, feature_ptr feature, int dimensions) case SDO_GTYPE_LINE:
{ {
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); if (ordinates_size >= dimensions)
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
if ((int) ordinates.size() >= dimensions)
{ {
const bool is_single_geom = true;
const bool is_point_type = false;
const bool multiple_geometries = false;
convert_ordinates (feature, convert_ordinates (feature,
mapnik::LineString, mapnik::LineString,
elem_info, elem_info,
ordinates, ordinates,
dimensions, dimensions,
is_single_geom, true, // is_single_geom
is_point_type, false, // is_point_type
multiple_geometries); false); // multiple_geometries
} }
} }
break;
void occi_featureset::convert_polygon (SDOGeometry* geom, feature_ptr feature, int dimensions) case SDO_GTYPE_POLYGON:
{ {
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); if (ordinates_size >= dimensions)
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
if ((int) ordinates.size() >= dimensions)
{ {
const bool is_single_geom = true;
const bool is_point_type = false;
const bool multiple_geometries = false;
convert_ordinates (feature, convert_ordinates (feature,
mapnik::Polygon, mapnik::Polygon,
elem_info, elem_info,
ordinates, ordinates,
dimensions, dimensions,
is_single_geom, true, // is_single_geom
is_point_type, false, // is_point_type
multiple_geometries); false); // multiple_geometries
} }
} }
break;
void occi_featureset::convert_multipoint (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) case SDO_GTYPE_MULTIPOINT:
{ {
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); if (ordinates_size >= dimensions)
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
if ((int) ordinates.size() >= dimensions)
{ {
const bool is_single_geom = false; const bool is_single_geom = false;
const bool is_point_type = true; const bool is_point_type = true;
// Todo - force using true as multiple_geometries until we have proper multipoint handling
// http://trac.mapnik.org/ticket/458
convert_ordinates (feature, convert_ordinates (feature,
mapnik::Point, mapnik::Point,
elem_info, elem_info,
ordinates, ordinates,
dimensions, dimensions,
is_single_geom, false, // is_single_geom
is_point_type, true, // is_point_type
multiple_geometries); true); // multiple_geometries
} }
} }
break;
void occi_featureset::convert_multilinestring (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) case SDO_GTYPE_MULTILINE:
{ {
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); if (ordinates_size >= dimensions)
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
if ((int) ordinates.size() >= dimensions)
{ {
const bool is_single_geom = false;
const bool is_point_type = false;
convert_ordinates (feature, convert_ordinates (feature,
mapnik::LineString, mapnik::LineString,
elem_info, elem_info,
ordinates, ordinates,
dimensions, dimensions,
is_single_geom, false, // is_single_geom
is_point_type, false, // is_point_type
multiple_geometries); multiple_geometries);
} }
}
break;
case SDO_GTYPE_MULTIPOLYGON:
{
if (ordinates_size >= dimensions)
{
convert_ordinates (feature,
mapnik::Polygon,
elem_info,
ordinates,
dimensions,
false, // is_single_geom
false, // is_point_type
multiple_geometries);
} }
void occi_featureset::convert_multipolygon (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) }
break;
case SDO_GTYPE_COLLECTION:
{ {
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); if (ordinates_size >= dimensions)
const std::vector<Number>& ordinates = geom->getSdo_ordinates();
if ((int) ordinates.size() >= dimensions)
{ {
const bool is_single_geom = false; const bool is_single_geom = false;
const bool is_point_type = false; const bool is_point_type = false;
@ -386,30 +333,19 @@ void occi_featureset::convert_multipolygon (SDOGeometry* geom, feature_ptr featu
elem_info, elem_info,
ordinates, ordinates,
dimensions, dimensions,
is_single_geom, false, // is_single_geom,
is_point_type, false, // is_point_type
multiple_geometries); multiple_geometries);
} }
} }
break;
void occi_featureset::convert_collection (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) case SDO_GTYPE_UNKNOWN:
{ default:
const std::vector<Number>& elem_info = geom->getSdo_elem_info(); #ifdef MAPNIK_DEBUG
const std::vector<Number>& ordinates = geom->getSdo_ordinates(); std::clog << "OCCI Plugin: unknown <occi> " << occi_enums::resolve_gtype(geomtype)
<< "(gtype=" << gtype << ")" << std::endl;
if ((int) ordinates.size() >= dimensions) #endif
{ break;
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);
} }
} }
@ -552,3 +488,4 @@ void occi_featureset::fill_geometry_type (geometry_type * geom,
geom->line_to ((double) ordinates[p], (double) ordinates[p + 1]); geom->line_to ((double) ordinates[p], (double) ordinates[p + 1]);
} }
} }

View file

@ -50,13 +50,6 @@ class occi_featureset : public mapnik::Featureset
virtual ~occi_featureset(); virtual ~occi_featureset();
mapnik::feature_ptr next(); mapnik::feature_ptr next();
private: private:
void convert_point (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_linestring (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_polygon (SDOGeometry* geom, mapnik::feature_ptr feature, int dims);
void convert_multipoint (SDOGeometry* geom, mapnik::feature_ptr feature, int dims, bool multiple_geometries);
void convert_multilinestring (SDOGeometry* geom, mapnik::feature_ptr feature, int dims, bool multiple_geometries);
void convert_multipolygon (SDOGeometry* geom, mapnik::feature_ptr feature, int dims, bool multiple_geometries);
void convert_collection (SDOGeometry* geom, mapnik::feature_ptr feature, int dims, bool multiple_geometries);
void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries); void convert_geometry (SDOGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries);
void convert_ordinates (mapnik::feature_ptr feature, void convert_ordinates (mapnik::feature_ptr feature,
const mapnik::eGeomType& geom_type, const mapnik::eGeomType& geom_type,

View file

@ -36,15 +36,13 @@
// check for oracle support // check for oracle support
#if OCCI_MAJOR_VERSION >= 10 && OCCI_MINOR_VERSION >= 1 #if OCCI_MAJOR_VERSION >= 10 && OCCI_MINOR_VERSION >= 1
// Only ORACLE 10g (>= 10.2.0.X) is supported ! // We have at least ORACLE 10g >= 10.2.0.X
#else #else
#error Only ORACLE 10g (>= 10.2.0.X) is supported ! #error Only ORACLE 10g >= 10.2.0.X is supported !
#endif #endif
#define SDO_GEOMETRY_METADATA_TABLE "USER_SDO_GEOM_METADATA" // geometry types definitions
enum enum
{ {
SDO_GTYPE_UNKNOWN = 0, SDO_GTYPE_UNKNOWN = 0,
@ -93,7 +91,7 @@ public:
if (env_ == 0) if (env_ == 0)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "occi_environment constructor" << std::endl; std::clog << "OCCI Plugin: occi_environment constructor" << std::endl;
#endif #endif
int mode = oracle::occi::Environment::OBJECT int mode = oracle::occi::Environment::OBJECT
@ -117,7 +115,7 @@ private:
if (env_) if (env_)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
std::clog << "occi_environment destructor" << std::endl; std::clog << "OCCI Plugin: occi_environment destructor" << std::endl;
#endif #endif
oracle::occi::Environment::terminateEnvironment (env_); oracle::occi::Environment::terminateEnvironment (env_);