//---------------------------------------------------------
bool CSG_PointCloud::Del_Point(int iPoint)
{
    if( iPoint >= 0 && iPoint < Get_Count() )
    {
        if( is_Selected(iPoint) )
        {
            Select(iPoint, true);
        }

        m_Cursor	= m_Points[iPoint];

        for(int i=iPoint, j=iPoint+1; j<Get_Count(); i++, j++)
        {
            m_Points[i]	= m_Points[j];
        }

        m_Points[Get_Count() - 1]	= m_Cursor;

        m_Cursor	= NULL;

        _Dec_Array();

        Set_Modified();
        Set_Update_Flag();
        _Stats_Invalidate();

        return( true );
    }

    return( false );
}
//---------------------------------------------------------
bool CSG_PointCloud::Del_Field(int iField)
{
    int		i;

    if( iField < 3 || iField >= m_nFields )
    {
        return( false );
    }

    if( m_nFields == 1 )
    {
        return( Destroy() );
    }

    //-----------------------------------------------------
    m_nFields		--;
    m_nPointBytes	-= PC_GET_NBYTES(m_Field_Type[iField]);

    for(i=0; i<m_nRecords; i++)
    {
        if( iField < m_nFields )
        {
            memmove(
                m_Points[i] + m_Field_Offset[iField],
                m_Points[i] + m_Field_Offset[iField + 1],
                m_Field_Offset[iField + 1] - m_Field_Offset[iField]
            );
        }

        m_Points[i]	= (char *)SG_Realloc(m_Points[i], m_nPointBytes * sizeof(char));
    }

    //-----------------------------------------------------
    delete(m_Field_Name [iField]);
    delete(m_Field_Stats[iField]);

    for(i=iField; i<m_nFields; i++)
    {
        m_Field_Name  [i]	= m_Field_Name  [i + 1];
        m_Field_Type  [i]	= m_Field_Type  [i + 1];
        m_Field_Stats [i]	= m_Field_Stats [i + 1];
        m_Field_Offset[i]	= m_Field_Offset[i - 1] + PC_GET_NBYTES(m_Field_Type[i - 1]);
    }

    m_Field_Name	= (CSG_String            **)SG_Realloc(m_Field_Name  , m_nFields * sizeof(CSG_String *));
    m_Field_Type	= (TSG_Data_Type          *)SG_Realloc(m_Field_Type  , m_nFields * sizeof(TSG_Data_Type));
    m_Field_Stats	= (CSG_Simple_Statistics **)SG_Realloc(m_Field_Stats , m_nFields * sizeof(CSG_Simple_Statistics *));
    m_Field_Offset	= (int                    *)SG_Realloc(m_Field_Offset, m_nFields * sizeof(int));

    Set_Modified();

    return( true );
}
//---------------------------------------------------------
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 );
}
//---------------------------------------------------------
bool CSG_PointCloud::Add_Point(double x, double y, double z)
{
    if( _Inc_Array() )
    {
        _Set_Field_Value(m_Cursor, 0, x);
        _Set_Field_Value(m_Cursor, 1, y);
        _Set_Field_Value(m_Cursor, 2, z);

        Set_Modified();
        Set_Update_Flag();
        _Stats_Invalidate();

        return( true );
    }

    return( false );
}
Example #5
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 );
}
//---------------------------------------------------------
bool CSG_PointCloud::_Add_Field(const SG_Char *Name, TSG_Data_Type Type, int iField)
{
    if( !Name || PC_GET_NBYTES(Type) <= 0 )
    {
        return( false );
    }

    m_Field_Name	= (CSG_String            **)SG_Realloc(m_Field_Name  , (m_nFields + 1) * sizeof(CSG_String *));
    m_Field_Type	= (TSG_Data_Type          *)SG_Realloc(m_Field_Type  , (m_nFields + 1) * sizeof(TSG_Data_Type));
    m_Field_Stats	= (CSG_Simple_Statistics **)SG_Realloc(m_Field_Stats , (m_nFields + 1) * sizeof(CSG_Simple_Statistics *));
    m_Field_Offset	= (int                    *)SG_Realloc(m_Field_Offset, (m_nFields + 1) * sizeof(int));

    m_Field_Name  [m_nFields]	= new CSG_String(Name);
    m_Field_Type  [m_nFields]	= Type;
    m_Field_Stats [m_nFields]	= new CSG_Simple_Statistics();
    m_Field_Offset[m_nFields]	= m_nFields == 0 ? 1 : m_Field_Offset[m_nFields - 1] + PC_GET_NBYTES(m_Field_Type[m_nFields - 1]);

    if( m_nFields == 0 )
    {
        m_nPointBytes	= 1;
    }

    m_nPointBytes	+= PC_GET_NBYTES(m_Field_Type[m_nFields]);
    m_nFields		++;

    m_Shapes.Add_Field(Name, Type);

    for(int i=0; i<Get_Count(); i++)
    {
        m_Points[i]	= (char *)SG_Realloc(m_Points[i], m_nPointBytes * sizeof(char));
    }

    Set_Modified();

    return( true );
}
Example #7
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 );
}
Example #8
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 );
}
Example #9
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 );
}
Example #10
0
//---------------------------------------------------------
bool CSG_Table::_Load_DBase(const CSG_String &File_Name)
{
	int					iField;
	CSG_Table_DBase		dbf;
	CSG_Table_Record	*pRecord;

	//-----------------------------------------------------
	if( dbf.Open(File_Name) )
	{
		Destroy();

		for(iField=0; iField<dbf.Get_FieldCount(); iField++)
		{
			TSG_Data_Type	Type;

			switch( dbf.Get_FieldType(iField) )
			{
			case DBF_FT_LOGICAL:
				Type	= SG_DATATYPE_Char;
				break;

			case DBF_FT_CHARACTER:	default:
				Type	= SG_DATATYPE_String;
				break;

			case DBF_FT_DATE:
				Type	= SG_DATATYPE_Date;
				break;

			case DBF_FT_NUMERIC:
				Type	= dbf.Get_FieldDecimals(iField) > 0
						? SG_DATATYPE_Double
						: SG_DATATYPE_Long;
				break;
			}

			Add_Field(SG_STR_MBTOSG(dbf.Get_FieldName(iField)), Type);
		}

		//-------------------------------------------------
		if( dbf.Move_First() && dbf.Get_Record_Count() > 0 )
		{
			m_nRecords		= m_nBuffer	= dbf.Get_Record_Count();
			m_Records		= (CSG_Table_Record **)SG_Malloc(m_nRecords * sizeof(CSG_Table_Record *));

			for(int iRecord=0; iRecord<m_nRecords && SG_UI_Process_Set_Progress(iRecord, m_nRecords); iRecord++)
			{
				m_Records[iRecord]	= pRecord	= _Get_New_Record(iRecord);

				for(iField=0; iField<Get_Field_Count(); iField++)
				{
					switch( Get_Field_Type(iField) )
					{
					case SG_DATATYPE_Char:
						pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) );
						break;

					case SG_DATATYPE_String:	default:
						pRecord->Set_Value(iField, SG_STR_MBTOSG(dbf.asString(iField)) );
						break;

					case SG_DATATYPE_Date:
						pRecord->Set_Value(iField, dbf.asDouble(iField) );
						break;

					case SG_DATATYPE_Long:
						pRecord->Set_Value(iField, dbf.asInt(iField) );
						break;

					case SG_DATATYPE_Double:
						pRecord->Set_Value(iField, dbf.asDouble(iField) );
						break;
					}
				}

				dbf.Move_Next();
			}

			SG_UI_Process_Set_Ready();

			Set_Modified(false);

			Set_Update_Flag();

			_Stats_Invalidate();
		}

		return( true );
	}

	return( false );
}
Example #11
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 );
}