//---------------------------------------------------------
bool CSG_PointCloud::_Save(const CSG_String &File_Name)
{
    CSG_File	Stream;

    SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), _TL("Save point cloud"), File_Name.c_str()), true);

    CSG_String	sFile_Name = SG_File_Make_Path(NULL, File_Name, SG_T("spc"));

    if( Stream.Open(sFile_Name, SG_FILE_W, true) == false )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("unable to create file."));

        return( false );
    }

    int		i, iBuffer, nPointBytes	= m_nPointBytes - 1;

    Stream.Write((void *)PC_FILE_VERSION, 6);
    Stream.Write(&nPointBytes	, sizeof(int));
    Stream.Write(&m_nFields		, sizeof(int));

    for(i=0; i<m_nFields; i++)
    {
        Stream.Write(&m_Field_Type[i], sizeof(TSG_Data_Type));

        iBuffer	= (int)m_Field_Name[i]->Length();
        if( iBuffer >= 1024 - 1 )	iBuffer	= 1024 - 1;
        Stream.Write(&iBuffer, sizeof(int));
        Stream.Write((void *)m_Field_Name[i]->b_str(), sizeof(char), iBuffer);
    }

    _Set_Shape(m_Shapes_Index);

    for(i=0; i<Get_Count() && SG_UI_Process_Set_Progress(i, Get_Count()); i++)
    {
        Stream.Write(m_Points[i] + 1, nPointBytes);
    }

    Set_Modified(false);

    Set_File_Name(sFile_Name, true);

    Save_MetaData(File_Name);

    Get_Projection().Save(SG_File_Make_Path(NULL, File_Name, SG_T("prj")), SG_PROJ_FMT_WKT);

    SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);

    SG_UI_Process_Set_Ready();

    return( true );
}
示例#2
0
//---------------------------------------------------------
bool CSG_Grid::_Load(const CSG_String &File_Name, TSG_Data_Type Type, TSG_Grid_Memory_Type Memory_Type)
{
	bool	bResult;

	//-----------------------------------------------------
	Destroy();

	m_Type	= Type;

	//-----------------------------------------------------
	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load grid"), File_Name.c_str()), true);

	if( SG_File_Cmp_Extension(File_Name, SG_T("grd")) )
	{
		bResult	= _Load_Surfer(File_Name, Memory_Type);
	}
	else
	{
		bResult	= _Load_Native(File_Name, Memory_Type);
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Update_Flag();

		Set_File_Name(File_Name);

		Load_MetaData(File_Name);

		m_bCreated	= true;

		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
	}
	else
	{
		Destroy();

		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);

		SG_UI_Msg_Add_Error(LNG("[ERR] Grid file could not be opened."));
	}

	//-----------------------------------------------------
	return( bResult );
}
示例#3
0
//---------------------------------------------------------
bool CSG_Shapes::Save(const CSG_String &File_Name, int Format)
{
	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), _TL("Save shapes"), File_Name.c_str()), true);

	if( _Save_ESRI(File_Name) )
	{
		Set_Modified(false);

		Set_File_Name(File_Name, true);

		SG_UI_Process_Set_Ready();
		SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);

		return( true );
	}

	SG_UI_Process_Set_Ready();
	SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);

	return( false );
}
示例#4
0
//---------------------------------------------------------
bool CSG_Shapes::Create(const CSG_String &File_Name)
{
	Destroy();

	SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Load shapes"), File_Name.c_str()), true);

	//-----------------------------------------------------
	bool	bResult	= File_Name.BeforeFirst(':').Cmp("PGSQL") && SG_File_Exists(File_Name) && _Load_ESRI(File_Name);

	if( bResult )
	{
		Set_File_Name(File_Name, true);
	}

	//-----------------------------------------------------
	else if( File_Name.BeforeFirst(':').Cmp("PGSQL") == 0 )	// database source
	{
		CSG_String	s(File_Name);

		s	= s.AfterFirst(':');	CSG_String	Host  (s.BeforeFirst(':'));
		s	= s.AfterFirst(':');	CSG_String	Port  (s.BeforeFirst(':'));
		s	= s.AfterFirst(':');	CSG_String	DBName(s.BeforeFirst(':'));
		s	= s.AfterFirst(':');	CSG_String	Table (s.BeforeFirst(':'));

		CSG_Tool	*pTool	= SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 0);	// CGet_Connections

		if(	pTool != NULL )
		{
			SG_UI_ProgressAndMsg_Lock(true);

			//---------------------------------------------
			CSG_Table	Connections;
			CSG_String	Connection	= DBName + " [" + Host + ":" + Port + "]";

			pTool->Settings_Push();

			if( pTool->On_Before_Execution() && SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() )	// CGet_Connections
			{
				for(int i=0; !bResult && i<Connections.Get_Count(); i++)
				{
					if( !Connection.Cmp(Connections[i].asString(0)) )
					{
						bResult	= true;
					}
				}
			}

			pTool->Settings_Pop();

			//---------------------------------------------
			if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 20)) != NULL) == true )	// CPGIS_Shapes_Load
			{
				pTool->Settings_Push();

				bResult	= pTool->On_Before_Execution()
					&& SG_TOOL_PARAMETER_SET("CONNECTION", Connection)
					&& SG_TOOL_PARAMETER_SET("TABLES"    , Table)
					&& SG_TOOL_PARAMETER_SET("SHAPES"    , this)
					&& pTool->Execute();

				pTool->Settings_Pop();
			}

			SG_UI_ProgressAndMsg_Lock(false);
		}
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Modified(false);
		Set_Update_Flag();

		SG_UI_Process_Set_Ready();
		SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);

		return( true );
	}

	for(int iShape=Get_Count()-1; iShape>=0; iShape--)	// be kind, keep at least those shapes that have been loaded successfully
	{
		if( !Get_Shape(iShape)->is_Valid() )
		{
			Del_Shape(iShape);
		}
	}

	if( Get_Count() <= 0 )
	{
		Destroy();
	}

	SG_UI_Process_Set_Ready();
	SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);

	return( false );
}
示例#5
0
bool CSG_Grid::Save(const CSG_String &File_Name, int Format, int xA, int yA, int xN, int yN)
{
	bool		bResult;
	CSG_String	sFile_Name	= SG_File_Make_Path(NULL, File_Name, SG_T("sgrd"));

	//-----------------------------------------------------
	if( xA	< 0 || xA >= Get_NX() - 1 )
	{
		xA	= 0;
	}

	if( yA	< 0 || yA >= Get_NY() - 1 )
	{
		yA	= 0;
	}

	if( xN	> Get_NX() - xA )
	{
		xN	= Get_NX() - xA;
	}

	if( yN	> Get_NY() - yA )
	{
		yN	= Get_NY() - yA;
	}

	//-----------------------------------------------------
	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save grid"), File_Name.c_str()), true);

	switch( Format )
	{
	default:
	case GRID_FILE_FORMAT_Binary:	// 1 - Binary
		bResult	= _Save_Native(sFile_Name, xA, yA, xN, yN, true);
		break;

	case GRID_FILE_FORMAT_ASCII:	// 2 - ASCII
		bResult	= _Save_Native(sFile_Name, xA, yA, xN, yN, false);
		break;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Modified(false);

		Set_File_Name(sFile_Name);

		Save_MetaData(File_Name);

		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);
	}
	else
	{
		SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);

		SG_UI_Msg_Add_Error(LNG("[ERR] Grid file could not be saved."));
	}

	return( bResult );
}
//---------------------------------------------------------
bool CSG_PointCloud::_Load(const CSG_String &File_Name)
{
    TSG_Data_Type	Type;

    char		ID[6];
    int			i, iBuffer, nPointBytes, nFields;
    char		Name[1024];
    CSG_File	Stream;

    SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), _TL("Load point cloud"), File_Name.c_str()), true);

    //-----------------------------------------------------
    if( !Stream.Open(File_Name, SG_FILE_R, true) )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("file could not be opened."));

        return( false );
    }

    if( !Stream.Read(ID, 6) || strncmp(ID, PC_FILE_VERSION, 5) != 0 )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("incompatible file."));

        return( false );
    }

    if( !Stream.Read(&nPointBytes, sizeof(int)) || nPointBytes < (int)(3 * sizeof(float)) )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("incompatible file."));

        return( false );
    }

    if( !Stream.Read(&nFields, sizeof(int)) || nFields < 3 )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("incompatible file."));

        return( false );
    }

    //-----------------------------------------------------
    Destroy();

    for(i=0; i<nFields; i++)
    {
        if( !Stream.Read(&Type		, sizeof(TSG_Data_Type))
                ||	!Stream.Read(&iBuffer	, sizeof(int)) || !(iBuffer > 0 && iBuffer < 1024)
                ||	!Stream.Read(Name		, iBuffer) )
        {
            SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
            SG_UI_Msg_Add_Error(_TL("incompatible file."));

            return( false );
        }

        if( ID[5] == '0' )	// Data Type Definition changed!!!
        {
            switch( Type )
            {
            default:
                Type	= SG_DATATYPE_Undefined;
                break;
            case 1:
                Type	= SG_DATATYPE_Char;
                break;
            case 2:
                Type	= SG_DATATYPE_Short;
                break;
            case 3:
                Type	= SG_DATATYPE_Int;
                break;
            case 4:
                Type	= SG_DATATYPE_Long;
                break;
            case 5:
                Type	= SG_DATATYPE_Float;
                break;
            case 6:
                Type	= SG_DATATYPE_Double;
                break;
            }
        }

        Name[iBuffer]	= '\0';

        if( !_Add_Field(CSG_String((const char *)Name), Type) )
        {
            SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
            SG_UI_Msg_Add_Error(_TL("incompatible file."));

            return( false );
        }
    }

    if( m_nPointBytes != nPointBytes + 1 )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("incompatible file."));

        return( false );
    }

    //-----------------------------------------------------
    sLong		fLength	= Stream.Length();

    while( _Inc_Array() && Stream.Read(m_Cursor + 1, nPointBytes) && SG_UI_Process_Set_Progress((double)Stream.Tell(), (double)fLength) )
    {}

    _Dec_Array();

    Set_File_Name(File_Name, true);

    Load_MetaData(File_Name);

    if( 0 > Get_Count() )
    {
        SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);
        SG_UI_Msg_Add_Error(_TL("no records in file."));

        return( false );
    }

    //-----------------------------------------------------
    SG_UI_Process_Set_Ready();

    Get_Projection().Load(SG_File_Make_Path(NULL, File_Name, SG_T("prj")), SG_PROJ_FMT_WKT);

    SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS);

    return( true );
}
示例#7
0
//---------------------------------------------------------
bool CSG_Table::_Load(const CSG_String &File_Name, TSG_Table_File_Type Format, const SG_Char *Separator)
{
	if( !::SG_File_Exists(File_Name) )
	{
		return( false );
	}

	bool		bResult;
	CSG_String	fName, sSeparator(Separator);

	_Destroy();

	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Load table"), File_Name.c_str()), true);

	//-----------------------------------------------------
	if( Format == TABLE_FILETYPE_Undefined )
	{
		if( SG_File_Cmp_Extension(File_Name, SG_T("dbf")) )
		{
			Format	= TABLE_FILETYPE_DBase;
		}
		else if( SG_File_Cmp_Extension(File_Name, SG_T("csv")) )
		{
			Format	= TABLE_FILETYPE_Text;
			sSeparator	= ";";
		}
		else //if( SG_File_Cmp_Extension(File_Name, SG_T("txt")) )
		{
			Format	= TABLE_FILETYPE_Text;
		}
	}

	//-----------------------------------------------------
	switch( Format )
	{
	case TABLE_FILETYPE_Text:
		bResult	= _Load_Text (File_Name, true , sSeparator);
		break;

	case TABLE_FILETYPE_Text_NoHeadLine:
		bResult	= _Load_Text (File_Name, false, sSeparator);
		break;

	case TABLE_FILETYPE_DBase:
		bResult	= _Load_DBase(File_Name);
		break;

	default:
		bResult	= false;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Modified(false);

		Set_Update_Flag();

		Set_File_Name(File_Name);

		Load_MetaData(File_Name);

		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);

		return( true );
	}

	SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);

	return( false );
}
示例#8
0
//---------------------------------------------------------
bool CSG_Table::Save(const CSG_String &File_Name, int Format, const SG_Char *Separator)
{
	bool		bResult;
	CSG_String	sSeparator(Separator);

	SG_UI_Msg_Add(CSG_String::Format(SG_T("%s: %s..."), LNG("[MSG] Save table"), File_Name.c_str()), true);

	//-----------------------------------------------------
	if( Format <= TABLE_FILETYPE_Undefined || Format > TABLE_FILETYPE_DBase )
	{
		if( SG_File_Cmp_Extension(File_Name, SG_T("dbf")) )
		{
			Format	= TABLE_FILETYPE_DBase;
		}
		else if( SG_File_Cmp_Extension(File_Name, SG_T("csv")) )
		{
			Format	= TABLE_FILETYPE_Text;
			sSeparator	= ';';
		}
		else //if( SG_File_Cmp_Extension(File_Name, SG_T("txt")) )
		{
			Format	= TABLE_FILETYPE_Text;
		}
	}

	switch( Format )
	{
	case TABLE_FILETYPE_Text:
		bResult	= _Save_Text (File_Name, true , Separator);
		break;

	case TABLE_FILETYPE_Text_NoHeadLine:
		bResult	= _Save_Text (File_Name, false, Separator);
		break;

	case TABLE_FILETYPE_DBase:
		bResult	= _Save_DBase(File_Name);
		break;
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Modified(false);

		Set_Update_Flag();

		Set_File_Type(Format);

		Set_File_Name(File_Name);

		Save_MetaData(File_Name);

		SG_UI_Msg_Add(LNG("[MSG] okay"), false, SG_UI_MSG_STYLE_SUCCESS);

		return( true );
	}

	SG_UI_Msg_Add(LNG("[MSG] failed"), false, SG_UI_MSG_STYLE_FAILURE);

	return( false );
}