⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsgrid_zonal_statistics.cpp

📁 这是一个GPS相关的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}


			for(iGrid=0; iGrid<nCatGrids; iGrid++)								// collect categories
			{
				parent  = runList;
				if( runList->sub == NULL )										// no sub class found
				{
					newSub = new CList_Conti();
					runList->sub = newSub;
				}

				runList = runList->sub;

				pGrid	= pCatList->asGrid(iGrid);
				if( !pGrid->is_NoData(x, y) )
					catID	= pGrid->asInt(x, y);
				else
					catID	= (int)pGrid->Get_NoData_Value();


				while( runList->next != NULL && runList->cat < catID )		// search for last entry in list or insert point
				{
					runList = runList->next;
				}

				if( runList->dummy == true )
				{
					runList->cat = catID;										// first list entry, write and
					runList->dummy = false;										// setup
					runList->parent = parent;
				}
				else if( runList->cat == catID )
					runList = runList;											// zoneID found, all infos already written
				else if( runList->next == NULL && runList->cat < catID)								// append zoneID
				{
					newSub = new CList_Conti();
					newSub->cat		= catID;									//		... and write info
					newSub->previous	= runList;
					newSub->parent		= parent;
//
					newSub->dummy		= false;
					runList->next		= newSub;

					runList			= newSub;
				}
				else															// insert new entry
				{
					newSub = new CList_Conti();
					newSub->cat		= catID;									//		... and write info
					newSub->next		= runList;
					newSub->parent		= parent;
//
					newSub->dummy		= false;
					if( runList->previous != NULL )
					{
						newSub->previous = runList->previous;
						runList->previous->next = newSub;
					}
					else
						parent->sub		= newSub;
							
					runList->previous	= newSub;

					runList			= newSub;
				}
			}


			for(iGrid=0; iGrid<nStatGrids; iGrid++)									// collect statistics for StatGrids
			{
				if( iGrid == 0 )
				{
					if( runList->stats == NULL )
						runList->stats = new CList_Stat();
						
					runStats	= runList->stats;
				}
				else
				{
					if( runStats->next == NULL )
						runStats->next = new CList_Stat();

					runStats = runStats->next;
				}
				if( !pStatList->asGrid(iGrid)->is_NoData(x, y) )
				{
					statID		= pStatList->asGrid(iGrid)->asDouble(x, y);
						
					if( runStats->dummy == true )
					{
						runStats->min = statID;
						runStats->max = statID;
						runStats->dummy = false;
					}
					if( runStats->min > statID )	
						runStats->min = statID;
					if( runStats->max < statID )
						runStats->max = statID;

					runStats->sum += statID;
					runStats->dev += pow(statID, 2);
				}
				else
					NDcountStat += 1;
			}
				

			runList->count += 1;												// sum up unique condition area
		}
	}


	Gridname = pZones->Get_Name();													// Create fields in output table (1st = Zone, 2nd = Catgrid1, 3rd = Catgrid 2, ...)
	pOutTab->Add_Field(Gridname, TABLE_FIELDTYPE_Int);
	for(iGrid=0; iGrid<nCatGrids; iGrid++)
	{
		Gridname = pCatList->asGrid(iGrid)->Get_Name();
		pOutTab->Add_Field(Gridname, TABLE_FIELDTYPE_Int);
	}
	pOutTab->Add_Field("Count", TABLE_FIELDTYPE_Int);
	for(iGrid=0; iGrid<nStatGrids; iGrid++)
	{
		Gridname = pStatList->asGrid(iGrid)->Get_Name();

		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MIN")   , Gridname), TABLE_FIELDTYPE_Double);
		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MAX")   , Gridname), TABLE_FIELDTYPE_Double);
		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_MEAN")  , Gridname), TABLE_FIELDTYPE_Double);
		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_STDDEV"), Gridname), TABLE_FIELDTYPE_Double);
		pOutTab->Add_Field(CSG_String::Format(SG_T("%s_SUM")   , Gridname), TABLE_FIELDTYPE_Double);
	}




	while( startList != NULL )														// scan zone layer list and write cat values in table
	{
		runList = startList;
		while( runList->sub != NULL )												// fall down to lowest layer
			runList = runList->sub;
		
		subList = runList;															// use pointer to scan horizontal

		while( subList != NULL )													// move forward and read all categories of this layer (including the parent layers)
		{
			runSub = subList;
			catLevel = nCatGrids;
			pRecord	= pOutTab->Add_Record();										// create new record in table
			pRecord->Set_Value((catLevel+1), runSub->count);						// read/write field count			

			for(iGrid=0; iGrid<nStatGrids; iGrid++)									// read/write statistics
			{
				if( iGrid == 0 )
					runStats = runSub->stats;
				else
					runStats = runStats->next;

				pRecord->Set_Value(catLevel+2+iGrid*5, runStats->min);
				pRecord->Set_Value(catLevel+3+iGrid*5, runStats->max);
				pRecord->Set_Value(catLevel+4+iGrid*5, runStats->sum/runSub->count);
				pRecord->Set_Value(catLevel+5+iGrid*5, sqrt((runStats->dev - runSub->count*pow(runStats->sum/runSub->count, 2)) / (runSub->count - 1))); // sample
				//pRecord->Set_Value(catLevel+5+iGrid*5, sqrt((runStats->dev - pow(runStats->sum/runSub->count, 2)) / runSub->count)); // population
				pRecord->Set_Value(catLevel+6+iGrid*5, runStats->sum);
			}			
			
			while( runSub != NULL )													// read/write categories
			{
				pRecord->Set_Value(catLevel, runSub->cat);
				runSub = runSub->parent;
				catLevel -= 1;
			}
			subList = subList->next;
		}

		while( runList->parent != NULL && runList->parent->next == NULL )			// move up to next 'Caterory with -> next'
			runList = runList->parent;

		if( runList->parent != NULL )												// if not upper layer (zones)
		{	
			runList = runList->parent;												// move to parent of next 'Caterory with -> next'
			if( runList->next != NULL && runList->parent != NULL )
				runList->parent->sub = runList->next;								// redirect pointer to category which is next 'Categora with -> next' next
			else if (runList->parent == NULL && runList->next != NULL )				
				startList = runList->next;											// when upper layer (zones) is reached, move to next zone
			else
				startList = NULL;													// reading finished
			
			if( runList->parent == NULL )
				startList = runList->next;											// ?? when upper layer is reached, move to next zone
			else
				runList->sub = runList->sub->next;									// on sub layers redirect pointer to ->next
		}
		else
		{
			if( nCatGrids == 0 )
				startList = NULL;
			else
				startList = runList->next;												// ?? upper layer is reached, move to next zone
		}


		runList->next = NULL;					
		delete (runList);															// delete disconneted part of the list

	}


	if( NDcountStat > 0 )
	{
		Message_Add(CSG_String::Format(SG_T("\n\n\n%s: %d %s\n\n\n"), _TL("WARNING"), NDcountStat, _TL("no-data value(s) in statistic grid(s)!")));
	}

	return (true);
}


///////////////////////////////////////////////////////////
//														 //
//														 //
//														 //
///////////////////////////////////////////////////////////

//---------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -