本文整理汇总了C++中Geostat_grid::add_categorical_property方法的典型用法代码示例。如果您正苦于以下问题:C++ Geostat_grid::add_categorical_property方法的具体用法?C++ Geostat_grid::add_categorical_property怎么用?C++ Geostat_grid::add_categorical_property使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geostat_grid
的用法示例。
在下文中一共展示了Geostat_grid::add_categorical_property方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parameters
/* Convert_continuous_to_categorical_property grid_name::prop1::[prop2::]
* will copy convert the property from continuous to categorical
*/
bool Convert_continuous_to_categorical_property::
init( std::string& parameters, GsTL_project* proj,
Error_messages_handler* errors ) {
std::vector< std::string > params =
String_Op::decompose_string( parameters, Actions::separator,
Actions::unique );
if( params.size() <2 ) {
errors->report( "some parameters are missing, Needs at least two parameters (grid + property)" );
return false;
}
SmartPtr<Named_interface> grid_ni =
Root::instance()->interface( gridModels_manager + "/" + params[0] );
Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() );
if( !grid ) {
std::ostringstream message;
message << "No grid called \"" << params[0] << "\" was found";
errors->report( message.str() );
return false;
}
for(int i=1; i<params.size(); ++i) {
Grid_categorical_property* cprop = grid->categorical_property(params[i]);
if(cprop) continue;
Grid_continuous_property* prop = grid->property(params[i]);
if(prop == 0) continue;
std::set<int> cat_codes;
std::string prop_name = prop->name()+" - categorical";
cprop = grid->add_categorical_property(prop_name);
while(!cprop) {
prop_name.append("_0");
cprop = grid->add_categorical_property(prop_name);
}
for(int nodeid=0; nodeid < prop->size(); ++nodeid) {
if( prop->is_informed(nodeid)) {
int code = static_cast<int>(prop->get_value(nodeid));
cprop->set_value(code,nodeid);
cat_codes.insert(code);
}
}
// Check is sequential coding
bool is_sequential_coding = false;
std::set<int>::iterator it = cat_codes.begin();
if( *it == 0 ) {
std::advance(it, cat_codes.size()-1);
if( *it == cat_codes.size()-1 ) {
is_sequential_coding = true;
}
}
if( !is_sequential_coding ) { // Need to build a categorical definition
CategoricalPropertyDefinitionName* cat_def = 0;
std::string catdef_name = grid->name()+"-"+prop->name();
while(!cat_def) {
SmartPtr<Named_interface> ni = Root::instance()->new_interface( "categoricaldefinition://"+catdef_name,categoricalDefinition_manager +"/"+catdef_name );
cat_def = dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr());
if(!cat_def) catdef_name.append("_0");
}
std::set<int>::iterator it_cat_codes = cat_codes.begin();
for(; it_cat_codes != cat_codes.end(); ++it_cat_codes) {
cat_def->add_category(*it_cat_codes, QString("Code %1").arg(*it_cat_codes).toStdString() );
}
cprop->set_category_definition( cat_def );
}
}
proj->update( params[0] );
return true;
}
示例2: paramters
/* Convert_continuous_to_categorical_property grid_name::prop1::[prop2::]
* will copy convert the property from continuous to categorical
*/
bool Convert_categorical_property_to_sequential_coding::
init( std::string& parameters, GsTL_project* proj,
Error_messages_handler* errors ) {
std::vector< std::string > params =
String_Op::decompose_string( parameters, Actions::separator,
Actions::unique );
if( params.size() != 2 ) {
errors->report( "Some parameters are missing, needs two paramters (grid and categorical property)" );
return false;
}
SmartPtr<Named_interface> grid_ni =
Root::instance()->interface( gridModels_manager + "/" + params[0] );
Geostat_grid* grid = dynamic_cast<Geostat_grid*>( grid_ni.raw_ptr() );
if( !grid ) {
std::ostringstream message;
message << "No grid called \"" << params[0] << "\" was found";
errors->report( message.str() );
return false;
}
Grid_categorical_property* cprop = grid->categorical_property(params[1]);
if(cprop->get_category_definition()->is_sequential_coding()) return true;
const CategoricalPropertyDefinitionName* cdef = dynamic_cast<const CategoricalPropertyDefinitionName*>(cprop->get_category_definition());
if(!cdef) {
errors->report( "Error with the categorical definition" );
return false;
}
std::vector<int> current_codes = cdef->category_codes();
int ncat = cdef->number_of_category();
std::string sequential_catdef_name = cdef->name() + " - Sequential";
// Check if the categorical definition exist
SmartPtr<Named_interface> ni = Root::instance()->interface( categoricalDefinition_manager+"/"+sequential_catdef_name );
CategoricalPropertyDefinitionName* cat_def =
dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr());
while(!cat_def) {
sequential_catdef_name.append(" "+cprop->name());
SmartPtr<Named_interface> ni = Root::instance()->new_interface( "categoricaldefinition://"+sequential_catdef_name,categoricalDefinition_manager +"/"+sequential_catdef_name );
cat_def = dynamic_cast<CategoricalPropertyDefinitionName*>(ni.raw_ptr());
if(cat_def) {
for(int i=0; i< ncat; ++i) {
QString new_cat_name = QString("%1 (code:%2)").arg(cdef->get_category_name(current_codes[i]).c_str()).arg(current_codes[i]);
cat_def->add_category(i, new_cat_name.toStdString() );
}
}
}
//Get the new value
std::map<int,int> map_codes;
for(int i=0; i< current_codes.size(); ++i ) {
map_codes[current_codes[i]] = i;
}
std::string prop_name = cprop->name()+" sequential";
Grid_categorical_property* seq_cprop = grid->add_categorical_property(cprop->name()+" sequential",cdef->name());
while(!seq_cprop) {
prop_name.append("_0");
seq_cprop = grid->add_categorical_property(prop_name);
}
for(int i=0; i < cprop->size(); ++i) {
if( !cprop->is_informed(i) ) continue;
int code = cprop->get_value(i);
std::map<int,int>::const_iterator it = map_codes.find(code);
if( it == map_codes.end() ) continue;
seq_cprop->set_value(static_cast<Grid_continuous_property::property_type>(it->second),i);
}
seq_cprop->set_category_definition(cat_def);
proj->update( params[0] );
return true;
}