//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::from_WKBinary(CSG_Bytes &Bytes, CSG_Shape *pShape) { pShape->Del_Parts(); if( Bytes.Get_Count() > 3 ) { Bytes.Rewind(); bool bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR; switch( pShape->Get_Type() ) { default: break; case SHAPE_TYPE_Point: if( Bytes.Read_DWord() == SG_OGIS_TYPE_Point ) { return( _WKB_Read_Point(Bytes, bSwapBytes, pShape, 0) ); } break; case SHAPE_TYPE_Points: if( Bytes.Read_DWord() == SG_OGIS_TYPE_MultiPoint ) { return( _WKB_Read_Parts(Bytes, bSwapBytes, pShape) ); } break; case SHAPE_TYPE_Line: switch( Bytes.Read_DWord() ) { case SG_OGIS_TYPE_LineString: return( _WKB_Read_Points (Bytes, bSwapBytes, pShape) ); case SG_OGIS_TYPE_MultiLineString: return( _WKB_Read_MultiLine (Bytes, bSwapBytes, pShape) ); } break; case SHAPE_TYPE_Polygon: switch( Bytes.Read_DWord() ) { case SG_OGIS_TYPE_Polygon: return( _WKB_Read_Parts (Bytes, bSwapBytes, pShape) ); case SG_OGIS_TYPE_MultiPolygon: return( _WKB_Read_MultiPolygon (Bytes, bSwapBytes, pShape) ); } break; } } return( false ); }
//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::_WKB_Read_MultiLine(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape) { DWORD nLines = Bytes.Read_DWord(bSwapBytes); for(DWORD iLine=0; iLine<nLines; iLine++) { bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR; if( Bytes.Read_DWord(bSwapBytes) != SG_OGIS_TYPE_LineString || !_WKB_Read_Points(Bytes, bSwapBytes, pShape) ) { return( false ); } } return( pShape->Get_Part_Count() > 0 ); }
//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::_WKB_Read_MultiPolygon(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape) { DWORD nPolygons = Bytes.Read_DWord(bSwapBytes); for(DWORD iPolygon=0; iPolygon<nPolygons; iPolygon++) { bSwapBytes = Bytes.Read_Byte() != SG_OGIS_BYTEORDER_NDR; if( Bytes.Read_DWord(bSwapBytes) != SG_OGIS_TYPE_Polygon || !_WKB_Read_Parts(Bytes, bSwapBytes, pShape) ) { return( false ); } } return( pShape->Get_Part_Count() > 0 ); }
//--------------------------------------------------------- bool CSG_Shapes_OGIS_Converter::_WKB_Read_Parts(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape) { DWORD iPart, nParts = Bytes.Read_DWord(bSwapBytes); for(iPart=0; iPart<nParts; iPart++) { if( !_WKB_Read_Points(Bytes, bSwapBytes, pShape) ) { return( false ); } } return( pShape->Get_Part_Count() > 0 ); }
//--------------------------------------------------------- bool CSG_Grid_OGIS_Converter::from_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid) { Bytes.Rewind(); //----------------------------------------------------- // Raster System bool bSwap = Bytes.Read_Byte () == 0; // endiannes: 1=ndr/little endian, 0=xdr/big endian short version = Bytes.Read_Short (bSwap); // version short nBands = Bytes.Read_Short (bSwap); // number of bands double dx = Bytes.Read_Double(bSwap); // scaleX double dy = Bytes.Read_Double(bSwap); // scaleY double xMin = Bytes.Read_Double(bSwap); // ipX double yMax = Bytes.Read_Double(bSwap); // ipY double skewX = Bytes.Read_Double(bSwap); // skewX double skewY = Bytes.Read_Double(bSwap); // skewY int SRID = Bytes.Read_Int (bSwap); // srid short NX = Bytes.Read_Short (bSwap); // width short NY = Bytes.Read_Short (bSwap); // height //----------------------------------------------------- // Band TSG_Data_Type Type; BYTE Flags = Bytes.Read_Byte(); switch( Flags & 0x0F ) { case 0: Type = SG_DATATYPE_Bit ; break; // 0: 1-bit boolean case 1: Type = SG_DATATYPE_Char ; break; // 1: 2-bit unsigned integer case 2: Type = SG_DATATYPE_Char ; break; // 2: 4-bit unsigned integer case 3: Type = SG_DATATYPE_Char ; break; // 3: 8-bit signed integer case 4: Type = SG_DATATYPE_Byte ; break; // 4: 8-bit unsigned integer case 5: Type = SG_DATATYPE_Short ; break; // 5: 16-bit signed integer case 6: Type = SG_DATATYPE_Word ; break; // 6: 16-bit unsigned integer case 7: Type = SG_DATATYPE_Int ; break; // 7: 32-bit signed integer case 8: Type = SG_DATATYPE_DWord ; break; // 8: 32-bit unsigned integer case 10: Type = SG_DATATYPE_Float ; break; // 10: 32-bit float case 11: Type = SG_DATATYPE_Double; break; // 11: 64-bit float } // Flags |= 0x80; // isOffline: no, never here! Flags |= 0x40; // hasNodataValue // Flags |= 0x20; // isNoDataValue: no, never here! // Flags |= 0x10; // reserved (unused) if( !pGrid->Create(Type, NX, NY, dx, xMin + 0.5 * dx, yMax - (NY - 0.5) * dx) ) { return( false ); } pGrid->Get_Projection().Create(SRID); double noData; switch( pGrid->Get_Type() ) { case SG_DATATYPE_Bit : noData = Bytes.Read_Byte ( ); break; // 0: 1-bit boolean case SG_DATATYPE_Char : noData = Bytes.Read_Char ( ); break; // 3: 8-bit signed integer case SG_DATATYPE_Byte : noData = Bytes.Read_Byte ( ); break; // 4: 8-bit unsigned integer case SG_DATATYPE_Short : noData = Bytes.Read_Short (bSwap); break; // 5: 16-bit signed integer case SG_DATATYPE_Word : noData = Bytes.Read_Word (bSwap); break; // 6: 16-bit unsigned integer case SG_DATATYPE_Int : noData = Bytes.Read_Int (bSwap); break; // 7: 32-bit signed integer case SG_DATATYPE_DWord : noData = Bytes.Read_DWord (bSwap); break; // 8: 32-bit unsigned integer case SG_DATATYPE_Float : noData = Bytes.Read_Float (bSwap); break; // 9: 32-bit float case SG_DATATYPE_Double: noData = Bytes.Read_Double(bSwap); break; // 10: 64-bit float default: break; } pGrid->Set_NoData_Value(noData); for(int y=0; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++) { for(int x=0; x<pGrid->Get_NX(); x++) { switch( pGrid->Get_Type() ) { case SG_DATATYPE_Bit : pGrid->Set_Value(x, y, Bytes.Read_Byte ( )); break; // 0: 1-bit boolean case SG_DATATYPE_Char : pGrid->Set_Value(x, y, Bytes.Read_Char ( )); break; // 3: 8-bit signed integer case SG_DATATYPE_Byte : pGrid->Set_Value(x, y, Bytes.Read_Byte ( )); break; // 4: 8-bit unsigned integer case SG_DATATYPE_Short : pGrid->Set_Value(x, y, Bytes.Read_Short (bSwap)); break; // 5: 16-bit signed integer case SG_DATATYPE_Word : pGrid->Set_Value(x, y, Bytes.Read_Word (bSwap)); break; // 6: 16-bit unsigned integer case SG_DATATYPE_Int : pGrid->Set_Value(x, y, Bytes.Read_Int (bSwap)); break; // 7: 32-bit signed integer case SG_DATATYPE_DWord : pGrid->Set_Value(x, y, Bytes.Read_DWord (bSwap)); break; // 8: 32-bit unsigned integer case SG_DATATYPE_Float : pGrid->Set_Value(x, y, Bytes.Read_Float (bSwap)); break; // 9: 32-bit float case SG_DATATYPE_Double: pGrid->Set_Value(x, y, Bytes.Read_Double(bSwap)); break; // 10: 64-bit float default: break; } } } return( true ); }