//--------------------------------------------------------- bool CGrid_Volume::On_Execute(void) { int x, y, Method; double Level, Volume, z; CSG_Grid *pGrid; CSG_String s; //----------------------------------------------------- pGrid = Parameters("GRID") ->asGrid(); Level = Parameters("LEVEL") ->asDouble(); Method = Parameters("METHOD") ->asInt(); //----------------------------------------------------- for(y=0, Volume=0.0; y<Get_NY() && Set_Progress(y); y++) { for(x=0; x<Get_NX(); x++) { if( !pGrid->is_NoData(x, y) ) { z = pGrid->asDouble(x, y) - Level; switch( Method ) { case 0: // Count Only Above Base Level if( z > 0.0 ) { Volume += z; } break; case 1: // Count Only Below Base Level if( z < 0.0 ) { Volume -= z; } break; case 2: // Subtract Volumes Below Base Level Volume += z; break; case 3: // Add Volumes Below Base Level Volume += fabs(z); break; } } } } //----------------------------------------------------- Volume *= pGrid->Get_Cellarea(); s.Printf(_TL("Volume: %f"), Volume); Message_Add(s); Message_Dlg(s, _TL("Grid Volume")); //----------------------------------------------------- return( true ); }
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
//--------------------------------------------------------- CTL_Merge::CTL_Merge(void) { //----------------------------------------------------- Set_Name (SG_T("Merge Translation Files")); Set_Author (SG_T("O. Conrad (c) 2010")); Set_Description (SG_T("")); //----------------------------------------------------- CSG_String Filter; Filter.Printf(SG_T("%s|*.lng;*.txt|%s|*.lng|%s|*.txt|%s|*.*"), SG_T("All recognized Files"), SG_T("SAGA Translation File (*.lng)"), SG_T("Text Files (*.txt)"), SG_T("All Files") ); //----------------------------------------------------- Parameters.Add_FilePath( NULL , "TARGET" , SG_T("Target"), SG_T(""), Filter, NULL, true ); Parameters.Add_FilePath( NULL , "FILES" , SG_T("Files"), SG_T(""), Filter, NULL, false, false, true ); }
//--------------------------------------------------------- bool CSG_MetaData::Load(const CSG_String &File, const SG_Char *Extension) { Destroy(); //----------------------------------------------------- if( File.Find("http://") == 0 ) { CSG_String s(File.Right(File.Length() - CSG_String("http://").Length())); return( Load_HTTP(s.BeforeFirst('/'), s.AfterFirst('/')) ); } //----------------------------------------------------- wxXmlDocument XML; if( SG_File_Exists(SG_File_Make_Path(NULL, File, Extension)) && XML.Load(SG_File_Make_Path(NULL, File, Extension).c_str()) ) { _Load(XML.GetRoot()); return( true ); } //----------------------------------------------------- return( false ); }
//--------------------------------------------------------- CSG_String CSG_MetaData::asText(int Flags) const { CSG_String s; if( Flags == 0 ) { for(int i=0; i<Get_Children_Count(); i++) { s += Get_Child(i)->Get_Name() + ":\t" + Get_Child(i)->Get_Content() + "\n"; } } else { wxXmlDocument XML; wxXmlNode *pRoot = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, Get_Name().c_str()); XML.SetRoot(pRoot); _Save(pRoot); wxStringOutputStream Stream; XML.Save(Stream); s = &Stream.GetString(); if( Flags == 2 ) // remove <xml> { s = s.AfterFirst('\n'); } } return( s ); }
//--------------------------------------------------------- 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 CPointCloud_From_Text_File::Get_Data_Type(TSG_Data_Type &Type, const CSG_String &Value) { int iType; if( Value.asInt(iType) ) { switch( iType ) { case 0: Type = SG_DATATYPE_Char ; return( true ); case 1: Type = SG_DATATYPE_Short ; return( true ); case 2: Type = SG_DATATYPE_Int ; return( true ); case 3: Type = SG_DATATYPE_Float ; return( true ); case 4: Type = SG_DATATYPE_Double; return( true ); case 5: Type = SG_DATATYPE_String; return( true ); } } if( !Value.CmpNoCase("char" ) ) { Type = SG_DATATYPE_Char ; return( true ); } if( !Value.CmpNoCase("short" ) ) { Type = SG_DATATYPE_Short ; return( true ); } if( !Value.CmpNoCase("int" ) ) { Type = SG_DATATYPE_Int ; return( true ); } if( !Value.CmpNoCase("float" ) ) { Type = SG_DATATYPE_Float ; return( true ); } if( !Value.CmpNoCase("double") ) { Type = SG_DATATYPE_Double; return( true ); } if( !Value.CmpNoCase("string") ) { Type = SG_DATATYPE_String; return( true ); } return( false ); }
//--------------------------------------------------------- bool CShapes_SRID_Update::On_Execute(void) { if( !Get_Connection()->has_PostGIS() ) { Error_Set(_TL("no PostGIS layer")); return( false ); } //----------------------------------------------------- CSG_String Select; CSG_Table Table; Select.Printf(SG_T("f_table_name='%s'"), Parameters("TABLES")->asString()); if( !Get_Connection()->Table_Load(Table, "geometry_columns", "*", Select) || Table.Get_Count() != 1 ) { return( false ); } Select.Printf(SG_T("SELECT UpdateGeometrySRID('%s', '%s', %d)"), Parameters("TABLES")->asString(), Table[0].asString("f_geometry_column"), Get_SRID() ); //----------------------------------------------------- if( !Get_Connection()->Execute(Select) ) { return( false ); } return( true ); }
//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::_WKT_Read_Polygon(const CSG_String &Text, CSG_Shape *pShape) { CSG_String Part; for(int i=0, Level=-2; i<(int)Text.Length(); i++) { if( Text[i] == '(' ) { Level++; } else if( Text[i] == ')' ) { if( Level == 0 ) { Part += Text[i]; _WKT_Read_Parts(Part, pShape); Part.Clear(); } Level--; } if( Level >= 0 ) { Part += Text[i]; } } return( pShape->Get_Part_Count() > 0 ); }
void CSG_Doc_SVG::Draw_Text(double x, double y, const SG_Char *Text, int Color, const SG_Char* Font, double dSize, TSG_SVG_Alignment iAlignment) { CSG_String sAlignments[] = {SG_T(""), SG_T("middle"), SG_T("end")}; CSG_String sSize; sSize.Append(SG_Get_String(dSize,2)); sSize.Append(g_Unit); m_sSVGCode.Append(SG_T("<text ")); _AddAttribute(SG_T("x"), x); _AddAttribute(SG_T("y"), y); _AddAttribute(SG_T("font-family"), Font); _AddAttribute(SG_T("fill"), _Get_SVGColor(Color)); _AddAttribute(SG_T("font-size"), sSize); _AddAttribute(SG_T("text-anchor"), sAlignments[iAlignment]); m_sSVGCode.Append(SG_T(">\n")); m_sSVGCode.Append(Text); m_sSVGCode.Append(SG_T("</text>")); }
bool Cihacres_elev::_CreateDialog3() { CSG_String s; CSG_Parameters P; // used to add Parameters in the second dialog CSG_Parameter *pNode; // Dialog design P.Set_Name(_TL("Choose Time Range")); s.Printf(SG_T("Node1"), 1); pNode = P.Add_Node(NULL,s,SG_T("Time Range"),_TL("")); s.Printf(SG_T("FDAY") , 1-1); P.Add_String(pNode,s,_TL("First Day"),_TL(""), m_p_InputTable->Get_Record(0)->asString(m_dateField)); s.Printf(SG_T("LDAY") , 1-2); P.Add_String(pNode,s,_TL("Last Day"),_TL(""), m_p_InputTable->Get_Record(m_p_InputTable->Get_Record_Count()-1)->asString(m_dateField)); if( SG_UI_Dlg_Parameters(&P, _TL("Choose Time Range")) ) { /////////////////////////////////////////////////////////////// // // ASSIGN DATA FROM SECOND DIALOG // /////////////////////////////////////////////////////////////// m_date1 = P(CSG_String::Format(SG_T("FDAY"),m_dateField).c_str())->asString(); m_date2 = P(CSG_String::Format(SG_T("LDAY"),m_streamflowField).c_str())->asString(); return(true); } return(false); }
//--------------------------------------------------------- double SG_Degree_To_Double(const CSG_String &String) { double d, h, s, sig; sig = 1.0; d = h = s = 0.0; if( String.BeforeFirst('\xb0').asDouble(d) ) { if( d < 0.0 ) { sig = -1.0; d = -d; } String.AfterFirst('\xb0').asDouble(h); String.AfterFirst('\'' ).asDouble(s); } else { String.asDouble(d); } return( sig * (d + h / 60.0 + s / (60.0 * 60.0)) ); }
//--------------------------------------------------------- CSG_String SG_Double_To_Degree(double Value) { SG_Char c; int d, h; double s; CSG_String String; if( Value < 0.0 ) { Value = -Value; c = SG_T('-'); } else { c = SG_T('+'); } Value = fmod(Value, 360.0); d = (int)Value; Value = 60.0 * (Value - d); h = (int)Value; Value = 60.0 * (Value - h); s = Value; String.Printf(SG_T("%c%03d\xb0%02d'%02.*f''"), c, d, h, SG_Get_Significant_Decimals(s), s); return( String ); }
//--------------------------------------------------------- bool CGridding_Spline_MBA_Grid::_Get_Difference(CSG_Grid &Phi) { int xPoint, yPoint, nErrors; double x, y, z, zMax, zMean; TSG_Point_Z p; CSG_String s; //----------------------------------------------------- for(yPoint=0, p.y=m_Points.Get_YMin(), zMax=0.0, nErrors=0, zMean=0.0; yPoint<m_Points.Get_NY() && Set_Progress(yPoint, m_Points.Get_NY()); yPoint++, p.y+=m_Points.Get_Cellsize()) { for(xPoint=0, p.x=m_Points.Get_XMin(); xPoint<m_Points.Get_NX(); xPoint++, p.x+=m_Points.Get_Cellsize()) { if( !m_Points.is_NoData(xPoint, yPoint) ) { x = (p.x - Phi.Get_XMin()) / Phi.Get_Cellsize(); y = (p.y - Phi.Get_YMin()) / Phi.Get_Cellsize(); z = m_Points.asDouble(xPoint, yPoint) - BA_Get_Value(x, y, Phi); m_Points.Set_Value(xPoint, yPoint, z); if( (z = fabs(z)) > m_Epsilon ) { nErrors ++; zMean += fabs(z); if( fabs(z) > zMax ) { zMax = fabs(z); } } else { // m_Points.Set_Value(xPoint, yPoint, 0.0); m_Points.Set_NoData(xPoint, yPoint); } } } } if( nErrors > 0 ) { zMean /= nErrors; } //----------------------------------------------------- int i = 1 + (int)(0.5 + log(Phi.Get_NX() - 4.0) / log(2.0)); s.Printf(SG_T("%s:%d, %s:%d, %s:%f, %s:%f"), _TL("level"), i, _TL("error"), nErrors, _TL("max") , zMax, _TL("mean") , zMean ); Process_Set_Text(s); Message_Add (s); return( zMax >= m_Epsilon && i < m_Level_Max && Process_Get_Okay(false) ); }
//--------------------------------------------------------- bool CSG_mRMR::Set_Data(CSG_Table &Data, int ClassField, double Threshold) { if( !Get_Memory(Data.Get_Field_Count(), Data.Get_Count()) ) { return( false ); } //----------------------------------------------------- if( ClassField < 0 || ClassField >= m_nVars ) { ClassField = 0; } Data.Set_Index(ClassField, TABLE_INDEX_Ascending); CSG_String s; for(int iSample=0, Class=0; iSample<m_nSamples; iSample++) { double *pData = m_Samples[iSample] = m_Samples[0] + iSample * m_nVars; if( s.Cmp(Data[iSample].asString(ClassField)) ) { s = Data[iSample].asString(ClassField); Class++; } *pData++ = Class; for(int iVar=0; iVar<m_nVars; iVar++) { if( iVar != ClassField ) { *pData++ = Data[iSample].asDouble(iVar); } } } Data.Del_Index(); m_VarNames += Data.Get_Field_Name(ClassField); for(int iVar=0; iVar<m_nVars; iVar++) { if( iVar != ClassField ) { m_VarNames += Data.Get_Field_Name(iVar); } } //----------------------------------------------------- if( Threshold >= 0.0 ) // discretization { Discretize(Threshold); } return( true ); }
//--------------------------------------------------------- void CGrid_Cluster_Analysis::Save_Statistics(CSG_Parameter_Grid_List *pGrids, bool bNormalize, const CSG_Cluster_Analysis &Analysis) { int iCluster, iFeature; CSG_String s; CSG_Table *pTable = Parameters("STATISTICS")->asTable(); pTable->Destroy(); pTable->Set_Name(_TL("Cluster Analysis")); pTable->Add_Field(_TL("ClusterID") , SG_DATATYPE_Int); pTable->Add_Field(_TL("Elements") , SG_DATATYPE_Int); pTable->Add_Field(_TL("Std.Dev.") , SG_DATATYPE_Double); s.Printf(SG_T("\n%s:\t%d \n%s:\t%ld \n%s:\t%d \n%s:\t%d \n%s:\t%f\n\n%s\t%s\t%s"), _TL("Number of Iterations") , Analysis.Get_Iteration(), _TL("Number of Elements") , Analysis.Get_nElements(), _TL("Number of Variables") , Analysis.Get_nFeatures(), _TL("Number of Clusters") , Analysis.Get_nClusters(), _TL("Standard Deviation") , sqrt(Analysis.Get_SP()), _TL("Cluster"), _TL("Elements"), _TL("Std.Dev.") ); for(iFeature=0; iFeature<Analysis.Get_nFeatures(); iFeature++) { s += CSG_String::Format(SG_T("\t%s"), pGrids->asGrid(iFeature)->Get_Name()); pTable->Add_Field(pGrids->asGrid(iFeature)->Get_Name(), SG_DATATYPE_Double); } Message_Add(s); for(iCluster=0; iCluster<Analysis.Get_nClusters(); iCluster++) { s.Printf(SG_T("\n%d\t%d\t%f"), iCluster, Analysis.Get_nMembers(iCluster), sqrt(Analysis.Get_Variance(iCluster))); CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, iCluster); pRecord->Set_Value(1, Analysis.Get_nMembers(iCluster)); pRecord->Set_Value(2, sqrt(Analysis.Get_Variance(iCluster))); for(iFeature=0; iFeature<Analysis.Get_nFeatures(); iFeature++) { double Centroid = Analysis.Get_Centroid(iCluster, iFeature); if( bNormalize ) { Centroid = pGrids->asGrid(iFeature)->Get_Mean() + Centroid * pGrids->asGrid(iFeature)->Get_StdDev(); } s += CSG_String::Format(SG_T("\t%f"), Centroid); pRecord->Set_Value(iFeature + 3, Centroid); } Message_Add(s, false); } }
//--------------------------------------------------------- bool CWKSP_Project::_Save_Data(CSG_MetaData &Entry, const wxString &ProjectDir, CSG_Data_Object *pDataObject, CSG_Parameters *pParameters) { if( !pDataObject || !pDataObject->Get_File_Name(false) || SG_STR_LEN(pDataObject->Get_File_Name(false)) == 0 ) { return( false ); } CSG_MetaData *pEntry = Entry.Add_Child("DATASET"); switch( pDataObject->Get_ObjectType() ) { default: return( false ); case SG_DATAOBJECT_TYPE_Grid : pEntry->Add_Property("type", "GRID" ); break; case SG_DATAOBJECT_TYPE_Grids : pEntry->Add_Property("type", "GRIDS" ); break; case SG_DATAOBJECT_TYPE_Table : pEntry->Add_Property("type", "TABLE" ); break; case SG_DATAOBJECT_TYPE_Shapes : pEntry->Add_Property("type", "SHAPES"); break; case SG_DATAOBJECT_TYPE_TIN : pEntry->Add_Property("type", "TIN" ); break; case SG_DATAOBJECT_TYPE_PointCloud: pEntry->Add_Property("type", "POINTS"); break; } if( wxFileExists(pDataObject->Get_File_Name(false)) ) { pEntry->Add_Child("FILE", SG_File_Get_Path_Relative(&ProjectDir, pDataObject->Get_File_Name(false))); } else if( pDataObject->Get_MetaData_DB().Get_Children_Count() > 0 ) { pEntry->Add_Child("FILE", pDataObject->Get_File_Name(false)); } else { return( false ); } if( pParameters ) { pParameters->DataObjects_Check(true); pParameters->Serialize(*pEntry->Add_Child("PARAMETERS"), true); //------------------------------------------------- pEntry = pEntry->Get_Child("PARAMETERS"); for(int i=0; i<pEntry->Get_Children_Count(); i++) { if( !pEntry->Get_Child(i)->Get_Name().CmpNoCase("DATA") ) { CSG_String File = pEntry->Get_Child(i)->Get_Content(); if( File.BeforeFirst(':').CmpNoCase("PGSQL") && SG_File_Exists(File) ) { pEntry->Get_Child(i)->Set_Content(SG_File_Get_Path_Relative(&ProjectDir, File.w_str())); } } } } return( true ); }
//--------------------------------------------------------- bool CSRTM30_Import::On_Execute(void) { char x_sTile[9][5] = { "W180", "W140", "W100", "W060", "W020", "E020", "E060", "E100", "E140" }, y_sTile[3][4] = { "S10", "N40", "N90" }; double dSize = 30.0 / (60.0 * 60.0); //----------------------------------------------------- int xTile, yTile; double xMin, xMax, yMin, yMax; TSG_Rect rOut, rTile; CSG_String sTile; CSG_Grid *pOut; //----------------------------------------------------- xMin = Parameters("XMIN")->asInt(); xMax = Parameters("XMAX")->asInt(); yMin = Parameters("YMIN")->asInt(); yMax = Parameters("YMAX")->asInt(); rOut.xMin = (180 + xMin) / 40.0 * X_WIDTH; rOut.xMax = rOut.xMin + (int)((xMax - xMin) / dSize); rOut.yMin = ( 60 + yMin) / 50.0 * Y_WIDTH; rOut.yMax = rOut.yMin + (int)((yMax - yMin) / dSize); //----------------------------------------------------- pOut = SG_Create_Grid(SG_DATATYPE_Short, (int)(rOut.xMax - rOut.xMin), (int)(rOut.yMax - rOut.yMin), dSize, xMin + 0.5 * dSize, yMin + 0.5 * dSize ); pOut->Set_NoData_Value(-9999); pOut->Assign_NoData(); pOut->Set_Name(SG_T("SRTM30")); pOut->Get_Projection().Create(SG_T("GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]")); //----------------------------------------------------- for(yTile=0, rTile.yMin=0, rTile.yMax=Y_WIDTH; yTile<3; yTile++, rTile.yMin+=Y_WIDTH, rTile.yMax+=Y_WIDTH) { for(xTile=0, rTile.xMin=0, rTile.xMax=X_WIDTH; xTile<9; xTile++, rTile.xMin+=X_WIDTH, rTile.xMax+=X_WIDTH) { sTile.Printf(SG_T("Tile: %s%s"), x_sTile[xTile], y_sTile[yTile]); Process_Set_Text(sTile); sTile.Printf(SG_T("%s%s%s.dem"), Parameters("PATH")->asString(), x_sTile[xTile], y_sTile[yTile]); Tile_Load(sTile, rTile, pOut, rOut); } } //----------------------------------------------------- Parameters("GRID")->Set_Value(pOut); return( true ); }
//--------------------------------------------------------- void SG_Flip_Decimal_Separators(CSG_String &String) { for(size_t i=0; i<String.Length(); i++) { switch( String[i] ) { case SG_T('.'): String.Set_Char(i, ','); break; case SG_T(','): String.Set_Char(i, '.'); break; } } }
int SG_Grid_Cache_Check(CSG_Grid_System &m_System, int nValueBytes) { if( SG_Grid_Cache_Get_Automatic() && m_System.Get_NCells() * nValueBytes > SG_Grid_Cache_Get_Threshold() ) { switch( SG_Grid_Cache_Get_Confirm() ) { default: break; case 1: { CSG_String s; s.Printf(SG_T("%s\n%s\n%s: %.2fMB"), LNG("Shall I activate file caching for new grid."), m_System.Get_Name(), LNG("Total memory size"), (m_System.Get_NCells() * nValueBytes) / (double)N_MEGABYTE_BYTES ); if( SG_UI_Dlg_Continue(s, LNG("Activate Grid File Cache?")) ) { // Memory_Type = GRID_MEMORY_Cache; return( SG_Grid_Cache_Get_Threshold() ); } } break; case 2: { CSG_Parameters p(NULL, LNG("Activate Grid File Cache?"), SG_T("")); p.Add_Value( NULL , SG_T("BUFFERSIZE") , LNG("Buffer Size [MB]"), SG_T(""), PARAMETER_TYPE_Double, SG_Grid_Cache_Get_Threshold_MB(), 0.0, true ); if( SG_UI_Dlg_Parameters(&p, LNG("Activate Grid File Cache?")) ) { // Memory_Type = GRID_MEMORY_Cache; // Set_Buffer_Size((int)(p(SG_T("BUFFERSIZE"))->asDouble() * N_MEGABYTE_BYTES)); return( (int)(p(SG_T("BUFFERSIZE"))->asDouble() * N_MEGABYTE_BYTES) ); } } break; } } return( 0 ); }
//--------------------------------------------------------- bool CTable_Enumerate::On_Execute(void) { int iField, iField_ID, iID, iRecord, old_Field; TSG_Table_Index_Order old_Order; CSG_String Value; CSG_Table *pTable, *pOutput; CSG_Table_Record *pRecord; //----------------------------------------------------- pTable = Parameters("INPUT") ->asTable(); pOutput = Parameters("OUTPUT") ->asTable(); iField = Parameters("FIELD") ->asInt(); //----------------------------------------------------- if( iField >= 0 && iField < pTable->Get_Field_Count() && pTable->Get_Record_Count() > 0 ) { if( pOutput != NULL && pOutput != pTable ) { pOutput->Create (*pTable); pOutput->Set_Name ( pTable->Get_Name()); pTable = pOutput; } //------------------------------------------------- pTable->Add_Field(_TL("ENUM_ID"), SG_DATATYPE_Int); iField_ID = pTable->Get_Field_Count() - 1; old_Order = pTable->Get_Index_Order(0); old_Field = pTable->Get_Index_Field(0); pTable->Set_Index(iField, TABLE_INDEX_Descending); Value = pTable->Get_Record_byIndex(0)->asString(iField); for(iRecord=0, iID=1; iRecord<pTable->Get_Record_Count(); iRecord++) { pRecord = pTable->Get_Record_byIndex(iRecord); if( Value.Cmp(pRecord->asString(iField)) ) { Value = pRecord->asString(iField); iID++; } pRecord->Set_Value(iField_ID, iID); } pTable->Set_Index(old_Field, old_Order); return( true ); } return( false ); }
//--------------------------------------------------------- bool CTable_Save::On_Execute(void) { bool bResult = false; CSG_Table *pTable = Parameters("TABLE")->asTable(); CSG_String Name = Parameters("NAME" )->asString(); if( Name.Length() == 0 ) Name = pTable->Get_Name(); //----------------------------------------------------- if( Get_Connection()->Table_Exists(Name) ) { Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("table already exists"), Name.c_str())); switch( Parameters("EXISTS")->asInt() ) { case 0: // abort export break; case 1: // replace existing table Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("dropping table"), Name.c_str())); if( !Get_Connection()->Table_Drop(Name, false) ) { Message_Add(CSG_String::Format(SG_T(" ...%s!"), _TL("failed"))); } else { bResult = Get_Connection()->Table_Save(Name, *pTable, Get_Constraints(Parameters("FLAGS")->asParameters(), pTable)); } break; case 2: // append records, if table structure allows Message_Add(CSG_String::Format(SG_T("%s: %s"), _TL("appending to existing table"), Name.c_str())); if( !(bResult = Get_Connection()->Table_Insert(Name, *pTable)) ) { Message_Add(CSG_String::Format(SG_T(" ...%s!"), _TL("failed"))); } break; } } else { bResult = Get_Connection()->Table_Save(Name, *pTable, Get_Constraints(Parameters("FLAGS")->asParameters(), pTable)); } //----------------------------------------------------- if( bResult ) { SG_UI_ODBC_Update(Get_Connection()->Get_Server()); } return( bResult ); }
//--------------------------------------------------------- bool CSG_MetaData::Load_HTTP(const CSG_String &Server, const CSG_String &Path, const SG_Char *Username, const SG_Char *Password) { Destroy(); //----------------------------------------------------- wxHTTP HTTP; if( Username && *Username ) { HTTP.SetUser (Username); } if( Password && *Password ) { HTTP.SetPassword(Password); } wxString s = Server.c_str(); if( s.Find("http://") == 0 ) { s = s.Right(s.Length() - wxString("http://").Length()); } if( !HTTP.Connect(s) ) { return( false ); } //----------------------------------------------------- s = Path.c_str(); if( s[0] != '/' ) { s.Prepend("/"); } wxInputStream *pStream = HTTP.GetInputStream(s); if( !pStream ) { return( false ); } wxXmlDocument XML; if( XML.Load(*pStream) ) { _Load(XML.GetRoot()); delete(pStream); return( true ); } delete(pStream); return( false ); }
//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::_WKT_Read_Parts(const CSG_String &Text, CSG_Shape *pShape) { CSG_String s = Text.AfterFirst('(').BeforeLast(')'); while( s.Length() > 0 ) { _WKT_Read_Points(s, pShape); s = s.AfterFirst(','); } return( pShape->Get_Part_Count() > 0 ); }
//--------------------------------------------------------- int CTL_Extract::Read_Text(const SG_Char *String, CSG_String &Text) { int n, Level; Text.Clear(); for(n=0, Level=-1; String[n]!='\0' && Level<2; n++) { if( Level < 0 ) { if( String[n] == '(' ) { Level = 0; } else if( isspace(String[n]) ) { Level = 2; // exit ! } } else if( Level == 0 ) { switch( String[n] ) { case '\"': Level = 1; break; case ')': Level = 2; break; } } else switch( String[n] ) { case '\"': Level = 0; break; case '\\': Text.Append(String[n++]); Text.Append(String[n]); break; default: Text.Append(String[n]); break; } } return( n ); }
void CSG_Doc_SVG::Draw_Polygon(CSG_Points &Points, int Fill_Color, int Line_Color, double Line_Width) { if( Points.Get_Count() > 2 ) { int i; CSG_String sPoints; CSG_String sWidth; for (i = 0; i < Points.Get_Count(); i++) { sPoints.Append(SG_Get_String(Points.Get_X(i),2)); sPoints.Append(SG_T(",")); sPoints.Append(SG_Get_String(Points.Get_Y(i),2)); sPoints.Append(SG_T(" ")); } m_sSVGCode.Append(SG_T("<polygon ")); _AddAttribute(SG_T("points"), sPoints); sWidth.Append(SG_Get_String(Line_Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Line_Color)); _AddAttribute(SG_T("fill"), _Get_SVGColor(Fill_Color)); m_sSVGCode.Append(SG_T("/>\n")); } }
void CSG_Doc_SVG::Draw_Line(CSG_Points &Points, double Width, int Color) { int i; CSG_String sPoints; CSG_String sWidth; for (i = 0; i < Points.Get_Count(); i++) { sPoints.Append(SG_Get_String(Points.Get_X(i),2)); sPoints.Append(SG_T(",")); sPoints.Append(SG_Get_String(Points.Get_Y(i),2)); sPoints.Append(SG_T(" ")); } m_sSVGCode.Append(SG_T("<polyline ")); _AddAttribute(SG_T("points"), sPoints); sWidth.Append(SG_Get_String(Width,2)); sWidth.Append(g_Unit); _AddAttribute(SG_T("stroke-width"), sWidth); _AddAttribute(SG_T("stroke"), _Get_SVGColor(Color)); _AddAttribute(SG_T("fill"), SG_T("none")); m_sSVGCode.Append(SG_T("/>\n")); }
//--------------------------------------------------------- void CMD_Print (const CSG_String &Text, const SG_Char *XML_Tag) { if( g_bXML ) { if( XML_Tag && XML_Tag[0] ) { SG_PRINTF(SG_T("<%s>%s</%s>\n"), XML_Tag, Text.c_str(), XML_Tag); } } else { SG_PRINTF(SG_T("%s\n"), Text.c_str()); } }
//--------------------------------------------------------- inline bool CXYZ_Import::Read_Values(CSG_File &Stream, double &x, double &y, double &z) { CSG_String sLine; if( Stream.Read_Line(sLine) ) { sLine.Trim(); if( sLine.asDouble(x) ) { sLine = sLine.AfterFirst(m_Separator); sLine.Trim(); if( sLine.asDouble(y) ) { sLine = sLine.AfterFirst(m_Separator); if( sLine.asDouble(z) ) { return( true ); } } } } return( false ); }
//--------------------------------------------------------- bool CGridding_Spline_MBA::_Get_Difference(CSG_Grid &Phi) { int i, nErrors; double x, y, z, zMax, zMean; CSG_String s; //----------------------------------------------------- for(i=0, zMax=0.0, nErrors=0, zMean=0.0; i<m_Points.Get_Count(); i++) { x = (m_Points[i].x - Phi.Get_XMin()) / Phi.Get_Cellsize(); y = (m_Points[i].y - Phi.Get_YMin()) / Phi.Get_Cellsize(); z = (m_Points[i].z = m_Points[i].z - BA_Get_Value(x, y, Phi)); if( (z = fabs(z)) > m_Epsilon ) { nErrors ++; zMean += fabs(z); if( fabs(z) > zMax ) { zMax = fabs(z); } } else { m_Points[i].z = 0.0; } } if( nErrors > 0 ) { zMean /= nErrors; } //----------------------------------------------------- i = 1 + (int)(0.5 + log(Phi.Get_NX() - 4.0) / log(2.0)); s.Printf(SG_T("%s:%d, %s:%d, %s:%f, %s:%f"), _TL("level"), i, _TL("error"), nErrors, _TL("max") , zMax, _TL("mean") , zMean ); Process_Set_Text(s); Message_Add (s); return( zMax >= m_Epsilon && i < m_Level_Max && Process_Get_Okay(false) ); }