//--------------------------------------------------------- bool CDecision_Tree::On_Execute(void) { CSG_Grid *pClasses; //----------------------------------------------------- pClasses = Parameters("CLASSES") ->asGrid(); pClasses ->Set_NoData_Value(-1); //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { pClasses->Set_Value(x, y, Get_Class(Parameters("ROOT")->asParameters(), Get_System()->Get_Grid_to_World(x, y))); } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pClasses, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); Get_Class(Parameters("ROOT")->asParameters(), pTable); P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pClasses, P); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CTOBIA::On_Execute(void) { double fB = Parameters("fB")->asDouble(); double fC = Parameters("fC")->asDouble(); CSG_Grid *pA, *pB, *pC, *pD, *pE, *pF; pA = Parameters("A" )->asGrid(); //slope pB = Parameters("B" )->asGrid(); //aspect pC = Parameters("C" )->asGrid(); //dip grid pD = Parameters("D" )->asGrid(); //dip dir grid pE = Parameters("E" )->asGrid(); //output TOBIA classes pF = Parameters("F" )->asGrid(); //output TOBIA index for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double a, b, c, d, e, f; a = pA->asDouble(x, y); b = pB->asDouble(x, y); //Abfrage ob Raster oder Globalwerte c = pC ? pC->asDouble(x, y) : fB; d = pC ? pD->asDouble(x, y) : fC; if (pA->is_NoData(x, y)) { pE->Set_NoData(x, y); if (pF) pF->Set_NoData(x, y); } else if ((pC || pD) && (pC->is_NoData(x, y) || (pD->is_NoData(x, y)))) { pE->Set_NoData(x, y); if (pF) pF->Set_NoData(x, y); } else { e = pow(pow((cos(d/57.2958) - cos(b)), 2) + pow((sin(d/57.2958) - sin(b)), 2), 0.5); //TOBIA-classes if (((0 <= e) && (e < 0.7654)) && ((c - (a*57.2958)) > 5)) pE->Set_Value(x, y, TO_UNDERDIP_SLOPE); else if (((0 <= e) && (e < 0.7654)) && ((-5 <= (c - (a*57.2958))) && ((c - (a*57.2958) <= 5)))) pE->Set_Value(x, y, TO_DIP_SLOPE); else if (((0 <= e) && (e < 0.7654)) && ((c - (a*57.2958)) < -5)) pE->Set_Value(x, y, TO_OVERDIP_SLOPE); else if (((1.8478 < e) && (e <= 2)) && ((c - (a*57.2958)) < -5)) pE->Set_Value(x, y, TO_STEEPENED_ESCARPMENT); else if (((1.8478 < e) && (e <= 2)) && ((-5 <= (c - (a*57.2958))) && ((c - (a*57.2958) <= 5)))) pE->Set_Value(x, y, TO_NORMAL_ESCARPMENT); else if (((1.8478 < e) && (e <= 2)) && ((c - (a*57.2958)) > 5)) pE->Set_Value(x, y, TO_SUBDUED_ESCARPMENT); else if ((0.7654 < e) && (e <= 1.8478)) pE->Set_Value(x, y, TO_ORTHOCLINAL_SLOPE); else pE->Set_NoData_Value(0); if (pF) { f = (cos((c/57.2958)) * (cos(a))) + (sin(c/57.2958) * sin(a) * ((cos((d/57.2958) - b)))); //TOBIA-index pF->Set_Value(x, y, f); } } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pE, P) && P("COLORS_TYPE") && P("LUT") ) { int TO_Colors[TO_COUNT] = { SG_GET_RGB(255, 255, 0), // TO_UNDERDIP SG_GET_RGB(255, 128, 0), // TO_DIP SG_GET_RGB(255, 0, 0), // TO_OVERDIP SG_GET_RGB( 0, 0, 128), // TO_STEEPENED SG_GET_RGB( 0, 128, 255), // TO_NORMAL SG_GET_RGB(128, 255, 255), // TO_SUBDUED SG_GET_RGB( 0, 255, 64), // TO_ORTHOCLINAL }; //------------------------------------------------- CSG_Strings Name, Desc; Name += _TL("Underdip slope"); Desc += _TL(""); Name += _TL("Dip slope"); Desc += _TL(""); Name += _TL("Overdip slope"); Desc += _TL(""); Name += _TL("Steepened escarpment"); Desc += _TL(""); Name += _TL("Normal escarpment"); Desc += _TL(""); Name += _TL("Subdued escarpment"); Desc += _TL(""); Name += _TL("Orthoclinal slope"); Desc += _TL(""); //------------------------------------------------- CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); for(int i=0; i<TO_COUNT; i++) { CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, TO_Colors[i]); pRecord->Set_Value(1, Name[i].c_str()); pRecord->Set_Value(2, Desc[i].c_str()); pRecord->Set_Value(3, i); pRecord->Set_Value(4, i); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pE, P); } return( true ); }
//--------------------------------------------------------- bool CChange_Detection::On_Execute(void) { bool bNoChange; int iInitial, iFinal; CSG_Matrix Identity; CSG_Table Initial, Final, *pChanges; CSG_Grid *pInitial, *pFinal, *pChange; //----------------------------------------------------- pInitial = Parameters("INITIAL") ->asGrid(); pFinal = Parameters("FINAL") ->asGrid(); pChange = Parameters("CHANGE") ->asGrid(); pChanges = Parameters("CHANGES") ->asTable(); bNoChange = Parameters("NOCHANGE")->asBool(); if( !Get_Classes(Initial, pInitial, true) ) { Error_Set(_TL("no class definitions for initial state")); return( false ); } if( !Get_Classes(Final, pFinal, false) ) { Error_Set(_TL("no class definitions for final state")); return( false ); } if( !Get_Changes(Initial, Final, pChanges, Identity) ) { return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { iInitial = Get_Class(Initial, pInitial->asDouble(x, y)); iFinal = Get_Class(Final , pFinal ->asDouble(x, y)); if( bNoChange || !Identity[iInitial][iFinal] ) { pChanges->Get_Record(iInitial)->Add_Value(1 + iFinal, 1); pChange->Set_Value(x, y, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); } else { pChange->Set_Value(x, y, -1); } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pChange, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pLUT = P("LUT")->asTable(); CSG_Colors cRandom(pChanges->Get_Count()); cRandom.Random(); pLUT->Del_Records(); for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++) { CSG_Colors cRamp(pChanges->Get_Field_Count() - 1); cRamp.Set_Ramp(cRandom[iInitial], cRandom[iInitial]); cRamp.Set_Ramp_Brighness(225, 50); for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++) { if( pChanges->Get_Record(iInitial)->asInt(1 + iFinal) > 0 ) { CSG_Table_Record *pClass = pLUT->Add_Record(); pClass->Set_Value(0, cRamp.Get_Color(iFinal)); pClass->Set_Value(1, CSG_String::Format(SG_T("%s >> %s"), pChanges->Get_Record(iInitial)->asString(0), pChanges->Get_Field_Name(1 + iFinal))); pClass->Set_Value(3, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); pClass->Set_Value(4, (pChanges->Get_Field_Count() - 1) * iInitial + iFinal); } } } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pChange, P); } //----------------------------------------------------- double Factor; switch( Parameters("OUTPUT")->asInt() ) { default: Factor = 1.0; break; // cells case 1: Factor = 100.0 / Get_NCells(); break; // percent case 2: Factor = M_SQR(Get_Cellsize()); break; // area } if( Factor != 1.0 ) { for(iInitial=0; iInitial<pChanges->Get_Count(); iInitial++) { for(iFinal=0; iFinal<pChanges->Get_Field_Count()-1; iFinal++) { pChanges->Get_Record(iInitial)->Mul_Value(1 + iFinal, Factor); } } } //----------------------------------------------------- pChanges ->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name())); pChange ->Set_Name(CSG_String::Format(SG_T("%s [%s >> %s]"), _TL("Changes"), pInitial->Get_Name(), pFinal->Get_Name())); pChange ->Set_NoData_Value(-1); return( true ); }
bool CSHALSTAB::On_Execute(void) { double fCmin = Parameters("fCmin")->asDouble(); double fDmin = Parameters("fDmin")->asDouble(); double fEmin = Parameters("fEmin")->asDouble(); double fFmin = Parameters("fFmin")->asDouble(); double fJmin = Parameters("fJmin")->asDouble(); double fCmax = Parameters("fCmax")->asDouble(); double fDmax = Parameters("fDmax")->asDouble(); double fEmax = Parameters("fEmax")->asDouble(); double fFmax = Parameters("fFmax")->asDouble(); double fJmax = Parameters("fJmax")->asDouble(); double fK = Parameters("fK")->asInt(); double grav = 9.81; CSG_Grid *pA, *pB, *pCmin, *pDmin, *pEmin, *pFmin, *pG, *pH, *pJmin, *pCmax, *pDmax, *pEmax, *pFmax, *pJmax; pA = Parameters("A" )->asGrid(); //slope pB = Parameters("B" )->asGrid(); //flow accumulation pCmin = Parameters("Cmin" )->asGrid(); //density pDmin = Parameters("Dmin" )->asGrid(); //conductivity pEmin = Parameters("Emin" )->asGrid(); //depth pFmin = Parameters("Fmin" )->asGrid(); //friction pCmax = Parameters("Cmax" )->asGrid(); //density pDmax = Parameters("Dmax" )->asGrid(); //conductivity pEmax = Parameters("Emax" )->asGrid(); //depth pFmax = Parameters("Fmax" )->asGrid(); //friction pG = Parameters("G" )->asGrid(); //output critical recharge pH = Parameters("H" )->asGrid(); //optional output classified grid pJmin = Parameters("Jmin" )->asGrid(); //bulk cohesion pJmax = Parameters("Jmax" )->asGrid(); //bulk cohesion for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double a, b, c, d, e, f, g, j, l; double cmin, dmin, emin, fmin, jmin; double cmax, dmax, emax, fmax, jmax; double cc, dd, ee, ff, jj; int cperc, dperc, eperc, fperc, jperc; int rand_int, k, n; a = pA->asDouble(x, y); b = pB->asDouble(x, y); //Abfrage ob Raster oder Globalwerte: cmin = pCmin ? pCmin->asDouble(x, y) : fCmin; dmin = pDmin ? pDmin->asDouble(x, y) : fDmin; emin = pEmin ? pEmin->asDouble(x, y) : fEmin; fmin = pFmin ? pFmin->asDouble(x, y) : fFmin; jmin = pJmin ? pJmin->asDouble(x, y) : fJmin; cmax = pCmax ? pCmax->asDouble(x, y) : fCmax; dmax = pDmax ? pDmax->asDouble(x, y) : fDmax; emax = pEmax ? pEmax->asDouble(x, y) : fEmax; fmax = pFmax ? pFmax->asDouble(x, y) : fFmax; jmax = pJmax ? pJmax->asDouble(x, y) : fJmax; k = fK; if (pA->is_NoData(x, y) || pB->is_NoData(x, y)) { pG->Set_NoData(x, y); if (pH) pH->Set_Value(x, y, CR_NODATA); } else if ((pCmin || pCmax || pDmin || pDmax || pEmin || pEmax || pFmin || pFmax || pJmin || pJmax) && (pCmin && pCmax->is_NoData(x, y) || pDmin && pDmax->is_NoData(x, y) || pEmin && pEmax->is_NoData(x, y) || pFmin && pFmax->is_NoData(x, y) || pJmin && pJmax->is_NoData(x, y))) { pG->Set_NoData(x, y); if (pH) pH->Set_Value(x, y, CR_NODATA); } else { cperc = ((cmax - cmin) / cmax) * 100; //calculate parameter range %: density if (cperc > 0) { n = 0; cc = 0; while ( n < k) //loop through specified random number iterations: { rand_int = rand() % cperc + 0; //calculate random percentage c = ((cmax/100) * rand_int) + cmin; //calculate value cc = cc + c; //sum n = n + 1; } c = cc / n; // calculate mean from random values } else { c = cmax; } dperc = ((dmax - dmin) / dmax) * 100; if (dperc > 0) { n = 0; dd = 0; while ( n < k) { rand_int = rand() % dperc + 0; d = ((dmax/100) * rand_int) + dmin; dd = dd + d; n = n + 1; } d = dd / n; } else { d = dmax; } eperc = ((emax - emin) / emax) * 100; if (eperc > 0) { n = 0; ee = 0; while ( n < k) { rand_int = rand() % eperc + 0; e = ((emax/100) * rand_int) + emin; ee = ee + e; n = n + 1; } e = ee / n; } else { e = emax; } fperc = ((fmax - fmin) / fmax) * 100; if (fperc > 0) { n = 0; ff = 0; while ( n < k) { rand_int = rand() % fperc + 0; f = ((fmax/100) * rand_int) + fmin; ff = ff + f; n = n + 1; } f = ff / n; } else { f = fmax; } jperc = ((jmax - jmin) / jmax) * 100; if (jperc > 0) { n = 0; jj = 0; while ( n < k) { rand_int = rand() % jperc + 0; j = ((jmax/100) * rand_int) + jmin; jj = jj + j; n = n + 1; } j = jj / n; } else { j = jmax; } l = j/((e/cos(a))*c*grav); //calculate dimensionless cohesion //g = ((((sin(a) * (d*24*e)) * c)/(b/pB->Get_Cellsize())) * (1-(tan(a)/tan(f/57.2958)))) *1000; //cohesionless SHALSTAB calculation g = ((((sin(a) * (d*24*e)) * c)/(b/pB->Get_Cellsize())) * (1-((sin(a) - l)/(cos(a)*tan(f/57.2958))))) *1000; //SHALSTAB calculation //if ((tan(a) > (tan(f/57.2958) * (1-(1/c))))) //general stability criterion if (tan(a) > ((tan(f/57.2958) * (1-(1/c)))+(j/cos(a)))) { if (g > 0) //critical recharge pG->Set_Value(x, y, g); else pG->Set_Value(x, y, 0); //unconditionally unstable = 0 } //else if (tan(a) <= (tan(f/57.2958) * (1-(1/c)))) else if (tan(a) <= ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { pG->Set_NoData(x, y); //unconditionally stable = nodata } if (pH) //calculate optional classified grid { //if ((tan(a) > (tan(f/57.2958) * (1-(1/c))))) if (tan(a) > ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { if (g <= 0) pH->Set_Value(x, y, CR_UNSTABLE); else if ((g > 0) && (g <= 50)) pH->Set_Value(x, y, CR_0_TO_50); else if ((g > 50) && (g <= 100)) pH->Set_Value(x, y, CR_50_TO_100); else if ((g > 100) && (g <= 200)) pH->Set_Value(x, y, CR_100_TO_200); else if ((g > 200) && (g <= 400)) pH->Set_Value(x, y, CR_200_TO_400); else if (g > 400) pH->Set_Value(x, y, CR_GR_400); } //else if (tan(a) <= (tan(f/57.2958) * (1-(1/c)))) else if (tan(a) <= ((tan(f/57.2958) * (1-(1/c)))+(l/cos(a)))) { pH->Set_Value(x, y, CR_STABLE); } } } } } //----------------------------------------------------- CSG_Parameters P; if( DataObject_Get_Parameters(pH, P) && P("COLORS_TYPE") && P("LUT") ) { int CR_Colors[CR_COUNT] = { SG_GET_RGB(255, 255, 255), // CR_NODATA SG_GET_RGB(255, 0, 0), // CR_UNSTAB SG_GET_RGB(255, 128, 64), // CR_0-50 SG_GET_RGB(255, 255, 0), // CR_50-100 SG_GET_RGB( 0, 255, 0), // CR_100-200 SG_GET_RGB(128, 255, 255), // CR_200-400 SG_GET_RGB( 0, 0, 255), // CR_>400 SG_GET_RGB(128, 128, 128), // CR_STABLE }; //------------------------------------------------- CSG_Strings Name, Desc; Name += _TL("No data"); Desc += _TL(""); Name += _TL("Uncond. unstable"); Desc += _TL(""); Name += _TL("0-50 mm/day"); Desc += _TL(""); Name += _TL("50-100 mm/day"); Desc += _TL(""); Name += _TL("100-200 mm/day"); Desc += _TL(""); Name += _TL("200-400 mm/day"); Desc += _TL(""); Name += _TL(">400 mm/day"); Desc += _TL(""); Name += _TL("Uncond. stable"); Desc += _TL(""); //------------------------------------------------- CSG_Table *pTable = P("LUT")->asTable(); pTable->Del_Records(); for(int i=0; i<CR_COUNT; i++) { CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, CR_Colors[i]); pRecord->Set_Value(1, Name[i].c_str()); pRecord->Set_Value(2, Desc[i].c_str()); pRecord->Set_Value(3, i); pRecord->Set_Value(4, i); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pH, P); } return( true ); }