Esempio n. 1
0
//---------------------------------------------------------
bool CGrid_Colors_Fit::On_Execute(void)
{
	int		iColor;
	long	aC, bC;
	double	aZ, bZ, dColor, zMin, zRange;
	CSG_Colors	Colors_Old, Colors_New;
	CSG_Grid	*pGrid;

	pGrid	= Parameters("GRID")->asGrid();

	Colors_New.Set_Count(Parameters("COUNT")->asInt());

	switch( Parameters("SCALE")->asInt() )
	{
	case 0:	default:
		zMin	= pGrid->Get_ZMin();
		zRange	= pGrid->Get_ZMax() - zMin;
		break;

	case 1:
		zMin	= Parameters("RANGE")->asRange()->Get_LoVal();
		zRange	= Parameters("RANGE")->asRange()->Get_HiVal() - zMin;
		break;
	}

	DataObject_Get_Colors(pGrid, Colors_Old);

	if( Colors_Old.Get_Count() > 1 && pGrid->Get_ZRange() > 0.0 && zRange != 0.0 )
	{
		dColor	= 100.0 / Colors_Old.Get_Count();

		aZ		= 0.0;
		aC		= Colors_Old.Get_Color(0);

		for(iColor=1; iColor<Colors_Old.Get_Count()-1; iColor++)
		{
			bZ	= aZ;
			bC	= aC;
			aZ	= (pGrid->Get_Percentile(iColor * dColor) - zMin) / zRange;
			aC	= Colors_Old.Get_Color(iColor);
			_Set_Colors(Colors_New, bZ, bC, aZ, aC);
		}

		bZ	= aZ;
		bC	= aC;
		aZ	= 1.0;
		aC	= Colors_Old.Get_Color(Colors_Old.Get_Count() - 1);
		_Set_Colors(Colors_New, bZ, bC, aZ, aC);

		DataObject_Set_Colors	(pGrid, Colors_New);
		DataObject_Update		(pGrid, zMin, zMin + zRange);

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CGrid_Invert::On_Execute(void)
{
	CSG_Grid	*pGrid	= Parameters("INVERSE")->asGrid();

	if( pGrid == NULL )
	{
		pGrid	= Parameters("GRID")->asGrid();
	}
	else if( pGrid != Parameters("GRID")->asGrid() )
	{
		pGrid->Create(*Parameters("GRID")->asGrid());

		pGrid->Set_Name(CSG_String::Format("%s [%s]", pGrid->Get_Name(), Parameters("METHOD")->asString()));
	}

	//-----------------------------------------------------
	double	zMin	= pGrid->Get_ZMin();
	double	zMax	= pGrid->Get_ZMax();

	for(int y=0; y<Get_NY() && SG_UI_Process_Set_Progress(y, Get_NY()); y++)
	{
		#pragma omp parallel for
		for(int x=0; x<Get_NX(); x++)
		{
			if( !pGrid->is_NoData(x, y) )
			{
				pGrid->Set_Value(x, y, zMax - (pGrid->asDouble(x, y) - zMin));
			}
		}
	}

	//-----------------------------------------------------
	if( pGrid == Parameters("GRID")->asGrid() )
	{
		DataObject_Update(pGrid);
	}

	return( true );
}
Esempio n. 3
0
//---------------------------------------------------------
bool CGSGrid_Statistics_To_Table::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Parameter_Grid_List	*pGrids	= Parameters("GRIDS")->asGridList();

	if( pGrids->Get_Count() < 1 )
	{
		Error_Set(_TL("no grids in selection"));

		return( false );
	}

	//-----------------------------------------------------
	CSG_Table	*pTable	= Parameters("STATS")->asTable();

	pTable->Destroy();
	pTable->Set_Name(_TL("Statistics for Grids"));
	pTable->Add_Field(_TL("NAME"), SG_DATATYPE_String);

	if( Parameters("DATA_CELLS"  )->asBool() )	pTable->Add_Field(_TL("DATA_CELLS"  ), SG_DATATYPE_Int);
	if( Parameters("NODATA_CELLS")->asBool() )	pTable->Add_Field(_TL("NODATA_CELLS"), SG_DATATYPE_Int);
	if( Parameters("CELLSIZE"    )->asBool() )	pTable->Add_Field(_TL("CELLSIZE"    ), SG_DATATYPE_Double);
	if( Parameters("MEAN"        )->asBool() )	pTable->Add_Field(_TL("MEAN"        ), SG_DATATYPE_Double);
	if( Parameters("MIN"         )->asBool() )	pTable->Add_Field(_TL("MIN"         ), SG_DATATYPE_Double);
	if( Parameters("MAX"         )->asBool() )	pTable->Add_Field(_TL("MAX"         ), SG_DATATYPE_Double);
	if( Parameters("RANGE"       )->asBool() )	pTable->Add_Field(_TL("RANGE"       ), SG_DATATYPE_Double);
	if( Parameters("VAR"         )->asBool() )	pTable->Add_Field(_TL("VAR"         ), SG_DATATYPE_Double);
	if( Parameters("STDDEV"      )->asBool() )	pTable->Add_Field(_TL("STDDEV"      ), SG_DATATYPE_Double);
	if( Parameters("STDDEVLO"    )->asBool() )	pTable->Add_Field(_TL("STDDEVLO"    ), SG_DATATYPE_Double);
	if( Parameters("STDDEVHI"    )->asBool() )	pTable->Add_Field(_TL("STDDEVHI"    ), SG_DATATYPE_Double);
	if( Parameters("PCTL"        )->asBool() )	pTable->Add_Field(_TL("PCTL"        ), SG_DATATYPE_Double);

	if( pTable->Get_Field_Count() <= 1 )
	{
		Error_Set(_TL("no parameter output specified"));

		return( false );
	}

	double	dRank	= Parameters("PCTL")->asBool() ? Parameters("PCTL_VAL")->asDouble() : -1.0;

	//-----------------------------------------------------
	for(int i=0; i<pGrids->Get_Count() && Process_Get_Okay(); i++)
	{
		CSG_Grid			*pGrid		= pGrids->asGrid(i);
		CSG_Table_Record	*pRecord	= pTable->Add_Record();

		pRecord->Set_Value("NAME"        , pGrid->Get_Name());
		pRecord->Set_Value("DATA_CELLS"  , pGrid->Get_NCells() - pGrid->Get_NoData_Count());
		pRecord->Set_Value("NODATA_CELLS", pGrid->Get_NoData_Count());
		pRecord->Set_Value("CELLSIZE"    , pGrid->Get_Cellsize());
		pRecord->Set_Value("MEAN"        , pGrid->Get_ArithMean());
		pRecord->Set_Value("MIN"         , pGrid->Get_ZMin());
		pRecord->Set_Value("MAX"         , pGrid->Get_ZMax());
		pRecord->Set_Value("RANGE"       , pGrid->Get_ZRange());
		pRecord->Set_Value("VAR"         , pGrid->Get_Variance());
		pRecord->Set_Value("STDDEV"      , pGrid->Get_StdDev());
		pRecord->Set_Value("STDDEVLO"    , pGrid->Get_ArithMean() - pGrid->Get_StdDev());
		pRecord->Set_Value("STDDEVHI"    , pGrid->Get_ArithMean() + pGrid->Get_StdDev());

		if( dRank > 0.0 && dRank < 100.0 )
		{
			pRecord->Set_Value("PCTL", pGrid->Get_Percentile(dRank));	// this is a time consuming operation
		}
	}

	if( dRank > 0.0 && dRank < 100.0 )
	{
		pTable->Set_Field_Name(pTable->Get_Field_Count() - 1, CSG_String::Format(SG_T("%s%02d"), _TL("PCTL"), (int)dRank));
	}

	return( true );
}
Esempio n. 4
0
//---------------------------------------------------------
bool CSurfer_Export::On_Execute(void)
{
	const char	ID_BINARY[]	= "DSBB";

	bool		bNoData;
	short		sValue;
	int			x, y;
	float		*fLine;
	double		dValue;
	FILE		*Stream;
	CSG_String	fName;
	CSG_Grid	*pGrid;

	//-----------------------------------------------------
	pGrid	= Parameters("GRID")	->asGrid();
	fName	= Parameters("FILE")	->asString();
	bNoData	= Parameters("NODATA")	->asBool();

	switch( Parameters("FORMAT")->asInt() )
	{
	//-----------------------------------------------------
	case 0:	// Surfer 6 - Binary...

		if( (Stream = fopen(fName.b_str(), "wb")) != NULL )
		{
			fwrite(ID_BINARY, 4, sizeof(char  ), Stream);

			sValue	= (short)pGrid->Get_NX();
			fwrite(&sValue	, 1, sizeof(short ), Stream);
			sValue	= (short)pGrid->Get_NY();
			fwrite(&sValue	, 1, sizeof(short ), Stream);

			dValue	= pGrid->Get_XMin();
			fwrite(&dValue	, 1, sizeof(double), Stream);
			dValue	= pGrid->Get_XMax();
			fwrite(&dValue	, 1, sizeof(double), Stream);

			dValue	= pGrid->Get_YMin();
			fwrite(&dValue	, 1, sizeof(double), Stream);
			dValue	= pGrid->Get_YMax();
			fwrite(&dValue	, 1, sizeof(double), Stream);

			dValue	= pGrid->Get_ZMin();
			fwrite(&dValue	, 1, sizeof(double), Stream);
			dValue	= pGrid->Get_ZMax();
			fwrite(&dValue	, 1, sizeof(double), Stream);

			//---------------------------------------------
			fLine	= (float *)SG_Malloc(pGrid->Get_NX() * sizeof(float));

			for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
			{
				for(x=0; x<pGrid->Get_NX(); x++)
				{
					fLine[x]	= bNoData && pGrid->is_NoData(x, y) ? NODATAVALUE : pGrid->asFloat(x, y);
				}

				fwrite(fLine, pGrid->Get_NX(), sizeof(float), Stream);
			}

			SG_Free(fLine);

			fclose(Stream);

			return( true );
		}
		break;

	//-----------------------------------------------------
	case 1:	// Surfer - ASCII...

		if( (Stream = fopen(fName.b_str(), "w")) != NULL )
		{
			fprintf(Stream, "DSAA\n" );
			fprintf(Stream, "%d %d\n", pGrid->Get_NX()	, pGrid->Get_NY()	);
			fprintf(Stream, "%f %f\n", pGrid->Get_XMin(), pGrid->Get_XMax()	);
			fprintf(Stream, "%f %f\n", pGrid->Get_YMin(), pGrid->Get_YMax()	);
			fprintf(Stream, "%f %f\n", pGrid->Get_ZMin(), pGrid->Get_ZMax()	);

			//---------------------------------------------
			for(y=0; y<pGrid->Get_NY() && Set_Progress(y, pGrid->Get_NY()); y++)
			{
				for(x=0; x<pGrid->Get_NX(); x++)
				{
					if( bNoData && pGrid->is_NoData(x, y) )
					{
						fprintf(Stream, "1.70141e38 ");
					}
					else
					{
						fprintf(Stream, "%f ", pGrid->asFloat(x, y));
					}
				}

				fprintf(Stream, "\n");
			}

			fclose(Stream);

			return( true );
		}
		break;
	}

	//-----------------------------------------------------
	return( false );
}