//--------------------------------------------------------- bool CVIEW_ScatterPlot::_Initialize_Table(void) { int xField = m_Parameters("FIELD_X")->asInt(); int yField = m_Parameters("FIELD_Y")->asInt(); CHECK_DATA(m_pTable); if( !m_pTable || xField < 0 || xField >= m_pTable->Get_Field_Count() || yField < 0 || yField >= m_pTable->Get_Field_Count() ) { return( false ); } int maxSamples = m_Options("SAMPLES_MAX")->asInt(); double Step = maxSamples > 0 && m_pTable->Get_Count() > maxSamples ? m_pTable->Get_Count() / maxSamples : 1.0; m_sTitle.Printf("%s: [%s]", _TL("Scatterplot"), m_pTable->Get_Name()); m_sX.Printf("%s", m_pTable->Get_Field_Name(xField)); m_sY.Printf("%s", m_pTable->Get_Field_Name(yField)); for(double i=0; i<m_pTable->Get_Record_Count() && PROGRESSBAR_Set_Position(i, m_pTable->Get_Record_Count()); i+=Step) { CSG_Table_Record *pRecord = m_pTable->Get_Record((int)i); if( !pRecord->is_NoData(xField) && !pRecord->is_NoData(yField) ) { m_Trend.Add_Data(pRecord->asDouble(xField), pRecord->asDouble(yField)); } } return( true ); }
//--------------------------------------------------------- bool CActive_Attributes_Control::_Set_Record(int iRecord) { CSG_Table_Record *pRecord = m_pTable->Get_Record(iRecord); if( m_Field_Offset ) // feature attributes { SetRowLabelValue(iRecord, pRecord->asString(0)); } else // grid cell values { SetRowLabelValue(iRecord, wxString::Format("%d", 1 + iRecord)); } for(int iCol=0, iField=m_Field_Offset; iField<m_pTable->Get_Field_Count(); iCol++, iField++) { switch( m_pTable->Get_Field_Type(iField) ) { default: SetCellValue(iRecord, iCol, pRecord->is_NoData(iField) ? SG_T("") : pRecord->asString(iField)); break; case SG_DATATYPE_Color: SetCellBackgroundColour(iRecord, iCol, Get_Color_asWX(pRecord->asInt(iField))); break; } } if( pRecord->is_Selected() ) { SelectRow(iRecord, true); } return( true ); }
//--------------------------------------------------------- inline bool CTable_PCA::is_NoData(int iElement) { CSG_Table_Record *pElement = m_pTable->Get_Record(iElement); for(int iFeature=0; iFeature<m_nFeatures; iFeature++) { if( pElement->is_NoData(m_Features[iFeature]) ) { return( true ); } } return( false ); }
//--------------------------------------------------------- bool CSG_ODBC_Connection::Table_Insert(const CSG_String &Table_Name, const CSG_Table &Table, bool bCommit) { //----------------------------------------------------- if( !is_Connected() ) { _Error_Message(_TL("no database connection")); return( false ); } if( !Table_Exists(Table_Name) ) { return( false ); } CSG_Table Fields = Get_Field_Desc(Table_Name); if( Fields.Get_Count() != Table.Get_Field_Count() ) { return( false ); } //----------------------------------------------------- try { bool bLOB = false; int iField, iRecord; CSG_String Insert; otl_stream Stream; //------------------------------------------------- Insert.Printf(SG_T("INSERT INTO %s VALUES("), Table_Name.c_str()); for(iField=0; iField<Table.Get_Field_Count(); iField++) { if( iField > 0 ) { Insert += SG_T(","); } Insert += CSG_String::Format(SG_T(":f%d"), 1 + iField); switch( Table.Get_Field_Type(iField) ) { default: case SG_DATATYPE_String: Insert += SG_T("<varchar>"); break; case SG_DATATYPE_Date: Insert += SG_T("<char[12]>"); break; case SG_DATATYPE_Char: Insert += SG_T("<char>"); break; case SG_DATATYPE_Short: Insert += SG_T("<short>"); break; case SG_DATATYPE_Int: Insert += SG_T("<int>"); break; case SG_DATATYPE_Color: Insert += SG_T("<long>"); break; case SG_DATATYPE_Long: Insert += SG_T("<long>"); break; case SG_DATATYPE_Float: Insert += SG_T("<float>"); break; case SG_DATATYPE_Double: Insert += SG_T("<double>"); break; } } Insert += SG_T(")"); Stream.set_all_column_types(otl_all_date2str); Stream.set_lob_stream_mode(bLOB); Stream.open(bLOB ? 1 : m_Size_Buffer, Insert, m_Connection); std_string valString; //------------------------------------------------- for(iRecord=0; iRecord<Table.Get_Count() && SG_UI_Process_Set_Progress(iRecord, Table.Get_Count()); iRecord++) { CSG_Table_Record *pRecord = Table.Get_Record(iRecord); for(iField=0; iField<Table.Get_Field_Count(); iField++) { if( pRecord->is_NoData(iField) ) { Stream << otl_null(); } else switch( Table.Get_Field_Type(iField) ) { default: case SG_DATATYPE_String: case SG_DATATYPE_Date: valString = CSG_String(pRecord->asString(iField)); Stream << valString; break; case SG_DATATYPE_Char: Stream << (char)pRecord->asChar (iField); break; case SG_DATATYPE_Short: Stream << pRecord->asShort (iField); break; case SG_DATATYPE_Int: Stream << pRecord->asInt (iField); break; case SG_DATATYPE_Color: case SG_DATATYPE_Long: Stream << (long)pRecord->asInt (iField); break; case SG_DATATYPE_Float: Stream << pRecord->asFloat (iField); break; case SG_DATATYPE_Double: Stream << pRecord->asDouble(iField); break; } } } } //----------------------------------------------------- catch( otl_exception &e ) { _Error_Message(e); return( false ); } return( true ); }
//--------------------------------------------------------- bool CTable_Record_Statistics_Base::On_Execute(void) { //----------------------------------------------------- CSG_Table *pTable = Parameters("TABLE")->asTable(); if( !pTable->is_Valid() || pTable->Get_Field_Count() <= 0 || pTable->Get_Record_Count() <= 0 ) { Error_Set(_TL("invalid table")); return( false ); } //----------------------------------------------------- CSG_Array_Int _Fields; int *Fields = (int *)Parameters("FIELDS")->asPointer(); int nFields = Parameters("FIELDS")->asInt (); if( nFields == 0 ) { for(int i=0; i<pTable->Get_Field_Count(); i++) { if( SG_Data_Type_is_Numeric(pTable->Get_Field_Type(i)) ) { _Fields.Inc_Array(); _Fields[nFields++] = i; } } if( nFields == 0 ) { Error_Set(_TL("could not find any numeric attribute field")); return( false ); } Fields = _Fields.Get_Array(); } //----------------------------------------------------- if( Parameters("RESULT")->asTable() && Parameters("RESULT")->asTable() != pTable ) { pTable = Parameters("RESULT")->asTable(); pTable->Create( *Parameters("TABLE")->asTable()); pTable->Set_Name(Parameters("TABLE")->asTable()->Get_Name()); } //----------------------------------------------------- double Quantile = Parameters("PCTL_VAL")->asDouble(); int offResult = pTable->Get_Field_Count(); bool bStats[STATS_COUNT]; { for(int i=0; i<STATS_COUNT; i++) { if( (bStats[i] = Parameters(STATS[i][0])->asBool()) == true ) { pTable->Add_Field(STATS[i][1], SG_DATATYPE_Double); } } if( pTable->Get_Field_Count() == offResult ) { Error_Set(_TL("no statistical measure has been selected")); return( false ); } } //----------------------------------------------------- for(int iRecord=0; iRecord<pTable->Get_Count() && Set_Progress(iRecord, pTable->Get_Count()); iRecord++) { CSG_Table_Record *pRecord = pTable->Get_Record(iRecord); CSG_Simple_Statistics s(bStats[STATS_PCTL]); for(int iField=0; iField<nFields; iField++) { if( !pRecord->is_NoData(Fields[iField]) ) { s += pRecord->asDouble(Fields[iField]); } } //------------------------------------------------- int iField = offResult; if( s.Get_Count() > 0 ) { if( bStats[STATS_MEAN ] ) pRecord->Set_Value(iField++, s.Get_Mean ()); if( bStats[STATS_MIN ] ) pRecord->Set_Value(iField++, s.Get_Minimum ()); if( bStats[STATS_MAX ] ) pRecord->Set_Value(iField++, s.Get_Maximum ()); if( bStats[STATS_RANGE] ) pRecord->Set_Value(iField++, s.Get_Range ()); if( bStats[STATS_SUM ] ) pRecord->Set_Value(iField++, s.Get_Sum ()); if( bStats[STATS_NUM ] ) pRecord->Set_Value(iField++, s.Get_Count ()); if( bStats[STATS_VAR ] ) pRecord->Set_Value(iField++, s.Get_Variance()); if( bStats[STATS_STDV ] ) pRecord->Set_Value(iField++, s.Get_StdDev ()); if( bStats[STATS_PCTL ] ) pRecord->Set_Value(iField++, s.Get_Quantile(Quantile)); } else { for(int i=0; i<STATS_COUNT; i++) { if( bStats[i] ) { pRecord->Set_NoData(iField++); } } } } //----------------------------------------------------- if( pTable == Parameters("TABLE")->asTable() ) { DataObject_Update(pTable); } return( true ); }
//--------------------------------------------------------- bool CSoil_Texture_Table::On_Execute(void) { //----------------------------------------------------- CSG_Table *pTable = Parameters("TABLE")->asTable(); int iSand = Parameters("SAND" )->asInt(); int iSilt = Parameters("SILT" )->asInt(); int iClay = Parameters("CLAY" )->asInt(); int iTexture = Parameters("TEXTURE")->asInt(); //----------------------------------------------------- if( (iSand >= 0 ? 1 : 0) + (iSilt >= 0 ? 1 : 0) + (iClay >= 0 ? 1 : 0) < 2 ) { Error_Set(_TL("at least two contents (sand, silt, clay) have to be given")); return( false ); } //----------------------------------------------------- if( iTexture < 0 ) { iTexture = pTable->Get_Field_Count(); pTable->Add_Field("TEXTURE", SG_DATATYPE_String); } //----------------------------------------------------- for(int i=0; i<pTable->Get_Count() && Set_Progress(i, pTable->Get_Count()); i++) { CSG_Table_Record *pRecord = pTable->Get_Record(i); if( (iSand >= 0 && pRecord->is_NoData(iSand)) || (iSilt >= 0 && pRecord->is_NoData(iSilt)) || (iClay >= 0 && pRecord->is_NoData(iClay)) ) { pRecord->Set_NoData(iTexture); } else { int Class = -1; if( iSand >= 0 && iSilt >= 0 && iClay >= 0 ) { double Sum; Class = Get_Texture(pRecord->asDouble(iSand), pRecord->asDouble(iSilt), pRecord->asDouble(iClay), Sum); } else if( iSilt < 0 ) { Class = Get_Texture_SandClay(pRecord->asDouble(iSand), pRecord->asDouble(iClay)); } else if( iClay < 0 ) { Class = Get_Texture_SandSilt(pRecord->asDouble(iSand), pRecord->asDouble(iSilt)); } else if( iSand < 0 ) { Class = Get_Texture_SiltClay(pRecord->asDouble(iSilt), pRecord->asDouble(iClay)); } pRecord->Set_Value (iTexture, Classes[Class].Key); } } DataObject_Update(pTable); //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pTable, "LUT"); if( pLUT && pLUT->asTable() ) { CSG_Table *pClasses = pLUT->asTable(); for(int iClass=0; iClass<12; iClass++) { CSG_Table_Record *pClass = pClasses->Get_Record(iClass); if( pClass == NULL ) { pClass = pClasses->Add_Record(); } pClass->Set_Value(0, Classes[iClass].Color); pClass->Set_Value(1, Classes[iClass].Name); pClass->Set_Value(2, Classes[iClass].Name); pClass->Set_Value(3, Classes[iClass].Key); pClass->Set_Value(4, Classes[iClass].Key); } while( pClasses->Get_Count() > 12 ) { pClasses->Del_Record(pClasses->Get_Count() - 1); } DataObject_Set_Parameter(pTable, pLUT); // Lookup Table DataObject_Set_Parameter(pTable, "LUT_ATTRIB" , iTexture); // Lookup Table Attribute DataObject_Set_Parameter(pTable, "COLORS_TYPE", 1 ); // Color Classification Type: Lookup Table } //----------------------------------------------------- return( true ); }