From 1d7acffadb19ceb9fad59c3f2394193748cd8d73 Mon Sep 17 00:00:00 2001 From: Lucio Asnaghi Date: Mon, 22 Nov 2010 11:40:08 +0000 Subject: [PATCH] + improved and cleaned up occi plugin --- plugins/input/occi/occi_datasource.cpp | 101 ++--- plugins/input/occi/occi_datasource.hpp | 1 + plugins/input/occi/occi_featureset.cpp | 507 +++++++++++-------------- plugins/input/occi/occi_featureset.hpp | 7 - plugins/input/occi/occi_types.hpp | 12 +- 5 files changed, 286 insertions(+), 342 deletions(-) diff --git a/plugins/input/occi/occi_datasource.cpp b/plugins/input/occi/occi_datasource.cpp index e0972a34c..0c41a05ce 100644 --- a/plugins/input/occi/occi_datasource.cpp +++ b/plugins/input/occi/occi_datasource.cpp @@ -40,10 +40,6 @@ #include #include -using std::clog; -using std::endl; -using std::vector; - using boost::lexical_cast; using boost::bad_lexical_cast; @@ -66,13 +62,14 @@ using oracle::occi::SQLException; using oracle::occi::Type; using oracle::occi::StatelessConnectionPool; +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), type_(datasource::Vector), - table_(*params_.get("table","")), fields_(*params_.get("fields","*")), geometry_field_(*params_.get("geometry_field","")), srid_initialized_(false), @@ -80,13 +77,23 @@ occi_datasource::occi_datasource(parameters const& params, bool bind) desc_(*params_.get("type"), *params_.get("encoding","utf-8")), row_limit_(*params_.get("row_limit",0)), row_prefetch_(*params_.get("row_prefetch",100)), - pool_(NULL), - conn_(NULL) + pool_(0), + conn_(0) { - if (! params_.get("user")) throw datasource_exception("No specified"); - if (! params_.get("password")) throw datasource_exception("No specified"); - if (! params_.get("host")) throw datasource_exception("No string specified"); + if (! params_.get("user")) throw datasource_exception("OCCI Plugin: no specified"); + if (! params_.get("password")) throw datasource_exception("OCCI Plugin: no specified"); + if (! params_.get("host")) throw datasource_exception("OCCI Plugin: no string specified"); + boost::optional table = params_.get("table"); + if (!table) + { + throw datasource_exception("OCCI Plugin: no parameter specified"); + } + else + { + table_ = *table; + } + multiple_geometries_ = *params_.get("multiple_geometries",false); use_spatial_index_ = *params_.get("use_spatial_index",true); use_connection_pool_ = *params_.get("use_connection_pool",true); @@ -115,12 +122,12 @@ occi_datasource::~occi_datasource() if (use_connection_pool_) { - if (pool_ != NULL) - env->terminateStatelessConnectionPool (pool_); + if (pool_ != 0) + env->terminateStatelessConnectionPool (pool_, StatelessConnectionPool::SPD_FORCE); } else { - if (conn_ != NULL) + if (conn_ != 0) env->terminateConnection(conn_); } } @@ -148,7 +155,7 @@ void occi_datasource::bind() const } catch (SQLException &ex) { - throw datasource_exception(ex.getMessage()); + throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } else @@ -164,7 +171,7 @@ void occi_datasource::bind() const } 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_ == "") { 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 << "')"; if (geometry_field_ != "") s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')"; +#ifdef MAPNIK_DEBUG + std::clog << "OCCI Plugin: " << s.str() << std::endl; +#endif + try { occi_connection_ptr conn; @@ -203,7 +214,7 @@ void occi_datasource::bind() const } 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; s << "SELECT " << fields_ << " FROM (" << table_name << ") WHERE rownum < 1"; +#ifdef MAPNIK_DEBUG + std::clog << "OCCI Plugin: " << s.str() << std::endl; +#endif + try { occi_connection_ptr conn; @@ -230,14 +245,14 @@ void occi_datasource::bind() const std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); -#if 0 + /* int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); if (type_code == OCCI_TYPECODE_OBJECT) { desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object)); continue; } -#endif + */ switch (type_oid) { @@ -301,14 +316,13 @@ void occi_datasource::bind() const case oracle::occi::OCCI_SQLT_BLOB: case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - clog << "unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << endl; + std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif break; default: #ifdef MAPNIK_DEBUG - clog << "unknown datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << endl; + std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; #endif break; } @@ -351,7 +365,7 @@ box2d occi_datasource::envelope() const s << " TABLE(SDO_UTIL.GETVERTICES(a.shape)) c"; #ifdef MAPNIK_DEBUG - clog << s.str() << endl; + std::clog << "OCCI Plugin: " << s.str() << std::endl; #endif try @@ -374,13 +388,13 @@ box2d occi_datasource::envelope() const } catch (bad_lexical_cast &ex) { - clog << ex.what() << endl; + std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } } catch (SQLException &ex) { - throw datasource_exception(ex.getMessage()); + throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } else if (use_spatial_index_) @@ -389,15 +403,15 @@ box2d occi_datasource::envelope() const std::ostringstream s; 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 << " UNION "; 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'"; #ifdef MAPNIK_DEBUG - clog << s.str() << endl; + std::clog << "OCCI Plugin: " << s.str() << std::endl; #endif try @@ -418,7 +432,7 @@ box2d occi_datasource::envelope() const } catch (bad_lexical_cast &ex) { - clog << ex.what() << endl; + std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } @@ -431,7 +445,7 @@ box2d occi_datasource::envelope() const } catch (bad_lexical_cast &ex) { - clog << ex.what() << endl; + std::clog << "OCCI Plugin: " << ex.what() << std::endl; } } @@ -441,12 +455,12 @@ box2d occi_datasource::envelope() const } catch (SQLException &ex) { - throw datasource_exception(ex.getMessage()); + throw datasource_exception("OCCI Plugin: " + ex.getMessage()); } } if (! extent_initialized_) - throw datasource_exception("Unable to determine the extent of a table"); + throw datasource_exception("OCCI Plugin: unable to determine the extent of a table"); return extent_; } @@ -465,13 +479,13 @@ featureset_ptr occi_datasource::features(query const& q) const box2d const& box=q.get_bbox(); std::ostringstream s; - s << "SELECT " << geometry_field_ << " AS geom"; + s << "SELECT " << geometry_field_; std::set const& props = q.property_names(); std::set::const_iterator pos = props.begin(); std::set::const_iterator end = props.end(); while (pos != end) { - s << ",\"" << *pos << "\""; + s << ", " << *pos; ++pos; } @@ -502,7 +516,7 @@ featureset_ptr occi_datasource::features(query const& q) const else { #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 } } @@ -522,7 +536,7 @@ featureset_ptr occi_datasource::features(query const& q) const else { #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 } } @@ -530,7 +544,7 @@ featureset_ptr occi_datasource::features(query const& q) const s << query; #ifdef MAPNIK_DEBUG - clog << s.str() << endl; + std::clog << "OCCI Plugin: " << s.str() << std::endl; #endif 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(); std::ostringstream s; - s << "SELECT " << geometry_field_ << " AS geom"; + s << "SELECT " << geometry_field_; std::vector::const_iterator itr = desc_.get_descriptors().begin(); std::vector::const_iterator end = desc_.get_descriptors().end(); unsigned size=0; while (itr != end) { - s << ",\"" << itr->get_name() << "\""; + s << ", " << itr->get_name(); ++itr; ++size; } @@ -585,7 +599,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const else { #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 } } @@ -605,7 +619,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const else { #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 } } @@ -613,7 +627,7 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const s << query; #ifdef MAPNIK_DEBUG - clog << s.str() << endl; + std::clog << "OCCI Plugin: " << s.str() << std::endl; #endif return featureset_ptr (new occi_featureset (pool_, @@ -625,3 +639,4 @@ featureset_ptr occi_datasource::features_at_point(coord2d const& pt) const row_prefetch_, size)); } + diff --git a/plugins/input/occi/occi_datasource.hpp b/plugins/input/occi/occi_datasource.hpp index 64c881167..53badc22d 100644 --- a/plugins/input/occi/occi_datasource.hpp +++ b/plugins/input/occi/occi_datasource.hpp @@ -65,6 +65,7 @@ class occi_datasource : public mapnik::datasource bool use_connection_pool_; bool multiple_geometries_; bool use_spatial_index_; + static const std::string METADATA_TABLE; }; diff --git a/plugins/input/occi/occi_featureset.cpp b/plugins/input/occi/occi_featureset.cpp index 5e4d6f8a2..101ddd7de 100644 --- a/plugins/input/occi/occi_featureset.cpp +++ b/plugins/input/occi/occi_featureset.cpp @@ -21,6 +21,7 @@ *****************************************************************************/ //$Id$ +// mapnik #include #include #include @@ -30,12 +31,12 @@ #include #include +// boost +#include + // ogr #include "occi_featureset.hpp" -using std::clog; -using std::endl; - using mapnik::query; using mapnik::box2d; using mapnik::CoordTransform; @@ -54,6 +55,7 @@ using oracle::occi::MetaData; using oracle::occi::SQLException; using oracle::occi::Type; using oracle::occi::Number; +using oracle::occi::Blob; occi_featureset::occi_featureset(StatelessConnectionPool* pool, Connection* conn, @@ -79,7 +81,7 @@ occi_featureset::occi_featureset(StatelessConnectionPool* pool, } catch (SQLException &ex) { - throw datasource_exception(ex.getMessage()); + std::clog << "OCCI Plugin: error processing " << sqlstring << " : " << ex.getMessage() << std::endl; } } @@ -103,107 +105,91 @@ feature_ptr occi_featureset::next() for (unsigned int i = 1; i < listOfColumns.size(); ++i) { - MetaData columnObj = listOfColumns[i]; + MetaData columnObj = listOfColumns[i]; - std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); - int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); + std::string fld_name = columnObj.getString(MetaData::ATTR_NAME); + int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE); -#if 0 - int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); - if (type_code == OCCI_TYPECODE_OBJECT) - { - continue; - } -#endif + /* + int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE); + if (type_code == OCCI_TYPECODE_OBJECT) + { + continue; + } + */ - switch (type_oid) - { - case oracle::occi::OCCIBOOL: - case oracle::occi::OCCIINT: - case oracle::occi::OCCIUNSIGNED_INT: - case oracle::occi::OCCIROWID: - { - boost::put(*feature,fld_name,rs_->getInt (i + 1)); - break; - } - - case oracle::occi::OCCIFLOAT: - case oracle::occi::OCCIBFLOAT: - case oracle::occi::OCCIDOUBLE: - case oracle::occi::OCCIBDOUBLE: - case oracle::occi::OCCINUMBER: - case oracle::occi::OCCI_SQLT_NUM: - { - boost::put(*feature,fld_name,rs_->getDouble (i + 1)); - break; - } - - case oracle::occi::OCCICHAR: - case oracle::occi::OCCISTRING: - case oracle::occi::OCCI_SQLT_AFC: - case oracle::occi::OCCI_SQLT_AVC: - case oracle::occi::OCCI_SQLT_CHR: - case oracle::occi::OCCI_SQLT_LVC: - case oracle::occi::OCCI_SQLT_RDD: - case oracle::occi::OCCI_SQLT_STR: - case oracle::occi::OCCI_SQLT_VCS: - case oracle::occi::OCCI_SQLT_VNU: - case oracle::occi::OCCI_SQLT_VBI: - case oracle::occi::OCCI_SQLT_VST: - { - UnicodeString ustr = tr_->transcode (rs_->getString (i + 1).c_str()); - boost::put(*feature,fld_name,ustr); - break; - } - - case oracle::occi::OCCIDATE: - case oracle::occi::OCCITIMESTAMP: - case oracle::occi::OCCIINTERVALDS: - case oracle::occi::OCCIINTERVALYM: - case oracle::occi::OCCI_SQLT_DAT: - case oracle::occi::OCCI_SQLT_DATE: - case oracle::occi::OCCI_SQLT_TIME: - case oracle::occi::OCCI_SQLT_TIME_TZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP: - case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: - case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: - case oracle::occi::OCCI_SQLT_INTERVAL_YM: - case oracle::occi::OCCI_SQLT_INTERVAL_DS: - case oracle::occi::OCCIANYDATA: - case oracle::occi::OCCIBLOB: - case oracle::occi::OCCIBFILE: - case oracle::occi::OCCIBYTES: - case oracle::occi::OCCICLOB: - case oracle::occi::OCCIVECTOR: - case oracle::occi::OCCIMETADATA: - case oracle::occi::OCCIPOBJECT: - case oracle::occi::OCCIREF: - case oracle::occi::OCCIREFANY: - case oracle::occi::OCCISTREAM: - case oracle::occi::OCCICURSOR: - case oracle::occi::OCCI_SQLT_FILE: - case oracle::occi::OCCI_SQLT_CFILE: - case oracle::occi::OCCI_SQLT_REF: - case oracle::occi::OCCI_SQLT_CLOB: - case oracle::occi::OCCI_SQLT_BLOB: - case oracle::occi::OCCI_SQLT_RSET: - { + switch (type_oid) + { + case oracle::occi::OCCIBOOL: + case oracle::occi::OCCIINT: + case oracle::occi::OCCIUNSIGNED_INT: + case oracle::occi::OCCIROWID: + boost::put(*feature,fld_name,rs_->getInt (i + 1)); + break; + case oracle::occi::OCCIFLOAT: + case oracle::occi::OCCIBFLOAT: + case oracle::occi::OCCIDOUBLE: + case oracle::occi::OCCIBDOUBLE: + case oracle::occi::OCCINUMBER: + case oracle::occi::OCCI_SQLT_NUM: + boost::put(*feature,fld_name,rs_->getDouble (i + 1)); + break; + case oracle::occi::OCCICHAR: + case oracle::occi::OCCISTRING: + case oracle::occi::OCCI_SQLT_AFC: + case oracle::occi::OCCI_SQLT_AVC: + case oracle::occi::OCCI_SQLT_CHR: + case oracle::occi::OCCI_SQLT_LVC: + case oracle::occi::OCCI_SQLT_RDD: + case oracle::occi::OCCI_SQLT_STR: + case oracle::occi::OCCI_SQLT_VCS: + case oracle::occi::OCCI_SQLT_VNU: + case oracle::occi::OCCI_SQLT_VBI: + case oracle::occi::OCCI_SQLT_VST: + boost::put(*feature,fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str())); + break; + case oracle::occi::OCCIDATE: + case oracle::occi::OCCITIMESTAMP: + case oracle::occi::OCCIINTERVALDS: + case oracle::occi::OCCIINTERVALYM: + case oracle::occi::OCCI_SQLT_DAT: + case oracle::occi::OCCI_SQLT_DATE: + case oracle::occi::OCCI_SQLT_TIME: + case oracle::occi::OCCI_SQLT_TIME_TZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP: + case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ: + case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ: + case oracle::occi::OCCI_SQLT_INTERVAL_YM: + case oracle::occi::OCCI_SQLT_INTERVAL_DS: + case oracle::occi::OCCIANYDATA: + case oracle::occi::OCCIBLOB: + case oracle::occi::OCCIBFILE: + case oracle::occi::OCCIBYTES: + case oracle::occi::OCCICLOB: + case oracle::occi::OCCIVECTOR: + case oracle::occi::OCCIMETADATA: + case oracle::occi::OCCIPOBJECT: + case oracle::occi::OCCIREF: + case oracle::occi::OCCIREFANY: + case oracle::occi::OCCISTREAM: + case oracle::occi::OCCICURSOR: + case oracle::occi::OCCI_SQLT_FILE: + case oracle::occi::OCCI_SQLT_CFILE: + case oracle::occi::OCCI_SQLT_REF: + case oracle::occi::OCCI_SQLT_CLOB: + case oracle::occi::OCCI_SQLT_BLOB: + case oracle::occi::OCCI_SQLT_RSET: #ifdef MAPNIK_DEBUG - clog << "unsupported datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << endl; + std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid) + << " (type_oid=" << type_oid << ")" << std::endl; #endif - break; - } - - default: // shouldn't get here - { + break; + default: // shouldn't get here #ifdef MAPNIK_DEBUG - clog << "unknown datatype " << occi_enums::resolve_datatype(type_oid) - << " (type_oid=" << type_oid << ")" << endl; + std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl; #endif - break; - } - } + break; + } } ++count_; @@ -216,200 +202,150 @@ feature_ptr occi_featureset::next() void occi_featureset::convert_geometry (SDOGeometry* geom, feature_ptr feature, bool multiple_geometries) { - int gtype = (int) geom->getSdo_gtype(); - int dimensions = gtype / 1000; - int lrsvalue = (gtype - dimensions * 1000) / 100; - int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); + int gtype = (int) geom->getSdo_gtype(); + int dimensions = gtype / 1000; + int lrsvalue = (gtype - dimensions * 1000) / 100; + int geomtype = (gtype - dimensions * 1000 - lrsvalue * 100); #if 0 - clog << "-----------Geometry Object ------------" << endl; - clog << "SDO GTYPE = " << gtype << endl; - clog << "SDO DIMENSIONS = " << dimensions << endl; - clog << "SDO LRS = " << lrsvalue << endl; - clog << "SDO GEOMETRY TYPE = " << geomtype << endl; + clog << "-----------Geometry Object ------------" << endl; + clog << "SDO GTYPE = " << gtype << endl; + clog << "SDO DIMENSIONS = " << dimensions << endl; + clog << "SDO LRS = " << lrsvalue << endl; + clog << "SDO GEOMETRY TYPE = " << geomtype << endl; - Number sdo_srid = geom->getSdo_srid(); - if (sdo_srid.isNull()) - clog << "SDO SRID = " << "Null" << endl; - else - clog << "SDO SRID = " << (int) sdo_srid << endl; + Number sdo_srid = geom->getSdo_srid(); + if (sdo_srid.isNull()) + clog << "SDO SRID = " << "Null" << endl; + else + clog << "SDO SRID = " << (int) sdo_srid << endl; #endif - switch (geomtype) - { - 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: + const std::vector& elem_info = geom->getSdo_elem_info(); + const std::vector& ordinates = geom->getSdo_ordinates(); + const int ordinates_size = (int) ordinates.size(); + + switch (geomtype) + { + case SDO_GTYPE_POINT: + { + 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); + } + } + break; + case SDO_GTYPE_LINE: + { + if (ordinates_size >= dimensions) + { + convert_ordinates (feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + true, // is_single_geom + false, // is_point_type + false); // multiple_geometries + } + } + break; + case SDO_GTYPE_POLYGON: + { + if (ordinates_size >= dimensions) + { + convert_ordinates (feature, + mapnik::Polygon, + elem_info, + ordinates, + dimensions, + true, // is_single_geom + false, // is_point_type + false); // multiple_geometries + } + } + break; + case SDO_GTYPE_MULTIPOINT: + { + if (ordinates_size >= dimensions) + { + const bool is_single_geom = false; + 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, + mapnik::Point, + elem_info, + ordinates, + dimensions, + false, // is_single_geom + true, // is_point_type + true); // multiple_geometries + } + } + break; + case SDO_GTYPE_MULTILINE: + { + if (ordinates_size >= dimensions) + { + convert_ordinates (feature, + mapnik::LineString, + elem_info, + ordinates, + dimensions, + false, // is_single_geom + false, // is_point_type + 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); + } + + } + break; + case SDO_GTYPE_COLLECTION: + { + 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, + false, // is_single_geom, + false, // is_point_type + multiple_geometries); + } + } + break; + case SDO_GTYPE_UNKNOWN: + default: #ifdef MAPNIK_DEBUG - clog << "unknown " << occi_enums::resolve_gtype(geomtype) - << "(gtype=" << gtype << ")" << endl; + std::clog << "OCCI Plugin: unknown " << occi_enums::resolve_gtype(geomtype) + << "(gtype=" << gtype << ")" << std::endl; #endif - break; - } -} - -void occi_featureset::convert_point (SDOGeometry* geom, feature_ptr feature, int dimensions) -{ - 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); - } -} - -void occi_featureset::convert_linestring (SDOGeometry* geom, feature_ptr feature, int dimensions) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& 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, - mapnik::LineString, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); - } -} - -void occi_featureset::convert_polygon (SDOGeometry* geom, feature_ptr feature, int dimensions) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& 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, - mapnik::Polygon, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); - } -} - -void occi_featureset::convert_multipoint (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& ordinates = geom->getSdo_ordinates(); - - if ((int) ordinates.size() >= dimensions) - { - const bool is_single_geom = false; - const bool is_point_type = true; - - convert_ordinates (feature, - mapnik::Point, - elem_info, - ordinates, - dimensions, - is_single_geom, - is_point_type, - multiple_geometries); - } -} - -void occi_featureset::convert_multilinestring (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& ordinates = geom->getSdo_ordinates(); - - if ((int) ordinates.size() >= dimensions) - { - 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); - } -} - -void occi_featureset::convert_multipolygon (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& ordinates = geom->getSdo_ordinates(); - - if ((int) 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); - } -} - -void occi_featureset::convert_collection (SDOGeometry* geom, feature_ptr feature, int dimensions, bool multiple_geometries) -{ - const std::vector& elem_info = geom->getSdo_elem_info(); - const std::vector& ordinates = geom->getSdo_ordinates(); - - if ((int) 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); + break; } } @@ -552,3 +488,4 @@ void occi_featureset::fill_geometry_type (geometry_type * geom, geom->line_to ((double) ordinates[p], (double) ordinates[p + 1]); } } + diff --git a/plugins/input/occi/occi_featureset.hpp b/plugins/input/occi/occi_featureset.hpp index 304d40f1c..99da718c5 100644 --- a/plugins/input/occi/occi_featureset.hpp +++ b/plugins/input/occi/occi_featureset.hpp @@ -50,13 +50,6 @@ class occi_featureset : public mapnik::Featureset virtual ~occi_featureset(); mapnik::feature_ptr next(); 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_ordinates (mapnik::feature_ptr feature, const mapnik::eGeomType& geom_type, diff --git a/plugins/input/occi/occi_types.hpp b/plugins/input/occi/occi_types.hpp index 6aa7f55b1..548c6321b 100644 --- a/plugins/input/occi/occi_types.hpp +++ b/plugins/input/occi/occi_types.hpp @@ -36,15 +36,13 @@ // check for oracle support #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 - #error Only ORACLE 10g (>= 10.2.0.X) is supported ! + #error Only ORACLE 10g >= 10.2.0.X is supported ! #endif -#define SDO_GEOMETRY_METADATA_TABLE "USER_SDO_GEOM_METADATA" - - +// geometry types definitions enum { SDO_GTYPE_UNKNOWN = 0, @@ -93,7 +91,7 @@ public: if (env_ == 0) { #ifdef MAPNIK_DEBUG - std::clog << "occi_environment constructor" << std::endl; + std::clog << "OCCI Plugin: occi_environment constructor" << std::endl; #endif int mode = oracle::occi::Environment::OBJECT @@ -117,7 +115,7 @@ private: if (env_) { #ifdef MAPNIK_DEBUG - std::clog << "occi_environment destructor" << std::endl; + std::clog << "OCCI Plugin: occi_environment destructor" << std::endl; #endif oracle::occi::Environment::terminateEnvironment (env_);