//--------------------------------------------------------- CDecision_Tree::CDecision_Tree(void) { //----------------------------------------------------- Set_Name (_TL("Decision Tree")); Set_Author (SG_T("O.Conrad (c) 2011")); Set_Description (_TW( "Decision Tree" )); //----------------------------------------------------- Parameters.Add_Grid( NULL , "CLASSES" , _TL("Decision Tree"), _TL(""), PARAMETER_OUTPUT, true, SG_DATATYPE_Short ); //----------------------------------------------------- CSG_Parameter *pRoot = Parameters.Add_Parameters( NULL , "ROOT" , _TL("Decision"), _TL("") ); Add_Decision(pRoot->asParameters()); }
//--------------------------------------------------------- void CTable_Drop::On_Connection_Changed(CSG_Parameters *pParameters) { CSG_Parameter *pParameter = pParameters->Get_Parameter("TABLES"); pParameter->asChoice()->Set_Items(Get_Connection()->Get_Tables()); pParameter->Set_Value(pParameter->asString()); }
bool CCreateChartLayer::GetExtraParameters(){ int i; CSG_Shapes *pInput; CSG_Parameter *pParam; CSG_String sName; bool bIsValidSelection = false; pInput = Parameters("INPUT")->asShapes(); m_pExtraParameters->Create(this, _TL("Fields for diagram"), _TL(""), SG_T("EXTRA")); m_bIncludeParam = new bool [pInput->Get_Field_Count() ]; for (i = 0; i < pInput->Get_Field_Count(); i++) { switch( pInput->Get_Field_Type(i) ) { default: break; case SG_DATATYPE_Byte: case SG_DATATYPE_Char: case SG_DATATYPE_Word: case SG_DATATYPE_Short: case SG_DATATYPE_DWord: case SG_DATATYPE_Int: case SG_DATATYPE_ULong: case SG_DATATYPE_Long: case SG_DATATYPE_Float: case SG_DATATYPE_Double: // is numeric field m_pExtraParameters->Add_Value( NULL, SG_Get_String(i,0).c_str(), pInput->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false ); break; } }//for if(Dlg_Parameters("EXTRA")){ for (i = 0; i < pInput->Get_Field_Count(); i++){ sName = SG_Get_String(i,0); if (pParam = Get_Parameters("EXTRA")->Get_Parameter(sName.c_str())){ m_bIncludeParam[i] = pParam->asBool(); bIsValidSelection = true; }//try else{ m_bIncludeParam[i] = false; }//else }//for m_pExtraParameters->Destroy(); return bIsValidSelection; }//if m_pExtraParameters->Destroy(); return false; }//method
//--------------------------------------------------------- bool CWKSP_Project::_Compatibility_Data(TSG_Data_Type Type, CSG_Parameters *pParameters, const CSG_String &Version) { if( !pParameters ) { return( false ); } if( !Version.Cmp(SAGA_VERSION) ) { return( true ); } //----------------------------------------------------- if( Version.is_Empty() ) { CSG_Parameter *pParameter; if( Type == SG_DATAOBJECT_TYPE_Grid ) { if( (pParameter = pParameters->Get_Parameter("COLORS_TYPE")) != NULL ) { if( pParameter->asInt() == 3 ) { // 0:Single >> 1:LUT >> 2:Discrete >> 3:Graduated >> 4:RGB Overlay >> 5:RGB Composite >> 6:Shade pParameter->Set_Value(5); // RGB moved to position 5 } } } } return( true ); }
//--------------------------------------------------------- bool CMine_Sweeper::MakeBoard(int level) { int i, x, y; CSG_Colors Colors; switch( level ) { case 0: Mine_NX = 8; Mine_NY = 8; N_Mines=10; break; case 1: Mine_NX = 16; Mine_NY = 16; N_Mines=40; break; case 2: Mine_NX = 30; Mine_NY = 16; N_Mines=99; break; } pInput = SG_Create_Grid(SG_DATATYPE_Int,SPRITE_SIZE*Mine_NX, SPRITE_SIZE*Mine_NY); pInput->Set_Name(_TL("Mine Sweeper")); Parameters("GRID")->Set_Value(pInput); //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pInput, "LUT"); if( pLUT && pLUT->asTable() ) { pLUT->asTable()->Del_Records(); for(i=0; i<16; i++) { CSG_Table_Record *pRecord = pLUT->asTable()->Add_Record(); pRecord->Set_Value(0, SG_GET_RGB(mine_res_color[i*3], mine_res_color[i*3+1], mine_res_color[i*3+2])); pRecord->Set_Value(3, i); } DataObject_Set_Parameter(pInput, pLUT); DataObject_Set_Parameter(pInput, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } Colors.Set_Count(16); for ( i=0;i<16; i++) { Colors.Set_Color(i, SG_GET_RGB(mine_res_color[i*3], mine_res_color[i*3+1], mine_res_color[i*3+2])); } DataObject_Set_Colors(pInput, Colors); DataObject_Update(pInput, 0.0, 15.0, true); //----------------------------------------------------- for( y = 0; y < Mine_NY; y++) for( x = 0; x < Mine_NX; x++) { SetSprite(x,y,SPRITE_CLOSE); } pInput->Set_Value(0, 0); return true; }
//--------------------------------------------------------- int CSG_Distance_Weighting::Enable_Parameters(CSG_Parameters *pParameters) { if( pParameters ) { CSG_Parameter *pParameter = pParameters->Get_Parameter("DW_WEIGHTING"); if( pParameter ) { int Method = pParameter->asInt(); if( (pParameter = pParameters->Get_Parameter("DW_IDW_OFFSET")) != NULL ) pParameter->Set_Enabled(Method == 1); if( (pParameter = pParameters->Get_Parameter("DW_IDW_POWER" )) != NULL ) pParameter->Set_Enabled(Method == 1); if( (pParameter = pParameters->Get_Parameter("DW_BANDWIDTH" )) != NULL ) pParameter->Set_Enabled(Method >= 2); } } return( 1 ); }
//--------------------------------------------------------- bool DLG_Table_Fields(const wxString &Caption, CSG_Parameter_Table_Fields *pFields) { CSG_Table *pTable = pFields->Get_Table(); if( pTable ) { int i; CSG_Parameters P; for(i=0; i<pTable->Get_Field_Count(); i++) { P.Add_Value(NULL, SG_Get_String(i), pTable->Get_Field_Name(i), _TL(""), PARAMETER_TYPE_Bool, false); } for(i=0; i<pFields->Get_Count(); i++) { CSG_Parameter *pParameter = P(pFields->Get_Index(i)); if( pParameter ) { pParameter->Set_Value(true); } } if( DLG_Parameters(&P) ) { CSG_String s; for(i=0; i<pTable->Get_Field_Count(); i++) { if( P(i)->asBool() ) { s += CSG_String::Format(s.Length() ? SG_T(",%d") : SG_T("%d"), i); } } pFields->Set_Value(s); return( true ); } } return( false ); }
//--------------------------------------------------------- void CGrid_Cluster_Analysis::Save_LUT(CSG_Grid *pCluster) { CSG_Parameter *pLUT = DataObject_Get_Parameter(pCluster, "LUT"); if( pLUT && pLUT->asTable() ) { CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); CSG_Table &Statistics = *Parameters("STATISTICS")->asTable(); bool bRGB = pGrids->Get_Count() >= 3 && Parameters("RGB_COLORS")->asBool(); for(int iCluster=0; iCluster<Statistics.Get_Count(); iCluster++) { CSG_Table_Record *pClass = pLUT->asTable()->Get_Record(iCluster); if( !pClass ) { (pClass = pLUT->asTable()->Add_Record())->Set_Value(0, SG_Color_Get_Random()); } pClass->Set_Value(1, CSG_String::Format("%s %d", _TL("Cluster"), iCluster + 1)); pClass->Set_Value(2, ""); pClass->Set_Value(3, iCluster + 1); pClass->Set_Value(4, iCluster + 1); if( bRGB ) { #define SET_COLOR_COMPONENT(c, i) c = (int)(127 + (Statistics[iCluster].asDouble(3 + i) - pGrids->asGrid(i)->Get_Mean()) * 127 / pGrids->asGrid(i)->Get_StdDev()); if( c < 0 ) c = 0; else if( c > 255 ) c = 255; int r; SET_COLOR_COMPONENT(r, 2); int g; SET_COLOR_COMPONENT(g, 1); int b; SET_COLOR_COMPONENT(b, 0); pClass->Set_Value(0, SG_GET_RGB(r, g, b)); } } pLUT->asTable()->Set_Record_Count(Statistics.Get_Count()); DataObject_Set_Parameter(pCluster, pLUT); DataObject_Set_Parameter(pCluster, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } }
//--------------------------------------------------------- bool CParameters_Control::Update_DataObjects(void) { if( m_pParameters ) { for(int i=0; i<m_pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = m_pParameters->Get_Parameter(i); wxPGProperty *pProperty = m_pPG->GetProperty(_Get_Identifier(pParameter)); if( pProperty ) { switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_Grid_System: case PARAMETER_TYPE_Grid: case PARAMETER_TYPE_Table: case PARAMETER_TYPE_Shapes: case PARAMETER_TYPE_TIN: case PARAMETER_TYPE_PointCloud: ((CParameters_PG_Choice *)pProperty)->Update(); break; case PARAMETER_TYPE_Grid_List: case PARAMETER_TYPE_Table_List: case PARAMETER_TYPE_Shapes_List: case PARAMETER_TYPE_TIN_List: case PARAMETER_TYPE_PointCloud_List: if( pParameter->Check() == false ) { } break; } } } } return( true ); }
//--------------------------------------------------------- void CParameters_Control::_Set_Parameter(const wxString &Identifier) { wxPGProperty *pProperty = m_pPG->GetProperty(Identifier); if( pProperty ) { CSG_Parameter *pParameter = m_pParameters->Get_Parameter( !pProperty->IsSubProperty() ? Identifier.wx_str() : Identifier.AfterLast(wxT('.')).wx_str() ); if( pParameter ) { switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_String: case PARAMETER_TYPE_FilePath: pParameter->Set_Value(m_pPG->GetPropertyValueAsString(pProperty).wx_str()); break; case PARAMETER_TYPE_Bool: pParameter->Set_Value(m_pPG->GetPropertyValueAsBool (pProperty)); break; case PARAMETER_TYPE_Int: pParameter->Set_Value(m_pPG->GetPropertyValueAsInt (pProperty)); break; case PARAMETER_TYPE_Double: pParameter->Set_Value(m_pPG->GetPropertyValueAsDouble (pProperty)); break; case PARAMETER_TYPE_Color: pParameter->Set_Value(Get_Color_asInt(((wxColourProperty *)pProperty)->GetVal().m_colour)); break; } m_bModified = true; _Update_Parameters(); } } }
//--------------------------------------------------------- CDVWK_SoilMoisture::CDVWK_SoilMoisture(void) { CSG_Parameter *pNode; //----------------------------------------------------- Set_Name (_TL("Soil Moisture Content")); Set_Author (SG_T("(c) 2002 by O.Conrad")); Set_Description (_TW( "The WEELS (Wind Erosion on European Light Soils) soil moisture " "model dynamically calculates the soil moisture based on the rules " "proposed by the DVWK (1996) with input data about:\n" "- soil properties (grids: field capacity and permanent wilting point)\n" "- land use (grid: crop types)\n" "- climate (table: daily values of precipitation, temperature, air humidity)\n\n" "References:\n" "- DVWK - Deutscher Verband fuer Wasserwirtschaft und Kulturbau e.V. (1996): " "'Ermittlung der Verdunstung von Land- und Wasserflaechen', " "DVWK Merkblaetter 238/1996, Bonn, 135p.\n" "- Boehner, J., Schaefer, W., Conrad, O., Gross, J., Ringeler, A. (2001): " "'The WEELS Model: methods, results and limits of wind erosion modelling', " "In: Catena, Special Issue\n") ); //----------------------------------------------------- pNode = Parameters.Add_Grid( NULL , "STA_FC" , _TL("Field Capacity [mm]"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Value( pNode , "STA_FC_DEF" , _TL("Default"), _TL(""), PARAMETER_TYPE_Double , 20.0 , 0.0, true ); pNode = Parameters.Add_Grid( NULL , "STA_PWP" , _TL("Permanent Wilting Point [mm]"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Value( pNode , "STA_PWP_DEF" , _TL("Default"), _TL(""), PARAMETER_TYPE_Double , 2.0 , 0.0, true ); pNode = Parameters.Add_Grid( NULL , "LANDUSE" , _TL("Land Use"), _TL(""), PARAMETER_INPUT_OPTIONAL ); Parameters.Add_Value( pNode , "LANDUSE_DEF" , _TL("Default"), _TL(""), PARAMETER_TYPE_Int , -1.0 ); //----------------------------------------------------- pNode = Parameters.Add_Grid( NULL , "DYN_W" , _TL("Soil Moisture"), _TL(""), PARAMETER_OUTPUT ); //----------------------------------------------------- pNode = Parameters.Add_FixedTable( NULL , "DYN_CLIMATE" , _TL("Climate Data"), _TL("") ); pClimate = pNode->asTable(); pClimate->Set_Name(_TL("Climate Data")); pClimate->Add_Field(_TL("Precipitation [mm]") , SG_DATATYPE_Double); pClimate->Add_Field(_TL("Temperature (2pm) [DegreeC]"), SG_DATATYPE_Double); pClimate->Add_Field(_TL("Air Humidity (2pm) [%%]"), SG_DATATYPE_Double); //----------------------------------------------------- pNode = Parameters.Add_FixedTable( NULL , "STA_KC" , _TL("Crop Coefficients"), _TL("") ); pCropCoeff = pNode->asTable(); pCropCoeff->Set_Name(_TL("Crop Coefficients")); pCropCoeff->Add_Field(_TL("Land Use ID") , SG_DATATYPE_Int); pCropCoeff->Add_Field(_TL("Name") , SG_DATATYPE_String); pCropCoeff->Add_Field(_TL("January") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("February") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("March") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("April") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("May") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("June") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("July") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("August") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("September") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("October") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("November") , SG_DATATYPE_Double); pCropCoeff->Add_Field(_TL("December") , SG_DATATYPE_Double); CSG_Table_Record *pRec; #define ADD_RECORD(ID, NAME, m01, m02, m03, m04, m05, m06, m07, m08, m09, m10, m11, m12) pRec = pCropCoeff->Add_Record();\ pRec->Set_Value( 0, ID); pRec->Set_Value( 1, NAME);\ pRec->Set_Value( 2, m01); pRec->Set_Value( 3, m02); pRec->Set_Value( 4, m03); pRec->Set_Value( 5, m04);\ pRec->Set_Value( 6, m05); pRec->Set_Value( 7, m06); pRec->Set_Value( 8, m07); pRec->Set_Value( 9, m08);\ pRec->Set_Value(10, m09); pRec->Set_Value(11, m10); pRec->Set_Value(12, m11); pRec->Set_Value(13, m12); // ID NAME Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dec ADD_RECORD(1.0, _TL("Maehweide") , 1 , 1 , 1 , 1 , 1.05, 1.10, 1.10, 1.05, 1.05, 1 , 1 , 1 ); ADD_RECORD(2.0, _TL("Winterweizen") , 0.65, 0.65, 0.80, 0.85, 1.15, 1.45, 1.40, 1 , 0.80, 0.70, 0.65, 0.65); ADD_RECORD(3.0, _TL("Wintergerste") , 1 , 1 , 0.85, 0.95, 1.30, 1.35, 1.25, 1 , 1 , 1 , 1 , 1 ); ADD_RECORD(4.0, _TL("Sommergerste") , 1 , 1 , 0.80, 0.90, 1.20, 1.35, 1.20, 1 , 1 , 1 , 1 , 1 ); ADD_RECORD(5.0, _TL("Winterroggen") , 0.65, 0.65, 0.85, 0.90, 1.20, 1.30, 1.25, 0.95, 0.80, 0.70, 0.65, 0.65); ADD_RECORD(6.0, _TL("Hafer" ) , 1 , 1 , 0.65, 0.70, 1.10, 1.45, 1.35, 0.95, 1 , 1 , 1 , 1 ); ADD_RECORD(7.0, _TL("Zuckerrueben") , 1 , 1 , 1 , 0.50, 0.75, 1.05, 1.40, 1.30, 1.10, 0.85, 1 , 1 ); ADD_RECORD(8.0, _TL("Kartoffeln") , 1 , 1 , 1 , 0.50, 0.90, 1.05, 1.45, 1.20, 0.90, 1 , 1 , 1 ); ADD_RECORD(9.0, _TL("Winterraps") , 0.65, 0.65, 0.85, 1 , 1.35, 1.35, 1.10, 0.85, 1 , 1 , 0.65, 0.65); ADD_RECORD(0.0, _TL("Unknown") , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ); #undef ADD_RECORD }
//--------------------------------------------------------- bool CPolygonStatisticsFromPoints::On_Execute(void) { int i, j, n, Offset, *bAttribute; CSG_Simple_Statistics *Statistics; CSG_Parameters *pParameters; CSG_Shapes *pPolygons, *pPoints; //----------------------------------------------------- pPoints = Parameters("POINTS") ->asShapes(); pPolygons = Parameters("POLYGONS") ->asShapes(); if( pPolygons->Get_Count() <= 0 || pPoints->Get_Count() <= 0 ) { return( false ); } //----------------------------------------------------- pParameters = Get_Parameters("ATTRIBUTES"); pParameters->Del_Parameters(); for(i=0; i<pPoints->Get_Field_Count(); i++) { if( SG_Data_Type_is_Numeric(pPoints->Get_Field_Type(i)) ) { CSG_Parameter *pNode = pParameters->Add_Node(NULL, CSG_String::Format(SG_T("%d"), i), pPoints->Get_Field_Name(i), _TL("")); for(j=0; j<STAT_Count; j++) { pParameters->Add_Value(pNode, CSG_String::Format(SG_T("%d|%d"), i, j), CSG_String::Format(SG_T("[%s]"), STAT_Name[j].c_str()), _TL(""), PARAMETER_TYPE_Bool, false ); } } } if( !Dlg_Parameters("ATTRIBUTES") ) { return( false ); } //----------------------------------------------------- if( Parameters("STATISTICS")->asShapes() == NULL ) { Parameters("STATISTICS")->Set_Value(pPolygons); } else if( pPolygons != Parameters("STATISTICS")->asShapes() ) { Parameters("STATISTICS")->asShapes()->Assign(pPolygons); pPolygons = Parameters("STATISTICS")->asShapes(); } //----------------------------------------------------- bAttribute = new int[pPoints->Get_Field_Count()]; Offset = pPolygons->Get_Field_Count(); for(i=0, n=0; i<pPoints->Get_Field_Count(); i++) { bAttribute[i] = 0; if( SG_Data_Type_is_Numeric(pPoints->Get_Field_Type(i)) ) { for(j=0; j<STAT_Count; j++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(CSG_String::Format(SG_T("%d|%d"), i, j)); if( pParameter && pParameter->asBool() ) { bAttribute[i] |= STAT_Flag[j]; pPolygons->Add_Field(CSG_String::Format(SG_T("%s_%s"), pPoints->Get_Field_Name(i), STAT_Name[j].c_str()), SG_DATATYPE_Double); n++; } } } } if( n == 0 ) { delete[](bAttribute); return( false ); } //----------------------------------------------------- Statistics = new CSG_Simple_Statistics[pPoints->Get_Field_Count()]; for(int iPolygon=0; iPolygon<pPolygons->Get_Count() && Set_Progress(iPolygon, pPolygons->Get_Count()); iPolygon++) { CSG_Shape_Polygon *pPolygon = (CSG_Shape_Polygon *)pPolygons->Get_Shape(iPolygon); //------------------------------------------------- for(i=0; i<pPoints->Get_Field_Count(); i++) { Statistics[i].Invalidate(); } //------------------------------------------------- for(int iPoint=0; iPoint<pPoints->Get_Count() && Process_Get_Okay(); iPoint++) { CSG_Shape *pPoint = pPoints->Get_Shape(iPoint); if( pPolygon->is_Containing(pPoint->Get_Point(0)) ) { for(i=0; i<pPoints->Get_Field_Count(); i++) { if( bAttribute[i] ) { Statistics[i].Add_Value(pPoint->asDouble(i)); } } } } //------------------------------------------------- for(i=0, n=Offset; i<pPoints->Get_Field_Count(); i++) { if( bAttribute[i] ) { if( Statistics[i].Get_Count() > 0 ) { if( bAttribute[i] & STAT_Flag[STAT_Sum] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Sum()); } if( bAttribute[i] & STAT_Flag[STAT_Avg] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Mean()); } if( bAttribute[i] & STAT_Flag[STAT_Var] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Variance()); } if( bAttribute[i] & STAT_Flag[STAT_Dev] ) { pPolygon->Set_Value(n++, Statistics[i].Get_StdDev()); } if( bAttribute[i] & STAT_Flag[STAT_Min] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Minimum()); } if( bAttribute[i] & STAT_Flag[STAT_Max] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Maximum()); } if( bAttribute[i] & STAT_Flag[STAT_Num] ) { pPolygon->Set_Value(n++, Statistics[i].Get_Count()); } } else { if( bAttribute[i] & STAT_Flag[STAT_Sum] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Avg] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Var] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Dev] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Min] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Max] ) { pPolygon->Set_NoData(n++); } if( bAttribute[i] & STAT_Flag[STAT_Num] ) { pPolygon->Set_NoData(n++); } } } } } //----------------------------------------------------- delete[](Statistics); delete[](bAttribute); DataObject_Update(pPolygons); return( true ); }
//--------------------------------------------------------- bool 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 CWKSP_Project::_Load_Data(CSG_MetaData &Entry, const wxString &ProjectDir, bool bLoad, const CSG_String &Version) { if( !Entry.Cmp_Name("DATASET") || !Entry("FILE") || Entry["FILE"].Get_Content().is_Empty() ) { return( false ); } TSG_Data_Object_Type Type = Entry.Cmp_Property("type", "GRID" ) ? SG_DATAOBJECT_TYPE_Grid : Entry.Cmp_Property("type", "GRIDS" ) ? SG_DATAOBJECT_TYPE_Grids : Entry.Cmp_Property("type", "TABLE" ) ? SG_DATAOBJECT_TYPE_Table : Entry.Cmp_Property("type", "SHAPES") ? SG_DATAOBJECT_TYPE_Shapes : Entry.Cmp_Property("type", "TIN" ) ? SG_DATAOBJECT_TYPE_TIN : Entry.Cmp_Property("type", "POINTS") ? SG_DATAOBJECT_TYPE_PointCloud : SG_DATAOBJECT_TYPE_Undefined; if( Type == SG_DATAOBJECT_TYPE_Undefined ) { return( false ); } //----------------------------------------------------- wxString File = Entry("FILE")->Get_Content().c_str(); if( File.Find("PGSQL") != 0 && wxFileExists(Get_FilePath_Absolute(ProjectDir, File)) ) { File = Get_FilePath_Absolute(ProjectDir, File); } //----------------------------------------------------- CWKSP_Base_Item *pItem = NULL; if( bLoad ) { if( Type == SG_DATAOBJECT_TYPE_Grid && Entry("PARAMETERS")) { for(int i=0; i<Entry["PARAMETERS"].Get_Children_Count() && !pItem; i++) { if( Entry["PARAMETERS"][i].Cmp_Property("id", "FILE_CACHE") ) { bool bCached = Entry["PARAMETERS"][i].Cmp_Content("TRUE", true); pItem = g_pData->Add(SG_Create_Grid(&File, SG_DATATYPE_Undefined, bCached)); } } } } if( !pItem ) { pItem = bLoad ? g_pData->Open(File, Type) : _Get_byFileName(File); } //----------------------------------------------------- if( !pItem || !pItem->Get_Parameters() || !Entry.Get_Child("PARAMETERS") ) { if( bLoad ) { MSG_Error_Add(wxString::Format("%s [%s]", _TL("failed to load data"), File.c_str())); } return( false ); } //----------------------------------------------------- CSG_MetaData *pEntry = Entry("PARAMETERS"); for(int i=0; i<pEntry->Get_Children_Count(); i++) { if( !pEntry->Get_Child(i)->Get_Name().CmpNoCase("DATA") && !pEntry->Get_Child(i)->Get_Content().is_Empty() && pEntry->Get_Child(i)->Get_Content().BeforeFirst(':').CmpNoCase("PGSQL") ) { wxString File(Get_FilePath_Absolute(ProjectDir, pEntry->Get_Child(i)->Get_Content().w_str())); pEntry->Get_Child(i)->Set_Content(&File); // if( SG_Compare_SAGA_Version(Version) < 0 ) { if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_1") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_G"); } if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_2") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_B"); } } } } pItem->Get_Parameters()->Serialize(*Entry.Get_Child("PARAMETERS"), false); //----------------------------------------------------- if( SG_Compare_Version(Version, "7.0.0") < 0 ) // inter-version-compatibility { CSG_Parameter *pParameter = pItem->Get_Parameter("COLORS_TYPE"); if( pParameter && Type == SG_DATAOBJECT_TYPE_Grid ) { if( pParameter->asInt() == 4 ) { pParameter->Set_Value(6); } // Shade if( pParameter->asInt() == 5 ) { pParameter->Set_Value(4); } // RGB Overlay if( pParameter->asInt() == 6 ) { pParameter->Set_Value(5); } // RGB Composite } } //----------------------------------------------------- if( Type == SG_DATAOBJECT_TYPE_Grid ) { pItem->Get_Parameter("FILE_CACHE")->Set_Value(((CWKSP_Grid *)pItem)->Get_Grid()->is_Cached()); } pItem->Parameters_Changed(); return( true ); }
//--------------------------------------------------------- void CTC_Classification::Set_LUT(CSG_Grid *pLandforms, int nLevels) { CSG_Parameter *pLUT = DataObject_Get_Parameter(pLandforms, "LUT"); if( !pLUT || !pLUT->asTable() ) { return; } pLUT->asTable()->Del_Records(); switch( nLevels ) { case 1: // 8 classes // l s c t ADD_CLASS(1, 1, 1, 1, 0x7F4633, "steep" ); // class 1 ADD_CLASS(1, 1, 1, 0, 0xFF00FF, "steep" ); // class 2 ADD_CLASS(1, 1, 0, 1, 0xC16E2E, "steep" ); // class 3 ADD_CLASS(1, 1, 0, 0, 0xFC97CF, "steep" ); // class 4 ADD_CLASS(1, 0, 1, 1, 0x66A726, "gentle" ); // class 5 ADD_CLASS(1, 0, 1, 0, 0xFFFF40, "gentle" ); // class 6 ADD_CLASS(1, 0, 0, 1, 0xAEFF7B, "gentle" ); // class 7 ADD_CLASS(1, 0, 0, 0, 0xFFFFBF, "gentle" ); // class 8 break; case 2: // 12 classes ADD_CLASS(1, 1, 1, 1, 0x7F4633, "steep" ); // class 1 ADD_CLASS(1, 1, 1, 0, 0xFF00FF, "steep" ); // class 2 ADD_CLASS(1, 1, 0, 1, 0xC16E2E, "steep" ); // class 3 ADD_CLASS(1, 1, 0, 0, 0xFC97CF, "steep" ); // class 4 ADD_CLASS(2, 1, 1, 1, 0xFA9600, "moderate" ); // class 5 ADD_CLASS(2, 1, 1, 0, 0xFD43A8, "moderate" ); // class 6 ADD_CLASS(2, 1, 0, 1, 0xFBCF66, "moderate" ); // class 7 ADD_CLASS(2, 1, 0, 0, 0xF9C4D4, "moderate" ); // class 8 ADD_CLASS(2, 0, 1, 1, 0x66A726, "gentle" ); // class 9 ADD_CLASS(2, 0, 1, 0, 0xFFFF40, "gentle" ); // class 10 ADD_CLASS(2, 0, 0, 1, 0xAEFF7B, "gentle" ); // class 11 ADD_CLASS(2, 0, 0, 0, 0xFFFFBF, "gentle" ); // class 12 break; default: // 16 classes ADD_CLASS(1, 1, 1, 1, 0x7F4633, "very steep"); // class 1 ADD_CLASS(1, 1, 1, 0, 0xFF00FF, "very steep"); // class 2 ADD_CLASS(1, 1, 0, 1, 0xC16E2E, "very steep"); // class 3 ADD_CLASS(1, 1, 0, 0, 0xFC97CF, "very steep"); // class 4 ADD_CLASS(2, 1, 1, 1, 0xFA9600, "steep" ); // class 5 ADD_CLASS(2, 1, 1, 0, 0xFD43A8, "steep" ); // class 6 ADD_CLASS(2, 1, 0, 1, 0xFBCF66, "steep" ); // class 7 ADD_CLASS(2, 1, 0, 0, 0xF9C4D4, "steep" ); // class 8 ADD_CLASS(3, 1, 1, 1, 0x019E73, "moderate" ); // class 9 ADD_CLASS(3, 1, 1, 0, 0xC4B71D, "moderate" ); // class 10 ADD_CLASS(3, 1, 0, 1, 0x0072B1, "moderate" ); // class 11 ADD_CLASS(3, 1, 0, 0, 0xD7D700, "moderate" ); // class 12 ADD_CLASS(3, 0, 1, 1, 0xA0FD8E, "gentle" ); // class 13 ADD_CLASS(3, 0, 1, 0, 0xE9E915, "gentle" ); // class 14 ADD_CLASS(3, 0, 0, 1, 0x003B5B, "gentle" ); // class 15 ADD_CLASS(3, 0, 0, 0, 0xF2FEC0, "gentle" ); // class 16 break; } DataObject_Set_Parameter(pLandforms, pLUT); DataObject_Set_Parameter(pLandforms, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table }
//--------------------------------------------------------- bool CParam_Scale::On_Execute(void) { //----------------------------------------------------- bool bConstrain; int Index[6]; double zScale, Tol_Slope, Tol_Curve; CSG_Matrix Normal; //----------------------------------------------------- bConstrain = Parameters("CONSTRAIN")->asBool(); zScale = Parameters("ZSCALE" )->asDouble(); if( zScale <= 0.0 ) { zScale = 1.0; } Tol_Slope = Parameters("TOL_SLOPE")->asDouble(); Tol_Curve = Parameters("TOL_CURVE")->asDouble(); m_pDEM = Parameters("DEM" )->asGrid(); //----------------------------------------------------- CSG_Grid *pFeature = Parameters("FEATURES" )->asGrid(); CSG_Grid *pElevation = Parameters("ELEVATION")->asGrid(); CSG_Grid *pSlope = Parameters("SLOPE" )->asGrid(); CSG_Grid *pAspect = Parameters("ASPECT" )->asGrid(); CSG_Grid *pProfC = Parameters("PROFC" )->asGrid(); CSG_Grid *pPlanC = Parameters("PLANC" )->asGrid(); CSG_Grid *pLongC = Parameters("LONGC" )->asGrid(); CSG_Grid *pCrosC = Parameters("CROSC" )->asGrid(); CSG_Grid *pMiniC = Parameters("MINIC" )->asGrid(); CSG_Grid *pMaxiC = Parameters("MAXIC" )->asGrid(); //----------------------------------------------------- if( !Get_Weights() ) { return( false ); } if( !Get_Normal(Normal) ) { return( false ); } // To constrain the quadtratic through the central cell, ignore the calculations involving the // coefficient f. Since these are all in the last row and column of the matrix, simply redimension. if( !SG_Matrix_LU_Decomposition(bConstrain ? 5 : 6, Index, Normal.Get_Data()) ) { return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { CSG_Vector Observed; double elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic; if( Get_Observed(x, y, Observed, bConstrain) && SG_Matrix_LU_Solve(bConstrain ? 5 : 6, Index, Normal, Observed.Get_Data()) ) { Get_Parameters(zScale, Observed.Get_Data(), elevation, slope, aspect, profc, planc, longc, crosc, minic, maxic); GRID_SET_VALUE(pFeature , Get_Feature(slope, minic, maxic, crosc, Tol_Slope, Tol_Curve)); GRID_SET_VALUE(pElevation, elevation + m_pDEM->asDouble(x, y)); // Add central elevation back GRID_SET_VALUE(pSlope , slope); GRID_SET_VALUE(pAspect , aspect); GRID_SET_VALUE(pProfC , profc); GRID_SET_VALUE(pPlanC , planc); GRID_SET_VALUE(pLongC , longc); GRID_SET_VALUE(pCrosC , crosc); GRID_SET_VALUE(pMiniC , minic); GRID_SET_VALUE(pMaxiC , maxic); } else { GRID_SET_NODATA(pFeature); GRID_SET_NODATA(pElevation); GRID_SET_NODATA(pSlope); GRID_SET_NODATA(pAspect); GRID_SET_NODATA(pProfC); GRID_SET_NODATA(pPlanC); GRID_SET_NODATA(pLongC); GRID_SET_NODATA(pCrosC); GRID_SET_NODATA(pMiniC); GRID_SET_NODATA(pMaxiC); } } } //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pFeature, "LUT"); if( pLUT && pLUT->asTable() ) { pLUT->asTable()->Del_Records(); LUT_SET_CLASS(FLAT , _TL("Planar" ), SG_GET_RGB(180, 180, 180)); LUT_SET_CLASS(PIT , _TL("Pit" ), SG_GET_RGB( 0, 0, 0)); LUT_SET_CLASS(CHANNEL, _TL("Channel" ), SG_GET_RGB( 0, 0, 255)); LUT_SET_CLASS(PASS , _TL("Pass (saddle)"), SG_GET_RGB( 0, 255, 0)); LUT_SET_CLASS(RIDGE , _TL("Ridge" ), SG_GET_RGB(255, 255, 0)); LUT_SET_CLASS(PEAK , _TL("Peak" ), SG_GET_RGB(255, 0, 0)); DataObject_Set_Parameter(pFeature, pLUT); DataObject_Set_Parameter(pFeature, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } //----------------------------------------------------- DataObject_Set_Colors(pSlope , 11, SG_COLORS_YELLOW_RED); DataObject_Set_Colors(pAspect, 11, SG_COLORS_ASPECT_3); DataObject_Set_Colors(pProfC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pPlanC , 11, SG_COLORS_RED_GREY_BLUE, false); DataObject_Set_Colors(pLongC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pCrosC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMiniC , 11, SG_COLORS_RED_GREY_BLUE, true); DataObject_Set_Colors(pMaxiC , 11, SG_COLORS_RED_GREY_BLUE, true); //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Classify_Supervised::Set_Classification(CSG_Classifier_Supervised &Classifier) { //----------------------------------------------------- CSG_Grid *pClasses = Parameters("CLASSES")->asGrid(); //----------------------------------------------------- CSG_Parameter *pLUT = DataObject_Get_Parameter(pClasses, "LUT"); if( pLUT && pLUT->asTable() ) { CSG_Parameter_Grid_List *pGrids = Parameters("GRIDS")->asGridList(); bool bRGB = pGrids->Get_Count() >= 3 && Parameters("RGB_COLORS")->asBool(); for(int iClass=0; iClass<Classifier.Get_Class_Count(); iClass++) { CSG_Table_Record *pClass = pLUT->asTable()->Get_Record(iClass); if( !pClass ) { (pClass = pLUT->asTable()->Add_Record())->Set_Value(0, SG_Color_Get_Random()); } pClass->Set_Value(1, Classifier.Get_Class_ID(iClass).c_str()); pClass->Set_Value(2, ""); pClass->Set_Value(3, iClass + 1); pClass->Set_Value(4, iClass + 1); if( bRGB ) { #define SET_COLOR_COMPONENT(c, i) c = (int)(127 + (Classifier.Get_Class_Mean(iClass, i) - pGrids->asGrid(i)->Get_Mean()) * 127 / pGrids->asGrid(i)->Get_StdDev()); if( c < 0 ) c = 0; else if( c > 255 ) c = 255; int r; SET_COLOR_COMPONENT(r, 2); int g; SET_COLOR_COMPONENT(g, 1); int b; SET_COLOR_COMPONENT(b, 0); pClass->Set_Value(0, SG_GET_RGB(r, g, b)); } } pLUT->asTable()->Set_Record_Count(Classifier.Get_Class_Count()); DataObject_Set_Parameter(pClasses, pLUT); DataObject_Set_Parameter(pClasses, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } pClasses->Set_Name(CSG_String::Format("%s [%s]", _TL("Classification"), CSG_Classifier_Supervised::Get_Name_of_Method(Parameters("METHOD")->asInt()).c_str())); //----------------------------------------------------- CSG_Grid *pQuality = Parameters("QUALITY")->asGrid(); if( pQuality ) { DataObject_Set_Colors(pQuality, 11, SG_COLORS_YELLOW_GREEN); pQuality->Set_Name(CSG_String::Format("%s [%s]", _TL("Classification Quality"), CSG_Classifier_Supervised::Get_Name_of_Quality(Parameters("METHOD")->asInt()).c_str())); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CGrid_Value_Replace::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pGrid = Parameters("OUTPUT")->asGrid(); if( !pGrid || pGrid == Parameters("INPUT")->asGrid() ) { pGrid = Parameters("INPUT")->asGrid(); } else { pGrid->Assign(Parameters("INPUT")->asGrid()); DataObject_Set_Parameters(pGrid, Parameters("INPUT")->asGrid()); pGrid->Fmt_Name("%s [%s]", Parameters("INPUT")->asGrid()->Get_Name(), _TL("Changed")); } //----------------------------------------------------- int Method = Parameters("METHOD")->asInt(); CSG_Table LUT; switch( Method ) { default: LUT.Create(*Parameters("IDENTITY")->asTable()); break; case 1: LUT.Create(*Parameters("RANGE" )->asTable()); break; case 2: LUT.Create( Parameters("RANGE" )->asTable()); if( SG_UI_Get_Window_Main() // gui only && DataObject_Get_Parameter(Parameters("GRID" )->asGrid(), "LUT") && DataObject_Get_Parameter(Parameters("INPUT")->asGrid(), "LUT") ) { CSG_Table LUTs[2]; LUTs[0].Create(*DataObject_Get_Parameter(Parameters("GRID" )->asGrid(), "LUT")->asTable()); LUTs[1].Create(*DataObject_Get_Parameter(Parameters("INPUT")->asGrid(), "LUT")->asTable()); for(int i=0; i<LUTs[0].Get_Count(); i++) { CSG_String Name = LUTs[0][i].asString(1); for(int j=LUTs[1].Get_Count()-1; j>=0; j--) { if( !Name.Cmp(LUTs[1][j].asString(1)) ) { CSG_Table_Record *pReplace = LUT.Add_Record(); pReplace->Set_Value(0, LUTs[0][i].asDouble(3)); pReplace->Set_Value(1, LUTs[1][j].asDouble(3)); pReplace->Set_Value(2, LUTs[1][j].asDouble(4)); LUTs[1].Del_Record(j); break; } } } for(int j=0; j<LUTs[1].Get_Count(); j++) { LUTs[0].Add_Record(LUTs[1].Get_Record(j)); } DataObject_Add(pGrid); CSG_Parameter *pLUT = DataObject_Get_Parameter(pGrid, "LUT"); pLUT->asTable()->Assign_Values(&LUTs[0]); DataObject_Set_Parameter(pGrid, pLUT); } break; } //----------------------------------------------------- if( LUT.Get_Count() == 0 ) { Error_Set(_TL("empty look-up table, nothing to replace")); return( false ); } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #ifndef _DEBUG #pragma omp parallel for #endif for(int x=0; x<Get_NX(); x++) { double Value = pGrid->asDouble(x, y); for(int i=0; i<LUT.Get_Count(); i++) { if( Method == 0 ) { if( LUT[i].asDouble(1) == Value ) { pGrid->Set_Value(x, y, LUT[i].asDouble(0)); break; } } else { if( LUT[i].asDouble(1) <= Value && Value <= LUT[i].asDouble(2) ) { pGrid->Set_Value(x, y, LUT[i].asDouble(0)); break; } } } } } //----------------------------------------------------- if( pGrid == Parameters("INPUT")->asGrid() ) { DataObject_Update(pGrid); } return( true ); }
//--------------------------------------------------------- bool CWMS_Import::Get_Map(wxHTTP *pServer, const CSG_String &Directory, CWMS_Capabilities &Cap) { bool bResult = false; int i, n; CSG_Rect r(Cap.m_Extent); CSG_Parameters p; //----------------------------------------------------- // if( Cap.m_MaxWidth > 2 && NX > Cap.m_MaxWidth ) NX = Cap.m_MaxWidth; // if( Cap.m_MaxHeight > 2 && NY > Cap.m_MaxHeight ) NY = Cap.m_MaxHeight; p.Add_Range (NULL , "X_RANGE" , _TL("X Range") , _TL(""), r.Get_XMin(), r.Get_XMax(), r.Get_XMin(), r.Get_XRange() > 0.0, r.Get_XMax(), r.Get_XRange() > 0.0); p.Add_Range (NULL , "Y_RANGE" , _TL("Y Range") , _TL(""), r.Get_YMin(), r.Get_YMax(), r.Get_YMin(), r.Get_YRange() > 0.0, r.Get_YMax(), r.Get_YRange() > 0.0); p.Add_Value (NULL , "CELLSIZE", _TL("Cellsize") , _TL(""), PARAMETER_TYPE_Double, r.Get_XRange() / 2001.0, 0.0, true); p.Add_Choice(NULL , "FORMAT" , _TL("Format") , _TL(""), Cap.m_Formats); p.Add_Choice(NULL , "PROJ" , _TL("Projections"), _TL(""), Cap.m_Projections); CSG_Parameter *pNode = p("FORMAT"); for(i=0; i<pNode->asChoice()->Get_Count(); i++) { CSG_String s(pNode->asChoice()->Get_Item(i)); if( !s.CmpNoCase(SG_T("image/png")) ) pNode->Set_Value(i); } for(i=0; i<Cap.m_Layers_Name.Get_Count(); i++) { p.Add_Value(NULL, Cap.m_Layers_Name[i], Cap.m_Layers_Title[i], "", PARAMETER_TYPE_Bool, false); } //----------------------------------------------------- if( pServer && Dlg_Parameters(&p, _TL("WMS Import")) ) { int NX, NY; double Cellsize; CSG_String Layers, Format; //------------------------------------------------- r.Assign( p("X_RANGE")->asRange()->Get_LoVal(), p("Y_RANGE")->asRange()->Get_LoVal(), p("X_RANGE")->asRange()->Get_HiVal(), p("Y_RANGE")->asRange()->Get_HiVal() ); Cellsize = p("CELLSIZE") ->asDouble(); NX = 1 + (int)(r.Get_XRange() / Cellsize); NY = 1 + (int)(r.Get_YRange() / Cellsize); //------------------------------------------------- Layers.Clear(); for(i=0, n=0; i<Cap.m_Layers_Name.Get_Count(); i++) { if( p(Cap.m_Layers_Name[i])->asBool() ) { if( n++ > 0 ) Layers += ","; Layers += Cap.m_Layers_Name[i]; } } if( n == 0 ) { return( false ); } //------------------------------------------------- wxBitmapType tFormat; Format = p("FORMAT")->asString(); if( Format.Contains(SG_T("image/gif" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("image/jpeg")) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("image/png" )) ) tFormat = wxBITMAP_TYPE_PNG ; else if( Format.Contains(SG_T("image/wbmp")) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/bmp" )) ) tFormat = wxBITMAP_TYPE_BMP ; else if( Format.Contains(SG_T("image/tiff")) ) tFormat = wxBITMAP_TYPE_TIF ; else if( Format.Contains(SG_T("GIF" )) ) tFormat = wxBITMAP_TYPE_GIF ; else if( Format.Contains(SG_T("JPEG" )) ) tFormat = wxBITMAP_TYPE_JPEG; else if( Format.Contains(SG_T("PNG" )) ) tFormat = wxBITMAP_TYPE_PNG ; else { return( false ); } //------------------------------------------------- CSG_String sRequest(Directory); sRequest += SG_T("?SERVICE=WMS"); sRequest += SG_T("&VERSION=") + Cap.m_Version; sRequest += SG_T("&REQUEST=GetMap"); sRequest += SG_T("&LAYERS=") + Layers; if( Cap.m_Projections.Length() > 0 ) sRequest += CSG_String(S_SRS(Cap.m_Version)) + p("PROJ")->asString(); sRequest += SG_T("&FORMAT=") + Format; sRequest += CSG_String::Format(SG_T("&WIDTH=%d&HEIGHT=%d"), NX, NY); sRequest += CSG_String::Format(SG_T("&BBOX=%f,%f,%f,%f"), r.m_rect.xMin, r.m_rect.yMin, r.m_rect.xMax, r.m_rect.yMax); Message_Add(sRequest, true); //------------------------------------------------- wxInputStream *pStream; if( (pStream = pServer->GetInputStream(sRequest.c_str())) == NULL ) { Message_Add(_TL("could not open GetMap stream")); } else { wxImage Image; if( Image.LoadFile(*pStream, tFormat) == false ) { Message_Add(_TL("could not read image")); CSG_String s = SG_T("\n"); pStream->SeekI(0, wxFromStart); while( !pStream->Eof() ) { s += (char)pStream->GetC(); } Message_Add(s); } else { CSG_Grid *pGrid = SG_Create_Grid(SG_DATATYPE_Int, Image.GetWidth(), Image.GetHeight(), Cellsize, r.m_rect.xMin, r.m_rect.yMin); for(int y=0, yy=pGrid->Get_NY()-1; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++, yy--) { for(int x=0; x<pGrid->Get_NX(); x++) { pGrid->Set_Value(x, y, SG_GET_RGB(Image.GetRed(x, yy), Image.GetGreen(x, yy), Image.GetBlue(x, yy))); } } //----------------------------------------- pGrid->Set_Name(Cap.m_Title); Parameters("MAP")->Set_Value(pGrid); DataObject_Set_Colors(pGrid, 100, SG_COLORS_BLACK_WHITE); CSG_Parameters Parms; if( DataObject_Get_Parameters(pGrid, Parms) && Parms("COLORS_TYPE") ) { Parms("COLORS_TYPE")->Set_Value(3); // Color Classification Type: RGB DataObject_Set_Parameters(pGrid, Parms); } bResult = true; } delete(pStream); } } return( bResult ); }
//--------------------------------------------------------- bool CCMD_Module::_Get_Parameters(CSG_Parameters *pParameters) { if( !pParameters || m_CMD.Parse(false) != 0 ) { return( false ); } //----------------------------------------------------- int i; for(i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); if( pParameter->is_Input() ) { // nop now, loading options first } else if( pParameter->is_Output() ) { if( pParameter->is_DataObject() && pParameter->is_Optional() && !pParameter->asDataObject() && m_CMD.Found(_Get_ID(pParameter)) ) { pParameter->Set_Value(DATAOBJECT_CREATE); } } else if( pParameter->is_Option() && !pParameter->is_Information() ) { long l; double d; wxString s; switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_Parameters: _Get_Parameters(pParameter->asParameters()); break; case PARAMETER_TYPE_Bool: pParameter->Set_Value(m_CMD.Found(_Get_ID(pParameter)) ? 1 : 0); break; case PARAMETER_TYPE_Int: if( m_CMD.Found(_Get_ID(pParameter), &l) ) { pParameter->Set_Value((int)l); } break; case PARAMETER_TYPE_Choice: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( s.ToLong(&l) ) { pParameter->Set_Value((int)l); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_Double: case PARAMETER_TYPE_Degree: if( m_CMD.Found(_Get_ID(pParameter), &s) && s.ToDouble(&d) ) { pParameter->Set_Value(d); } break; case PARAMETER_TYPE_Range: if( m_CMD.Found(_Get_ID(pParameter, wxT("MIN")), &s) && s.ToDouble(&d) ) { pParameter->asRange()->Set_LoVal(d); } if( m_CMD.Found(_Get_ID(pParameter, wxT("MAX")), &s) && s.ToDouble(&d) ) { pParameter->asRange()->Set_HiVal(d); } break; case PARAMETER_TYPE_String: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { pParameter->Set_Value(CSG_String(&s)); } break; case PARAMETER_TYPE_Text: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { CSG_File Stream; if( Stream.Open(CSG_String(&s)) ) { CSG_String t; Stream.Read(t, Stream.Length()); pParameter->Set_Value(t.c_str()); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_FilePath: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( pParameter->asFilePath()->is_Multiple() ) { s.Prepend(wxT("\"")); s.Replace(wxT(";"), wxT("\" \"")); s.Append (wxT("\"")); } pParameter->Set_Value(CSG_String(&s)); } break; case PARAMETER_TYPE_FixedTable: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { CSG_Table Table(&s); pParameter->asTable()->Assign_Values(&Table); } break; case PARAMETER_TYPE_Grid_System: if( pParameter->Get_Children_Count() == 0 ) { long nx, ny; double d, x, y; if( !m_CMD.Found(_Get_ID(pParameter, wxT("NX")), &nx) || !m_CMD.Found(_Get_ID(pParameter, wxT("NY")), &ny) || !m_CMD.Found(_Get_ID(pParameter, wxT( "X")), &s) || !s.ToDouble(&x) || !m_CMD.Found(_Get_ID(pParameter, wxT( "Y")), &s) || !s.ToDouble(&y) || !m_CMD.Found(_Get_ID(pParameter, wxT( "D")), &s) || !s.ToDouble(&d) ) { pParameter->asGrid_System()->Assign(-1, 0.0, 0.0, 0, 0); } else { pParameter->asGrid_System()->Assign(d, x, y, (int)nx, (int)ny); } } break; } } } m_pModule->Update_Parameter_States(); //----------------------------------------------------- for(i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); if( pParameter->is_Input() ) { if( !_Load_Input(pParameters->Get_Parameter(i)) ) { CMD_Print_Error(pParameters->Get_Parameter(i)->Get_Name()); return( false ); } } else if( pParameter->is_Option() && !pParameter->is_Information() ) { long l; wxString s; switch( pParameter->Get_Type() ) { case PARAMETER_TYPE_Table_Field: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { if( s.ToLong(&l) ) { pParameter->Set_Value((int)l); } else { pParameter->Set_Value(CSG_String(&s)); } } break; case PARAMETER_TYPE_Table_Fields: if( m_CMD.Found(_Get_ID(pParameter), &s) ) { pParameter->Set_Value(CSG_String(&s)); } break; } } } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CCMD_Module::_Set_Parameters(CSG_Parameters *pParameters, bool bOptional) { if( !pParameters ) { return( false ); } //----------------------------------------------------- for(int i=0; i<pParameters->Get_Count(); i++) { CSG_Parameter *pParameter = pParameters->Get_Parameter(i); wxString Description = pParameter->Get_Description( PARAMETER_DESCRIPTION_NAME|PARAMETER_DESCRIPTION_TYPE|PARAMETER_DESCRIPTION_PROPERTIES, SG_T("\n\t") ).c_str(); Description.Replace(wxT("\xb2"), wxT("2")); // unicode problem: quick'n'dirty bug fix, to be replaced if( pParameter->is_Input() || pParameter->is_Output() ) { m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_NEEDS_SEPARATOR | (pParameter->is_Optional() || pParameter->is_Output() || bOptional ? wxCMD_LINE_PARAM_OPTIONAL : wxCMD_LINE_OPTION_MANDATORY )); } else if( pParameter->is_Option() && !pParameter->is_Information() ) { switch( pParameter->Get_Type() ) { default: break; case PARAMETER_TYPE_Parameters: _Set_Parameters(pParameter->asParameters(), true); break; case PARAMETER_TYPE_Bool: m_CMD.AddSwitch(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Int: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Choice: case PARAMETER_TYPE_Table_Field: case PARAMETER_TYPE_Table_Fields: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Double: case PARAMETER_TYPE_Degree: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Range: m_CMD.AddOption(_Get_ID(pParameter, wxT("MIN")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT("MAX")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_String: case PARAMETER_TYPE_Text: case PARAMETER_TYPE_FilePath: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_FixedTable: m_CMD.AddOption(_Get_ID(pParameter), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); break; case PARAMETER_TYPE_Grid_System: if( pParameter->Get_Children_Count() == 0 ) { m_CMD.AddOption(_Get_ID(pParameter, wxT("NX")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT("NY")), wxEmptyString, Description, wxCMD_LINE_VAL_NUMBER, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "X")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "Y")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); m_CMD.AddOption(_Get_ID(pParameter, wxT( "D")), wxEmptyString, Description, wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL); } break; } } } return( true ); }
//--------------------------------------------------------- bool CGrid_CVA::On_Execute(void) { //----------------------------------------------------- CSG_Parameter_Grid_List *pA = Parameters("A")->asGridList(); CSG_Parameter_Grid_List *pB = Parameters("B")->asGridList(); CSG_Parameter_Grid_List *pC = Parameters("C")->asGridList(); if( pA->Get_Grid_Count() != pB->Get_Grid_Count() ) { Error_Set(_TL("number of initial and final state grids differs")); return( false ); } if( pA->Get_Grid_Count() == 0 ) { Error_Set(_TL("no grids in list")); return( false ); } //----------------------------------------------------- int n = pA->Get_Grid_Count(); bool bAngle = Parameters("ANGLE")->asBool() && n == 2; bool bC_Out = Parameters("C_OUT")->asBool(); CSG_Grid *pDist = Parameters("DIST")->asGrid(); CSG_Grid *pDir = Parameters("DIR" )->asGrid(); //----------------------------------------------------- pC->Del_Items(); if( bC_Out ) { for(int i=0; i<n; i++) { CSG_Grid *pGrid = SG_Create_Grid(Get_System()); pGrid->Fmt_Name("%s %01d", _TL("Change Vector"), i + 1); pC->Add_Item(pGrid); } } //----------------------------------------------------- CSG_Parameter *pLUT; CSG_Colors Colors; Colors.Set_Count(100); Colors.Set_Ramp(SG_GET_RGB(255, 255, 255), SG_GET_RGB( 0, 127, 127), 0, Colors.Get_Count() / 2); Colors.Set_Ramp(SG_GET_RGB( 0, 127, 127), SG_GET_RGB(255, 0, 0), Colors.Get_Count() / 2, Colors.Get_Count()); DataObject_Set_Colors(pDist, Colors); if( (pLUT = DataObject_Get_Parameter(pDir, "LUT")) == NULL || pLUT->asTable() == NULL || bAngle ) { Colors.Set_Default(100); Colors.Set_Ramp_Brighness(255, 0, 0, Colors.Get_Count() / 2); Colors.Set_Ramp_Brighness( 0, 255, Colors.Get_Count() / 2, Colors.Get_Count()); DataObject_Set_Colors(pDir, Colors); DataObject_Set_Parameter(pDir, "COLORS_TYPE", 2); } else { pLUT->asTable()->Del_Records(); for(int i=0, nClasses=(int)pow(2.0, n); i<nClasses; i++) { CSG_String s; for(int j=0; j<n; j++) { s += i & (int)pow(2.0, j) ? '+' : '-'; } CSG_Table_Record *pClass = pLUT->asTable()->Add_Record(); pClass->Set_Value(1, s); pClass->Set_Value(3, i); pClass->Set_Value(4, i); } Colors.Set_Count(pLUT->asTable()->Get_Count()); Colors.Random(); for(int c=0; c<pLUT->asTable()->Get_Count(); c++) { pLUT->asTable()->Get_Record(c)->Set_Value(0, Colors.Get_Color(c)); } DataObject_Set_Parameter(pDir, pLUT); DataObject_Set_Parameter(pDir, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { bool bOkay; int i, j; double d; CSG_Vector v(n); for(i=0, bOkay=true; i<n && bOkay; i++) { if( pA->Get_Grid(i)->is_NoData(x, y) || pB->Get_Grid(i)->is_NoData(x, y) ) { bOkay = false; } else { v[i] = pB->Get_Grid(i)->asDouble(x, y) - pA->Get_Grid(i)->asDouble(x, y); } } //--------------------------------------------- if( bOkay ) { if( bAngle ) { d = atan2(v[0], v[1]); } else for(i=0, j=1, d=0.0; i<n; i++, j*=2) { if( v[i] >= 0.0 ) { d += j; } } pDist->Set_Value(x, y, v.Get_Length()); pDir ->Set_Value(x, y, d); for(i=0; i<n && bC_Out; i++) { pC->Get_Grid(i)->Set_Value(x, y, v[i]); } } //--------------------------------------------- else { pDist->Set_NoData(x, y); pDir ->Set_NoData(x, y); for(i=0; i<n && bC_Out; i++) { pC->Get_Grid(i)->Set_NoData(x, y); } } } } return( true ); }
//--------------------------------------------------------- bool CCMD_Module::_Save_Output(CSG_Parameters *pParameters) { for(int j=0; j<pParameters->Get_Count(); j++) { wxString FileName; CSG_Parameter *pParameter = pParameters->Get_Parameter(j); //------------------------------------------------- if( pParameter->is_Input() ) { if( pParameter->is_DataObject() ) { CSG_Data_Object *pObject = pParameter->asDataObject(); if( pObject && pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) ) { pObject->Save(pObject->Get_File_Name()); } } else if( pParameter->is_DataObject_List() ) { for(int i=0; i<pParameter->asList()->Get_Count(); i++) { CSG_Data_Object *pObject = pParameter->asList()->asDataObject(i); if( pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) ) { pObject->Save(pObject->Get_File_Name()); } } } } //------------------------------------------------- else if( pParameter->is_Output() && m_CMD.Found(_Get_ID(pParameter), &FileName) && FileName.Length() > 0 ) { if( pParameter->is_DataObject() ) { if( pParameter->asDataObject() ) { pParameter->asDataObject()->Save(&FileName); } } else if( pParameter->is_DataObject_List() ) { CSG_Strings FileNames; while( FileName.Length() > 0 ) { CSG_String s(&FileName); s = s.BeforeFirst(';'); if( s.Length() > 0 ) { FileNames += s; FileName = FileName.AfterFirst(';'); } else { FileNames += &FileName; FileName .Clear(); } } int nFileNames = pParameter->asList()->Get_Count() <= FileNames.Get_Count() ? FileNames.Get_Count() : FileNames.Get_Count() - 1; for(int i=0; i<pParameter->asList()->Get_Count(); i++) { if( i < nFileNames ) { pParameter->asList()->asDataObject(i)->Save(FileNames[i]); } else { pParameter->asList()->asDataObject(i)->Save(CSG_String::Format(SG_T("%s_%0*d"), FileNames[FileNames.Get_Count() - 1].c_str(), SG_Get_Digit_Count(pParameter->asList()->Get_Count()), 1 + i - nFileNames )); } } } } } return( true ); }
//--------------------------------------------------------- bool CSoil_Texture::On_Execute(void) { //----------------------------------------------------- CSG_Grid *pSand = Parameters("SAND" )->asGrid(); CSG_Grid *pSilt = Parameters("SILT" )->asGrid(); CSG_Grid *pClay = Parameters("CLAY" )->asGrid(); CSG_Grid *pClass = Parameters("TEXTURE")->asGrid(); CSG_Grid *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 ); } //----------------------------------------------------- pClass->Set_NoData_Value(-1.0); CSG_Parameter *pLUT = DataObject_Get_Parameter(pClass, "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].Key); pClass->Set_Value(3, iClass); pClass->Set_Value(4, iClass); } while( pClasses->Get_Count() > 12 ) { pClasses->Del_Record(pClasses->Get_Count() - 1); } DataObject_Set_Parameter(pClass, pLUT); // Lookup Table DataObject_Set_Parameter(pClass, "COLORS_TYPE", 1); // Color Classification Type: Lookup Table } //----------------------------------------------------- for(int y=0; y<Get_NY() && Set_Progress(y); y++) { #pragma omp parallel for for(int x=0; x<Get_NX(); x++) { if( (pSand && pSand->is_NoData(x, y)) || (pSilt && pSilt->is_NoData(x, y)) || (pClay && pClay->is_NoData(x, y)) ) { SG_GRID_PTR_SAFE_SET_NODATA(pClass, x, y); SG_GRID_PTR_SAFE_SET_NODATA(pSum , x, y); } else { int Class = -1; double Sum = 100.0; if( pSand && pSilt && pClay ) { Class = Get_Texture(pSand->asDouble(x, y), pSilt->asDouble(x, y), pClay->asDouble(x, y), Sum); } else if( !pSilt ) { Class = Get_Texture_SandClay(pSand->asDouble(x, y), pClay->asDouble(x, y)); } else if( !pClay ) { Class = Get_Texture_SandSilt(pSand->asDouble(x, y), pSilt->asDouble(x, y)); } else if( !pSand ) { Class = Get_Texture_SiltClay(pSilt->asDouble(x, y), pClay->asDouble(x, y)); } SG_GRID_PTR_SAFE_SET_VALUE(pClass, x, y, Class); SG_GRID_PTR_SAFE_SET_VALUE(pSum , x, y, Sum ); } } } //----------------------------------------------------- return( true ); }