//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- void CVariogram_Dialog::Set_Model(void) { //----------------------------------------------------- if( m_Distance < 0 || m_Distance != m_pDistance->Get_Value() ) { m_Distance = m_pDistance->Get_Value(); m_pModel->Clr_Data(); for(int i=0; i<m_pVariogram->Get_Count(); i++) { CSG_Table_Record *pRecord = m_pVariogram->Get_Record(i); if( pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE) <= m_Distance ) { m_pModel->Add_Data(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE), pRecord->asDouble(CSG_Variogram::FIELD_VAR_EXP)); } } m_pModel->Get_Trend(); } //----------------------------------------------------- wxString s; if( !m_pModel->Set_Formula(m_pFormula->GetValue().c_str()) ) { s += m_pModel->Get_Error().w_str(); } else if( !m_pModel->Get_Trend() ) { s += _TL("function fitting failed !"); } else { s += m_pModel->Get_Formula(SG_TREND_STRING_Function).w_str(); s += wxString::Format(wxT("\n%s:\t%.2f%%"), _TL("Determination") , m_pModel->Get_R2() * 100.0); s += wxString::Format(wxT("\n%s:\t%.*f") , _TL("Fitting range") , SG_Get_Significant_Decimals(m_pDistance->Get_Value()), m_pDistance->Get_Value()); s += wxString::Format(wxT("\n%s:\t%d") , _TL("Samples in range") , m_pModel->Get_Data_Count()); s += wxString::Format(wxT("\n%s:\t%d") , _TL("Lag Classes") , m_pVariogram->Get_Count()); s += wxString::Format(wxT("\n%s:\t%.2f") , _TL("Lag Distance") , m_Settings("LAGDIST")->asDouble()); s += wxString::Format(wxT("\n%s:\t%.2f") , _TL("Maximum Distance") , m_Settings("MAXDIST")->asDouble()); m_Settings("MODEL")->Set_Value(m_pModel->Get_Formula(SG_TREND_STRING_Formula)); } m_pParameters->SetValue(s); m_pDiagram->m_bPairs = m_pPairs->GetValue(); m_pDiagram->Refresh(true); }
bool CPoints_From_Table::On_Execute(void) { int iRecord, iXField, iYField; double dX, dY; CSG_Table *pTable; CSG_Table_Record *pRecord; CSG_Shapes *pShapes; CSG_Shape *pShape; pTable = Parameters("TABLE") ->asTable(); pShapes = Parameters("POINTS") ->asShapes(); iXField = Parameters("X") ->asInt(); iYField = Parameters("Y") ->asInt(); pShapes->Create(SHAPE_TYPE_Point, pTable->Get_Name(), pTable); if( pTable->Get_Field_Count() > 1 && pTable->Get_Record_Count() > 0 ) { for(iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++) { pRecord = pTable->Get_Record(iRecord); dX = pRecord->asDouble(iXField); dY = pRecord->asDouble(iYField); pShape = pShapes->Add_Shape(pRecord, SHAPE_COPY_ATTR); pShape->Add_Point(dX, dY); }//for return( true ); }//if return( false ); }//method
//--------------------------------------------------------- double CDVWK_SoilMoisture::Get_Pi(int Day) { const double Messfehler[] = // --- Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez { 0.000, 0.228, 0.236, 0.200, 0.160, 0.120, 0.103, 0.105, 0.103, 0.115, 0.136, 0.162, 0.189 }; double P, Pi; //----------------------------------------------------- CSG_Table_Record *pRecord; if( (pRecord = pClimate->Get_Record(Day)) == NULL ) { return( 0 ); } P = pRecord->asDouble(0); //----------------------------------------------------- // VKR 4.11: Berechnung der korrigierten Niederschlaege (Pi [mm/d]) // // Pi = N * kn // // N : Niederschlag gemessen [mm/d] // kn : Korrekturfaktor ergibt sich aus den prozentualen Meßfehlern... // Month : 1=Jan, 2=Feb... 0=NA; // Pi = P + P * Messfehler[Get_Month(Day)]; return( Pi ); }
//--------------------------------------------------------- inline double CTable_PCA::Get_Value(int iFeature, int iElement) { CSG_Table_Record *pElement = m_pTable->Get_Record(iElement); switch( m_Method ) { default: case 0: // Correlation matrix: Center and reduce the column vectors. return( (pElement->asDouble(iFeature) - m_pTable->Get_Mean(iFeature)) / (sqrt(m_pTable->Get_Count() * m_pTable->Get_Variance(iFeature))) ); case 1: // Variance-covariance matrix: Center the column vectors. return( (pElement->asDouble(iFeature) - m_pTable->Get_Mean(iFeature)) ); case 2: // Sums-of-squares-and-cross-products matrix return( (pElement->asDouble(iFeature)) ); } }
//--------------------------------------------------------- inline int CChange_Detection::Cmp_Class(CSG_Table &Classes, double Value, int iClass) { CSG_Table_Record *pClass = Classes.Get_Record_byIndex(iClass); double min = pClass->asDouble(CLASS_MIN); if( Value < min ) { return( 1 ); } double max = pClass->asDouble(CLASS_MAX); return( min < max ? (Value < max ? 0 : -1) : (Value > min ? -1 : 0) ); }
//--------------------------------------------------------- bool CTOPMODEL::Get_Climate(int iTimeStep, double &Precipitation, double &Evaporation) { CSG_Table_Record *pRecord; if( pClimate && pClimate->Get_Field_Count() >= 2 && (pRecord = pClimate->Get_Record(iTimeStep)) != NULL ) { Precipitation = pRecord->asDouble(0); Evaporation = pRecord->asDouble(1); return( true ); } else { Precipitation = 0.0; Evaporation = 0.0; return( false ); } }
//--------------------------------------------------------- double CRGA_Basic::Get_Similarity(int x, int y, int Segment) { CSG_Table_Record *pSeed; if( is_InGrid(x, y) && (pSeed = m_pSeeds->Get_Record(Segment)) != NULL ) { int i; double a, b, Result; switch( m_Method ) { //------------------------------------------------- case 0: // feature space and position for(i=0, a=0.0; i<m_nFeatures; i++) { a += SG_Get_Square(Get_Feature(x, y, i) - pSeed->asDouble(SEEDFIELD_Z + i)); } b = SG_Get_Square(x - pSeed->asDouble(SEEDFIELD_X)) + SG_Get_Square(y - pSeed->asDouble(SEEDFIELD_Y)); Result = a / m_Var_1 + b / m_Var_2; break; //------------------------------------------------- case 1: // feature space for(i=0, a=0.0; i<m_nFeatures; i++) { a += SG_Get_Square(Get_Feature(x, y, i) - pSeed->asDouble(SEEDFIELD_Z + i)); } Result = a / m_Var_1; break; } return( 1.0 / (1.0 + Result) ); // from 'distance' to 'similarity' !!! // return( exp(-0.5 * Result) ); } return( -1.0 ); }
bool CFit::On_Execute(void) { int i, j, NrVars; vector < double> x, y, StartValue, Result; CSG_String msg; CSG_Parameters StartParameters; const SG_Char *formel = Parameters("FORMEL")->asString(); Formel.Add_Function(SG_T("NUG"), (TSG_PFNC_Formula_1) NUG, 1, 0); Formel.Add_Function(SG_T("SPH"), (TSG_PFNC_Formula_1) SPH, 2, 0); Formel.Add_Function(SG_T("EXP"), (TSG_PFNC_Formula_1) EXP, 2, 0); Formel.Add_Function(SG_T("LIN"), (TSG_PFNC_Formula_1) LIN, 2, 0); Formel.Set_Formula(formel); if (Formel.Get_Error(msg)) { Message_Add(msg); return false; } const SG_Char *uservars = NULL; uservars = Formel.Get_Used_Variables(); NrVars = 0; for (i = 0; i < SG_STR_LEN(uservars); i++) { if (uservars[i] >='a' && uservars[i] <= 'z') { if (uservars[i] != 'x') vars[NrVars++] = uservars[i]; } } vars[NrVars] =(char) 0; StartParameters.Add_Info_String(NULL, _TL(""), _TL("Formula"), _TL("Formula"), formel); for (i = 0; i < strlen(vars); i++) { CSG_String c(vars[i]); StartParameters.Add_Value(NULL, c, c, _TL("Start Value"), PARAMETER_TYPE_Double, 1.0); } Dlg_Parameters(&StartParameters, _TL("Start Values")); for (i = 0; i < strlen(vars); i++) { char c[3]; sprintf(c, "%c", vars[i]); StartValue.push_back(StartParameters(c)->asDouble()); } CSG_Table *pTable = Parameters("SOURCE")->asTable(); int Record_Count = pTable->Get_Record_Count(); int yField = Parameters("YFIELD")->asInt(); int xField = Parameters("XFIELD")->asInt(); bool Use_X = Parameters("USE_X")->asBool(); pTable->Add_Field(_TL("Fit") , SG_DATATYPE_Double); for (i = 0; i < Record_Count; i++) { CSG_Table_Record * Record = pTable->Get_Record(i); if (Use_X) { x.push_back(Record->asDouble(xField)); } else { x.push_back(i); } y.push_back(Record->asDouble(yField)); } TLMFit *Fit; Fit = new TLMFit(x, y, StartValue, FitFunc); int max_iter = Parameters("ITER")->asInt(); double Max_lamda = Parameters("LAMDA")->asInt(); int iter = 0; try { Fit->Fit(); while ((Fit->Alamda() < Max_lamda) &&(iter < max_iter) &&Process_Get_Okay(true)) { Fit->Fit(); iter++; } } catch (ESingularMatrix &E) { if (E.Type == 1 || E.Type == 2) { msg.Printf(_TL("Matrix signular\n")); Message_Add(msg); return false; } } Result = Fit->Param(); for (i = 0; i < NrVars; i++) { Formel.Set_Variable(vars[i], (double) Result[i]); } msg.Printf(_TL("Model Parameters:")); Message_Add(msg); for (i = 0; i < NrVars; i++) { msg.Printf(SG_T("%c = %f\n"), vars[i], Result[i]); Message_Add(msg); } msg.Printf(_TL("\nRMS of Residuals (stdfit):\t%f\n"), sqrt(Fit->Chisq()/x.size())); Message_Add(msg); msg.Printf(_TL("Correlation Matrix of the Fit Parameters:\n")); Message_Add(msg); vector< vector < double> > covar = Fit->Covar(); msg.Printf(_TL("")); for (j = 0; j < NrVars; j++) msg.Printf(SG_T("%s\t%c"), msg.c_str(), vars[j]); msg.Printf(SG_T("%s\n"), msg.c_str()); Message_Add(msg); for (i = 0; i < NrVars; i++) { msg.Printf(SG_T("%c"), vars[i]); for (j = 0; j <= i; j++) { msg.Printf(SG_T("%s\t%f"), msg.c_str(), covar[i][j]/covar[i][i]); } msg.Printf(SG_T("%s\n"), msg.c_str()); Message_Add(msg); } int Field_Count = pTable->Get_Field_Count(); for (i = 0; i < Record_Count; i++) { CSG_Table_Record * Record = pTable->Get_Record(i); Record->Set_Value(Field_Count - 1, Formel.Get_Value(x[i])); } // API_FREE (uservars); return (true); }
//--------------------------------------------------------- bool CGrid_Table_Import::On_Execute(void) { bool bDown; int x, y, nx, ny; double dxy, xmin, ymin, zFactor, zNoData; TSG_Data_Type data_type; CSG_String FileName, Unit; CSG_Grid *pGrid; CSG_Table Table; CSG_Table_Record *pRecord; //----------------------------------------------------- FileName = Parameters("FILE_DATA") ->asString(); dxy = Parameters("DXY") ->asDouble(); xmin = Parameters("XMIN") ->asDouble(); ymin = Parameters("YMIN") ->asDouble(); bDown = Parameters("TOPDOWN") ->asInt() == 1; Unit = Parameters("UNIT") ->asString(); zFactor = Parameters("ZFACTOR") ->asDouble(); zNoData = Parameters("NODATA") ->asDouble(); switch( Parameters("DATA_TYPE")->asInt() ) { default: data_type = SG_DATATYPE_Undefined; break; // not handled case 0: data_type = SG_DATATYPE_Byte; break; // 1 Byte Integer (unsigned) case 1: data_type = SG_DATATYPE_Char; break; // 1 Byte Integer (signed) case 2: data_type = SG_DATATYPE_Word; break; // 2 Byte Integer (unsigned) case 3: data_type = SG_DATATYPE_Short; break; // 2 Byte Integer (signed) case 4: data_type = SG_DATATYPE_DWord; break; // 4 Byte Integer (unsigned) case 5: data_type = SG_DATATYPE_Int; break; // 4 Byte Integer (signed) case 6: data_type = SG_DATATYPE_Float; break; // 4 Byte Floating Point case 7: data_type = SG_DATATYPE_Double; break; // 8 Byte Floating Point } //----------------------------------------------------- if( Table.Create(FileName) && (nx = Table.Get_Field_Count()) > 0 && (ny = Table.Get_Record_Count()) > 0 ) { pGrid = SG_Create_Grid(data_type, nx, ny, dxy, xmin, ymin); for(y=0; y<ny && Set_Progress(y, ny); y++) { pRecord = Table.Get_Record(bDown ? ny - 1 - y : y); for(x=0; x<nx; x++) { pGrid->Set_Value(x, y, pRecord->asDouble(x)); } } pGrid->Set_Unit (Unit); pGrid->Set_ZFactor (zFactor); pGrid->Set_NoData_Value (zNoData); pGrid->Set_Name (SG_File_Get_Name(FileName, false)); Parameters("GRID")->Set_Value(pGrid); return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- 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 CGrid_Table_Import::On_Execute(void) { //----------------------------------------------------- CSG_Table Table; if( !Table.Create(Parameters("FILE")->asString()) ) { Error_Fmt("%s [%s]", _TL("could not open table file"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- int nx, ny, nHeadLines = Parameters("HEADLINES")->asInt(); if( (nx = Table.Get_Field_Count()) < 1 || (ny = Table.Get_Record_Count()) < 1 ) { Error_Fmt("%s [%s]", _TL("no data in table file"), Parameters("FILE")->asString()); return( false ); } //----------------------------------------------------- TSG_Data_Type Type; switch( Parameters("DATA_TYPE")->asInt() ) { case 0: Type = SG_DATATYPE_Byte ; break; // 1 Byte Integer (unsigned) case 1: Type = SG_DATATYPE_Char ; break; // 1 Byte Integer (signed) case 2: Type = SG_DATATYPE_Word ; break; // 2 Byte Integer (unsigned) case 3: Type = SG_DATATYPE_Short ; break; // 2 Byte Integer (signed) case 4: Type = SG_DATATYPE_DWord ; break; // 4 Byte Integer (unsigned) case 5: Type = SG_DATATYPE_Int ; break; // 4 Byte Integer (signed) default: Type = SG_DATATYPE_Float ; break; // 4 Byte Floating Point case 7: Type = SG_DATATYPE_Double; break; // 8 Byte Floating Point } //----------------------------------------------------- CSG_Grid *pGrid = SG_Create_Grid(Type, nx, ny, Parameters("CELLSIZE")->asDouble(), Parameters("XMIN" )->asDouble(), Parameters("YMIN" )->asDouble() ); pGrid->Set_Name (SG_File_Get_Name(Parameters("FILE")->asString(), false)); pGrid->Set_Unit (Parameters("UNIT" )->asString()); pGrid->Set_NoData_Value(Parameters("NODATA" )->asDouble()); pGrid->Set_Scaling (Parameters("ZFACTOR")->asDouble()); Parameters("GRID")->Set_Value(pGrid); //----------------------------------------------------- bool bDown = Parameters("TOPDOWN")->asInt() == 1; for(int y=0; y<ny && Set_Progress(y, ny); y++) { CSG_Table_Record *pRecord = Table.Get_Record(y + nHeadLines); for(int x=0, yy=bDown?ny-1-y:y; x<nx; x++) { pGrid->Set_Value(x, yy, pRecord->asDouble(x)); } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CFilter_3x3::On_Execute(void) { int x, y, ix, iy, dx, dy, fx, fy, fdx, fdy; double Sum, nSum, **f; CSG_Grid *pInput, *pResult; CSG_Table *pFilter; CSG_Table_Record *pRecord; //----------------------------------------------------- pInput = Parameters("INPUT")->asGrid(); pResult = Parameters("RESULT")->asGrid(); //----------------------------------------------------- pFilter = Parameters("FILTER")->asTable(); fdx = pFilter->Get_Field_Count(); fdy = pFilter->Get_Record_Count(); dx = (fdx - 1) / 2; dy = (fdy - 1) / 2; f = (double **)SG_Malloc(fdy * sizeof(double *)); f[0] = (double *)SG_Malloc(fdy * fdx * sizeof(double)); for(fy=0; fy<fdy; fy++) { f[fy] = f[0] + fy * fdx; pRecord = pFilter->Get_Record(fy); for(fx=0; fx<fdx; fx++) { f[fy][fx] = pRecord->asDouble(fx); } } //----------------------------------------------------- for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { Sum = nSum = 0.0; for(fy=0, iy=y-dy; fy<fdy; fy++, iy++) { for(fx=0, ix=x-dx; fx<fdx; fx++, ix++) { if( pInput->is_InGrid(ix, iy) ) { Sum += f[fy][fx] * pInput->asDouble(ix, iy); nSum += fabs(f[fy][fx]); } } } if( nSum > 0.0 ) { pResult->Set_Value(x, y, Sum / nSum); } else { pResult->Set_NoData(x, y); } } } //----------------------------------------------------- SG_Free(f[0]); SG_Free(f); return( true ); }
//--------------------------------------------------------- bool CTable_Trend_Base::On_Execute(void) { int i, j, xField, yField; CSG_String Name; CSG_Table_Record *pRecord; CSG_Table *pTable; pTable = Parameters("TABLE") ->asTable(); xField = Parameters("FIELD_X") ->asInt(); yField = Parameters("FIELD_Y") ->asInt(); //----------------------------------------------------- if( m_Trend.Set_Formula(Parameters("FORMULA")->asString()) ) { m_Trend.Clr_Data(); for(i=0; i<pTable->Get_Record_Count(); i++) { pRecord = pTable->Get_Record(i); m_Trend.Add_Data(pRecord->asDouble(xField), pRecord->asDouble(yField)); } //------------------------------------------------- if( m_Trend.Get_Trend() ) { Message_Fmt("\n%s\n%s: %f", m_Trend.Get_Formula().c_str(), SG_T("r\xb2"), 100.0 * m_Trend.Get_R2()); if( Parameters("TREND")->asTable() == NULL ) { pTable->Add_Field("TREND" , SG_DATATYPE_Double); for(i=0, j=pTable->Get_Field_Count()-1; i<m_Trend.Get_Data_Count(); i++) { pRecord = pTable->Get_Record(i); pRecord->Set_Value(j, m_Trend.Get_Value(m_Trend.Get_Data_X(i))); } } else { Name.Printf("%s [%s]", pTable->Get_Name(), _TL("Trend")); pTable = Parameters("TREND")->asTable(); pTable->Destroy(); pTable->Set_Name(Name); pTable->Add_Field("X" , SG_DATATYPE_Double); pTable->Add_Field("Y" , SG_DATATYPE_Double); pTable->Add_Field("Y_TREND", SG_DATATYPE_Double); for(i=0; i<m_Trend.Get_Data_Count(); i++) { pRecord = pTable->Add_Record(); pRecord->Set_Value(0, m_Trend.Get_Data_X(i)); pRecord->Set_Value(1, m_Trend.Get_Data_Y(i)); pRecord->Set_Value(2, m_Trend.Get_Value(m_Trend.Get_Data_X(i))); } } return( true ); } } return( false ); }
//--------------------------------------------------------- bool CGrid_Value_Reclassify::ReclassTable(bool bUser) { bool set, otherOpt, noDataOpt; int n, x, y, opera, recCount, count[MAX_CAT], field_Min, field_Max, field_Code; double min[MAX_CAT], max[MAX_CAT], code[MAX_CAT], value, others, noData, noDataValue; CSG_Table *pReTab; CSG_Table_Record *pRecord = NULL; if( bUser ) { pReTab = Parameters("RETAB_2") ->asTable(); field_Min = Parameters("F_MIN") ->asInt(); field_Max = Parameters("F_MAX") ->asInt(); field_Code = Parameters("F_CODE") ->asInt(); } else { pReTab = Parameters("RETAB") ->asTable(); field_Min = 0; field_Max = 1; field_Code = 2; } others = Parameters("OTHERS")->asDouble(); noData = Parameters("NODATA")->asDouble(); otherOpt = Parameters("OTHEROPT")->asBool(); noDataOpt = Parameters("NODATAOPT")->asBool(); opera = Parameters("TOPERATOR")->asInt(); noDataValue = pInput->Get_NoData_Value(); if( pReTab == NULL ) { Error_Set(_TL("You must specify a reclass table with a minimium (field 1), a maximum (field 2) and a code value (field 3)!\n")); return( false ); } recCount = pReTab->Get_Record_Count(); if( recCount > MAX_CAT ) { Error_Set(_TL("At the moment the reclass table is limited to 128 categories!\n")); return( false ); } if( recCount == 0 ) { Error_Set(_TL("You must specify a reclass table with a minimium of one record!\n")); return( false ); } for(n=0; n<recCount ; n++) // initialize reclass arrays { pRecord = pReTab->Get_Record(n); min[n] = pRecord->asDouble(field_Min); max[n] = pRecord->asDouble(field_Max); code[n] = pRecord->asDouble(field_Code); count[n] = 0; } for(y=0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { value = pInput->asDouble(x, y); set = false; for(n=0; n< recCount; n++) // reclass { if( opera == 0 ) // min <= value < max { if( value >= min[n] && value < max[n] ) { pResult->Set_Value(x, y, code[n]); set = true; count[n] += 1; break; } } else if( opera == 1 ) // min <= value <= max { if( value >= min[n] && value <= max[n] ) { pResult->Set_Value(x, y, code[n]); set = true; count[n] += 1; break; } } else if( opera == 2 ) // min < value <= max { if( value > min[n] && value <= max[n] ) { pResult->Set_Value(x, y, code[n]); set = true; count[n] += 1; break; } } else if( opera == 3 ) // min < value < max { if( value > min[n] && value < max[n] ) { pResult->Set_Value(x, y, code[n]); set = true; count[n] += 1; break; } } } if( set == false ) { if( noDataOpt == true && value == noDataValue ) // noData option pResult->Set_Value(x, y, noData); else if( otherOpt == true && value != noDataValue) // other values option pResult->Set_Value(x, y, others); else pResult->Set_Value(x, y, value); // or original value } } } return (true); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- double CDVWK_SoilMoisture::Get_ETP_Haude(int Day) { const double f[] = // --- Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez { 0.00, 0.22, 0.22, 0.22, 0.29, 0.29, 0.28, 0.26, 0.25, 0.23, 0.22, 0.22, 0.22 }; double T14, U14, es, e, ETP_Haude; //----------------------------------------------------- CSG_Table_Record *pRecord; if( (pRecord = pClimate->Get_Record(Day)) == NULL ) { return( 0 ); } T14 = pRecord->asDouble(1); U14 = pRecord->asDouble(2); //----------------------------------------------------- // VKR 4.6: Berechnung des Saettigungsdampfdruckes (es [hPa]) // // 17,62 * T14 // es(T14) = 6,11 * exp( -------------- ); bei T14 > 0 // 243,12 + T14 // // 22,46 * T14 // es(T14) = 6,11 * exp( -------------- ); bei T14 < 0 // 272,62 + T14 // // T14 : Temperatur 14 Uhr [DegreeC] // if( T14 < 0 ) { es = 6.11 * exp( (22.46 * T14) / (272.62 + T14) ); } else { es = 6.11 * exp( (17.62 * T14) / (243.12 + T14) ); } //----------------------------------------------------- // VKR 4.7: Berechnung des aktuellen Dampfdruckes (e [hPa]) // // e = es(T14) * U14 / 100 // // es(T14) : Saettigungsdampfdruck 14 Uhr [hPa] // U14 : relative Luftfeuchte 14 Uhr [%] (Dampfdruck in % des Saettigungsdampfdruckes) // e = es * U14 / 100.0; //----------------------------------------------------- // VKR 4.8: Berechnung der potentiellen Verdunstung nach Haude (ETPhaude [mm/d]) // // ETPhaude = f(m) * (es - e) // // f(m) : Monatsfaktor [mm/mbar/d] // e : aktueller Dampfdruck [hPa] // es : Saettigungsdampfdruck // ETP_Haude = f[Get_Month(Day)] * (es - e); return( ETP_Haude ); }
//--------------------------------------------------------- bool CPC_Reclass_Extract::Reclass_Table(bool bUser) { bool set, otherOpt, noDataOpt; int opera, field_Min, field_Max, field_Code; double value, others, noData, noDataValue; CSG_Table *pReTab; CSG_Table_Record *pRecord = NULL; if( bUser ) { pReTab = Parameters("RETAB_2") ->asTable(); field_Min = Parameters("F_MIN") ->asInt(); field_Max = Parameters("F_MAX") ->asInt(); field_Code = Parameters("F_CODE") ->asInt(); } else { pReTab = Parameters("RETAB") ->asTable(); field_Min = 0; field_Max = 1; field_Code = 2; } others = Parameters("OTHERS")->asDouble(); noData = Parameters("NODATA")->asDouble(); opera = Parameters("TOPERATOR")->asInt(); otherOpt = m_bExtract ? false : Parameters("OTHEROPT")->asBool(); noDataOpt = m_bExtract ? false : Parameters("NODATAOPT")->asBool(); noDataValue = m_pInput->Get_NoData_Value(); if( pReTab == NULL ) { Error_Set(_TL("You must specify a reclass table with a minimium (field 1), a maximum (field 2) and a code value (field 3)!\n")); return( false ); } if( pReTab->Get_Record_Count() == 0 ) { Error_Set(_TL("You must specify a reclass table with a minimium of one record!\n")); return( false ); } for (int i=0; i<m_pInput->Get_Point_Count() && Set_Progress(i, m_pInput->Get_Point_Count()); i++) { value = m_pInput->Get_Value(i, m_AttrField); set = false; for(int iRecord=0; iRecord<pReTab->Get_Record_Count(); iRecord++) // reclass { pRecord = pReTab->Get_Record(iRecord); if( opera == 0 ) // min <= value < max { if( value >= pRecord->asDouble(field_Min) && value < pRecord->asDouble(field_Max) ) { Set_Value(i, pRecord->asDouble(field_Code)); set = true; break; } } else if( opera == 1 ) // min <= value <= max { if( value >= pRecord->asDouble(field_Min) && value <= pRecord->asDouble(field_Max) ) { Set_Value(i, pRecord->asDouble(field_Code)); set = true; break; } } else if( opera == 2 ) // min < value <= max { if( value > pRecord->asDouble(field_Min) && value <= pRecord->asDouble(field_Max) ) { Set_Value(i, pRecord->asDouble(field_Code)); set = true; break; } } else if( opera == 3 ) // min < value < max { if( value > pRecord->asDouble(field_Min) && value < pRecord->asDouble(field_Max) ) { Set_Value(i, pRecord->asDouble(field_Code)); set = true; break; } } } if( set == false ) { if( noDataOpt == true && value == noDataValue ) // noData option Set_Value(i, noData); else if( otherOpt == true && value != noDataValue) // other values option Set_Value(i, others); else { if (!m_bExtract) Set_Value(i, value); // or original value m_iOrig++; } } } return (true); }
//--------------------------------------------------------- bool CFilter_3x3::On_Execute(void) { //----------------------------------------------------- CSG_Table *pFilter = Parameters("FILTER")->asTable() ? Parameters("FILTER" )->asTable() : Parameters("FILTER_3X3")->asTable(); if( pFilter->Get_Count() < 1 || pFilter->Get_Field_Count() < 1 ) { Error_Set(_TL("invalid filter matrix")); return( false ); } //----------------------------------------------------- CSG_Matrix Filter(pFilter->Get_Field_Count(), pFilter->Get_Count()); { for(int iy=0; iy<Filter.Get_NY(); iy++) { CSG_Table_Record *pRecord = pFilter->Get_Record(iy); for(int ix=0; ix<Filter.Get_NX(); ix++) { Filter[iy][ix] = pRecord->asDouble(ix); } } } int nx = (Filter.Get_NX() - 1) / 2; int ny = (Filter.Get_NY() - 1) / 2; //----------------------------------------------------- CSG_Grid *pInput = Parameters("INPUT" )->asGrid(); CSG_Grid *pResult = Parameters("RESULT")->asGrid(); if( !pResult || pResult == pInput ) { pResult = SG_Create_Grid(pInput); } else { pResult->Fmt_Name("%s [%s]", pInput->Get_Name(), _TL("Filter")); pResult->Set_NoData_Value(pInput->Get_NoData_Value()); } //----------------------------------------------------- bool bAbsolute = Parameters("ABSOLUTE")->asBool(); for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double s = 0.0; double n = 0.0; if( pInput->is_InGrid(x, y) ) { for(int iy=0, jy=y-ny; iy<Filter.Get_NY(); iy++, jy++) { for(int ix=0, jx=x-nx; ix<Filter.Get_NX(); ix++, jx++) { if( pInput->is_InGrid(jx, jy) ) { s += Filter[iy][ix] * pInput->asDouble(jx, jy); n += fabs(Filter[iy][ix]); } } } } if( n > 0.0 ) { pResult->Set_Value(x, y, bAbsolute ? s : s / n); } else { pResult->Set_NoData(x, y); } } } //----------------------------------------------------- if( !Parameters("RESULT")->asGrid() || Parameters("RESULT")->asGrid() == pInput ) { pInput->Assign(pResult); delete(pResult); DataObject_Update(pInput); } return( true ); }
//--------------------------------------------------------- bool CSG_Table::_Save_DBase(const CSG_String &File_Name) { int iField, iRecord, nBytes; CSG_Table_DBase dbf; //----------------------------------------------------- CSG_Table_DBase::TFieldDesc *dbfFields = new CSG_Table_DBase::TFieldDesc[Get_Field_Count()]; for(iField=0; iField<Get_Field_Count(); iField++) { strncpy(dbfFields[iField].Name, SG_STR_SGTOMB(Get_Field_Name(iField)), 11); switch( Get_Field_Type(iField) ) { case SG_DATATYPE_String: default: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)((nBytes = Get_Field_Length(iField)) > 255 ? 255 : nBytes); break; case SG_DATATYPE_Date: dbfFields[iField].Type = DBF_FT_DATE; dbfFields[iField].Width = (BYTE)8; break; case SG_DATATYPE_Char: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)1; break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: case SG_DATATYPE_Long: case SG_DATATYPE_Color: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)0; break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)8; break; } } if( !dbf.Open(File_Name, Get_Field_Count(), dbfFields) ) { delete[](dbfFields); SG_UI_Msg_Add_Error(LNG("[ERR] dbase file could not be opened")); return( false ); } delete[](dbfFields); //----------------------------------------------------- for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++) { CSG_Table_Record *pRecord = Get_Record(iRecord); dbf.Add_Record(); for(iField=0; iField<Get_Field_Count(); iField++) { switch( dbf.Get_FieldType(iField) ) { case DBF_FT_DATE: case DBF_FT_CHARACTER: dbf.Set_Value(iField, SG_STR_SGTOMB(pRecord->asString(iField))); break; case DBF_FT_NUMERIC: dbf.Set_Value(iField, pRecord->asDouble(iField)); break; } } dbf.Flush_Record(); } SG_UI_Process_Set_Ready(); return( true ); }
//--------------------------------------------------------- bool CTable_Text_Export::On_Execute(void) { CSG_String StrFormat, Separator; CSG_File Stream; CSG_Table *pTable; //----------------------------------------------------- pTable = Parameters("TABLE" )->asTable(); StrFormat = Parameters("STRQUOTA")->asBool() ? SG_T("\"%s\"") : SG_T("%s"); switch( Parameters("SEPARATOR")->asInt() ) { case 0: Separator = "\t"; break; case 1: Separator = ";"; break; case 2: Separator = ","; break; case 3: Separator = " "; break; default: Separator = Parameters("SEP_OTHER")->asString(); break; } //----------------------------------------------------- if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_W, false) ) { Message_Add(_TL("file could not be opened.")); } //----------------------------------------------------- else { if( Parameters("HEADLINE")->asBool() ) { for(int iField=0; iField<pTable->Get_Field_Count(); iField++) { Stream.Printf(StrFormat.c_str(), pTable->Get_Field_Name(iField)); Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n")); } } //------------------------------------------------- for(int iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++) { CSG_Table_Record *pRecord = pTable->Get_Record(iRecord); for(int iField=0; iField<pTable->Get_Field_Count(); iField++) { switch( pTable->Get_Field_Type(iField) ) { default: case SG_DATATYPE_Char: case SG_DATATYPE_String: case SG_DATATYPE_Date: Stream.Printf(StrFormat.c_str(), pRecord->asString(iField)); break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: case SG_DATATYPE_Color: Stream.Printf(SG_T("%d") , pRecord->asInt(iField)); break; case SG_DATATYPE_Long: Stream.Printf(SG_T("%ld") , (long)pRecord->asDouble(iField)); break; case SG_DATATYPE_ULong: Stream.Printf(SG_T("%lu") , (unsigned long)pRecord->asDouble(iField)); break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: Stream.Printf(SG_T("%f") , pRecord->asDouble(iField)); break; } Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n")); } } //------------------------------------------------- Stream.Close(); return( true ); } return( false ); }
//--------------------------------------------------------- void CVariogram_Diagram::On_Draw(wxDC &dc, wxRect rDraw) { if( m_pVariogram->Get_Count() > 0 ) { int i, ix, iy, jx, jy; double x, dx; //------------------------------------------------- if( m_pModel->Get_Data_Count() > 0 ) { ix = Get_xToScreen(m_pModel->Get_Data_XMax()); dc.SetPen (wxPen(wxColour( 0, 127, 0), 2)); dc.DrawLine(ix, Get_yToScreen(m_yMin), ix, Get_yToScreen(m_yMax)); } //------------------------------------------------- if( m_bPairs && m_pVariogram->Get_Maximum(CSG_Variogram::FIELD_COUNT) > 0 ) { double dScale = m_yMax / m_pVariogram->Get_Maximum(CSG_Variogram::FIELD_COUNT); dc.SetPen (wxColour(191, 191, 191)); dc.SetBrush(wxColour(191, 191, 191)); for(i=0; i<m_pVariogram->Get_Count(); i++) { CSG_Table_Record *pRecord = m_pVariogram->Get_Record(i); ix = Get_xToScreen(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE)); iy = Get_yToScreen(pRecord->asDouble(CSG_Variogram::FIELD_COUNT ) * dScale); dc.DrawCircle(ix, iy, 3); } } //------------------------------------------------- dc.SetPen (wxColour(127, 127, 127)); dc.SetBrush(wxColour( 0, 0, 0)); for(i=0; i<m_pVariogram->Get_Count(); i++) { CSG_Table_Record *pRecord = m_pVariogram->Get_Record(i); ix = Get_xToScreen(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE)); iy = Get_yToScreen(pRecord->asDouble(CSG_Variogram::FIELD_VAR_EXP )); dc.DrawCircle(ix, iy, 3); } //------------------------------------------------- if( m_pModel->is_Okay() ) { dc.SetPen(wxPen(*wxRED, 2)); dx = (m_xMax - m_xMin) / (double)rDraw.GetWidth(); ix = Get_xToScreen(m_xMin); iy = Get_yToScreen(m_pModel->Get_Value(m_xMin)); for(x=m_xMin+dx; x<=m_xMax; x+=dx) { jx = ix; jy = iy; ix = Get_xToScreen(x); iy = Get_yToScreen(m_pModel->Get_Value(x)); dc.DrawLine(jx, jy, ix, iy); } } } }
//--------------------------------------------------------- bool CSemiVariogram::On_Execute(void) { bool bLog, bResult = false; int Attribute; CSG_Trend Model; CSG_Shapes *pPoints; CSG_Table *pVariogram; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); Attribute = Parameters("ATTRIBUTE") ->asInt(); bLog = Parameters("LOG") ->asBool(); pVariogram = Parameters("VARIOGRAM") ->asTable(); //----------------------------------------------------- if( SG_UI_Get_Window_Main() ) { static CVariogram_Dialog dlg; if( dlg.Execute(pPoints, Attribute, bLog, pVariogram, &Model) ) { bResult = true; } } //----------------------------------------------------- else { int nSkip = Parameters("VAR_NSKIP") ->asInt(); int nClasses = Parameters("VAR_NCLASSES") ->asInt(); double maxDistance = Parameters("VAR_MAXDIST") ->asDouble(); Model.Set_Formula(Parameters("VAR_MODEL")->asString()); if( CSG_Variogram::Calculate(pPoints, Attribute, bLog, pVariogram, nClasses, maxDistance, nSkip) ) { Model.Clr_Data(); for(int i=0; i<pVariogram->Get_Count(); i++) { CSG_Table_Record *pRecord = pVariogram->Get_Record(i); Model.Add_Data(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE), pRecord->asDouble(CSG_Variogram::FIELD_VAR_EXP)); } bResult = Model.Get_Trend() || Model.Get_Parameter_Count() == 0; } } //----------------------------------------------------- if( bResult ) { Message_Add(Model.Get_Formula(), false); for(int i=0; i<pVariogram->Get_Count(); i++) { CSG_Table_Record *pRecord = pVariogram->Get_Record(i); pRecord->Set_Value(CSG_Variogram::FIELD_VAR_MODEL, Model.Get_Value(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE))); } } return( bResult ); }
//--------------------------------------------------------- bool CGridsFromTableAndGrid::On_Execute(void) { int iField, iRecord, iAttribute, nAttributes, *Attribute; sLong iCell, jCell; CSG_Parameter_Grid_List *pGrids; CSG_Grid *pClasses; CSG_Table *pTable; //----------------------------------------------------- pClasses = Parameters("CLASSES" )->asGrid(); pGrids = Parameters("GRIDS" )->asGridList(); pTable = Parameters("TABLE" )->asTable(); iField = Parameters("ID_FIELD")->asInt(); pGrids->Del_Items(); if( !pClasses->Set_Index() ) { Error_Set(_TL("index creation failed")); return( false ); } //----------------------------------------------------- if( pTable->Get_Field_Count() == 0 || pTable->Get_Count() == 0 ) { Message_Add(_TL("selected table contains no valid records")); return( false ); } //----------------------------------------------------- if( !pTable->Set_Index(iField, TABLE_INDEX_Ascending) ) { Message_Add(_TL("failed to create index for table")); return( false ); } //----------------------------------------------------- Attribute = new int[pTable->Get_Field_Count()]; for(iAttribute=0, nAttributes=0; iAttribute<pTable->Get_Field_Count(); iAttribute++) { if( iAttribute != iField && pTable->Get_Field_Type(iAttribute) != SG_DATATYPE_String ) { Attribute[nAttributes++] = iAttribute; CSG_Grid *pGrid = SG_Create_Grid(*Get_System()); pGrid->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pClasses->Get_Name(), pTable->Get_Field_Name(iAttribute))); pGrids->Add_Item(pGrid); } } if( nAttributes == 0 ) { delete[](Attribute); Message_Add(_TL("selected table does not have numeric attributes")); return( false ); } //----------------------------------------------------- CSG_Table_Record *pRecord = pTable->Get_Record_byIndex(0); for(iCell=0, iRecord=0; iCell<Get_NCells() && pRecord && Set_Progress_NCells(iCell); iCell++) { if( pClasses->Get_Sorted(iCell, jCell, false, true) ) { double valClass = pClasses->asDouble(jCell); while( pRecord && pRecord->asDouble(iField) < valClass ) { pRecord = pTable->Get_Record_byIndex(++iRecord); } if( !pRecord || pRecord->asDouble(iField) > valClass ) { for(iAttribute=0; iAttribute<nAttributes; iAttribute++) { pGrids->asGrid(iAttribute)->Set_NoData(jCell); } } else { for(iAttribute=0; iAttribute<nAttributes; iAttribute++) { pGrids->asGrid(iAttribute)->Set_Value(jCell, pRecord->asDouble(Attribute[iAttribute])); } } } } //----------------------------------------------------- delete[](Attribute); 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 ); }
//--------------------------------------------------------- bool CKriging_Base::On_Execute(void) { bool bResult = false; //----------------------------------------------------- m_Block = Parameters("BLOCK" )->asBool() ? Parameters("DBLOCK")->asDouble() / 2.0 : 0.0; m_bStdDev = Parameters("TQUALITY")->asInt() == 0; m_bLog = Parameters("LOG" )->asBool(); m_pPoints = Parameters("POINTS" )->asShapes(); m_zField = Parameters("ZFIELD" )->asInt(); if( m_pPoints->Get_Count() <= 1 ) { SG_UI_Msg_Add(_TL("not enough points for interpolation"), true); return( false ); } //----------------------------------------------------- CSG_Table Variogram; if( SG_UI_Get_Window_Main() ) { static CVariogram_Dialog dlg; if( dlg.Execute(m_pPoints, m_zField, m_bLog, &Variogram, &m_Model) ) { bResult = true; } } else { int nSkip = Parameters("VAR_NSKIP" )->asInt(); int nClasses = Parameters("VAR_NCLASSES")->asInt(); double maxDistance = Parameters("VAR_MAXDIST" )->asDouble(); m_Model.Set_Formula(Parameters("VAR_MODEL")->asString()); if( CSG_Variogram::Calculate(m_pPoints, m_zField, m_bLog, &Variogram, nClasses, maxDistance, nSkip) ) { m_Model.Clr_Data(); for(int i=0; i<Variogram.Get_Count(); i++) { CSG_Table_Record *pRecord = Variogram.Get_Record(i); m_Model.Add_Data(pRecord->asDouble(CSG_Variogram::FIELD_DISTANCE), pRecord->asDouble(CSG_Variogram::FIELD_VAR_EXP)); } bResult = m_Model.Get_Trend() || m_Model.Get_Parameter_Count() == 0; } } //----------------------------------------------------- if( bResult && (bResult = _Initialise_Grids() && On_Initialize()) ) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("variogram model"), m_Model.Get_Formula(SG_TREND_STRING_Formula_Parameters).c_str()), false); for(int y=0; y<m_pGrid->Get_NY() && Set_Progress(y, m_pGrid->Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<m_pGrid->Get_NX(); x++) { double z, v; if( Get_Value(m_pGrid->Get_System().Get_Grid_to_World(x, y), z, v) ) { Set_Value(x, y, z, v); } else { Set_NoData(x, y); } } } } //----------------------------------------------------- m_Model.Clr_Data(); On_Finalize(); return( bResult ); }