//--------------------------------------------------------- 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 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 ); }
//--------------------------------------------------------- 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 ); }
//--------------------------------------------------------- int CSG_Grid::_Load_Native_Get_Key(CSG_File &Stream, CSG_String &Value) { int i; CSG_String sLine; if( Stream.Read_Line(sLine) && (i = sLine.Find('=')) > 0 ) { Value = sLine.AfterFirst('='); Value.Trim(); sLine.Remove(i); for(i=0; i<GRID_FILE_KEY_Count; i++) { CSG_String s(gSG_Grid_File_Key_Names[i]); if( s.Find(sLine.Left(s.Length())) >= 0 ) { return( i ); } } } return( -1 ); }
//--------------------------------------------------------- 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 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_OGIS_Converter::_WKT_Read_Points(const CSG_String &Text, CSG_Shape *pShape) { int iPart = pShape->Get_Part_Count(); CSG_String s(Text.AfterFirst('(').BeforeFirst(')')); while( s.Length() > 0 ) { if( !_WKT_Read_Point(s, pShape, iPart) ) { return( false ); } s = s.AfterFirst(','); } return( pShape->Get_Point_Count(iPart) > 0 ); }
bool CStreamNet::On_Execute(void) { // Inputs and Output Strings CSG_String InputBasename = CSG_String("input"); CSG_String OutputBasename = CSG_String("output"); CSG_String FEL_INPUT_FileName, FEL_INPUT_FilePath; CSG_String FLOWD8_INPUT_FileName, FLOWD8_INPUT_FilePath; CSG_String AREAD8_INPUT_FileName, AREAD8_INPUT_FilePath; CSG_String SRC_INPUT_FileName, SRC_INPUT_FilePath; CSG_String ORD_OUTPUT_FileName, ORD_OUTPUT_FilePath, ORD_OUTPUT_Name; CSG_String W_OUTPUT_FileName, W_OUTPUT_FilePath, W_OUTPUT_Name; CSG_String NET_OUTPUT_FileName, NET_OUTPUT_FilePath, NET_OUTPUT_Name; CSG_String TREE_OUTPUT_FileName, TREE_OUTPUT_FilePath, TREE_OUTPUT_Name; CSG_String COORD_OUTPUT_FileName, COORD_OUTPUT_FilePath, COORD_OUTPUT_Name; CSG_String OUTLET_INPUT_FileName, OUTLET_INPUT_FilePath; // Data Objects CSG_Grid *FEL_INPUT_Grid, *FLOWD8_INPUT_Grid, *SRC_INPUT_Grid, *AREAD8_INPUT_Grid, *ORD_OUTPUT_Grid, *W_OUTPUT_Grid; CSG_Shapes *OUTLET_INPUT_Shapes, *NET_OUTPUT_Shapes; CSG_Table *TREE_OUTPUT_Table, *COORD_OUTPUT_Table; // Misc TSG_Data_Type Type; CSG_String GDALDriver, sCmd, TempDirPath, TauDEMBinDir, BinaryName, BinaryPath, LogFile; CSG_Projection Projection; CSG_GDAL_DataSet DataSet; CSG_OGR_DataSource OGRDataSource; CSG_String OGRDriver = CSG_String("ESRI Shapefile"); bool sw; int nproc; // Grab inputs FEL_INPUT_Grid = Parameters("FEL_INPUT")->asGrid(); FLOWD8_INPUT_Grid = Parameters("FLOWD8_INPUT")->asGrid(); SRC_INPUT_Grid = Parameters("SRC_INPUT")->asGrid(); AREAD8_INPUT_Grid = Parameters("AREAD8_INPUT")->asGrid(); ORD_OUTPUT_Grid = Parameters("ORD_OUTPUT")->asGrid(); W_OUTPUT_Grid = Parameters("W_OUTPUT")->asGrid(); nproc = Parameters("NPROC")->asInt(); OUTLET_INPUT_Shapes = Parameters("OUTLET_INPUT")->asShapes(); NET_OUTPUT_Shapes = Parameters("NET_OUTPUT")->asShapes(); TREE_OUTPUT_Table = Parameters("TREE_OUTPUT")->asTable(); COORD_OUTPUT_Table = Parameters("COORD_OUTPUT")->asTable(); sw = Parameters("SW")->asBool(); GDALDriver = CSG_String("GTiff"); Get_Projection(Projection); Type = FEL_INPUT_Grid->Get_Type(); //TempDirPath = SG_File_Get_Path_Absolute(CSG_String("taudem_tmp")); TempDirPath = Parameters("TEMP_DIR")->asFilePath()->asString(); FEL_INPUT_FileName = InputBasename + CSG_String("fel"); FEL_INPUT_FilePath = SG_File_Make_Path(TempDirPath, FEL_INPUT_FileName, CSG_String("tif")); FLOWD8_INPUT_FileName = InputBasename + CSG_String("p"); FLOWD8_INPUT_FilePath = SG_File_Make_Path(TempDirPath, FLOWD8_INPUT_FileName, CSG_String("tif")); SRC_INPUT_FileName = InputBasename + CSG_String("src"); SRC_INPUT_FilePath = SG_File_Make_Path(TempDirPath, SRC_INPUT_FileName, CSG_String("tif")); AREAD8_INPUT_FileName = InputBasename + CSG_String("ad8"); AREAD8_INPUT_FilePath = SG_File_Make_Path(TempDirPath, AREAD8_INPUT_FileName, CSG_String("tif")); ORD_OUTPUT_FileName = OutputBasename + CSG_String("ord"); ORD_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, ORD_OUTPUT_FileName, CSG_String("tif")); ORD_OUTPUT_Name = CSG_String("NetworkOrder"); W_OUTPUT_FileName = OutputBasename + CSG_String("w"); W_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, W_OUTPUT_FileName, CSG_String("tif")); W_OUTPUT_Name = CSG_String("WatershedIDs"); OUTLET_INPUT_FileName = InputBasename + CSG_String("o"); OUTLET_INPUT_FilePath = SG_File_Make_Path(TempDirPath, OUTLET_INPUT_FileName, CSG_String("shp")); NET_OUTPUT_FileName = OutputBasename + CSG_String("net"); NET_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, NET_OUTPUT_FileName, CSG_String("shp")); NET_OUTPUT_Name = CSG_String("Channel Network"); TREE_OUTPUT_FileName = OutputBasename + CSG_String("tree"); TREE_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, TREE_OUTPUT_FileName, CSG_String("dat")); TREE_OUTPUT_Name = CSG_String("Channel Network Tree"); COORD_OUTPUT_FileName = OutputBasename + CSG_String("coord"); COORD_OUTPUT_FilePath = SG_File_Make_Path(TempDirPath, COORD_OUTPUT_FileName, CSG_String("dat")); COORD_OUTPUT_Name = CSG_String("Channel Network Coords"); LogFile = SG_File_Make_Path(TempDirPath, CSG_String("taudem_log.txt")); LogFile = SG_File_Get_Path_Absolute(LogFile); TauDEMBinDir = SG_File_Make_Path(CSG_String("bin"), CSG_String("TauDEM")); TauDEMBinDir = SG_File_Get_Path_Absolute(TauDEMBinDir); // options CSG_String OptionalFlags = CSG_String(""); if (OUTLET_INPUT_Shapes != NULL) { OptionalFlags = CSG_String::Format(SG_T("-o \"%s\" "), OUTLET_INPUT_FilePath.c_str()); } if (sw) { OptionalFlags = OptionalFlags + CSG_String::Format(SG_T("-sw")); } // exec commnad BinaryName = CSG_String("StreamNet"); // D8 BinaryPath = SG_File_Make_Path(TauDEMBinDir, BinaryName); sCmd = CSG_String::Format(SG_T("\"mpiexec -n %d \"%s\" -fel \"%s\" -p \"%s\" -ad8 \"%s\" -src \"%s\" -ord \"%s\" -tree \"%s\" -coord \"%s\" -net \"%s\" -w \"%s\" %s >\"%s\" 2>&1\""), nproc, BinaryPath.c_str(), FEL_INPUT_FilePath.c_str(), FLOWD8_INPUT_FilePath.c_str(), AREAD8_INPUT_FilePath.c_str(), SRC_INPUT_FilePath.c_str(), ORD_OUTPUT_FilePath.c_str(), TREE_OUTPUT_FilePath.c_str(), COORD_OUTPUT_FilePath.c_str(), NET_OUTPUT_FilePath.c_str(), W_OUTPUT_FilePath.c_str(), OptionalFlags.c_str(), LogFile.c_str()); // make sure temp dir exists if (!SG_Dir_Exists(TempDirPath)) { if (!SG_Dir_Create(TempDirPath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to create temp directory"), TempDirPath.c_str())); } } CSG_String FilePaths [10] = {FEL_INPUT_FilePath, FLOWD8_INPUT_FilePath, SRC_INPUT_FilePath, AREAD8_INPUT_FilePath, ORD_OUTPUT_FilePath, W_OUTPUT_FilePath, OUTLET_INPUT_FilePath, NET_OUTPUT_FilePath, TREE_OUTPUT_FilePath, COORD_OUTPUT_FilePath}; for (int i = 0; i < 10; i++) { CSG_String FilePath = FilePaths[i]; // Delete old file if exists if (SG_File_Exists(FilePath)) { if (!SG_File_Delete(FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to delete existing file: "), FilePath.c_str())); return( false ); } } } // SAVE TIFFS CSG_String TIFF_INPUT_FilePaths [4] = {FEL_INPUT_FilePath, FLOWD8_INPUT_FilePath, SRC_INPUT_FilePath, AREAD8_INPUT_FilePath}; CSG_Grid* TIFF_INPUT_Grids [4] = {FEL_INPUT_Grid, FLOWD8_INPUT_Grid, SRC_INPUT_Grid, AREAD8_INPUT_Grid}; for (int i = 0; i < 4; i++) { CSG_String FilePath = TIFF_INPUT_FilePaths[i]; CSG_Grid* Grid = TIFF_INPUT_Grids[i]; if( !DataSet.Open_Write(FilePath, GDALDriver, CSG_String(""), Type, 1, *Get_System(), Projection) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), FilePath.c_str())); return( false ); } DataSet.Write(0, Grid); if( !DataSet.Close() ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to close file after writing: "), FilePath.c_str())); return( false ); } } if (OUTLET_INPUT_Shapes != NULL) { // save outlet shapefile CSG_String OGRDriver = CSG_String("ESRI Shapefile"); if( !OGRDataSource.Create(OUTLET_INPUT_FilePath, OGRDriver) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for writing: "), OUTLET_INPUT_FilePath.c_str())); return( false ); } OGRDataSource.Write(OUTLET_INPUT_Shapes, OGRDriver); OGRDataSource.Destroy(); } // Run TauDEM StreamNet Message_Add(CSG_String("Executing ") + sCmd); if (system(sCmd.b_str()) != 0) { Error_Set(CSG_String::Format(SG_T("Error executing '%s' see Execution log for details"), BinaryName.c_str())); // read log output CSG_File File; if (File.Open(LogFile, SG_FILE_R, false)) { CSG_String Line; while (! File.is_EOF() && File.Read_Line(Line)) { Message_Add(Line); } File.Close(); } else { Message_Add(CSG_String("Unable to open " + LogFile + CSG_String(" for reading"))); } return( false ); } // Load output tiffs if( !DataSet.Open_Read(ORD_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open output file: "), ORD_OUTPUT_FilePath.c_str())); return( false ); } else { ORD_OUTPUT_Grid->Assign(DataSet.Read(0)); ORD_OUTPUT_Grid->Set_Name(ORD_OUTPUT_Name); Parameters("ORD_OUTPUT")->Set_Value(ORD_OUTPUT_Grid); } if( !DataSet.Open_Read(W_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open output file: "), W_OUTPUT_FilePath.c_str())); return( false ); } else { W_OUTPUT_Grid->Assign(DataSet.Read(0)); W_OUTPUT_Grid->Set_Name(W_OUTPUT_Name); Parameters("W_OUTPUT")->Set_Value(W_OUTPUT_Grid); CSG_Colors colors; DataObject_Get_Colors(SRC_INPUT_Grid, colors); DataObject_Set_Colors(ORD_OUTPUT_Grid, colors); DataObject_Update(ORD_OUTPUT_Grid, false); } // load output shapefile if( !OGRDataSource.Create(NET_OUTPUT_FilePath) ) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Failed to open file for reading: "), NET_OUTPUT_FilePath.c_str())); return( false ); } NET_OUTPUT_Shapes->Assign(OGRDataSource.Read(0, 0)); NET_OUTPUT_Shapes->Set_Name(NET_OUTPUT_Name); OGRDataSource.Destroy(); // load table data if (!SG_File_Exists(COORD_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Output file does not exist: "), COORD_OUTPUT_FilePath.c_str())); return false; } else { COORD_OUTPUT_Table->Destroy(); COORD_OUTPUT_Table->Set_Name(COORD_OUTPUT_Name); // create table fields COORD_OUTPUT_Table->Add_Field(SG_T("X"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Y"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Terminal Distance"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Elevation"), SG_DATATYPE_Double); COORD_OUTPUT_Table->Add_Field(SG_T("Contributing Area"), SG_DATATYPE_Double); // read table data CSG_File File; if (File.Open(COORD_OUTPUT_FilePath, SG_FILE_R, false)) { CSG_String Line; // determine number of lines while (! File.is_EOF() && File.Read_Line(Line)) { Line.Trim(); if (Line.Length() == 0) { break; } else { CSG_Table_Record *Record = COORD_OUTPUT_Table->Add_Record(); for (int i = 0; i < COORD_OUTPUT_Table->Get_Field_Count(); i++) { Record->Set_Value(i, Line.asDouble()); Line = Line.AfterFirst('\t'); Line.Trim(); } } } File.Close(); } else { Message_Add(CSG_String("Unable to open " + COORD_OUTPUT_FilePath + CSG_String(" for reading"))); } } if (!SG_File_Exists(TREE_OUTPUT_FilePath)) { Error_Set(CSG_String::Format(SG_T("%s: '%s' "), _TL("Output file does not exist: "), TREE_OUTPUT_FilePath.c_str())); return false; } else { TREE_OUTPUT_Table->Destroy(); TREE_OUTPUT_Table->Set_Name(TREE_OUTPUT_Name); // create table fields TREE_OUTPUT_Table->Add_Field(SG_T("Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Start Point"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("End Point"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Next (Downstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("First Previous (Upstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Second Previous (Upstream) Link"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Strahler Order"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Monitoring Point ID"), SG_DATATYPE_Int); TREE_OUTPUT_Table->Add_Field(SG_T("Link Network Magnitude"), SG_DATATYPE_Int); // read table data CSG_File File; if (File.Open(TREE_OUTPUT_FilePath, SG_FILE_R, false)) { CSG_String Line; // determine number of lines while (! File.is_EOF() && File.Read_Line(Line)) { Line.Trim(); if (Line.Length() == 0) { break; } else { CSG_Table_Record *Record = TREE_OUTPUT_Table->Add_Record(); for (int i = 0; i < TREE_OUTPUT_Table->Get_Field_Count(); i++) { Record->Set_Value(i, Line.asDouble()); Line = Line.AfterFirst('\t'); Line.Trim(); } } } File.Close(); } else { Message_Add(CSG_String("Unable to open " + TREE_OUTPUT_FilePath + CSG_String(" for reading"))); } } return( true ); }
//--------------------------------------------------------- bool CSG_MetaData::from_JSON(const CSG_String &JSON) { Destroy(); Set_Name("root"); CSG_MetaData *pNode = this; const SG_Char *pc = JSON.c_str(); while( *pc ) { CSG_String Element; for(bool bQuota=false;;) { SG_Char c = *pc++; if( !c || c == '\n' ) { break; } else { if( c == '\"' ) { Element += c; bQuota = !bQuota; } else if( bQuota || (c != ' ' && c != '\t' && c != ',') ) { Element += c; } } } //------------------------------------------------- if( Element.is_Empty() ) { // nop } else if( Element.Find('[') >= 0 ) // array begins { pNode = pNode->Add_Child(Element.AfterFirst('\"').BeforeFirst('\"')); pNode->Add_Property("array", 1); } else if( Element.Find(']') >= 0 ) // array ends { if( pNode != this ) { pNode = pNode->Get_Parent(); } } else if( Element.Find('{') >= 0 ) // object begins { Element = Element.AfterFirst('\"').BeforeFirst('\"'); if( !Element.is_Empty() ) { pNode = pNode->Add_Child(Element); } else if( pNode->Get_Property("array") ) { pNode = pNode->Add_Child(CSG_String::Format("%d", pNode->Get_Children_Count())); } } else if( Element.Find('}') >= 0 ) // object ends { if( pNode != this ) { pNode = pNode->Get_Parent(); } } else { CSG_String Key (Element.AfterFirst('\"').BeforeFirst('\"')); CSG_String Value(Element.AfterFirst(':')); if( Value.Find('\"') > -1 ) { Value = Value.AfterFirst('\"').BeforeFirst('\"'); } pNode->Add_Child(Key, Value); } } return( true ); }
//--------------------------------------------------------- bool CWRF_Import::Load(const CSG_String &File) { //----------------------------------------------------- // 00001-00600.00001-00600 // 01234567890123456789012 CSG_String Name = SG_File_Get_Name(File, true); if( Name.Length() != 23 || Name[5] != SG_T('-') || Name[11] != SG_T('.') || Name[17] != SG_T('-') ) { Error_Set(_TL("invalid geogrid file name")); return( false ); } int xOffset = Name.asInt() - 1; int yOffset = Name.AfterFirst(SG_T('.')).asInt() - 1; //----------------------------------------------------- CSG_File Stream; if( !Stream.Open(File, SG_FILE_R) ) { Error_Set(_TL("data file could not be openend")); return( false ); } //----------------------------------------------------- TSG_Data_Type Type; switch( m_Index.m_WORDSIZE ) { default: Error_Set(_TL("invalid word size")); return( false ); case 1: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_Byte : SG_DATATYPE_Char; break; case 2: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_Word : SG_DATATYPE_Short; break; case 4: Type = m_Index.m_SIGNED == false ? SG_DATATYPE_DWord : SG_DATATYPE_Int; break; } //----------------------------------------------------- char *pLine, *pValue; int x, y, nBytes_Line; nBytes_Line = (m_Index.m_TILE_X + 2 * m_Index.m_TILE_BDR) * m_Index.m_WORDSIZE; pLine = (char *)SG_Malloc(nBytes_Line); //----------------------------------------------------- for(int z=m_Index.m_TILE_Z_START; z<=m_Index.m_TILE_Z_END && !Stream.is_EOF() && Process_Get_Okay(); z++) { CSG_Grid *pGrid = SG_Create_Grid( Type, m_Index.m_TILE_X + 2 * m_Index.m_TILE_BDR, m_Index.m_TILE_Y + 2 * m_Index.m_TILE_BDR, m_Index.m_DX, m_Index.m_KNOWN_LON + (xOffset - m_Index.m_TILE_BDR) * m_Index.m_DX, m_Index.m_KNOWN_LAT + (yOffset - m_Index.m_TILE_BDR) * m_Index.m_DY ); pGrid->Set_Name (CSG_String::Format(SG_T("%s_%02d"), SG_File_Get_Name(File, false).c_str(), z)); pGrid->Set_Description (m_Index.m_DESCRIPTION); pGrid->Set_Unit (m_Index.m_UNITS); pGrid->Set_NoData_Value (m_Index.m_MISSING_VALUE); pGrid->Set_Scaling (m_Index.m_SCALE_FACTOR); Parameters("GRIDS")->asGridList()->Add_Item(pGrid); //------------------------------------------------- for(y=0; y<pGrid->Get_NY() && !Stream.is_EOF() && Set_Progress(y, pGrid->Get_NY()); y++) { int yy = m_Index.m_ROW_ORDER == VAL_TOP_BOTTOM ? pGrid->Get_NY() - 1 - y : y; Stream.Read(pLine, sizeof(char), nBytes_Line); for(x=0, pValue=pLine; x<pGrid->Get_NX(); x++, pValue+=m_Index.m_WORDSIZE) { if( m_Index.m_ENDIAN == VAL_ENDIAN_BIG ) { SG_Swap_Bytes(pValue, m_Index.m_WORDSIZE); } switch( pGrid->Get_Type() ) { case SG_DATATYPE_Byte: pGrid->Set_Value(x, yy, *(unsigned char *)pValue); break; // 1 Byte Integer (unsigned) case SG_DATATYPE_Char: pGrid->Set_Value(x, yy, *(signed char *)pValue); break; // 1 Byte Integer (signed) case SG_DATATYPE_Word: pGrid->Set_Value(x, yy, *(unsigned short *)pValue); break; // 2 Byte Integer (unsigned) case SG_DATATYPE_Short: pGrid->Set_Value(x, yy, *(signed short *)pValue); break; // 2 Byte Integer (signed) case SG_DATATYPE_DWord: pGrid->Set_Value(x, yy, *(unsigned int *)pValue); break; // 4 Byte Integer (unsigned) case SG_DATATYPE_Int: pGrid->Set_Value(x, yy, *(signed int *)pValue); break; // 4 Byte Integer (signed) } } } } //----------------------------------------------------- SG_Free(pLine); return( true ); }