//---------------------------------------------------------
void CSG_PointCloud::_On_Construction(void)
{
    m_Type			= SHAPE_TYPE_Point;
    m_Vertex_Type	= SG_VERTEX_TYPE_XYZ;

    m_nFields		= 0;
    m_Field_Name	= NULL;
    m_Field_Type	= NULL;
    m_Field_Stats	= NULL;
    m_Field_Offset	= NULL;

    m_Points		= NULL;
    m_nRecords		= 0;
    m_nPointBytes	= 0;

    m_Cursor		= NULL;
    m_bXYZPrecDbl	= true;

    Set_NoData_Value(-999999);

    Set_Update_Flag();

    m_Shapes.Create(SHAPE_TYPE_Point, NULL, NULL, SG_VERTEX_TYPE_XYZ);
    m_Shapes.Add_Shape();
    m_Shapes_Index	= -1;

    m_Array_Points.Create(sizeof(char *), 0, SG_ARRAY_GROWTH_3);
}
Beispiel #2
0
//---------------------------------------------------------
bool CSG_Grid::_Assign_ExtremeValue(CSG_Grid *pGrid, bool bMaximum)
{
	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
	{
		return( false );
	}

	//-----------------------------------------------------
	int			x, y, ix, iy;
	double		px, py, ax, ay, d, z;
	CSG_Matrix	S(Get_NY(), Get_NX()), N(Get_NY(), Get_NX());

	d	= pGrid->Get_Cellsize() / Get_Cellsize();

	Set_NoData_Value(pGrid->Get_NoData_Value());

	Assign_NoData();

	//-----------------------------------------------------
	ax	= 0.5 + (pGrid->Get_XMin() - Get_XMin()) / Get_Cellsize();
	ay	= 0.5 + (pGrid->Get_YMin() - Get_YMin()) / Get_Cellsize();

	for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
	{
		if( (iy = (int)floor(py)) >= 0 && iy < Get_NY() )
		{
			for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
			{
				if( !pGrid->is_NoData(x, y) && (ix = (int)floor(px)) >= 0 && ix < Get_NX() )
				{
					z	= pGrid->asDouble(x, y);

					if( is_NoData(ix, iy)
					||	(bMaximum == true  && z > asDouble(ix, iy))
					||	(bMaximum == false && z < asDouble(ix, iy)) )
					{
						Set_Value(ix, iy, z);
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	Get_History()	= pGrid->Get_History();
	Get_History().Add_Child(SG_T("GRID_OPERATION"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()))->Add_Property(SG_T("NAME"), LNG("Resampling"));

	SG_UI_Process_Set_Ready();

	return( true );
}
Beispiel #3
0
//---------------------------------------------------------
void CSG_Grid::Normalise(void)
{
	if( is_Valid() )
	{
		Update();

		if( m_zStats.Get_StdDev() > 0.0 )
		{
			int		x, y;

			if(	(Get_NoData_hiValue() > -NORMALISED_NODATA && Get_NoData_hiValue() < NORMALISED_NODATA)
			||	(Get_NoData_Value  () > -NORMALISED_NODATA && Get_NoData_Value  () < NORMALISED_NODATA) )
			{
				for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
				{
					for(x=0; x<Get_NX(); x++)
					{
						if( is_NoData(x, y) )
						{
							Set_Value(x, y, -NORMALISED_NODATA);
						}
					}
				}

				Set_NoData_Value(-NORMALISED_NODATA);
			}

			for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
			{
				for(x=0; x<Get_NX(); x++)
				{
					if( !is_NoData(x, y) )
					{
						Set_Value(x, y, (asDouble(x, y) - m_zStats.Get_Mean()) / m_zStats.Get_StdDev() );
					}
				}
			}

			SG_UI_Process_Set_Ready();

			Get_History().Add_Child(SG_T("GRID_OPERATION"), LNG("Normalisation"));
		}
	}
}
Beispiel #4
0
//---------------------------------------------------------
bool CSG_Grid::_Assign_MeanValue(CSG_Grid *pGrid, bool bAreaProportional)
{
	if( Get_Cellsize() < pGrid->Get_Cellsize() || is_Intersecting(pGrid->Get_Extent()) == INTERSECTION_None )
	{
		return( false );
	}

	//-----------------------------------------------------
	int			x, y, ix, iy, jx, jy;
	double		px, py, ax, ay, d, w, wx, wy, z;
	CSG_Matrix	S(Get_NY(), Get_NX()), N(Get_NY(), Get_NX());

	d	= pGrid->Get_Cellsize() / Get_Cellsize();

	Set_NoData_Value(pGrid->Get_NoData_Value());

	Assign_NoData();

	//-----------------------------------------------------
	if( bAreaProportional == false )
	{
		ax	= 0.5 + (pGrid->Get_XMin() - Get_XMin()) / Get_Cellsize();
		ay	= 0.5 + (pGrid->Get_YMin() - Get_YMin()) / Get_Cellsize();

		for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
		{
			if( (iy = (int)floor(py)) >= 0 && iy < Get_NY() )
			{
				for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
				{
					if( !pGrid->is_NoData(x, y) && (ix = (int)floor(px)) >= 0 && ix < Get_NX() )
					{
						S[ix][iy]	+= pGrid->asDouble(x, y);
						N[ix][iy]	++;
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	else // if( bAreaProportional == true )
	{
		ax	= ((pGrid->Get_XMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_XMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();
		ay	= ((pGrid->Get_YMin() - 0.5 * pGrid->Get_Cellsize()) - (Get_YMin() - 0.5 * Get_Cellsize())) / Get_Cellsize();

		for(y=0, py=ay; y<pGrid->Get_NY() && SG_UI_Process_Set_Progress(y, pGrid->Get_NY()); y++, py+=d)
		{
			if( py > -d || py < Get_NY() )
			{
				iy	= (int)floor(py);
				wy	= (py + d) - iy;
				wy	= wy < 1.0 ? 1.0 : wy - 1.0; 

				for(x=0, px=ax; x<pGrid->Get_NX(); x++, px+=d)
				{
					if( !pGrid->is_NoData(x, y) && (px > -d && px < Get_NX()) )
					{
						ix	= (int)floor(px);
						wx	= (px + d) - ix;
						wx	= wx < 1.0 ? 1.0 : wx - 1.0; 

						z	= pGrid->asDouble(x, y);

						if( iy >= 0 && iy < Get_NY() )		// wy > 0.0 is always true
						{
							if( ix >= 0 && ix < Get_NX() )	// wx > 0.0 is always true
							{
								w	= wx * wy;
								S[ix][iy]	+= w * z;
								N[ix][iy]	+= w;
							}

							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
							{
								w	= (1.0 - wx) * wy;
								S[jx][iy]	+= w * z;
								N[jx][iy]	+= w;
							}
						}

						if( wy < 1.0 && (jy = iy + 1) >= 0 && jy < Get_NY() )
						{
							if( ix >= 0 && ix < Get_NX() )
							{
								w	= wx * (1.0 - wy);
								S[ix][jy]	+= w * z;
								N[ix][jy]	+= w;
							}

							if( wx < 1.0 && (jx = ix + 1) >= 0 && jx < Get_NX() )
							{
								w	= (1.0 - wx) * (1.0 - wy);
								S[jx][jy]	+= w * z;
								N[jx][jy]	+= w;
							}
						}
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	for(y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
	{
		for(x=0; x<Get_NX(); x++)
		{
			if( N[x][y] )
			{
				Set_Value(x, y, S[x][y] / N[x][y]);
			}
			else
			{
				Set_NoData(x, y);
			}
		}
	}

	//-----------------------------------------------------
	Get_History()	= pGrid->Get_History();
	Get_History().Add_Child(SG_T("GRID_OPERATION"), CSG_String::Format(SG_T("%f -> %f"), pGrid->Get_Cellsize(), Get_Cellsize()))->Add_Property(SG_T("NAME"), LNG("Resampling"));

	SG_UI_Process_Set_Ready();

	return( true );
}
Beispiel #5
0
//---------------------------------------------------------
bool CSG_Grid::_Load_Native(const CSG_String &File_Name, TSG_Grid_Memory_Type Memory_Type)
{
	bool			bResult, hdr_bFlip, hdr_bSwapBytes;
	int				iType, hdr_Offset, NX, NY;
	double			Cellsize, xMin, yMin;
	CSG_File		Stream;
	TSG_Data_Type	hdr_Type;
	CSG_Grid_System	System;
	CSG_String		File_Data, Value;

	//-----------------------------------------------------
	bResult	= false;

	if( Stream.Open(File_Name, SG_FILE_R, false) )
	{
		//-------------------------------------------------
		// Load Header...

		hdr_Type		= SG_DATATYPE_Undefined;
		hdr_Offset		= 0;
		hdr_bFlip		= false;
		hdr_bSwapBytes	= false;

		NX	= NY		= 0;
		Cellsize		= 0.0;
		xMin			= 0.0;
		yMin			= 0.0;

		//-------------------------------------------------
		do
		{
			switch( _Load_Native_Get_Key(Stream, Value) )
			{
			case GRID_FILE_KEY_NAME:			Set_Name		(Value);			break;
			case GRID_FILE_KEY_DESCRIPTION:		Set_Description	(Value);			break;
			case GRID_FILE_KEY_UNITNAME:		Set_Unit		(Value);			break;

			case GRID_FILE_KEY_CELLCOUNT_X:		NX				= Value.asInt();	break;
			case GRID_FILE_KEY_CELLCOUNT_Y:		NY				= Value.asInt();	break;
			case GRID_FILE_KEY_POSITION_XMIN:	xMin			= Value.asDouble();	break;
			case GRID_FILE_KEY_POSITION_YMIN:	yMin			= Value.asDouble();	break;
			case GRID_FILE_KEY_CELLSIZE:		Cellsize		= Value.asDouble();	break;
			case GRID_FILE_KEY_Z_FACTOR:		m_zFactor		= Value.asDouble();	break;
			case GRID_FILE_KEY_NODATA_VALUE:	Set_NoData_Value(Value.asDouble());	break;

			case GRID_FILE_KEY_DATAFILE_OFFSET:	hdr_Offset		= Value.asInt();	break;
			case GRID_FILE_KEY_BYTEORDER_BIG:	hdr_bSwapBytes	= Value.Find(GRID_FILE_KEY_TRUE) >= 0;	break;
			case GRID_FILE_KEY_TOPTOBOTTOM:		hdr_bFlip		= Value.Find(GRID_FILE_KEY_TRUE) >= 0;	break;

			case GRID_FILE_KEY_DATAFILE_NAME:
				if( SG_File_Get_Path(Value).Length() > 0 )
				{
					File_Data	= Value;
				}
				else
				{
					File_Data	= SG_File_Make_Path(SG_File_Get_Path(File_Name), Value);
				}
				break;

			case GRID_FILE_KEY_DATAFORMAT:
				for(iType=0; iType<SG_DATATYPE_Undefined && hdr_Type == SG_DATATYPE_Undefined; iType++)
				{
					if( Value.Find(gSG_Data_Type_Identifier[iType]) >= 0 )
					{
						hdr_Type	= (TSG_Data_Type)iType;
					}
				}
				break;
			}
		}
		while( !Stream.is_EOF() );


		//-------------------------------------------------
		// Load Data...

		if( m_System.Assign(Cellsize, xMin, yMin, NX, NY) )
		{
			//---------------------------------------------
			// ASCII...

			if( !SG_Data_Type_is_Numeric(hdr_Type) )
			{
				if( m_Type >= SG_DATATYPE_Undefined )
				{
					m_Type	= SG_DATATYPE_Float;
				}

				if(	Stream.Open(File_Data											, SG_FILE_R, false)
				||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, SG_FILE_R, false)
				||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, SG_FILE_R, false) )
				{
					Stream.Seek(hdr_Offset);
					bResult	= _Load_ASCII(Stream, Memory_Type, hdr_bFlip);
				}
			}

			//---------------------------------------------
			// Binary...

			else
			{
				if( m_Type >= SG_DATATYPE_Undefined )
				{
					m_Type	= hdr_Type;
				}

				if( (NX = SG_Grid_Cache_Check(m_System, Get_nValueBytes())) > 0 )
				{
					Set_Buffer_Size(NX);

					if( _Cache_Create(File_Data											, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip)
					||	_Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip)
					||	_Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) )
					{
						return( true );
					}

					Memory_Type	= GRID_MEMORY_Cache;
				}

				if( _Memory_Create(Memory_Type) )
				{
					if(	Stream.Open(File_Data											, SG_FILE_R, true)
					||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat"))	, SG_FILE_R, true)
					||	Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat"))	, SG_FILE_R, true) )
					{
						Stream.Seek(hdr_Offset);
						bResult	= _Load_Binary(Stream, hdr_Type, hdr_bFlip, hdr_bSwapBytes);
					}
				}
			}
		}
	}

	return( bResult );
}