Esempio n. 1
0
//---------------------------------------------------------
inline bool CSG_Shapes_OGIS_Converter::_WKB_Read_Point(CSG_Bytes &Bytes, bool bSwapBytes, CSG_Shape *pShape, int iPart)
{
	if( Bytes.is_EOF() )
	{
		return( false );
	}

	double	x, y;

	x	= Bytes.Read_Double(bSwapBytes);
	y	= Bytes.Read_Double(bSwapBytes);

	pShape->Add_Point(x, y, iPart);

	switch( ((CSG_Shapes *)pShape->Get_Table())->Get_Vertex_Type() )
	{
	case SG_VERTEX_TYPE_XY:
		break;

	case SG_VERTEX_TYPE_XYZ:
		pShape->Set_Z(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
		break;

	case SG_VERTEX_TYPE_XYZM:
		pShape->Set_Z(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
		pShape->Set_M(Bytes.Read_Double(bSwapBytes), pShape->Get_Point_Count(iPart) - 1, iPart);
		break;
	}

	return( true );
}
Esempio n. 2
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 );
}