//--------------------------------------------------------- int COpenCV_NNet::On_Parameter_Changed(CSG_Parameters *p_Parameters, CSG_Parameter *p_Parameter) { if(!SG_STR_CMP(p_Parameter->Get_Identifier(), SG_T("TRAIN_INPUT_TABLE")) ) { CSG_Table* t_TrainInput = p_Parameter->asTable(); CSG_Parameters* p_TrainFeatures = p_Parameters->Get_Parameter("TRAIN_FEATURES_TABLE")->asParameters(); p_TrainFeatures->Del_Parameters(); if (t_TrainInput && t_TrainInput->Get_Field_Count() > 0) { int i_fieldCount = t_TrainInput->Get_Field_Count(); for (int i = 0; i < i_fieldCount; i++) { if( SG_Data_Type_is_Numeric(t_TrainInput->Get_Field_Type(i)) ) { // Add a bool choice for every numeric field to mark it as an possible output feature p_TrainFeatures->Add_Value(NULL, CSG_String::Format(SG_T("%d_FEATURE"), i), t_TrainInput->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false); } } } } //----------------------------------------------------- return( 1 ); }
//--------------------------------------------------------- bool CLine_Crossings::Set_Attributes(CSG_Shape *pCrossing, CSG_Shape *pLine, int &Offset) { for(int i=0; i<pLine->Get_Table()->Get_Field_Count(); i++) { if( SG_Data_Type_is_Numeric(pLine->Get_Table()->Get_Field_Type(i)) ) { pCrossing->Set_Value(Offset++, pLine->asDouble(i)); } else { pCrossing->Set_Value(Offset++, pLine->asString(i)); } } return( true ); }
//--------------------------------------------------------- int CTable_PCA::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if( !SG_STR_CMP(pParameter->Get_Identifier(), SG_T("TABLE")) ) { CSG_Table *pTable = pParameter->asTable(); CSG_Parameters *pFields = pParameters->Get_Parameter("FIELDS")->asParameters(); pFields->Del_Parameters(); if( pTable && pTable->Get_Field_Count() > 0 ) { for(int i=0; i<pTable->Get_Field_Count(); i++) { if( SG_Data_Type_is_Numeric(pTable->Get_Field_Type(i)) ) { pFields->Add_Value(NULL, CSG_String::Format(SG_T("%d"), i), pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false); } } } } return( 0 ); }
//--------------------------------------------------------- bool CJoin_Tables_Base::On_Execute(void) { //----------------------------------------------------- int id_A, id_B; CSG_Table *pT_A, *pT_B; pT_A = Parameters("TABLE_A")->asTable(); id_A = Parameters("ID_A" )->asInt(); pT_B = Parameters("TABLE_B")->asTable(); id_B = Parameters("ID_B" )->asInt(); if( id_A < 0 || id_A >= pT_A->Get_Field_Count() || pT_A->Get_Count() <= 0 || id_B < 0 || id_B >= pT_B->Get_Field_Count() || pT_B->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- if( Parameters("RESULT")->asTable() && Parameters("RESULT")->asTable() != pT_A ) { pT_A = Parameters("RESULT")->asTable(); if( Parameters("RESULT")->asTable()->Get_ObjectType() == DATAOBJECT_TYPE_Shapes ) { ((CSG_Shapes *)pT_A)->Create(*Parameters("TABLE_A")->asShapes()); } else { pT_A->Create(*Parameters("TABLE_A")->asTable()); } } //----------------------------------------------------- int nJoins, *Join, Offset = pT_A->Get_Field_Count(); if( Parameters("FIELDS_ALL")->asBool() ) { if( (nJoins = pT_B->Get_Field_Count() - 1) <= 0 ) { Error_Set(_TL("no fields to add")); return( false ); } Join = new int[nJoins]; for(int i=0, j=0; i<pT_B->Get_Field_Count(); i++) { if( i != id_B ) { pT_A->Add_Field(pT_B->Get_Field_Name(i), pT_B->Get_Field_Type(i)); Join[j++] = i; } } } else { CSG_Parameter_Table_Fields *pFields = Parameters("FIELDS")->asTableFields(); if( (nJoins = pFields->Get_Count()) <= 0 ) { Error_Set(_TL("no fields to add")); return( false ); } Join = new int[nJoins]; for(int j=0; j<pFields->Get_Count(); j++) { int i = pFields->Get_Index(j); pT_A->Add_Field(pT_B->Get_Field_Name(i), pT_B->Get_Field_Type(i)); Join[j] = i; } } pT_A->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pT_A->Get_Name(), pT_B->Get_Name())); //----------------------------------------------------- bool bCmpNumeric = SG_Data_Type_is_Numeric(pT_A->Get_Field_Type(id_A)) || SG_Data_Type_is_Numeric(pT_B->Get_Field_Type(id_B)); CSG_Table Delete; if( !Parameters("KEEP_ALL")->asBool() ) Delete.Add_Field("ID", SG_DATATYPE_Int); pT_A->Set_Index(id_A, TABLE_INDEX_Ascending); pT_B->Set_Index(id_B, TABLE_INDEX_Ascending); CSG_Table_Record *pRecord_B = pT_B->Get_Record_byIndex(0); for(int a=0, b=0, Cmp; pRecord_B && a<pT_A->Get_Count() && Set_Progress(a, pT_A->Get_Count()); a++) { CSG_Table_Record *pRecord_A = pT_A->Get_Record_byIndex(a); while( pRecord_B && (Cmp = Cmp_Keys(pRecord_A->Get_Value(id_A), pRecord_B->Get_Value(id_B), bCmpNumeric)) < 0 ) { pRecord_B = pT_B->Get_Record_byIndex(++b); } if( pRecord_B && Cmp == 0 ) { for(int i=0; i<nJoins; i++) { *pRecord_A->Get_Value(Offset + i) = *pRecord_B->Get_Value(Join[i]); } } else if( Delete.Get_Field_Count() == 0 ) { for(int i=0; i<nJoins; i++) { pRecord_A->Set_NoData(Offset + i); } } else { Delete.Add_Record()->Set_Value(0, pRecord_A->Get_Index()); } } //----------------------------------------------------- delete[](Join); pT_A->Set_Index(id_A, TABLE_INDEX_None); pT_B->Set_Index(id_B, TABLE_INDEX_None); if( Delete.Get_Count() > 0 ) { Delete.Set_Index(0, TABLE_INDEX_Descending); for(int i=0; i<Delete.Get_Count(); i++) { // ((CSG_Shapes *)pT_A)->Del_Shape(Delete[i].asInt(0)); pT_A->Del_Record(Delete[i].asInt(0)); } Message_Add(CSG_String::Format(SG_T("%d %s"), pT_A->Get_Selection_Count(), _TL("unjoined records have been removed"))); } if( pT_A == Parameters("TABLE_A")->asTable() ) { DataObject_Update(pT_A); } return( pT_A->Get_Count() > 0 ); }
//--------------------------------------------------------- bool CPolygonStatisticsFromPoints::On_Execute(void) { int i, j, n, Offset, *bAttribute; CSG_Simple_Statistics *Statistics; CSG_Parameters *pParameters; CSG_Shapes *pPolygons, *pPoints; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pPolygons = Parameters("POLYGONS") ->asShapes(); if( pPolygons->Get_Count() <= 0 || pPoints->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- pParameters = Get_Parameters("ATTRIBUTES"); pParameters->Del_Parameters(); for(i=0; i<pPoints->Get_Field_Count(); i++) { if( SG_Data_Type_is_Numeric(pPoints->Get_Field_Type(i)) ) { CSG_Parameter *pNode = pParameters->Add_Node(NULL, CSG_String::Format(SG_T("%d"), i), pPoints->Get_Field_Name(i), _TL("")); for(j=0; j<STAT_Count; j++) { pParameters->Add_Value(pNode, CSG_String::Format(SG_T("%d|%d"), i, j), CSG_String::Format(SG_T("[%s]"), STAT_Name[j].c_str()), _TL(""), PARAMETER_TYPE_Bool, false ); } } } if( !Dlg_Parameters("ATTRIBUTES") ) { return( false ); } //----------------------------------------------------- if( Parameters("STATISTICS")->asShapes() == NULL ) { Parameters("STATISTICS")->Set_Value(pPolygons); } else if( pPolygons != Parameters("STATISTICS")->asShapes() ) { Parameters("STATISTICS")->asShapes()->Assign(pPolygons); pPolygons = Parameters("STATISTICS")->asShapes(); } //----------------------------------------------------- bAttribute = new int[pPoints->Get_Field_Count()]; Offset = pPolygons->Get_Field_Count(); for(i=0, n=0; i<pPoints->Get_Field_Count(); i++) { bAttribute[i] = 0; if( SG_Data_Type_is_Numeric(pPoints->Get_Field_Type(i)) ) { for(j=0; j<STAT_Count; j++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(CSG_String::Format(SG_T("%d|%d"), i, j)); if( pParameter && pParameter->asBool() ) { bAttribute[i] |= STAT_Flag[j]; pPolygons->Add_Field(CSG_String::Format(SG_T("%s_%s"), pPoints->Get_Field_Name(i), STAT_Name[j].c_str()), SG_DATATYPE_Double); n++; } } } } if( n == 0 ) { delete[](bAttribute); return( false ); } //----------------------------------------------------- Statistics = new CSG_Simple_Statistics[pPoints->Get_Field_Count()]; for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++) { CSG_Shape_Polygon *pPolygon = (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon); //------------------------------------------------- for(i=0; i<pPoints->Get_Field_Count(); i++) { Statistics[i].Invalidate(); } //------------------------------------------------- for(int iPoint=0; iPoint<pPoints->Get_Count() && Process_Get_Okay(); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Shape(iPoint); if( pPolygon->is_Containing(pPoint->Get_Point(0)) ) { for(i=0; i<pPoints->Get_Field_Count(); i++) { if( bAttribute[i] ) { Statistics[i].Add_Value(pPoint->asDouble(i)); } } } } //------------------------------------------------- for(i=0, n=Offset; i<pPoints->Get_Field_Count(); i++) { if( bAttribute[i] ) { if( Statistics[i].Get_Count() > 0 ) { if( bAttribute[i] & STAT_Flag[STAT_Sum] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Sum()); } if( bAttribute[i] & STAT_Flag[STAT_Avg] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Mean()); } if( bAttribute[i] & STAT_Flag[STAT_Var] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Variance()); } if( bAttribute[i] & STAT_Flag[STAT_Dev] ) { pPolygon->Set_Value(n++, Statistics[i].Get_StdDev()); } if( bAttribute[i] & STAT_Flag[STAT_Min] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Minimum()); } if( bAttribute[i] & STAT_Flag[STAT_Max] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Maximum()); } if( bAttribute[i] & STAT_Flag[STAT_Num] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Count()); } } else { if( bAttribute[i] & STAT_Flag[STAT_Sum] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Avg] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Var] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Dev] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Min] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Max] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Num] ) { pPolygon->Set_NoData(n++); } } } } } //----------------------------------------------------- delete[](Statistics); delete[](bAttribute); DataObject_Update(pPolygons); 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 CShapes2Grid::On_Execute(void) { //----------------------------------------------------- m_pShapes = Parameters("INPUT" )->asShapes(); m_Method_Lines = Parameters("LINE_TYPE")->asInt(); m_Method_Polygon = Parameters("POLY_TYPE")->asInt(); m_Method_Multi = Parameters("MULTIPLE" )->asInt(); if( m_pShapes->Get_Type() == SHAPE_TYPE_Polygon && m_Method_Polygon == 1 ) // all cells intersected have to be marked { m_Method_Lines = 1; // thick, each cell crossed by polygon boundary will be marked additionally } //----------------------------------------------------- int iField; switch( Parameters("OUTPUT")->asInt() ) { case 0: iField = -1; break; case 1: iField = -2; break; case 2: if( (iField = Parameters("FIELD")->asInt()) < 0 || !SG_Data_Type_is_Numeric(m_pShapes->Get_Field_Type(iField)) ) { iField = -2; Message_Add(_TL("WARNING: selected attribute is not numeric; generating unique identifiers instead.")); } break; } //----------------------------------------------------- m_Grid_Target.Cmd_Update(m_pShapes); // if called from saga_cmd if( (m_pGrid = m_Grid_Target.Get_Grid("GRID", Get_Grid_Type(Parameters("GRID_TYPE")->asInt()))) == NULL ) { return( false ); } if( iField < 0 ) { m_pGrid->Set_NoData_Value(0.0); } m_pGrid->Set_Name(CSG_String::Format("%s [%s]", m_pShapes->Get_Name(), iField < 0 ? _TL("ID") : m_pShapes->Get_Field_Name(iField))); m_pGrid->Assign_NoData(); //------------------------------------------------- m_pCount = m_Grid_Target.Get_Grid("COUNT", m_pShapes->Get_Count() < 256 ? SG_DATATYPE_Byte : SG_DATATYPE_Word); if( m_pCount == NULL ) { m_Count.Create(m_pGrid->Get_System(), SG_DATATYPE_Word); m_pCount = &m_Count; } m_pCount->Set_Name(CSG_String::Format("%s [%s]", m_pShapes->Get_Name(), _TL("Count"))); m_pCount->Set_NoData_Value(0.0); m_pCount->Assign(0.0); //----------------------------------------------------- for(int iShape=0; iShape<m_pShapes->Get_Count() && Set_Progress(iShape, m_pShapes->Get_Count()); iShape++) { CSG_Shape *pShape = m_pShapes->Get_Shape(iShape); if( m_pShapes->Get_Selection_Count() <= 0 || pShape->is_Selected() ) { if( iField < 0 || !pShape->is_NoData(iField) ) { m_Value = iField >= 0 ? pShape->asDouble(iField) : iField == -2 ? iShape + 1 : 1; if( pShape->Intersects(m_pGrid->Get_Extent()) ) { switch( m_pShapes->Get_Type() ) { case SHAPE_TYPE_Point: case SHAPE_TYPE_Points: Set_Points (pShape); break; case SHAPE_TYPE_Line: Set_Line (pShape); break; case SHAPE_TYPE_Polygon: Set_Polygon (pShape); if( m_Method_Polygon == 1 ) // all cells intersected have to be marked { Set_Line(pShape); // thick, each cell crossed by polygon boundary will be marked additionally } break; } } } } } //----------------------------------------------------- if( m_Method_Multi == 4 ) // mean { for(int y=0; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++) { for(int x=0; x<m_pGrid->Get_NX(); x++) { if( m_pCount->asInt(x, y) > 1 ) { m_pGrid->Mul_Value(x, y, 1.0 / m_pCount->asDouble(x, y)); } } } } //----------------------------------------------------- m_Count.Destroy(); return( true ); }
//--------------------------------------------------------- bool CSG_Grid::_Load_Native(const CSG_String &File_Name, TSG_Grid_Memory_Type Memory_Type) { bool bResult, hdr_bFlip, hdr_bSwapBytes; int iType, hdr_Offset, NX, NY; double Cellsize, xMin, yMin; CSG_File Stream; TSG_Data_Type hdr_Type; CSG_Grid_System System; CSG_String File_Data, Value; //----------------------------------------------------- bResult = false; if( Stream.Open(File_Name, SG_FILE_R, false) ) { //------------------------------------------------- // Load Header... hdr_Type = SG_DATATYPE_Undefined; hdr_Offset = 0; hdr_bFlip = false; hdr_bSwapBytes = false; NX = NY = 0; Cellsize = 0.0; xMin = 0.0; yMin = 0.0; //------------------------------------------------- do { switch( _Load_Native_Get_Key(Stream, Value) ) { case GRID_FILE_KEY_NAME: Set_Name (Value); break; case GRID_FILE_KEY_DESCRIPTION: Set_Description (Value); break; case GRID_FILE_KEY_UNITNAME: Set_Unit (Value); break; case GRID_FILE_KEY_CELLCOUNT_X: NX = Value.asInt(); break; case GRID_FILE_KEY_CELLCOUNT_Y: NY = Value.asInt(); break; case GRID_FILE_KEY_POSITION_XMIN: xMin = Value.asDouble(); break; case GRID_FILE_KEY_POSITION_YMIN: yMin = Value.asDouble(); break; case GRID_FILE_KEY_CELLSIZE: Cellsize = Value.asDouble(); break; case GRID_FILE_KEY_Z_FACTOR: m_zFactor = Value.asDouble(); break; case GRID_FILE_KEY_NODATA_VALUE: Set_NoData_Value(Value.asDouble()); break; case GRID_FILE_KEY_DATAFILE_OFFSET: hdr_Offset = Value.asInt(); break; case GRID_FILE_KEY_BYTEORDER_BIG: hdr_bSwapBytes = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break; case GRID_FILE_KEY_TOPTOBOTTOM: hdr_bFlip = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break; case GRID_FILE_KEY_DATAFILE_NAME: if( SG_File_Get_Path(Value).Length() > 0 ) { File_Data = Value; } else { File_Data = SG_File_Make_Path(SG_File_Get_Path(File_Name), Value); } break; case GRID_FILE_KEY_DATAFORMAT: for(iType=0; iType<SG_DATATYPE_Undefined && hdr_Type == SG_DATATYPE_Undefined; iType++) { if( Value.Find(gSG_Data_Type_Identifier[iType]) >= 0 ) { hdr_Type = (TSG_Data_Type)iType; } } break; } } while( !Stream.is_EOF() ); //------------------------------------------------- // Load Data... if( m_System.Assign(Cellsize, xMin, yMin, NX, NY) ) { //--------------------------------------------- // ASCII... if( !SG_Data_Type_is_Numeric(hdr_Type) ) { if( m_Type >= SG_DATATYPE_Undefined ) { m_Type = SG_DATATYPE_Float; } if( Stream.Open(File_Data , SG_FILE_R, false) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , SG_FILE_R, false) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , SG_FILE_R, false) ) { Stream.Seek(hdr_Offset); bResult = _Load_ASCII(Stream, Memory_Type, hdr_bFlip); } } //--------------------------------------------- // Binary... else { if( m_Type >= SG_DATATYPE_Undefined ) { m_Type = hdr_Type; } if( (NX = SG_Grid_Cache_Check(m_System, Get_nValueBytes())) > 0 ) { Set_Buffer_Size(NX); if( _Cache_Create(File_Data , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) || _Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) || _Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) ) { return( true ); } Memory_Type = GRID_MEMORY_Cache; } if( _Memory_Create(Memory_Type) ) { if( Stream.Open(File_Data , SG_FILE_R, true) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , SG_FILE_R, true) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , SG_FILE_R, true) ) { Stream.Seek(hdr_Offset); bResult = _Load_Binary(Stream, hdr_Type, hdr_bFlip, hdr_bSwapBytes); } } } } } return( bResult ); }
//--------------------------------------------------------- bool CTable_Field_Statistics::On_Execute(void) { CSG_Table *pTab_in, *pTab_out; int nFeatures, *Features; //----------------------------------------------------- pTab_in = Parameters("TABLE")->asTable(); pTab_out = Parameters("STATISTICS")->asTable(); Features = (int *)Parameters("FIELDS")->asPointer(); nFeatures = Parameters("FIELDS")->asInt (); //----------------------------------------------------- if( !Features || nFeatures <= 0 ) { Error_Set(_TL("No attribute fields selected!")); return( false ); } //----------------------------------------------------- pTab_out->Destroy(); pTab_out->Set_Name(CSG_String::Format(_TL("%s_stats"), pTab_in->Get_Name())); pTab_out->Add_Field(_TL("Field") , SG_DATATYPE_String); pTab_out->Add_Field(_TL("n") , SG_DATATYPE_Long); pTab_out->Add_Field(_TL("min") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("max") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("range") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("sum") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("mean") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("variance") , SG_DATATYPE_Double); pTab_out->Add_Field(_TL("stddev") , SG_DATATYPE_Double); //----------------------------------------------------- for(int iFeature=0; iFeature<nFeatures; iFeature++) { if( SG_Data_Type_is_Numeric(pTab_in->Get_Field_Type(Features[iFeature])) ) { CSG_Table_Record *pRecord = pTab_out->Add_Record(); pRecord->Set_Value(0, pTab_in->Get_Field_Name(Features[iFeature])); pRecord->Set_Value(1, pTab_in->Get_N(Features[iFeature])); pRecord->Set_Value(2, pTab_in->Get_Minimum(Features[iFeature])); pRecord->Set_Value(3, pTab_in->Get_Maximum(Features[iFeature])); pRecord->Set_Value(4, pTab_in->Get_Range(Features[iFeature])); pRecord->Set_Value(5, pTab_in->Get_Sum(Features[iFeature])); pRecord->Set_Value(6, pTab_in->Get_Mean(Features[iFeature])); pRecord->Set_Value(7, pTab_in->Get_Variance(Features[iFeature])); pRecord->Set_Value(8, pTab_in->Get_StdDev(Features[iFeature])); } else { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: skipping non-numeric field '%s'!"), pTab_in->Get_Field_Name(Features[iFeature])), true); } } //----------------------------------------------------- DataObject_Update(pTab_out); return( true ); }