//--------------------------------------------------------- bool CGrid_Gaps_Resampling::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pGrid = Parameters("RESULT")->asGrid(); CSG_Grid *pMask = Parameters("MASK" )->asGrid(); if( pGrid == NULL ) { pGrid = Parameters("INPUT")->asGrid(); } else { pGrid->Assign(Parameters("INPUT")->asGrid()); pGrid->Fmt_Name("%s [%s]", Parameters("INPUT")->asGrid()->Get_Name(), _TL("no gaps")); } //----------------------------------------------------- TSG_Grid_Resampling Resampling; switch( Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear ; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline ; break; case 3: Resampling = GRID_RESAMPLING_BSpline ; break; } //----------------------------------------------------- CSG_Grid_Pyramid Pyramid; if( !Pyramid.Create(pGrid, Parameters("GROW")->asDouble()) ) { Error_Set(_TL("failed to create pyramid")); return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { double py = Get_YMin() + y * Get_Cellsize(); #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pGrid->is_NoData(x, y) && (!pMask || !pMask->is_NoData(x, y)) ) { double px = Get_XMin() + x * Get_Cellsize(); for(int i=0; i<Pyramid.Get_Count(); i++) { CSG_Grid *pPatch = Pyramid.Get_Grid(i); if( pPatch->is_InGrid_byPos(px, py) ) { pGrid->Set_Value(x, y, pPatch->Get_Value(px, py, Resampling)); break; } } } } } //----------------------------------------------------- if( pGrid == Parameters("INPUT")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- Cdirectional1::Cdirectional1(void) { // 1. Info... Set_Name(_TL("Directional Average")); Set_Author(_TL("Alessandro Perego")); Set_Description(_TL("directional1 average for Grids")); // 2. Parameters... Parameters.Add_Grid(NULL, "INPUT", _TL("Input"), _TL("This must be your input data of type grid."), PARAMETER_INPUT); Parameters.Add_Grid(NULL, "RESULT", _TL("Output Grid"), _TL("New grid filtered with the directional1 tool"), PARAMETER_OUTPUT); Parameters.Add_Value(NULL, "ANG", _TL("Angle (in degrees)"), _TL("0 is horizontal, 90 is vertical."), PARAMETER_TYPE_Double, 0.0); Parameters.Add_Value(NULL, "R1", _TL("Main Radius"), _TL(""), PARAMETER_TYPE_Double, 1); Parameters.Add_Value(NULL, "R2", _TL("Transversal radius"), _TL(""), PARAMETER_TYPE_Double, 0.5); }
//--------------------------------------------------------- bool CGWR_Grid_Downscaling::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pPredictors = Parameters("PREDICTORS")->asGridList(); if( (m_nPredictors = pPredictors->Get_Count()) <= 0 ) { return( false ); } m_pDependent = Parameters("DEPENDENT")->asGrid(); if( !m_pDependent->Get_Extent().Intersects(Get_System()->Get_Extent()) ) { return( false ); } //----------------------------------------------------- int i; Process_Set_Text(_TL("upscaling of predictors")); m_pPredictors = (CSG_Grid **)SG_Calloc(m_nPredictors , sizeof(CSG_Grid *)); m_pModel = (CSG_Grid **)SG_Calloc(m_nPredictors + 1, sizeof(CSG_Grid *)); for(i=0; i<m_nPredictors; i++) { m_pPredictors[i] = SG_Create_Grid(m_pDependent->Get_System()); m_pPredictors[i] ->Assign(pPredictors->asGrid(i), GRID_INTERPOLATION_NearestNeighbour); // GRID_INTERPOLATION_Mean_Cells m_pModel [i] = SG_Create_Grid(m_pDependent->Get_System()); m_pModel [i] ->Set_Name(CSG_String::Format(SG_T("%s [%s]"), pPredictors->asGrid(i)->Get_Name(), _TL("Factor"))); } m_pModel[m_nPredictors] = SG_Create_Grid(m_pDependent->Get_System()); m_pModel[m_nPredictors] ->Set_Name(_TL("Intercept")); //----------------------------------------------------- Process_Set_Text(_TL("model creation")); bool bResult = Get_Model(); //----------------------------------------------------- for(i=0; i<m_nPredictors; i++) { delete(m_pPredictors[i]); m_pPredictors[i] = pPredictors->asGrid(i); } //----------------------------------------------------- if( bResult ) { Process_Set_Text(_TL("downscaling")); bResult = Set_Model(); } //----------------------------------------------------- if( Parameters("MODEL_OUT")->asBool() ) { CSG_Parameter_Grid_List *pModel = Parameters("MODEL")->asGridList(); pModel->Del_Items(); pModel->Add_Item(m_pModel[m_nPredictors]); for(i=0; i<m_nPredictors; i++) { pModel->Add_Item(m_pModel[i]); } } else { for(i=0; i<=m_nPredictors; i++) { delete(m_pModel[i]); } } SG_FREE_SAFE(m_pModel); SG_FREE_SAFE(m_pPredictors); return( bResult ); }
void _LVarSt (void) { // Set (store) Long Var value _TL(); // like !TL // ML(AT)= AITEM(1); // ADELn(2); }
//--------------------------------------------------------- bool CGrid_Export::On_Execute(void) { //----------------------------------------------------- int y, iy, Method; double dTrans; CSG_Grid *pGrid, *pShade, Grid, Shade; //----------------------------------------------------- pGrid = Parameters("GRID" )->asGrid(); pShade = Parameters("SHADE" )->asGrid(); Method = Parameters("COLOURING" )->asInt (); dTrans = Parameters("SHADE_TRANS" )->asDouble() / 100.0; if( !pGrid ) { return( false ); } //----------------------------------------------------- if( Method == 5 ) // same as in graphical user interface { if( !SG_UI_DataObject_asImage(pGrid, &Grid) ) { Error_Set("could not retrieve colour coding from graphical user interface."); return( false ); } } else { double zMin, zScale; CSG_Colors Colors; CSG_Table LUT; if( SG_UI_Get_Window_Main() ) { Colors.Assign(Parameters("COL_PALETTE")->asColors()); } else { Colors.Set_Palette( Parameters("COL_PALETTE")->asInt (), Parameters("COL_REVERT" )->asBool(), Parameters("COL_COUNT" )->asInt () ); } switch( Method ) { case 0: // stretch to grid's standard deviation zMin = pGrid->Get_Mean() - Parameters("STDDEV")->asDouble() * pGrid->Get_StdDev(); zScale = Colors.Get_Count() / (2 * Parameters("STDDEV")->asDouble() * pGrid->Get_StdDev()); break; case 1: // stretch to grid's value range zMin = pGrid->Get_ZMin(); zScale = Colors.Get_Count() / pGrid->Get_ZRange(); break; case 2: // stretch to specified value range zMin = Parameters("STRETCH")->asRange()->Get_LoVal(); if( zMin >= (zScale = Parameters("STRETCH")->asRange()->Get_HiVal()) ) { Error_Set(_TL("invalid user specified value range.")); return( false ); } zScale = Colors.Get_Count() / (zScale - zMin); break; case 3: // lookup table if( !Parameters("LUT")->asTable() || Parameters("LUT")->asTable()->Get_Field_Count() < 5 ) { Error_Set(_TL("invalid lookup table.")); return( false ); } LUT.Create(*Parameters("LUT")->asTable()); break; case 4: // rgb coded values break; } //------------------------------------------------- Grid.Create(*Get_System(), SG_DATATYPE_Int); for(y=0, iy=Get_NY()-1; y<Get_NY() && Set_Progress(y); y++, iy--) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { double z = pGrid->asDouble(x, y); if( Method == 3 ) // lookup table { int i, iColor = -1; for(i=0; iColor<0 && i<LUT.Get_Count(); i++) { if( z == LUT[i][3] ) { Grid.Set_Value(x, iy, LUT[iColor = i].asInt(0)); } } for(i=0; iColor<0 && i<LUT.Get_Count(); i++) { if( z >= LUT[i][3] && z <= LUT[i][4] ) { Grid.Set_Value(x, iy, LUT[iColor = i].asInt(0)); } } if( iColor < 0 ) { Grid.Set_NoData(x, iy); } } else if( pGrid->is_NoData(x, y) ) { Grid.Set_NoData(x, iy); } else if( Method == 4 ) // rgb coded values { Grid.Set_Value(x, iy, z); } else { int i = (int)(zScale * (z - zMin)); Grid.Set_Value(x, iy, Colors[i < 0 ? 0 : i >= Colors.Get_Count() ? Colors.Get_Count() - 1 : i]); } } } } //----------------------------------------------------- if( !pShade || pShade->Get_ZRange() <= 0.0 ) { pShade = NULL; } else { double dMinBright, dMaxBright; dMinBright = Parameters("SHADE_BRIGHT")->asRange()->Get_LoVal() / 100.0; dMaxBright = Parameters("SHADE_BRIGHT")->asRange()->Get_HiVal() / 100.0; if( dMinBright >= dMaxBright ) { SG_UI_Msg_Add_Error(_TL("Minimum shade brightness must be lower than maximum shade brightness!")); return( false ); } int nColors = 100; CSG_Colors Colors(nColors, SG_COLORS_BLACK_WHITE, true); //------------------------------------------------- Shade.Create(*Get_System(), SG_DATATYPE_Int); for(y=0, iy=Get_NY()-1; y<Get_NY() && Set_Progress(y); y++, iy--) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( pShade->is_NoData(x, y) ) { Shade.Set_NoData(x, iy); } else { Shade.Set_Value (x, iy, Colors[(int)(nColors * (dMaxBright - dMinBright) * (pShade->asDouble(x, y) - pShade->Get_ZMin()) / pShade->Get_ZRange() + dMinBright)]); } } } } //----------------------------------------------------- wxImage Image(Get_NX(), Get_NY()); if( Grid.Get_NoData_Count() > 0 ) { Image.SetAlpha(); } for(y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( Grid.is_NoData(x, y) || (pShade != NULL && Shade.is_NoData(x, y)) ) { if( Image.HasAlpha() ) { Image.SetAlpha(x, y, wxIMAGE_ALPHA_TRANSPARENT); } Image.SetRGB(x, y, 255, 255, 255); } else { if( Image.HasAlpha() ) { Image.SetAlpha(x, y, wxIMAGE_ALPHA_OPAQUE); } int r, g, b, c = Grid.asInt(x, y); r = SG_GET_R(c); g = SG_GET_G(c); b = SG_GET_B(c); if( pShade ) { c = Shade.asInt(x, y); r = dTrans * r + SG_GET_R(c) * (1.0 - dTrans); g = dTrans * g + SG_GET_G(c) * (1.0 - dTrans); b = dTrans * b + SG_GET_B(c) * (1.0 - dTrans); } Image.SetRGB(x, y, r, g, b); } } } //------------------------------------------------- CSG_String fName(Parameters("FILE")->asString()); if( !SG_File_Cmp_Extension(fName, SG_T("bmp")) && !SG_File_Cmp_Extension(fName, SG_T("jpg")) && !SG_File_Cmp_Extension(fName, SG_T("pcx")) && !SG_File_Cmp_Extension(fName, SG_T("png")) && !SG_File_Cmp_Extension(fName, SG_T("tif")) ) { fName = SG_File_Make_Path(NULL, fName, SG_T("png")); Parameters("FILE")->Set_Value(fName); } //----------------------------------------------------- wxImageHandler *pImgHandler = NULL; if( !SG_UI_Get_Window_Main() ) { if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) pImgHandler = new wxJPEGHandler; else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) pImgHandler = new wxPCXHandler; else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) pImgHandler = new wxTIFFHandler; #ifdef _SAGA_MSW else if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) pImgHandler = new wxBMPHandler; #endif else // if( SG_File_Cmp_Extension(fName, SG_T("png")) ) pImgHandler = new wxPNGHandler; wxImage::AddHandler(pImgHandler); } if( !Image.SaveFile(fName.c_str()) ) { Error_Set(CSG_String::Format(SG_T("%s [%s]"), _TL("could not save image file"), fName.c_str())); return( false ); } pGrid->Get_Projection().Save(SG_File_Make_Path(NULL, fName, SG_T("prj")), SG_PROJ_FMT_WKT); //----------------------------------------------------- CSG_File Stream; if( SG_File_Cmp_Extension(fName, SG_T("bmp")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("bpw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("jpg")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("jgw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("pcx")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("pxw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("png")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("pgw")), SG_FILE_W, false); else if( SG_File_Cmp_Extension(fName, SG_T("tif")) ) Stream.Open(SG_File_Make_Path(NULL, fName, SG_T("tfw")), SG_FILE_W, false); if( Stream.is_Open() ) { Stream.Printf(SG_T("%.10f\n%f\n%f\n%.10f\n%.10f\n%.10f\n"), pGrid->Get_Cellsize(), 0.0, 0.0, -pGrid->Get_Cellsize(), pGrid->Get_XMin(), pGrid->Get_YMax() ); } //----------------------------------------------------- if( Parameters("FILE_KML")->asBool() ) { CSG_MetaData KML; KML.Set_Name("kml"); KML.Add_Property("xmlns", "http://www.opengis.net/kml/2.2"); // CSG_MetaData *pFolder = KML.Add_Child("Folder"); // pFolder->Add_Child("name" , "Raster exported from SAGA"); // pFolder->Add_Child("description", "System for Automated Geoscientific Analyses - www.saga-gis.org"); // CSG_MetaData *pOverlay = pFolder->Add_Child("GroundOverlay"); CSG_MetaData *pOverlay = KML.Add_Child("GroundOverlay"); pOverlay->Add_Child("name" , pGrid->Get_Name()); pOverlay->Add_Child("description", pGrid->Get_Description()); pOverlay->Add_Child("Icon" )->Add_Child("href", SG_File_Get_Name(fName, true)); pOverlay->Add_Child("LatLonBox" ); pOverlay->Get_Child("LatLonBox" )->Add_Child("north", pGrid->Get_YMax()); pOverlay->Get_Child("LatLonBox" )->Add_Child("south", pGrid->Get_YMin()); pOverlay->Get_Child("LatLonBox" )->Add_Child("east" , pGrid->Get_XMax()); pOverlay->Get_Child("LatLonBox" )->Add_Child("west" , pGrid->Get_XMin()); KML.Save(fName, SG_T("kml")); } //----------------------------------------------------- if( !SG_UI_Get_Window_Main() && pImgHandler != NULL) { wxImage::RemoveHandler(pImgHandler->GetName()); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGSGrid_Statistics_To_Table::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); if( pGrids->Get_Count() < 1 ) { Error_Set(_TL("no grids in selection")); return( false ); } //----------------------------------------------------- CSG_Table *pTable = Parameters("STATS")->asTable(); pTable->Destroy(); pTable->Set_Name(_TL("Statistics for Grids")); pTable->Add_Field(_TL("NAME"), SG_DATATYPE_String); if( Parameters("DATA_CELLS" )->asBool() ) pTable->Add_Field(_TL("DATA_CELLS" ), SG_DATATYPE_Int); if( Parameters("NODATA_CELLS")->asBool() ) pTable->Add_Field(_TL("NODATA_CELLS"), SG_DATATYPE_Int); if( Parameters("CELLSIZE" )->asBool() ) pTable->Add_Field(_TL("CELLSIZE" ), SG_DATATYPE_Double); if( Parameters("MEAN" )->asBool() ) pTable->Add_Field(_TL("MEAN" ), SG_DATATYPE_Double); if( Parameters("MIN" )->asBool() ) pTable->Add_Field(_TL("MIN" ), SG_DATATYPE_Double); if( Parameters("MAX" )->asBool() ) pTable->Add_Field(_TL("MAX" ), SG_DATATYPE_Double); if( Parameters("RANGE" )->asBool() ) pTable->Add_Field(_TL("RANGE" ), SG_DATATYPE_Double); if( Parameters("VAR" )->asBool() ) pTable->Add_Field(_TL("VAR" ), SG_DATATYPE_Double); if( Parameters("STDDEV" )->asBool() ) pTable->Add_Field(_TL("STDDEV" ), SG_DATATYPE_Double); if( Parameters("STDDEVLO" )->asBool() ) pTable->Add_Field(_TL("STDDEVLO" ), SG_DATATYPE_Double); if( Parameters("STDDEVHI" )->asBool() ) pTable->Add_Field(_TL("STDDEVHI" ), SG_DATATYPE_Double); if( Parameters("PCTL" )->asBool() ) pTable->Add_Field(_TL("PCTL" ), SG_DATATYPE_Double); if( pTable->Get_Field_Count() <= 1 ) { Error_Set(_TL("no parameter output specified")); return( false ); } double dRank = Parameters("PCTL")->asBool() ? Parameters("PCTL_VAL")->asDouble() : -1.0; //----------------------------------------------------- for(int i=0; i<pGrids->Get_Count() && Process_Get_Okay(); i++) { CSG_Grid *pGrid = pGrids->asGrid(i); CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value("NAME" , pGrid->Get_Name()); pRecord->Set_Value("DATA_CELLS" , pGrid->Get_NCells() - pGrid->Get_NoData_Count()); pRecord->Set_Value("NODATA_CELLS", pGrid->Get_NoData_Count()); pRecord->Set_Value("CELLSIZE" , pGrid->Get_Cellsize()); pRecord->Set_Value("MEAN" , pGrid->Get_ArithMean()); pRecord->Set_Value("MIN" , pGrid->Get_ZMin()); pRecord->Set_Value("MAX" , pGrid->Get_ZMax()); pRecord->Set_Value("RANGE" , pGrid->Get_ZRange()); pRecord->Set_Value("VAR" , pGrid->Get_Variance()); pRecord->Set_Value("STDDEV" , pGrid->Get_StdDev()); pRecord->Set_Value("STDDEVLO" , pGrid->Get_ArithMean() - pGrid->Get_StdDev()); pRecord->Set_Value("STDDEVHI" , pGrid->Get_ArithMean() + pGrid->Get_StdDev()); if( dRank > 0.0 && dRank < 100.0 ) { pRecord->Set_Value("PCTL", pGrid->Get_Percentile(dRank)); // this is a time consuming operation } } if( dRank > 0.0 && dRank < 100.0 ) { pTable->Set_Field_Name(pTable->Get_Field_Count() - 1, CSG_String::Format(SG_T("%s%02d"), _TL("PCTL"), (int)dRank)); } return( true ); }
//--------------------------------------------------------- bool CGrid_Cross_Profiles::On_Execute(void) { int iLine, iPart, iPoint, nSamples; double Distance, Length, dLine, dist, dx, dy; TSG_Point iPt, jPt, dPt, aPt, bPt; CSG_Shapes *pLines, *pProfiles; CSG_Shape *pLine, *pProfile; //----------------------------------------------------- m_pDEM = Parameters("DEM") ->asGrid(); pProfiles = Parameters("PROFILES") ->asShapes(); pLines = Parameters("LINES") ->asShapes(); Distance = Parameters("DIST_LINE") ->asDouble(); Length = Parameters("DIST_PROFILE")->asDouble(); nSamples = Parameters("NUM_PROFILE") ->asInt(); //----------------------------------------------------- pProfiles->Create(SHAPE_TYPE_Line, _TL("Profiles")); pProfiles->Add_Field("ID" , SG_DATATYPE_Int); pProfiles->Add_Field("LINE" , SG_DATATYPE_Int); pProfiles->Add_Field("PART" , SG_DATATYPE_Int); for(iPoint=0; iPoint<nSamples; iPoint++) { pProfiles->Add_Field(CSG_String::Format(SG_T("X%03d"), iPoint), SG_DATATYPE_Double); } //----------------------------------------------------- for(iLine=0; iLine<pLines->Get_Count() && Set_Progress(iLine, pLines->Get_Count()); iLine++) { pLine = pLines->Get_Shape(iLine); for(iPart=0; iPart<pLine->Get_Part_Count(); iPart++) { if( pLine->Get_Point_Count(iPart) > 1 ) { dist = 0.0; iPt = pLine->Get_Point(0, iPart); for(iPoint=1; iPoint<pLine->Get_Point_Count(iPart); iPoint++) { jPt = iPt; iPt = pLine->Get_Point(iPoint, iPart); dx = iPt.x - jPt.x; dy = iPt.y - jPt.y; dLine = sqrt(dx*dx + dy*dy); dx /= dLine; dy /= dLine; while( dist < dLine ) { dPt.x = jPt.x + dist * dx; dPt.y = jPt.y + dist * dy; if( m_pDEM->is_InGrid_byPos(dPt) ) { aPt.x = dPt.x + dy * Length; aPt.y = dPt.y - dx * Length; bPt.x = dPt.x - dy * Length; bPt.y = dPt.y + dx * Length; pProfile = pProfiles->Add_Shape(); pProfile->Add_Point(aPt); pProfile->Add_Point(bPt); pProfile->Set_Value(0, pProfiles->Get_Count()); pProfile->Set_Value(1, iLine); pProfile->Set_Value(2, iPart); Get_Profile(pProfile, aPt, bPt, nSamples); } dist += Distance; } dist -= dLine; } } } } //----------------------------------------------------- if( pProfiles->Get_Count() > 0 ) { if( Parameters("DOCUMENT")->asString() ) { Make_Report(Parameters("DOCUMENT")->asString(), m_pDEM, pLines, pProfiles, Distance); } return( true ); } return( false ); }
bool CFlowDepth::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode){ int iX, iY; int iNextX, iNextY; int x,y; int iOutletX, iOutletY; double fArea; double fDepth, fPreviousDepth = 0; if( Mode != MODULE_INTERACTIVE_LDOWN || !Get_Grid_Pos(iOutletX, iOutletY) ) { return( false ); } m_pFlowDepth->Assign((double)0); fArea = m_pCatchArea->asFloat(iOutletX, iOutletY); if (fArea < m_dThreshold * 2.){ //check outlet point iNextX = iOutletX; iNextY = iOutletY; do{ iOutletX = iNextX; iOutletY = iNextY; getNextCell(m_pDEM, iOutletX, iOutletY, iNextX, iNextY); }while (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2. && (iOutletX != iNextX || iOutletY != iNextY)); if (m_pCatchArea->asFloat(iOutletX, iOutletY) < m_dThreshold * 2.){ Message_Add(_TL("** Error : Wrong outlet point selected **")); return false; }//if Message_Add(_TL("** Warning : Outlet point was modified **")); }//if CalculateBasinGrid(m_pBasinGrid, m_pDEM, iOutletX, iOutletY); m_fMaxFlowAcc = m_pCatchArea->asFloat(iOutletX, iOutletY); for(y=0; y<Get_NY() && Set_Progress(y); y++){ for(x=0; x<Get_NX(); x++){ if (m_pCatchArea->asFloat(x,y) > m_dThreshold){ if (isHeader(x,y)){ iNextX = x; iNextY = y; do { iX = iNextX; iY = iNextY; if (m_pFlowDepth->asFloat(iX,iY) == 0. && m_pBasinGrid->asInt(iX, iY) != 0){ getNextCell(m_pDEM, iX, iY, iNextX, iNextY); fDepth = CalculateFlowDepth(iX,iY); if (fDepth == NO_DEPTH){ m_pFlowDepth->Set_Value(iX,iY, fPreviousDepth); }//if else{ fPreviousDepth = fDepth; }//else }//if }while ((iX != iOutletX || iY != iOutletY) && (iX != iNextX || iY != iNextY)); }//if }//if }//for }// for DataObject_Update(m_pFlowDepth); return true; }//method
struct SClass { int ID, Color; CSG_String Name; int nPoints; double Sand[8], Clay[8]; }; //--------------------------------------------------------- const struct SClass Classes[12] = { { 1, SG_GET_RGB(000, 000, 255), _TL("Clay"), 6, { 0, 0, 20, 45, 45, 0 }, { 100, 60, 40, 40, 55, 100 } }, { 2, SG_GET_RGB(000, 200, 255), _TL("Silty Clay"), 4, { 0, 0, 20, 0 }, { 100, 60, 40, 40 } }, { 3, SG_GET_RGB(000, 200, 200), _TL("Silty Clay-Loam"), 5, { 0, 0, 20, 20, 0 }, { 40, 27, 27, 40, 40 } }, { 4, SG_GET_RGB(200, 000, 255), _TL("Sandy Clay"), 4, { 45, 45, 65, 45 }, { 55, 35, 35, 55 } }, {
//--------------------------------------------------------- bool CGDAL_Formats::On_Execute(void) { CSG_Table *pFormats = Parameters("FORMATS")->asTable(); pFormats->Destroy(); pFormats->Set_Name(_TL("GDAL Formats")); pFormats->Add_Field("ID" , SG_DATATYPE_String); pFormats->Add_Field("NAME" , SG_DATATYPE_String); pFormats->Add_Field("FILTER", SG_DATATYPE_String); pFormats->Add_Field("TYPE" , SG_DATATYPE_String); pFormats->Add_Field("ACCESS", SG_DATATYPE_String); //----------------------------------------------------- int Type = Parameters("TYPE" )->asInt(); int Access = Parameters("ACCESS")->asInt(); //----------------------------------------------------- if( Type != 1 ) // not vectors only { for(int i=0; i<SG_Get_GDAL_Drivers().Get_Count(); i++) { if( SG_Get_GDAL_Drivers().is_Raster(i) ) { CSG_String R(SG_Get_GDAL_Drivers().Can_Read (i) ? "R" : ""); CSG_String W(SG_Get_GDAL_Drivers().Can_Write(i) ? "W" : ""); if( (Access != 0 || !R.is_Empty()) && (Access != 1 || !W.is_Empty()) ) { CSG_Table_Record *pFormat = pFormats->Add_Record(); pFormat->Set_Value(GDAL_LIST_FMT_ID , SG_Get_GDAL_Drivers().Get_Description(i)); pFormat->Set_Value(GDAL_LIST_FMT_NAME , SG_Get_GDAL_Drivers().Get_Name (i)); pFormat->Set_Value(GDAL_LIST_FMT_FILTER, SG_Get_GDAL_Drivers().Get_Extension (i)); pFormat->Set_Value(GDAL_LIST_FMT_TYPE , "RASTER"); pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, R + W); } } } } //----------------------------------------------------- if( Type != 0 ) // not rasters only { for(int i=0; i<SG_Get_OGR_Drivers().Get_Count(); i++) { if( SG_Get_OGR_Drivers().is_Vector(i) ) { CSG_String R(SG_Get_OGR_Drivers().Can_Read (i) ? "R" : ""); CSG_String W(SG_Get_OGR_Drivers().Can_Write(i) ? "W" : ""); if( (Access != 0 || !R.is_Empty()) && (Access != 1 || !W.is_Empty()) ) { CSG_Table_Record *pFormat = pFormats->Add_Record(); pFormat->Set_Value(GDAL_LIST_FMT_ID , SG_Get_OGR_Drivers().Get_Description(i)); pFormat->Set_Value(GDAL_LIST_FMT_NAME , SG_Get_OGR_Drivers().Get_Name (i)); pFormat->Set_Value(GDAL_LIST_FMT_FILTER, SG_Get_OGR_Drivers().Get_Extension (i)); pFormat->Set_Value(GDAL_LIST_FMT_TYPE , "VECTOR"); pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, R + W); } } } } //----------------------------------------------------- if( Parameters("RECOGNIZED")->asBool() ) { CSG_String Filter_All; for(int i=0; i<pFormats->Get_Count(); i++) { CSG_String Filter = pFormats->Get_Record(i)->asString(GDAL_LIST_FMT_FILTER); if( !Filter.is_Empty() ) { Filter.Replace("/", ";"); Filter_All += (Filter_All.is_Empty() ? "*." : ";*.") + Filter; } } if( !Filter_All.is_Empty() ) { CSG_Table_Record *pFormat = pFormats->Add_Record(); pFormat->Set_Value(GDAL_LIST_FMT_NAME , _TL("All Recognized Files")); pFormat->Set_Value(GDAL_LIST_FMT_FILTER, Filter_All); pFormat->Set_Value(GDAL_LIST_FMT_TYPE , Type == 0 ? "RASTER" : Type == 1 ? "VECTOR" : "RASTER/VECTOR"); pFormat->Set_Value(GDAL_LIST_FMT_ACCESS, Access == 0 ? "R" : Access == 1 ? "W" : "RW" ); } } //----------------------------------------------------- return( pFormats->Get_Count() > 0 ); }
//--------------------------------------------------------- CGDAL_Formats::CGDAL_Formats(void) { //----------------------------------------------------- Set_Name (_TL("GDAL Formats")); Set_Author ("O.Conrad (c) 2016"); CSG_String Description; Description = _TW( "This tool lists all (file) formats supported by the currently loaded GDAL library. " "For more information have a look at the GDAL homepage:\n" " <a target=\"_blank\" href=\"http://www.gdal.org/\">" " http://www.gdal.org</a>\n" ); Description += CSG_String::Format("\nGDAL %s:%s\n\n", _TL("Version"), SG_Get_GDAL_Drivers().Get_Version().c_str()); Set_Description(Description); //----------------------------------------------------- Parameters.Add_Table(NULL, "FORMATS" , _TL("GDAL Formats"), _TL(""), PARAMETER_OUTPUT ); Parameters.Add_Choice(NULL, "TYPE" , _TL("Type"), _TL(""), CSG_String::Format("%s|%s|%s|", _TL("raster"), _TL("vector"), _TL("all") ), 2 ); Parameters.Add_Choice(NULL, "ACCESS" , _TL("Access"), _TL(""), CSG_String::Format("%s|%s|%s|", _TL("read"), _TL("write"), _TL("read or write") ), 2 ); Parameters.Add_Bool(NULL, "RECOGNIZED", _TL("All Recognized Files"), _TL("Add an entry for all recognized files."), true ); }
//--------------------------------------------------------- CGW_Regression::CGW_Regression(void) { CSG_Parameter *pNode; //----------------------------------------------------- Set_Name (_TL("GWR for Single Predictor (Gridded Model Output)")); Set_Author ("O.Conrad (c) 2010"); Set_Description (_TW( "Reference:\n" ) + GWR_References); //----------------------------------------------------- pNode = Parameters.Add_Shapes( NULL , "POINTS" , _TL("Points"), _TL(""), PARAMETER_INPUT, SHAPE_TYPE_Point ); Parameters.Add_Table_Field( pNode , "DEPENDENT" , _TL("Dependent Variable"), _TL("") ); Parameters.Add_Table_Field( pNode , "PREDICTOR" , _TL("Predictor"), _TL("") ); //----------------------------------------------------- m_Grid_Target.Create(&Parameters, true, NULL, "TARGET_"); m_Grid_Target.Add_Grid("INTERCEPT", _TL("Intercept"), false); m_Grid_Target.Add_Grid("SLOPE" , _TL("Slope" ), false); m_Grid_Target.Add_Grid("QUALITY" , _TL("Quality" ), false); //----------------------------------------------------- m_Weighting.Set_Weighting(SG_DISTWGHT_GAUSS); m_Weighting.Create_Parameters(&Parameters, false); //----------------------------------------------------- m_Search.Create(&Parameters, Parameters.Add_Node(NULL, "NODE_SEARCH", _TL("Search Options"), _TL("")), 16); Parameters("SEARCH_RANGE")->Set_Value(1); Parameters("SEARCH_POINTS_ALL")->Set_Value(1); }
//--------------------------------------------------------- bool CGW_Regression::On_Execute(void) { //----------------------------------------------------- m_pPoints = Parameters("POINTS" )->asShapes(); m_iDependent = Parameters("DEPENDENT")->asInt (); m_iPredictor = Parameters("PREDICTOR")->asInt (); m_Weighting.Set_Parameters(&Parameters); //----------------------------------------------------- if( !m_Search.Initialize(m_pPoints, -1) ) { return( false ); } //----------------------------------------------------- m_pQuality = m_Grid_Target.Get_Grid("QUALITY" ); m_pSlope = m_Grid_Target.Get_Grid("SLOPE" ); m_pIntercept = m_Grid_Target.Get_Grid("INTERCEPT"); if( !m_pIntercept || !m_pSlope || !m_pQuality ) { m_Search.Finalize(); return( false ); } m_pIntercept->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Intercept"))); m_pSlope ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Slope"))); m_pQuality ->Set_Name(CSG_String::Format(SG_T("%s (%s)"), Parameters("DEPENDENT")->asString(), _TL("GWR Quality"))); //----------------------------------------------------- for(int y=0; y<m_pIntercept->Get_NY() && Set_Progress(y, m_pIntercept->Get_NY()); y++) { for(int x=0; x<m_pIntercept->Get_NX(); x++) { CSG_Regression_Weighted Model; if( Get_Model(x, y, Model) ) { m_pIntercept->Set_Value(x, y, Model[0]); m_pSlope ->Set_Value(x, y, Model[1]); m_pQuality ->Set_Value(x, y, Model.Get_R2()); } else { m_pIntercept->Set_NoData(x, y); m_pSlope ->Set_NoData(x, y); m_pQuality ->Set_NoData(x, y); } } } //----------------------------------------------------- m_Search.Finalize(); DataObject_Update(m_pIntercept); DataObject_Update(m_pSlope); DataObject_Update(m_pQuality); return( true ); }
//--------------------------------------------------------- CGrid_Gaps_Resampling::CGrid_Gaps_Resampling(void) { //----------------------------------------------------- Set_Name (_TL("Close Gaps with Stepwise Resampling")); Set_Author ("O.Conrad (c) 2012"); Set_Description (_TW( "Close gaps of a grid data set (i.e. eliminate no data values). " "If the target is not set, the changes will be stored to the original grid. " )); //----------------------------------------------------- Parameters.Add_Grid("", "INPUT" , _TL("Grid"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid("", "MASK" , _TL("Mask"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Grid("", "RESULT" , _TL("Result"), _TL(""), PARAMETER_OUTPUT_OPTIONAL ); Parameters.Add_Choice("", "RESAMPLING" , _TL("Resampling"), _TL(""), CSG_String::Format("%s|%s|%s|%s|", _TL("Nearest Neighbour"), _TL("Bilinear Interpolation"), _TL("Bicubic Spline Interpolation"), _TL("B-Spline Interpolation") ), 3 ); Parameters.Add_Double("", "GROW" , _TL("Grow Factor"), _TL(""), 2.0, 1.0, true ); }
//--------------------------------------------------------- bool CGSGrid_Statistics::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); if( pGrids->Get_Count() <= 1 ) { Error_Set(_TL("no grids in selection")); return( false ); } //----------------------------------------------------- CSG_Grid *pMean = Parameters("MEAN" )->asGrid(); CSG_Grid *pMin = Parameters("MIN" )->asGrid(); CSG_Grid *pMax = Parameters("MAX" )->asGrid(); CSG_Grid *pRange = Parameters("RANGE" )->asGrid(); CSG_Grid *pSum = Parameters("SUM" )->asGrid(); CSG_Grid *pVar = Parameters("VAR" )->asGrid(); CSG_Grid *pStdDev = Parameters("STDDEV" )->asGrid(); CSG_Grid *pStdDevLo = Parameters("STDDEVLO")->asGrid(); CSG_Grid *pStdDevHi = Parameters("STDDEVHI")->asGrid(); CSG_Grid *pPercentile = Parameters("PCTL" )->asGrid(); if( !pMean && !pMin && !pMax && !pRange && !pSum && !pVar && !pStdDev && !pStdDevLo && !pStdDevHi && !pPercentile ) { Error_Set(_TL("no parameter output specified")); return( false ); } double dRank = Parameters("PCTL_VAL")->asDouble() / 100.0; //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { CSG_Table Values; CSG_Simple_Statistics s; for(int i=0; i<pGrids->Get_Count(); i++) { if( !pGrids->asGrid(i)->is_NoData(x, y) ) { double z = pGrids->asGrid(i)->asDouble(x, y); s.Add_Value(z); if( pPercentile ) { if( Values.Get_Field_Count() == 0 ) { Values.Add_Field("Z", SG_DATATYPE_Double); } Values.Add_Record()->Set_Value(0, z); } } } //----------------------------------------- if( s.Get_Count() <= 0 ) { if( pMean ) pMean ->Set_NoData(x, y); if( pMin ) pMin ->Set_NoData(x, y); if( pMax ) pMax ->Set_NoData(x, y); if( pRange ) pRange ->Set_NoData(x, y); if( pSum ) pSum ->Set_NoData(x, y); if( pVar ) pVar ->Set_NoData(x, y); if( pStdDev ) pStdDev ->Set_NoData(x, y); if( pStdDevLo ) pStdDevLo ->Set_NoData(x, y); if( pStdDevHi ) pStdDevHi ->Set_NoData(x, y); if( pPercentile ) pPercentile ->Set_NoData(x, y); } else { if( pMean ) pMean ->Set_Value(x, y, s.Get_Mean()); if( pMin ) pMin ->Set_Value(x, y, s.Get_Minimum()); if( pMax ) pMax ->Set_Value(x, y, s.Get_Maximum()); if( pRange ) pRange ->Set_Value(x, y, s.Get_Range()); if( pSum ) pSum ->Set_Value(x, y, s.Get_Sum()); if( pVar ) pVar ->Set_Value(x, y, s.Get_Variance()); if( pStdDev ) pStdDev ->Set_Value(x, y, s.Get_StdDev()); if( pStdDevLo ) pStdDevLo ->Set_Value(x, y, s.Get_Mean() - s.Get_StdDev()); if( pStdDevHi ) pStdDevHi ->Set_Value(x, y, s.Get_Mean() + s.Get_StdDev()); if( pPercentile ) { Values.Set_Index(0, TABLE_INDEX_Ascending); pPercentile->Set_Value(x, y, Values.Get_Record_byIndex((int)(dRank * s.Get_Count()))->asDouble(0)); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- CSoil_Texture::CSoil_Texture(void) { Set_Name (_TL("Soil Texture Classification")); Set_Author (_TL("Gianluca Massei (c) 2007 ([email protected])")); Set_Description (_TW( "Derive soil texture classes with USDA scheme from sand, silt and clay contents.\n\n" " 1 - Clay\n" " 2 - Silty Clay\n" " 3 - Silty Clay-Loam\n" " 4 - Sandy Clay\n" " 5 - Sandy Clay-Loam\n" " 6 - Clay-Loam\n" " 7 - Silt\n" " 8 - Silt-Loam\n" " 9 - Loam\n" " 10 - Sand\n" " 11 - Loamy Sand\n" " 12 - Sandy Loam\n" "\nReference:\n" "<a target=\"_blank\" href=\"http://soils.usda.gov/technical/aids/investigations/texture/\">USDA NRCS Soils Website</a>\n" )); //----------------------------------------------------- // 2. Parameters... Parameters.Add_Grid( NULL, "SAND" , _TL("Sand"), _TL("sand content given as percentage"), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Grid( NULL, "SILT" , _TL("Silt"), _TL("silt content given as percentage"), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Grid( NULL, "CLAY" , _TL("Clay"), _TL("clay content given as percentage"), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Grid( NULL, "TEXTURE" , _TL("Soil Texture"), _TL("soil texture"), PARAMETER_OUTPUT, true, SG_DATATYPE_Byte ); Parameters.Add_Grid( NULL, "SUM" , _TL("Sum"), _TL("Sum of percentages"), PARAMETER_OUTPUT_OPTIONAL ); }
//--------------------------------------------------------- CGSGrid_Statistics_To_Table::CGSGrid_Statistics_To_Table(void) { Set_Name (_TL("Save Grid Statistics to Table")); Set_Author (SG_T("O.Conrad (c) 2013")); Set_Description (_TW( "Calculates statistical properties (arithmetic mean, minimum, maximum, " "variance, standard deviation) for each of the given grids and saves " "it to a table." )); Parameters.Add_Grid_List( NULL, "GRIDS" , _TL("Grids"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Table( NULL, "STATS" , _TL("Statistics for Grids"), _TL(""), PARAMETER_OUTPUT ); Parameters.Add_Value(NULL, "DATA_CELLS" , _TL("Number of Data Cells") , _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "NODATA_CELLS", _TL("Number of No-Data Cells") , _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "CELLSIZE" , _TL("Cellsize") , _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "MEAN" , _TL("Arithmetic Mean") , _TL(""), PARAMETER_TYPE_Bool, true); Parameters.Add_Value(NULL, "MIN" , _TL("Minimum") , _TL(""), PARAMETER_TYPE_Bool, true); Parameters.Add_Value(NULL, "MAX" , _TL("Maximum") , _TL(""), PARAMETER_TYPE_Bool, true); Parameters.Add_Value(NULL, "RANGE" , _TL("Range") , _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "VAR" , _TL("Variance") , _TL(""), PARAMETER_TYPE_Bool, true); Parameters.Add_Value(NULL, "STDDEV" , _TL("Standard Deviation") , _TL(""), PARAMETER_TYPE_Bool, true); Parameters.Add_Value(NULL, "STDDEVLO" , _TL("Mean less Standard Deviation"), _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "STDDEVHI" , _TL("Mean plus Standard Deviation"), _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value(NULL, "PCTL" , _TL("Percentile") , _TL(""), PARAMETER_TYPE_Bool, false); Parameters.Add_Value( NULL, "PCTL_VAL", _TL("Percentile"), _TL(""), PARAMETER_TYPE_Double, 50.0, 0.0, true, 100.0, true ); }
//--------------------------------------------------------- bool CSoil_Texture::On_Execute(void) { CSG_Grid *pSand, *pSilt, *pClay, *pTexture, *pSum; //----------------------------------------------------- pSand = Parameters("SAND") ->asGrid(); pSilt = Parameters("SILT") ->asGrid(); pClay = Parameters("CLAY") ->asGrid(); pTexture = Parameters("TEXTURE") ->asGrid(); pSum = Parameters("SUM") ->asGrid(); //----------------------------------------------------- if( (pSand ? 1 : 0) + (pSilt ? 1 : 0) + (pClay ? 1 : 0) < 2 ) { Error_Set(_TL("at least two contents (sand, silt, clay) have to be given")); return( false ); } //----------------------------------------------------- pTexture->Set_NoData_Value(0.0); CSG_Parameters P; if( DataObject_Get_Parameters(pTexture, P) && P("COLORS_TYPE") && P("LUT") ) { CSG_Table *pLUT = P("LUT")->asTable(); for(int iClass=0; iClass<12; iClass++) { CSG_Table_Record *pClass; if( (pClass = pLUT->Get_Record(iClass)) == NULL ) { pClass = pLUT->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].ID); pClass->Set_Value(4, Classes[iClass].ID); } while( pLUT->Get_Record_Count() > 12 ) { pLUT->Del_Record(pLUT->Get_Record_Count() - 1); } P("COLORS_TYPE")->Set_Value(1); // Color Classification Type: Lookup Table DataObject_Set_Parameters(pTexture, P); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { for(int x=0; x<Get_NX(); x++) { int Texture = 0; double Sum = 0.0; if( !(pSand && pSand->is_NoData(x, y)) && !(pSilt && pSilt->is_NoData(x, y)) && !(pClay && pClay->is_NoData(x, y)) ) { double Sand = pSand ? pSand->asDouble(x, y) : 100.0 - (pSilt->asDouble(x, y) + pClay->asDouble(x, y)); double Silt = pSilt ? pSilt->asDouble(x, y) : 100.0 - (pSand->asDouble(x, y) + pClay->asDouble(x, y)); double Clay = pClay ? pClay->asDouble(x, y) : 100.0 - (pSand->asDouble(x, y) + pSilt->asDouble(x, y)); if( (Sum = Sand + Silt + Clay) > 0.0 ) { if( Sum != 100.0 ) { Sand *= 100.0 / Sum; Clay *= 100.0 / Sum; } Texture = Get_Texture(Sand, Clay); } } if( Texture ) { pTexture->Set_Value(x, y, Texture); if( pSum ) { pSum->Set_Value(x, y, Sum); } } else { pTexture->Set_NoData(x, y); if( pSum ) { pSum->Set_NoData(x, y); } } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- CGSGrid_Statistics::CGSGrid_Statistics(void) { Set_Name (_TL("Statistics for Grids")); Set_Author (SG_T("O.Conrad (c) 2005")); Set_Description (_TW( "Calculates statistical properties (arithmetic mean, minimum, maximum, " "variance, standard deviation) for each cell position for the values of " "the selected grids." )); Parameters.Add_Grid_List( NULL, "GRIDS" , _TL("Grids"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid(NULL, "MEAN" , _TL("Arithmetic Mean") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "MIN" , _TL("Minimum") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "MAX" , _TL("Maximum") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "RANGE" , _TL("Range") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "SUM" , _TL("Sum") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "VAR" , _TL("Variance") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "STDDEV" , _TL("Standard Deviation") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "STDDEVLO", _TL("Mean less Standard Deviation"), _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "STDDEVHI", _TL("Mean plus Standard Deviation"), _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Grid(NULL, "PCTL" , _TL("Percentile") , _TL(""), PARAMETER_OUTPUT_OPTIONAL); Parameters.Add_Value( NULL, "PCTL_VAL", _TL("Percentile"), _TL(""), PARAMETER_TYPE_Double, 50.0, 0.0, true, 100.0, true ); }
//--------------------------------------------------------- CVariogram_Dialog::CVariogram_Dialog(void) : CSGDI_Dialog(_TL("Variogram")) { m_pPoints = NULL; m_nPoints = 0; m_Attribute = 0; m_pVariogram = NULL; m_pModel = NULL; m_Distance = -1; //----------------------------------------------------- wxArrayString Formulas; Formulas.Empty(); Formulas.Add(SG_T("a + b * x")); // 1st order polynom (linear) Formulas.Add(SG_T("a + b * x + c * x^2")); // 2nd order polynom (quadric) Formulas.Add(SG_T("a + b * x + c * x^2 + d * x^3")); // 3rd order polynom (cubic) Formulas.Add(SG_T("a + b * x + c * x^2 + d * x^3 + e * x^4")); // 4th order polynom Formulas.Add(SG_T("a + b * sqrt(x)")); // square root Formulas.Add(SG_T("a + b * ln(x)")); // logarithmic Formulas.Add(SG_T("a + b * x^c")); // exponential Formulas.Add(SG_T("a + b * (1 - exp(-(x / b)^2))")); // gaussian Formulas.Add(SG_T("a + b * ifelse(x > c, 1, 1.5 * x / c - 0.5 * x^3 / c^3)")); // spherical //----------------------------------------------------- Add_Button(_TL("Ok") , wxID_OK); Add_Button(_TL("Cancel") , wxID_CANCEL); Add_Spacer(); m_pSettings = Add_Button (_TL("Settings"), wxID_ANY); Add_Spacer(); m_pPairs = Add_CheckBox (_TL("Number of Pairs"), false); Add_Spacer(); m_pFormulas = Add_Choice (_TL("Predefined Functions"), Formulas, 0); Add_Spacer(); m_pDistance = Add_Slider (_TL("Function Fitting Range"), 1, 0, 1); Add_Spacer(); m_pParameters = Add_TextCtrl (_TL("Function Parameters"), wxTE_MULTILINE|wxTE_READONLY); //----------------------------------------------------- Add_Output( m_pDiagram = new CVariogram_Diagram(this), m_pFormula = new wxTextCtrl(this, wxID_ANY, SG_T("a + b * x"), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), 1, 0 ); //----------------------------------------------------- m_Settings.Set_Name(_TL("Variogram Settings")); m_Settings.Add_Value (NULL, "SKIP" , _TL("Skip" ), _TL(""), PARAMETER_TYPE_Int , 1, 1, true); m_Settings.Add_Value (NULL, "LAGDIST", _TL("Lag Distance" ), _TL(""), PARAMETER_TYPE_Double, 1, 0.0, true); m_Settings.Add_Value (NULL, "MAXDIST", _TL("Maximum Distance"), _TL(""), PARAMETER_TYPE_Double, 1, 0.0, true); m_Settings.Add_String(NULL, "MODEL" , _TL("Model" ), _TL(""), SG_T("a + b * x")); }
//--------------------------------------------------------- CGrid_Cross_Profiles::CGrid_Cross_Profiles(void) { Set_Name(_TL("Cross Profiles")); Set_Author (SG_T("(c) 2006 by O.Conrad")); Set_Description (_TW( "Create cross profiles from a grid based DEM for given lines.\n" )); Parameters.Add_Grid( NULL, "DEM" , _TL("DEM"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Shapes( NULL, "LINES" , _TL("Lines"), _TL(""), PARAMETER_INPUT , SHAPE_TYPE_Line ); Parameters.Add_Shapes( NULL, "PROFILES" , _TL("Cross Profiles"), _TL(""), PARAMETER_OUTPUT , SHAPE_TYPE_Line ); Parameters.Add_Value( NULL, "DIST_LINE" , _TL("Profile Distance"), _TL(""), PARAMETER_TYPE_Double, 10.0, 0.0, true ); Parameters.Add_Value( NULL, "DIST_PROFILE", _TL("Profile Length"), _TL(""), PARAMETER_TYPE_Double, 10.0, 0.0, true ); Parameters.Add_Value( NULL, "NUM_PROFILE" , _TL("Profile Samples"), _TL(""), PARAMETER_TYPE_Int , 10.0, 3.0, true ); Parameters.Add_FilePath( NULL, "DOCUMENT" , _TL("Report"), _TL(""), _TL("Portable Document Format (*.pdf)|*.pdf|All Files|*.*"), NULL, true ); }
//--------------------------------------------------------- bool CSG_Variogram::Calculate(CSG_Shapes *pPoints, int Attribute, bool bLog, CSG_Table *pVariogram, int nClasses, double maxDistance, int nSkip) { int i, j, k, n; double z, lagDistance; TSG_Point p; CSG_Vector Count, Variance; CSG_Table_Record *pRecord; CSG_Shape *pPoint; //----------------------------------------------------- if( nSkip < 1 ) { nSkip = 1; } if( maxDistance <= 0.0 || maxDistance > SG_Get_Length(pPoints->Get_Extent().Get_XRange(), pPoints->Get_Extent().Get_YRange()) ) { maxDistance = SG_Get_Length(pPoints->Get_Extent().Get_XRange(), pPoints->Get_Extent().Get_YRange()); // bounding box' diagonal } lagDistance = maxDistance / nClasses; Count .Create(nClasses); Variance .Create(nClasses); //----------------------------------------------------- for(i=0, n=0; i<pPoints->Get_Count()-nSkip && SG_UI_Process_Set_Progress(n, SG_Get_Square(pPoints->Get_Count()/nSkip)/2); i+=nSkip) { pPoint = pPoints->Get_Shape(i); if( !pPoint->is_NoData(Attribute) ) { p = pPoint->Get_Point(0); z = bLog ? log(pPoint->asDouble(Attribute)) : pPoint->asDouble(Attribute); for(j=i+nSkip; j<pPoints->Get_Count(); j+=nSkip, n++) { pPoint = pPoints->Get_Shape(j); if( !pPoint->is_NoData(Attribute) ) { k = (int)(SG_Get_Distance(p, pPoint->Get_Point(0)) / lagDistance); if( k < nClasses ) { Count [k] ++; Variance[k] += SG_Get_Square((bLog ? log(pPoint->asDouble(Attribute)) : pPoint->asDouble(Attribute)) - z); } } } } } //----------------------------------------------------- pVariogram->Destroy(); pVariogram->Set_Name(CSG_String::Format(SG_T("%s [%s]"), _TL("Variogram"), pPoints->Get_Name())); pVariogram->Add_Field(_TL("Class") , SG_DATATYPE_Int); // FIELD_CLASS pVariogram->Add_Field(_TL("Distance") , SG_DATATYPE_Double); // FIELD_DISTANCE pVariogram->Add_Field(_TL("Count") , SG_DATATYPE_Int); // FIELD_COUNT pVariogram->Add_Field(_TL("Variance") , SG_DATATYPE_Double); // FIELD_VAR_EXP pVariogram->Add_Field(_TL("Var.cum.") , SG_DATATYPE_Double); // FIELD_VAR_CUM pVariogram->Add_Field(_TL("Model") , SG_DATATYPE_Double); // FIELD_VAR_MODEL for(i=0, z=0.0, n=0; i<nClasses; i++) { if( Count[i] > 0 ) { n += (int)Count[i]; z += Variance[i]; pRecord = pVariogram->Add_Record(); pRecord->Set_Value(FIELD_CLASS , (i + 1)); pRecord->Set_Value(FIELD_DISTANCE , (i + 1) * lagDistance); pRecord->Set_Value(FIELD_COUNT , Count[i]); pRecord->Set_Value(FIELD_VAR_EXP , 0.5 * Variance[i] / Count[i]); pRecord->Set_Value(FIELD_VAR_CUM , 0.5 * z / n); } } //----------------------------------------------------- return( SG_UI_Process_Get_Okay() ); }
//--------------------------------------------------------- void CMD_Print_Error (const CSG_String &Error) { CMD_Print(stderr, CSG_String::Format("%s: %s", _TL("Error"), Error.c_str()), SG_XML_ERROR); }
//--------------------------------------------------------- void CData_Source_PgSQL::Table_Drop(const wxTreeItemId &Item) { CData_Source_PgSQL_Data *pData = Item.IsOk() ? (CData_Source_PgSQL_Data *)GetItemData(Item) : NULL; if( pData == NULL ) return; wxString Name = GetItemText(Item); switch( pData->Get_Type() ) { //----------------------------------------------------- case TYPE_GRID: if( DLG_Message_Confirm(wxString::Format("%s [%s]", _TL("Do you really want to delete this raster band"), Name.c_str()), _TL("Raster Band Deletion")) ) { MSG_General_Add(wxString::Format("%s: [%s] %s...", _TL("Deleting raster band"), pData->Get_Server().c_str(), Name.c_str()), true, true); CSG_String Table = pData->Get_Value().BeforeFirst(':'); CSG_String rid = pData->Get_Value().AfterFirst (':'); CSG_String SQL = "DELETE FROM \"" + Table + "\" WHERE " + rid + ";"; RUN_MODULE(DB_PGSQL_Execute_SQL, false, SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("SQL" , SQL) ); if( bResult ) { Delete(Item); MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); } else { MSG_General_Add(_TL("failed"), false, false, SG_UI_MSG_STYLE_FAILURE); } } break; //----------------------------------------------------- default: if( DLG_Message_Confirm(wxString::Format("%s [%s]", _TL("Do you really want to delete the table"), pData->Get_Value().c_str()), _TL("Table Deletion")) ) { MSG_General_Add(wxString::Format("%s: [%s] %s...", _TL("Deleting table"), pData->Get_Server().c_str(), pData->Get_Value().c_str()), true, true); RUN_MODULE(DB_PGSQL_Table_Drop, false, // CTable_Drop SET_PARAMETER("CONNECTION", pData->Get_Server()) && SET_PARAMETER("TABLES" , pData->Get_Value()) ); if( bResult ) { Delete(Item); MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); } else { MSG_General_Add(_TL("failed"), false, false, SG_UI_MSG_STYLE_FAILURE); } } break; } }
//--------------------------------------------------------- CGrid_Export::CGrid_Export(void) { Set_Name (_TL("Export Image (bmp, jpg, pcx, png, tif)")); Set_Author (SG_T("O.Conrad (c) 2005")); Set_Description (_TW( "The module allows one to save a grid as image.\n" "Optionally, a shade grid can be overlayed and it's " "transparency and brightness can be adjusted.\n\n") ); Parameters.Add_Grid( NULL , "GRID" , _TL("Grid"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid( NULL , "SHADE" , _TL("Shade"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_FilePath( NULL , "FILE" , _TL("Image File"), _TL(""), CSG_String::Format("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s", _TL("Portable Network Graphics (*.png)") , SG_T("*.png"), _TL("JPEG - JFIF Compliant (*.jpg, *.jif, *.jpeg)") , SG_T("*.jpg;*.jif;*.jpeg"), _TL("Tagged Image File Format (*.tif, *.tiff)") , SG_T("*.tif;*.tiff"), _TL("Windows or OS/2 Bitmap (*.bmp)") , SG_T("*.bmp"), _TL("Zsoft Paintbrush (*.pcx)") , SG_T("*.pcx") ), NULL, true ); Parameters.Add_Value( NULL , "FILE_KML" , _TL("Create KML File"), _TL(""), PARAMETER_TYPE_Bool, true ); if( SG_UI_Get_Window_Main() ) { Parameters.Add_Choice( NULL , "COLOURING" , _TL("Colouring"), _TL(""), CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|"), _TL("stretch to grid's standard deviation"), _TL("stretch to grid's value range"), _TL("stretch to specified value range"), _TL("lookup table"), _TL("rgb coded values"), _TL("same as in graphical user interface") ), 5 ); Parameters.Add_Colors( NULL , "COL_PALETTE" , _TL("Colours Palette"), _TL("") ); } else { Parameters.Add_Choice( NULL , "COLOURING" , _TL("Colouring"), _TL(""), CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"), _TL("stretch to grid's standard deviation"), _TL("stretch to grid's value range"), _TL("stretch to specified value range"), _TL("lookup table"), _TL("rgb coded values") ), 0 ); Parameters.Add_Choice( NULL , "COL_PALETTE" , _TL("Color Palette"), _TL(""), CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|"), _TL("DEFAULT"), _TL("DEFAULT_BRIGHT"), _TL("BLACK_WHITE"), _TL("BLACK_RED"), _TL("BLACK_GREEN"), _TL("BLACK_BLUE"), _TL("WHITE_RED"), _TL("WHITE_GREEN"), _TL("WHITE_BLUE"), _TL("YELLOW_RED"), _TL("YELLOW_GREEN"), _TL("YELLOW_BLUE"), _TL("RED_GREEN"), _TL("RED_BLUE"), _TL("GREEN_BLUE"), _TL("RED_GREY_BLUE"), _TL("RED_GREY_GREEN"), _TL("GREEN_GREY_BLUE"), _TL("RED_GREEN_BLUE"), _TL("RED_BLUE_GREEN"), _TL("GREEN_RED_BLUE"), _TL("RAINBOW"), _TL("NEON"), _TL("TOPOGRAPHY"), _TL("ASPECT_1"), _TL("ASPECT_2"), _TL("ASPECT_3") ), 0 ); Parameters.Add_Value( NULL , "COL_COUNT" , _TL("Number of Colors"), _TL(""), PARAMETER_TYPE_Int, 100 ); Parameters.Add_Value( NULL , "COL_REVERT" , _TL("Revert Palette"), _TL(""), PARAMETER_TYPE_Bool, false ); } Parameters.Add_Value( NULL , "STDDEV" , _TL("Standard Deviation"), _TL(""), PARAMETER_TYPE_Double, 2.0, 0.0, true ); Parameters.Add_Range( NULL , "STRETCH" , _TL("Stretch to Value Range"), _TL(""), 0.0, 100.0 ); Parameters.Add_Table( NULL , "LUT" , _TL("Lookup Table"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Value( NULL , "SHADE_TRANS" , _TL("Shade Transparency [%]"), _TL("The transparency of the shade [%]"), PARAMETER_TYPE_Double, 40.0, 0.0, true, 100.0, true ); Parameters.Add_Range( NULL , "SHADE_BRIGHT", _TL("Shade Brightness [%]"), _TL("Allows one to scale shade brightness [%]"), 0.0, 100.0, 0.0, true, 100.0, true ); }
//--------------------------------------------------------- CWatersheds::CWatersheds(void) { Set_Name(_TL("Watershed Basins")); Set_Author (SG_T("(c) 2001 by O.Conrad")); Set_Description(_TL("")); Parameters.Add_Grid( NULL, "ELEVATION" , _TL("Elevation"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid( NULL, "CHANNELS" , _TL("Channel Network"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid( NULL, "SINKROUTE" , _TL("Sink Route"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Grid( NULL, "BASINS" , _TL("Watershed Basins"), _TL(""), PARAMETER_OUTPUT ); Parameters.Add_Value( NULL, "MINSIZE" , _TL("Min. Size"), _TL("Minimum size of basin (cells)"), PARAMETER_TYPE_Int ); }
//--------------------------------------------------------- CGrid_Completion::CGrid_Completion(void) { //----------------------------------------------------- // 1. Info... Set_Name (_TL("Patching")); Set_Author (SG_T("(c) 2003 by O.Conrad")); Set_Description (_TW( "Fill gaps of a grid with data from another grid. " )); //----------------------------------------------------- // 2. Standard in- and output... Parameters.Add_Grid( NULL , "ORIGINAL" , _TL("Grid"), _TL(""), PARAMETER_INPUT ); Parameters.Add_Grid( NULL , "ADDITIONAL" , _TL("Patch Grid"), _TL(""), PARAMETER_INPUT, false ); Parameters.Add_Grid( NULL , "COMPLETED" , _TL("Completed Grid"), _TL(""), PARAMETER_OUTPUT ); Parameters.Add_Choice( NULL , "INTERPOLATION" , _TL("Interpolation Method"), _TL(""), CSG_String::Format(SG_T("%s|%s|%s|%s|%s|"), _TL("Nearest Neighbor"), _TL("Bilinear Interpolation"), _TL("Inverse Distance Interpolation"), _TL("Bicubic Spline Interpolation"), _TL("B-Spline Interpolation") ), 4 ); }
//--------------------------------------------------------- CLines_From_Points::CLines_From_Points(void) { CSG_Parameter *pNode; //----------------------------------------------------- Set_Name (_TL("Convert Points to Line(s)")); Set_Author (SG_T("O.Conrad (c) 2008")); Set_Description (_TW( "Converts points to line(s)." )); //----------------------------------------------------- pNode = Parameters.Add_Shapes( NULL , "LINES" , _TL("Lines"), _TL(""), PARAMETER_OUTPUT, SHAPE_TYPE_Line ); pNode = Parameters.Add_Shapes( NULL , "POINTS" , _TL("Points"), _TL(""), PARAMETER_INPUT, SHAPE_TYPE_Point ); Parameters.Add_Table_Field( pNode , "ORDER" , _TL("Order by..."), _TL(""), true ); Parameters.Add_Table_Field( pNode , "SEPARATE" , _TL("Separate by..."), _TL(""), true ); Parameters.Add_Table_Field( pNode , "ELEVATION" , _TL("Elevation"), _TL(""), true ); }
//--------------------------------------------------------- bool CGWR_Grid_Downscaling::Get_Model(void) { //----------------------------------------------------- m_pQuality = Parameters("QUALITY" )->asGrid(); m_pQuality ->Set_Name(CSG_String::Format(SG_T("%s [%s, %s]"), m_pDependent->Get_Name(), _TL("GWR"), _TL("Quality"))); m_pResiduals = Parameters("RESIDUALS")->asGrid(); m_pResiduals ->Set_Name(CSG_String::Format(SG_T("%s [%s, %s]"), m_pDependent->Get_Name(), _TL("GWR"), _TL("Residuals"))); //----------------------------------------------------- m_Search.Get_Weighting().Set_Parameters(&Parameters); m_Search.Set_Radius(Parameters("SEARCH_RANGE")->asInt() == 0 ? Parameters("SEARCH_RADIUS")->asInt() : 1 + (int)(SG_Get_Length(m_pDependent->Get_NX(), m_pDependent->Get_NY())) ); //----------------------------------------------------- CSG_Grid_System System(m_pDependent->Get_System()); for(int y=0; y<System.Get_NY() && Set_Progress(y, System.Get_NY()); y++) { #pragma omp parallel for for(int x=0; x<System.Get_NX(); x++) { if( !Get_Regression(x, y) ) { m_pQuality ->Set_NoData(x, y); m_pResiduals->Set_NoData(x, y); for(int i=0; i<=m_nPredictors; i++) { m_pModel[i]->Set_NoData(x, y); } } } } //----------------------------------------------------- m_Search.Destroy(); return( true ); }
//--------------------------------------------------------- bool CTable_Running_Average::On_Execute(void) { int iValue, nValues; CSG_Table *pTable; //----------------------------------------------------- pTable = Parameters("INPUT") ->asTable(); iValue = Parameters("FIELD") ->asInt(); nValues = Parameters("COUNT") ->asInt(); if( Parameters("OUTPUT")->asTable() && Parameters("OUTPUT")->asTable() != pTable ) { pTable = Parameters("OUTPUT") ->asTable(); pTable->Create(*Parameters("INPUT")->asTable()); } //----------------------------------------------------- if( pTable->is_Valid() ) { int i, iLo, iHi, nRange, iAverage; double sValues; iAverage = pTable->Get_Field_Count(); pTable->Add_Field(CSG_String::Format(SG_T("%s [%s]"), pTable->Get_Field_Name(iValue), _TL("Average")), SG_DATATYPE_Double); nRange = nValues / 2; sValues = 0.0; for(iLo=-nValues, i=-nRange, iHi=0; i<pTable->Get_Count() && Set_Progress(i, pTable->Get_Count() + nRange); iLo++, i++, iHi++) { sValues += pTable->Get_Record(iHi < pTable->Get_Count() ? iHi : pTable->Get_Count() - 1)->asDouble(iValue); if( i < 0 ) { sValues += pTable->Get_Record( 0 )->asDouble(iValue); } else { if( iLo < 0 ) { sValues -= pTable->Get_Record( 0 )->asDouble(iValue); } else if( iLo >= 0 ) { sValues -= pTable->Get_Record(iLo)->asDouble(iValue); } pTable->Get_Record(i)->Set_Value(iAverage, sValues / (double)nValues); } } return( true ); } //----------------------------------------------------- return( false ); }