//--------------------------------------------------------- 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)) ); }
//--------------------------------------------------------- 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 CSG_Shapes_OGIS_Converter::from_WKText(const CSG_String &Text, CSG_Shape *pShape) { pShape->Del_Parts(); CSG_String Type = Text.BeforeFirst('('); Type.Trim(true); Type.Trim(false); switch( pShape->Get_Type() ) { case SHAPE_TYPE_Point: if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_Point) ) { return( _WKT_Read_Point(Text.AfterFirst('(').BeforeFirst(')'), pShape, 0) ); } break; case SHAPE_TYPE_Points: if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPoint) ) { return( _WKT_Read_Parts(Text, pShape) ); } break; case SHAPE_TYPE_Line: if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_Line) ) { return( _WKT_Read_Points(Text, pShape) ); } if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiLine) ) { return( _WKT_Read_Parts(Text, pShape) ); } break; case SHAPE_TYPE_Polygon: if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_Polygon) ) { return( _WKT_Read_Parts(Text, pShape) ); } if( !Type.CmpNoCase(SG_OGIS_TYPE_STR_MultiPolygon) ) { return( _WKT_Read_Polygon(Text, pShape) ); } break; default: break; } return( false ); }
//--------------------------------------------------------- bool CWMS_Import::On_Execute(void) { CSG_String sServer = Parameters("SERVER")->asString(); //----------------------------------------------------- CWMS_Capabilities Capabilities; if( Capabilities.Create(sServer, "1.1.1") == false ) { Message_Add(_TL("Unable to get capabilities.")); return( false ); } //----------------------------------------------------- if( sServer.Find("http://") == 0 ) { sServer = Parameters("SERVER")->asString() + 7; } CSG_String sPath = "/" + sServer.AfterFirst('/'); sServer = sServer.BeforeFirst('/'); wxHTTP Server; Server.SetUser (Parameters("USERNAME")->asString()); Server.SetPassword(Parameters("PASSWORD")->asString()); if( Server.Connect(sServer.c_str()) == false ) { Message_Add(_TL("Unable to connect to server.")); return( false ); } //----------------------------------------------------- if( Get_Map(&Server, sPath, Capabilities) == false ) { Message_Add(_TL("Unable to get map.")); return( false ); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CSG_Shapes::Create(const CSG_String &File_Name) { Destroy(); SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Load shapes"), File_Name.c_str()), true); //----------------------------------------------------- bool bResult = File_Name.BeforeFirst(':').Cmp("PGSQL") && SG_File_Exists(File_Name) && _Load_ESRI(File_Name); if( bResult ) { Set_File_Name(File_Name, true); } //----------------------------------------------------- else if( File_Name.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source { CSG_String s(File_Name); s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String DBName(s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String Table (s.BeforeFirst(':')); CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 0); // CGet_Connections if( pTool != NULL ) { SG_UI_ProgressAndMsg_Lock(true); //--------------------------------------------- CSG_Table Connections; CSG_String Connection = DBName + " [" + Host + ":" + Port + "]"; pTool->Settings_Push(); if( pTool->On_Before_Execution() && SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() ) // CGet_Connections { for(int i=0; !bResult && i<Connections.Get_Count(); i++) { if( !Connection.Cmp(Connections[i].asString(0)) ) { bResult = true; } } } pTool->Settings_Pop(); //--------------------------------------------- if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 20)) != NULL) == true ) // CPGIS_Shapes_Load { pTool->Settings_Push(); bResult = pTool->On_Before_Execution() && SG_TOOL_PARAMETER_SET("CONNECTION", Connection) && SG_TOOL_PARAMETER_SET("TABLES" , Table) && SG_TOOL_PARAMETER_SET("SHAPES" , this) && pTool->Execute(); pTool->Settings_Pop(); } SG_UI_ProgressAndMsg_Lock(false); } } //----------------------------------------------------- if( bResult ) { Set_Modified(false); Set_Update_Flag(); SG_UI_Process_Set_Ready(); SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS); return( true ); } for(int iShape=Get_Count()-1; iShape>=0; iShape--) // be kind, keep at least those shapes that have been loaded successfully { if( !Get_Shape(iShape)->is_Valid() ) { Del_Shape(iShape); } } if( Get_Count() <= 0 ) { Destroy(); } SG_UI_Process_Set_Ready(); SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE); return( false ); }