コード例 #1
0
//---------------------------------------------------------
bool DLG_Get_FILE_Filter_GDAL_Read(int Type, wxString &Filter)
{
	bool		bResult;
	CSG_Table	Formats;

	SG_UI_ProgressAndMsg_Lock(true);

	SG_RUN_TOOL(bResult, "io_gdal", 10,	// GDAL Formats
		SG_TOOL_PARAMETER_SET("FORMATS"   , &Formats)
	&&	SG_TOOL_PARAMETER_SET("TYPE"      , Type    )	// all (rasters and vectors)
	&&	SG_TOOL_PARAMETER_SET("ACCESS"    , 0       )	// read
	&&	SG_TOOL_PARAMETER_SET("RECOGNIZED", true    )	// add an entry for all recognized files
	);

	SG_UI_ProgressAndMsg_Lock(false);

	if( bResult && Formats.Get_Count() > 0 )
	{
		Filter	+= Formats[Formats.Get_Count() - 1].asString(2);

		Filter.Replace("*.sdat;", "");	// we go for *.sgrd
		Filter.Replace("*.xml;" , "");	// too much noise
	}

	return( bResult );
}
コード例 #2
0
//---------------------------------------------------------
bool COGR_Export_KML::On_Execute(void)
{
	CSG_Shapes	Shapes, *pShapes	= Parameters("SHAPES")->asShapes();

	//-----------------------------------------------------
	if( pShapes->Get_Projection().Get_Type() == SG_PROJ_TYPE_CS_Undefined )
	{
		Message_Add(_TL("layer uses undefined coordinate system, assuming geographic coordinates"));
	}
	else if( pShapes->Get_Projection().Get_Type() != SG_PROJ_TYPE_CS_Geographic )
	{
		Message_Fmt("\n%s (%s: %s)\n", _TL("re-projection to geographic coordinates"), _TL("original"), pShapes->Get_Projection().Get_Name().c_str());

		bool	bResult;

		SG_RUN_TOOL(bResult, "pj_proj4", 2,
				SG_TOOL_PARAMETER_SET("SOURCE"   , pShapes)
			&&	SG_TOOL_PARAMETER_SET("TARGET"   , &Shapes)
			&&	SG_TOOL_PARAMETER_SET("CRS_PROJ4", SG_T("+proj=longlat +ellps=WGS84 +datum=WGS84"))
		);

		if( bResult )
		{
			pShapes	= &Shapes;

			Message_Fmt("\n%s: %s\n", _TL("re-projection"), _TL("success"));
		}
		else
		{
			Message_Fmt("\n%s: %s\n", _TL("re-projection"), _TL("failed" ));
		}
	}

	//-----------------------------------------------------
	CSG_OGR_DataSet	DataSource;

	if( !DataSource.Create(Parameters("FILE")->asString(), "KML") )
	{
		Error_Set(_TL("KML file creation failed"));

		return( false );
	}

	if( !DataSource.Write(pShapes) )
	{
		Error_Set(_TL("failed to store data"));

		return( false );
	}

	return( true );
}
コード例 #3
0
//---------------------------------------------------------
bool CPoint_Zonal_Multi_Grid_Regression::On_Execute(void)
{
	//-----------------------------------------------------
	CSG_Shapes	*pPoints		= Parameters("POINTS"    )->asShapes();
	CSG_Shapes	*pZones			= Parameters("ZONES"     )->asShapes();
	CSG_Grid	*pRegression	= Parameters("REGRESSION")->asGrid  ();

	pRegression->Assign_NoData();

	CSG_Grid	Regression(*Get_System(), SG_DATATYPE_Float);

	SG_UI_Progress_Lock(true);	// suppress dialogs from popping up

	for(int i=0; i<pZones->Get_Count() && Process_Get_Okay(); i++)
	{
		CSG_Shape_Polygon	*pZone	= (CSG_Shape_Polygon *)pZones->Get_Shape(i);

		//-------------------------------------------------
		// select all points located in current zone polygon

		bool	bResult;

		CSG_Shapes Zone(SHAPE_TYPE_Polygon);	Zone.Add_Shape(pZone);

		SG_RUN_TOOL(bResult, "shapes_tools", 5,	// select points by location
			   SG_TOOL_PARAMETER_SET("LOCATIONS", &Zone)
			&& SG_TOOL_PARAMETER_SET("SHAPES"   , pPoints)
		);

		if( !bResult )
		{
			SG_UI_Process_Set_Okay();	// don't stop overall work flow, if tool execution failed for current zone
		}
		else if( pPoints->Get_Selection_Count() > 0 )
		{
			//---------------------------------------------
			// copy selected points to a new (temporary) points layer

			CSG_Shapes	Selection;

			SG_RUN_TOOL(bResult, "shapes_tools", 6,	// copy selected points to a new layer
				   SG_TOOL_PARAMETER_SET("INPUT" , pPoints)
				&& SG_TOOL_PARAMETER_SET("OUTPUT", &Selection)
			);

			pPoints->asShapes()->Select();	// unselect everything from original points layer

			//---------------------------------------------
			// perform the regression analysis, regression grid for zone is temporary

			SG_RUN_TOOL(bResult, "statistics_regression", 1,	// multiple linear regression for points and predictor grids
				   SG_TOOL_PARAMETER_SET("PREDICTORS", Parameters("PREDICTORS"))
				&& SG_TOOL_PARAMETER_SET("REGRESSION", &Regression             )
				&& SG_TOOL_PARAMETER_SET("POINTS"    , &Selection              )
				&& SG_TOOL_PARAMETER_SET("ATTRIBUTE" , Parameters("ATTRIBUTE" ))
				&& SG_TOOL_PARAMETER_SET("RESAMPLING", Parameters("RESAMPLING"))
				&& SG_TOOL_PARAMETER_SET("COORD_X"   , Parameters("COORD_X"   ))
				&& SG_TOOL_PARAMETER_SET("COORD_Y"   , Parameters("COORD_Y"   ))
				&& SG_TOOL_PARAMETER_SET("INTERCEPT" , Parameters("INTERCEPT" ))
				&& SG_TOOL_PARAMETER_SET("METHOD"    , Parameters("METHOD"    ))
				&& SG_TOOL_PARAMETER_SET("P_VALUE"   , Parameters("P_VALUE"   ))
			);

			//---------------------------------------------
			// use zone polygon as mask for copying zonal regression result to final regression grid

			if( !bResult )
			{
				SG_UI_Process_Set_Okay();	// don't stop overall work flow, if tool execution failed for current zone
			}
			else
			{
				#pragma omp parallel for	// speed up using multiple processors
				for(int y=0; y<Get_NY(); y++)
				{
					for(int x=0; x<Get_NX(); x++)
					{
						if( !Regression.is_NoData(x, y) && pZone->Contains(Get_System()->Get_Grid_to_World(x, y)) )
						{
							pRegression->Set_Value(x, y, Regression.asDouble(x, y));
						}
					}
				}
			}
		}
	}

	//-----------------------------------------------------
	SG_UI_Progress_Lock(false);

	//-----------------------------------------------------
	Set_Residuals(pPoints, pRegression);

	//-----------------------------------------------------
	return( true );
}