//---------------------------------------------------------
CSG_Grid * CLandsat_Import::Get_Projection(CSG_Grid *pGrid, const CSG_String &Proj4)
{
	if( pGrid->Get_Projection().is_Okay() == false )
	{
		return( NULL );
	}

	CSG_Module	*pModule	= SG_Get_Module_Library_Manager().Get_Module(SG_T("pj_proj4"), 4);	// Coordinate Transformation (Grid)

	if(	pModule == NULL )
	{
		return( NULL );
	}

	int	Interpolation;

	switch( Parameters("INTERPOLATION")->asInt() )
	{
	case  0:	Interpolation	= GRID_INTERPOLATION_NearestNeighbour;	break;
	case  1:	Interpolation	= GRID_INTERPOLATION_Bilinear        ;	break;
	default:	Interpolation	= GRID_INTERPOLATION_BSpline         ;	break;
	}

	Message_Add(CSG_String::Format(SG_T("\n%s (%s: %s)\n"), _TL("re-projection to geographic coordinates"), _TL("original"), pGrid->Get_Projection().Get_Name().c_str()), false);

	pModule->Settings_Push(NULL);

	if( pModule->Set_Parameter("CRS_PROJ4"    , Proj4        )
	&&  pModule->Set_Parameter("INTERPOLATION", Interpolation)
	&&  pModule->Set_Parameter("SOURCE"       , pGrid        )
	&&  pModule->Execute() )
	{
		pGrid	= pModule->Get_Parameters("TARGET")->Get_Parameter("GRID")->asGrid();

		pModule->Settings_Pop();

		return( pGrid );
	}

	pModule->Settings_Pop();

	Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("re-projection"), _TL("failed")), false);

	return( NULL );
}
Пример #2
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);
		Load_MetaData(File_Name);
	}

	//-----------------------------------------------------
	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_Module	*pModule	= SG_Get_Module_Library_Manager().Get_Module("db_pgsql", 0);	// CGet_Connections

		if(	pModule != NULL )
		{
			SG_UI_ProgressAndMsg_Lock(true);

			//---------------------------------------------
			CSG_Table	Connections;
			CSG_String	Connection	= DBName + " [" + Host + ":" + Port + "]";

			pModule->Settings_Push();

			if( pModule->On_Before_Execution() && SG_MODULE_PARAMETER_SET("CONNECTIONS", &Connections) && pModule->Execute() )	// CGet_Connections
			{
				for(int i=0; !bResult && i<Connections.Get_Count(); i++)
				{
					if( !Connection.Cmp(Connections[i].asString(0)) )
					{
						bResult	= true;
					}
				}
			}

			pModule->Settings_Pop();

			//---------------------------------------------
			if( bResult && (bResult = (pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", 20)) != NULL) == true )	// CPGIS_Shapes_Load
			{
				pModule->Settings_Push();

				bResult	= pModule->On_Before_Execution()
					&& SG_MODULE_PARAMETER_SET("CONNECTION", Connection)
					&& SG_MODULE_PARAMETER_SET("TABLES"    , Table)
					&& SG_MODULE_PARAMETER_SET("SHAPES"    , this)
					&& pModule->Execute();

				pModule->Settings_Pop();
			}

			SG_UI_ProgressAndMsg_Lock(false);
		}
	}

	//-----------------------------------------------------
	if( bResult )
	{
		Set_Modified(false);
		Set_Update_Flag();

		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_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE);

	return( false );
}