//--------------------------------------------------------- CSG_Shapes * COGR_DataSource::Read_Shapes(int iLayer) { OGRLayer *pLayer = Get_Layer(iLayer); //----------------------------------------------------- if( pLayer && Get_Type(iLayer) != SHAPE_TYPE_Undefined ) { int iField; OGRFeature *pFeature; OGRFeatureDefn *pDef = pLayer->GetLayerDefn(); CSG_Shapes *pShapes = SG_Create_Shapes(Get_Type(iLayer), CSG_String(pDef->GetName())); for(iField=0; iField<pDef->GetFieldCount(); iField++) { OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField); pShapes->Add_Field(pDefField->GetNameRef(), COGR_Driver::Get_Type(pDefField->GetType())); } pLayer->ResetReading(); //------------------------------------------------- while( (pFeature = pLayer->GetNextFeature()) != NULL && SG_UI_Process_Get_Okay(false) ) { OGRGeometry *pGeometry = pFeature->GetGeometryRef(); if( pGeometry != NULL ) { CSG_Shape *pShape = pShapes->Add_Shape(); for(iField=0; iField<pDef->GetFieldCount(); iField++) { OGRFieldDefn *pDefField = pDef->GetFieldDefn(iField); switch( pDefField->GetType() ) { default: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break; case OFTString: pShape->Set_Value(iField, SG_STR_MBTOSG(pFeature->GetFieldAsString (iField))); break; case OFTInteger: pShape->Set_Value(iField, pFeature->GetFieldAsInteger(iField)); break; case OFTReal: pShape->Set_Value(iField, pFeature->GetFieldAsDouble (iField)); break; } } //----------------------------------------- if( _Read_Geometry(pShape, pGeometry) == false ) { pShapes->Del_Shape(pShape); } } OGRFeature::DestroyFeature(pFeature); } return( pShapes ); } //----------------------------------------------------- return( NULL ); }
//--------------------------------------------------------- CSG_String COGR_Driver::Get_Description(int iDriver) { OGRSFDriver *pDriver = m_pManager->GetDriver(iDriver); CSG_String s; s += pDriver->TestCapability(ODrCCreateDataSource) ? SG_T("\n[x] ") : SG_T("\n[ ] "); s += _TL("create data source"); s += pDriver->TestCapability(ODrCDeleteDataSource) ? SG_T("\n[x] ") : SG_T("\n[ ] "); s += _TL("delete data source"); /* s += pDriver->TestCapability(ODsCCreateLayer) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("create layer"); s += pDriver->TestCapability(ODsCDeleteLayer) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("delete layer"); s += pDriver->TestCapability(OLCDeleteFeature) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("delete feature"); s += pDriver->TestCapability(OLCRandomRead) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("random read"); s += pDriver->TestCapability(OLCRandomWrite) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("random write"); s += pDriver->TestCapability(OLCSequentialWrite) ? SG_T("\n[x]") : SG_T("\n[ ]"); s += _TL("sequential write"); /**/ return( SG_STR_MBTOSG(s) ); }
//--------------------------------------------------------- bool CSG_File::Read_Line(CSG_String &sLine) const { int c; if( m_pStream && !feof(m_pStream) ) { sLine.Clear(); while( !feof(m_pStream) && (c = fgetc(m_pStream)) != 0x0A && c != EOF ) { if( c != 0x0D ) { sLine.Append(SG_STR_MBTOSG(c)); } } return( true ); } return( false ); }
void Cihacres_elev::_CreateTableSim() { int i = 0; // used in function Get_Record(i) CSG_Table_Record *pRecord; CSG_String tmpName; double sim_eb, sim; // creating the column titles m_pTable->Add_Field("Date", SG_DATATYPE_String); m_pTable->Add_Field("Flow_OBS", SG_DATATYPE_Double); for (int eb = 0; eb < m_nElevBands; eb++) { tmpName = SG_T("ELEVB_"); tmpName += convert_sl::Int2String(eb+1).c_str(); m_pTable->Add_Field(tmpName.c_str(), SG_DATATYPE_Double); } m_pTable->Add_Field(SG_T("Flow_SIM"), SG_DATATYPE_Double); for (int j = 0; j < m_nValues; j++) { m_pTable->Add_Record(); pRecord = m_pTable->Get_Record(i); // writing the data into the rows pRecord->Set_Value(0,SG_STR_MBTOSG(m_vec_date[j].c_str())); pRecord->Set_Value(1,m_p_Q_obs_m3s[j]); sim_eb = 0.0; sim = 0.0; for (int eb = 0; eb < m_nElevBands; eb++) { sim_eb = model_tools::mmday_to_m3s(m_p_elevbands[eb].m_p_streamflow_sim[j],m_p_elevbands[eb].m_area); //pRecord->Set_Value(3+eb,model_tools::mmday_to_m3s(m_p_elevbands[eb].m_p_streamflow_sim[j],m_p_elevbands[eb].m_area)); pRecord->Set_Value(2+eb, sim_eb); sim += sim_eb; } pRecord->Set_Value(2+m_nElevBands,sim); i++; } }
//--------------------------------------------------------- CGDAL_Export::CGDAL_Export(void) { Set_Name (_TL("GDAL: Export Raster")); Set_Author (SG_T("(c) 2007 by O.Conrad")); CSG_String Description, Formats; Description = _TW( "The \"GDAL Raster Export\" module exports one or more grids to various file formats using the " "\"Geospatial Data Abstraction Library\" (GDAL) by Frank Warmerdam. " "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" "\n" "Following raster formats are currently supported:\n" "<table border=\"1\"><tr><th>ID</th><th>Name</th></tr>\n" ); for(int i=0; i<g_GDAL_Driver.Get_Count(); i++) { if( CSLFetchBoolean(g_GDAL_Driver.Get_Driver(i)->GetMetadata(), GDAL_DCAP_CREATE, false) ) { Description += CSG_String::Format(SG_T("<tr><td>%s</td><td>%s</td></tr>\n"), SG_STR_MBTOSG(g_GDAL_Driver.Get_Description(i)), SG_STR_MBTOSG(g_GDAL_Driver.Get_Name(i)) ); Formats += CSG_String::Format(SG_T("%s|"), SG_STR_MBTOSG(g_GDAL_Driver.Get_Name(i))); m_DriverNames.Add(SG_STR_MBTOSG(g_GDAL_Driver.Get_Description(i))); } } Description += SG_T("</table>"); Set_Description(Description); //----------------------------------------------------- Parameters.Add_Grid_List( NULL, "GRIDS" , _TL("Grid(s)"), _TL(""), PARAMETER_INPUT ); Parameters.Add_FilePath( NULL, "FILE" , _TL("File"), _TL(""), NULL, NULL, true ); Parameters.Add_Choice( NULL, "FORMAT" , _TL("Format"), _TL(""), Formats ); Parameters.Add_Choice( NULL, "TYPE" , _TL("Data Type"), _TL(""), CSG_String::Format(SG_T("%s|%s|%s|%s|%s|%s|%s|%s|"), _TL("match input data"), _TL("8 bit unsigned integer"), _TL("16 bit unsigned integer"), _TL("16 bit signed integer"), _TL("32 bit unsigned integer"), _TL("32 bit signed integer"), _TL("32 bit floating point"), _TL("64 bit floating point") ), 0 ); }
//--------------------------------------------------------- bool CSG_Table::_Load_DBase(const CSG_String &File_Name) { int iField; CSG_Table_DBase dbf; CSG_Table_Record *pRecord; //----------------------------------------------------- if( dbf.Open(File_Name) ) { Destroy(); for(iField=0; iField<dbf.Get_FieldCount(); iField++) { TSG_Data_Type Type; switch( dbf.Get_FieldType(iField) ) { case DBF_FT_LOGICAL: Type = SG_DATATYPE_Char; break; case DBF_FT_CHARACTER: default: Type = SG_DATATYPE_String; break; case DBF_FT_DATE: Type = SG_DATATYPE_Date; break; case DBF_FT_NUMERIC: Type = dbf.Get_FieldDecimals(iField) > 0 ? SG_DATATYPE_Double : SG_DATATYPE_Long; break; } Add_Field(SG_STR_MBTOSG(dbf.Get_FieldName(iField)), Type); } //------------------------------------------------- if( dbf.Move_First() && dbf.Get_Record_Count() > 0 ) { m_nRecords = m_nBuffer = dbf.Get_Record_Count(); m_Records = (CSG_Table_Record **)SG_Malloc(m_nRecords * sizeof(CSG_Table_Record *)); for(int iRecord=0; iRecord<m_nRecords && SG_UI_Process_Set_Progress(iRecord, m_nRecords); iRecord++) { m_Records[iRecord] = pRecord = _Get_New_Record(iRecord); for(iField=0; iField<Get_Field_Count(); iField++) { switch( Get_Field_Type(iField) ) { case SG_DATATYPE_Char: pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) ); break; case SG_DATATYPE_String: default: pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) ); break; case SG_DATATYPE_Date: pRecord->Set_Value(iField, dbf.asDouble(iField) ); break; case SG_DATATYPE_Long: pRecord->Set_Value(iField, dbf.asInt(iField) ); break; case SG_DATATYPE_Double: pRecord->Set_Value(iField, dbf.asDouble(iField) ); break; } } dbf.Move_Next(); } SG_UI_Process_Set_Ready(); Set_Modified(false); Set_Update_Flag(); _Stats_Invalidate(); } return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_CRSProjector::_Set_Projection(const CSG_Projection &Projection, void **ppProjection, bool bInverse) { PROJ4_FREE(*ppProjection); //------------------------------------------------- if( (*ppProjection = pj_init_plus(Projection.Get_Proj4())) == NULL ) { SG_UI_Msg_Add_Error(CSG_String::Format(SG_T("Proj4 [%s]: %s"), _TL("initialization"), SG_STR_MBTOSG(pj_strerrno(pj_errno)))); return( false ); } //------------------------------------------------- if( bInverse && ((PJ *)(*ppProjection))->inv == NULL ) { SG_UI_Msg_Add_Error(CSG_String::Format(SG_T("Proj4 [%s]: %s"), _TL("initialization"), _TL("inverse transformation not available"))); return( false ); } return( true ); }