コード例 #1
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #2
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
bool CSG_Shapes_OGIS_Converter::to_WKBinary(CSG_Shape *pShape, CSG_Bytes &Bytes)
{
	Bytes.Destroy();

	Bytes	+= (BYTE)SG_OGIS_BYTEORDER_NDR;

	switch( pShape->Get_Type() )
	{
	default:
		return( false );

	case SHAPE_TYPE_Point:
		Bytes	+= (DWORD)SG_OGIS_TYPE_Point;
		return( _WKB_Write_Point(Bytes, pShape, 0, 0) );

	case SHAPE_TYPE_Points:
		Bytes	+= (DWORD)SG_OGIS_TYPE_MultiPoint;
		return( _WKB_Write_Points(Bytes, pShape, 0) );

	case SHAPE_TYPE_Line:
		Bytes	+= (DWORD)SG_OGIS_TYPE_MultiLineString;
		return( _WKB_Write_MultiLine(Bytes, pShape) );

	case SHAPE_TYPE_Polygon:
		Bytes	+= (DWORD)SG_OGIS_TYPE_MultiPolygon;
		return( _WKB_Write_MultiPolygon(Bytes, pShape) );
	}

	return( false );
}
コード例 #3
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #4
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #5
0
//---------------------------------------------------------
bool CSG_HTTP::Request(const CSG_String &Request, CSG_Bytes &Answer)
{
	wxInputStream *pStream = _Request(Request); if( !pStream ) { return( false ); }

//	if( pStream->GetSize() == ((size_t)-1) )
//	{
//		delete(pStream);
//
//		return( false );
//	}

	Answer.Clear();

	while( pStream->CanRead() )
	{
		char	Byte;

		pStream->Read(&Byte, sizeof(Byte));

		Answer	+= Byte;
	}

	delete(pStream);

	return( true );
}
コード例 #6
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #7
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #8
0
//---------------------------------------------------------
bool CSG_CURL::Request(const CSG_String &Request, CSG_Bytes &Answer)
{
	if( !is_Connected() ) { return( false ); }

	Answer.Clear();

	CSG_String	URL	= m_Server + "/" + Request;

	CURL_SET_OPT(1, CURLOPT_URL           , URL.b_str());
	CURL_SET_OPT(1, CURLOPT_FOLLOWLOCATION, 1L);
	CURL_SET_OPT(1, CURLOPT_WRITEFUNCTION , _Callback_Write_Bytes);
	CURL_SET_OPT(1, CURLOPT_WRITEDATA     , &Answer);

	return( _Perform() );
}
コード例 #9
0
//---------------------------------------------------------
bool CSG_ODBC_Connection::_Table_Load(CSG_Table &Table, const CSG_String &Select, const CSG_String &Name, bool bLOB)
{
	//-----------------------------------------------------
	if( !is_Connected() )
	{
		_Error_Message(_TL("no database connection"));

		return( false );
	}

	//-----------------------------------------------------
	try
	{
		int				valInt, iField, nFields;
		long			valLong;
		float			valFloat;
		double			valDouble;
		std_string		valString;
		otl_long_string	valRaw(m_Connection.get_max_long_size());
		otl_column_desc	*Fields;
		otl_stream		Stream;
		CSG_Bytes		BLOB;

		Stream.set_all_column_types	(otl_all_date2str);
		Stream.set_lob_stream_mode	(bLOB);
		Stream.open					(bLOB ? 1 : m_Size_Buffer, Select, m_Connection);

		Fields	= Stream.describe_select(nFields);

		if( Fields == NULL || nFields <= 0 )
		{
			_Error_Message(_TL("no fields in selection"));

			return( false );
		}

		//-------------------------------------------------
		Table.Destroy();
		Table.Set_Name(Name);

		for(iField=0; iField<nFields; iField++)
		{
			if( _Get_Type_From_SQL(Fields[iField].otl_var_dbtype) == SG_DATATYPE_Undefined )
			{
				return( false );
			}

			Table.Add_Field(Fields[iField].name, _Get_Type_From_SQL(Fields[iField].otl_var_dbtype));
		}

		//-------------------------------------------------
		while( !Stream.eof() && SG_UI_Process_Get_Okay() )	// while not end-of-data
		{
			CSG_Table_Record	*pRecord	= Table.Add_Record();

			for(iField=0; iField<nFields; iField++)
			{
				switch( Table.Get_Field_Type(iField) )
				{
				case SG_DATATYPE_String:	Stream >> valString; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, CSG_String(valString.c_str()));	break;
				case SG_DATATYPE_Short:			
				case SG_DATATYPE_Int:		Stream >> valInt;    if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valInt);		break;
				case SG_DATATYPE_DWord:
				case SG_DATATYPE_Long:		Stream >> valLong;   if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valLong);		break;
				case SG_DATATYPE_Float:		Stream >> valFloat;  if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valFloat);		break;
				case SG_DATATYPE_Double:	Stream >> valDouble; if( Stream.is_null() ) pRecord->Set_NoData(iField); else pRecord->Set_Value(iField, valDouble);	break;
				case SG_DATATYPE_Binary:	Stream >> valRaw;    if( Stream.is_null() ) pRecord->Set_NoData(iField); else
					{
						BLOB.Clear();

						for(int i=0; i<valRaw.len(); i++)
						{
							BLOB.Add((BYTE)valRaw[i]);
						}

						pRecord->Set_Value(iField, BLOB);
					}
					break;
				}
			}
		}
	}
	//-----------------------------------------------------
	catch( otl_exception &e )
	{
		_Error_Message(e);

		return( false );
	}

	return( true );
}
コード例 #10
0
//---------------------------------------------------------
bool CSG_ODBC_Connection::Table_Load_BLOBs(CSG_Bytes_Array &BLOBs, const CSG_String &Table_Name, const CSG_String &Field, const CSG_String &Where, const CSG_String &Order)
{
	//-----------------------------------------------------
	if( !is_Connected() )
	{
		_Error_Message(_TL("no database connection"));

		return( false );
	}

	//-----------------------------------------------------
	try
	{
		bool			bLOB	= true;
		int				nFields;
		otl_column_desc	*Fields;
		otl_long_string	valRaw(m_Connection.get_max_long_size());
		otl_stream		Stream;
		CSG_String		Select;

		//-------------------------------------------------
		Select.Printf(SG_T("SELECT %s FROM %s"), Field.c_str(), Table_Name.c_str());

		if( Where.Length() )
		{
			Select	+= SG_T(" WHERE ") + Where;
		}

		if( Order.Length() )
		{
			Select	+= SG_T(" ORDER BY ") + Order;
		}

		//-------------------------------------------------
		Stream.set_lob_stream_mode	(bLOB);
		Stream.open					(bLOB ? 1 : m_Size_Buffer, Select, m_Connection);

		Fields	= Stream.describe_select(nFields);

		if( Fields == NULL || nFields <= 0 )
		{
			_Error_Message(_TL("no fields in selection"));

			return( false );
		}

		if( nFields != 1 )
		{
			_Error_Message(_TL("more than one field in selection"));

			return( false );
		}

		if( _Get_Type_From_SQL(Fields[0].otl_var_dbtype) != SG_DATATYPE_Binary )//|| _Get_Type_From_SQL(Fields[0].otl_var_dbtype) != SG_DATATYPE_String )
		{
			_Error_Message(_TL("field cannot be mapped to binary object"));

			return( false );
		}

		//-------------------------------------------------
		BLOBs.Destroy();

		while( !Stream.eof() && SG_UI_Process_Get_Okay() )	// while not end-of-data
		{
			CSG_Bytes	*pBLOB	= BLOBs.Add();

			Stream >> valRaw;

			if( !Stream.is_null() )
			{
				for(int i=0; i<valRaw.len(); i++)
				{
					pBLOB->Add((BYTE)valRaw[i]);
				}
			}
		}
	}
	//-----------------------------------------------------
	catch( otl_exception &e )
	{
		_Error_Message(e);

		return( false );
	}

	return( true );
}
コード例 #11
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
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 );
}
コード例 #12
0
ファイル: shapes_ogis.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
bool CSG_Grid_OGIS_Converter::to_WKBinary(CSG_Bytes &Bytes, class CSG_Grid *pGrid, int SRID)
{
	Bytes.Clear();

	//-----------------------------------------------------
	// Raster System

	if( pGrid->Get_Projection().Get_EPSG() > 0 )
	{
		SRID	= pGrid->Get_Projection().Get_EPSG();
	}

	Bytes	+= (BYTE  )1;						// endiannes
	Bytes	+= (short )0;						// version
	Bytes	+= (short )1;						// number of bands
	Bytes	+= (double)pGrid->Get_Cellsize();	// scaleX
	Bytes	+= (double)pGrid->Get_Cellsize();	// scaleY
	Bytes	+= (double)pGrid->Get_XMin(true);	// ipX
	Bytes	+= (double)pGrid->Get_YMax(true);	// ipY
	Bytes	+= (double)0.0;						// skewX
	Bytes	+= (double)0.0;						// skewY
	Bytes	+= (int   )SRID;					// srid
	Bytes	+= (short )pGrid->Get_NX();			// width
	Bytes	+= (short )pGrid->Get_NY();			// height

	//-----------------------------------------------------
	// Band

	BYTE	Flags;

	switch( pGrid->Get_Type() )
	{
	case SG_DATATYPE_Bit   : Flags =  0; break;	//  0:  1-bit boolean
//	case SG_DATATYPE_      : Flags =  1; break;	//  1:  2-bit unsigned integer
//	case SG_DATATYPE_      : Flags =  2; break;	//  2:  4-bit unsigned integer
	case SG_DATATYPE_Char  : Flags =  3; break;	//  3:  8-bit   signed integer
	case SG_DATATYPE_Byte  : Flags =  4; break;	//  4:  8-bit unsigned integer
	case SG_DATATYPE_Short : Flags =  5; break;	//  5: 16-bit   signed integer
	case SG_DATATYPE_Word  : Flags =  6; break;	//  6: 16-bit unsigned integer
	case SG_DATATYPE_Int   : Flags =  7; break;	//  7: 32-bit   signed integer
	case SG_DATATYPE_DWord : Flags =  8; break;	//  8: 32-bit unsigned integer
	case SG_DATATYPE_Float : Flags = 10; break;	// 10: 32-bit float
	case SG_DATATYPE_Double: Flags = 11; break;	// 11: 64-bit float
	default:
		break;
	}

//	Flags	|= 0x80;	// isOffline: no, never here!
	Flags	|= 0x40;	// hasNodataValue
//	Flags	|= 0x20;	// isNoDataValue: no, never here!
//	Flags	|= 0x10;	// reserved (unused)

	Bytes	+= Flags;

	switch( pGrid->Get_Type() )
	{
	case SG_DATATYPE_Bit   : Bytes	+= (BYTE  )0; break;	//  0:  1-bit boolean
	case SG_DATATYPE_Char  : Bytes	+= (char  )pGrid->Get_NoData_Value(); break;	//  3:  8-bit   signed integer
	case SG_DATATYPE_Byte  : Bytes	+= (BYTE  )pGrid->Get_NoData_Value(); break;	//  4:  8-bit unsigned integer
	case SG_DATATYPE_Short : Bytes	+= (short )pGrid->Get_NoData_Value(); break;	//  5: 16-bit   signed integer
	case SG_DATATYPE_Word  : Bytes	+= (WORD  )pGrid->Get_NoData_Value(); break;	//  6: 16-bit unsigned integer
	case SG_DATATYPE_Int   : Bytes	+= (int   )pGrid->Get_NoData_Value(); break;	//  7: 32-bit   signed integer
	case SG_DATATYPE_DWord : Bytes	+= (DWORD )pGrid->Get_NoData_Value(); break;	//  8: 32-bit unsigned integer
	case SG_DATATYPE_Float : Bytes	+= (float )pGrid->Get_NoData_Value(); break;	//  9: 32-bit float
	case SG_DATATYPE_Double: Bytes	+= (double)pGrid->Get_NoData_Value(); break;	// 10: 64-bit float
	default:
		break;
	}

	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   : Bytes	+= (BYTE  )pGrid->asDouble(x, y); break;	//  0:  1-bit boolean
			case SG_DATATYPE_Char  : Bytes	+= (char  )pGrid->asDouble(x, y); break;	//  3:  8-bit   signed integer
			case SG_DATATYPE_Byte  : Bytes	+= (BYTE  )pGrid->asDouble(x, y); break;	//  4:  8-bit unsigned integer
			case SG_DATATYPE_Short : Bytes	+= (short )pGrid->asDouble(x, y); break;	//  5: 16-bit   signed integer
			case SG_DATATYPE_Word  : Bytes	+= (WORD  )pGrid->asDouble(x, y); break;	//  6: 16-bit unsigned integer
			case SG_DATATYPE_Int   : Bytes	+= (int   )pGrid->asDouble(x, y); break;	//  7: 32-bit   signed integer
			case SG_DATATYPE_DWord : Bytes	+= (DWORD )pGrid->asDouble(x, y); break;	//  8: 32-bit unsigned integer
			case SG_DATATYPE_Float : Bytes	+= (float )pGrid->asDouble(x, y); break;	//  9: 32-bit float
			case SG_DATATYPE_Double: Bytes	+= (double)pGrid->asDouble(x, y); break;	// 10: 64-bit float
			default:
				break;	  
			}
		}
	}

	return( true );
}
コード例 #13
0
//---------------------------------------------------------
bool CShapes_Save::On_Execute(void)
{
	if( !Get_Connection()->has_PostGIS() )
	{
		Error_Set(_TL("not a valid PostGIS database!"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Shapes	*pShapes;
	CSG_String	SQL, Name, Type, Field, SavePoint;

	pShapes		= Parameters("SHAPES")->asShapes();
	Name		= Parameters("NAME"  )->asString();	if( Name.Length() == 0 )	Name	= pShapes->Get_Name();

	Field		= "geometry";

	int	SRID	= Get_SRID();

	//-----------------------------------------------------
	if( !CSG_Shapes_OGIS_Converter::from_ShapeType(Type, pShapes->Get_Type(), pShapes->Get_Vertex_Type()) )
	{
		Error_Set(_TL("invalid or unsupported shape or vertex type"));

		return( false );
	}

	//-----------------------------------------------------
	Get_Connection()->Begin(SavePoint = Get_Connection()->is_Transaction() ? "SHAPES_SAVE" : "");

	//-----------------------------------------------------
	if( Get_Connection()->Table_Exists(Name) )
	{
		Message_Add(_TL("table already exists") + CSG_String(": ") + Name);

		switch( Parameters("EXISTS")->asInt() )
		{
		case 0:	// abort export
			return( false );

		case 1:	// replace existing table
			Message_Add(_TL("trying to drop table") + CSG_String(": ") + Name);

			if( !Get_Connection()->Table_Drop(Name, false) )
			{
				Message_Add(CSG_String(" ...") + _TL("failed") + "!");

				return( false );
			}

			break;

		case 2:	// append records, if table structure allows
			break;
		}
	}

	//-----------------------------------------------------
	if( !Get_Connection()->Table_Exists(Name) )
	{
		if( !Get_Connection()->Table_Create(Name, *pShapes, Get_Constraints(&Parameters, "SHAPES"), false) )
		{
			Error_Set(_TL("could not create table"));

			Get_Connection()->Rollback(SavePoint);

			return( false );
		}

		//-------------------------------------------------
		// SELECT AddGeometryColumn(<table_name>, <column_name>, <srid>, <type>, <dimension>)

		SQL.Printf(SG_T("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)"),
			Name.c_str(), Field.c_str(), SRID, Type.c_str(),
			pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XY  ? 2 :
			pShapes->Get_Vertex_Type() == SG_VERTEX_TYPE_XYZ ? 3 : 4
		);

		if( !Get_Connection()->Execute(SQL) )
		{
			Error_Set(_TL("could not create geometry field"));

			Get_Connection()->Rollback(SavePoint);

			return( false );
		}
	}

	//-----------------------------------------------------
	bool	bBinary	= Get_Connection()->has_Version(9);

	int		iShape, iField, nAdded;

	CSG_String	Insert	= "INSERT INTO \"" + Name + "\" (" + Field;

	for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
	{
		Insert	+= CSG_String(", ") + pShapes->Get_Field_Name(iField);
	}

	Insert	+= ") VALUES (";

	//-----------------------------------------------------
	for(iShape=0, nAdded=0; iShape==nAdded && iShape<pShapes->Get_Count() && Set_Progress(iShape, pShapes->Get_Count()); iShape++)
	{
		CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

		if( pShape->is_Valid() )
		{
			SQL	= Insert;

			if( bBinary )
			{
				CSG_Bytes	WKB;

				CSG_Shapes_OGIS_Converter::to_WKBinary(pShape, WKB);

				SQL	+= "ST_GeomFromWKB(E'\\\\x" + WKB.toHexString() + CSG_String::Format("', %d)", SRID);
			}
			else
			{
				CSG_String	WKT;

				CSG_Shapes_OGIS_Converter::to_WKText(pShape, WKT);

				SQL	+= "ST_GeomFromText('" + WKT + CSG_String::Format("', %d)", SRID);
			}

			for(iField=0; iField<pShapes->Get_Field_Count(); iField++)
			{
				CSG_String	s = pShape->asString(iField);

				if( pShapes->Get_Field_Type(iField) == SG_DATATYPE_String )
				{
					if( 1 )
					{
						char	*_s	= NULL; if( s.to_ASCII(&_s) ) s = _s; SG_FREE_SAFE(_s);
					}

					s.Replace("'", "\"");

					s	= "'" + s + "'";
				}

				SQL	+= ", "  + s;
			}

			SQL	+= ")";

			if( Get_Connection()->Execute(SQL) )
			{
				nAdded++;
			}
			else
			{
				Message_Add(CSG_String::Format("%s [%d/%d]", _TL("could not save shape"), 1 + iShape, pShapes->Get_Count()));
			}
		}
	}

	//-----------------------------------------------------
	if( nAdded < pShapes->Get_Count() )
	{
		Message_Add(SQL);

		Get_Connection()->Rollback(SavePoint);

		return( false );
	}

	Get_Connection()->Commit(SavePoint);

	Get_Connection()->GUI_Update();

	Get_Connection()->Add_MetaData(*pShapes, Name);

	pShapes->Set_Modified(false);

	return( true );
}