MapSuiteGisEditor/GisEditorPluginCore/LayerPlugins/Share/LayerPluginHelper.cs
/// <summary>
/// This method sets projection for raster layers.
/// Just pass in the parameters it requires, then you don't need to do anything about raster layer's projection in your layer provider.
/// </summary>
/// <param name="infos">infos</param>
This method sets projection for raster layers.
Just pass in the parameters it requires, then you don't need to do anything about raster layer's projection in your layer provider.
This method sets projection for raster layers . Just pass in the parameters it requires then you don ' t need to do anything about raster layer ' s projection in your layer provider .
internal static void SetInternalProjectionForRasterLayers(IEnumerable<RasterLayerInfo> infos)
        {
            string proj4StringForAll = string.Empty;
            bool savePrjFileForAll = false;
            foreach (var info in infos)
            {
                string currentProj4 = string.Empty;
                info.Layer.Open();
                if (info.Layer.HasProjectionText)
                {
                    currentProj4 = info.Layer.GetProjectionText();
                }
                if (!string.IsNullOrEmpty(proj4StringForAll))
                {
                    info.Layer.InitializeProj4Projection(proj4StringForAll);
                    if (savePrjFileForAll)
                    {
                        File.WriteAllText(info.PrjFilePath, Proj4Projection.ConvertProj4ToPrj(proj4StringForAll));
                    }
                }
                else if (!string.IsNullOrEmpty(currentProj4))
                {
                    string proj4 = currentProj4;
                    if (proj4.Trim().Equals(Proj4Projection.GetEpsgParametersString(4326).Trim()))
                    {
                        if (info.Layer.HasBoundingBox)
                        {
                            if (!info.Layer.IsOpen) info.Layer.Open();
                            if (info.Layer.GetBoundingBox().Width > 361)
                            {
                                var result = System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("LayerPluginHelperLayerNotWGText"), GisEditor.LanguageManager.GetStringResource("LayerPluginHelperProjectionNotMatchCaption"), System.Windows.Forms.MessageBoxButtons.YesNo);
                                if (result == System.Windows.Forms.DialogResult.Yes)
                                {
                                    proj4 = Proj4Projection.GetGoogleMapParametersString();
                                }
                            }
                        }
                    }
                    info.Layer.InitializeProj4Projection(proj4);
                }
                else if (IsDecimalDegree(info.Layer))
                {
                    info.Layer.InitializeProj4Projection(Proj4Projection.GetEpsgParametersString(4326));
                }
                else
                {
                    string description = GisEditor.LanguageManager.GetStringResource("selectAProjectionForAllLayersDescription");
                    ProjectionWindow projectionWindow = new ProjectionWindow("", description, "Apply For All Layers");
                    if (projectionWindow.ShowDialog().GetValueOrDefault())
                    {
                        info.Layer.InitializeProj4Projection(projectionWindow.Proj4ProjectionParameters);
                        savePrjFileForAll = true;
                        File.WriteAllText(info.PrjFilePath, Proj4Projection.ConvertProj4ToPrj(projectionWindow.Proj4ProjectionParameters));
                        if (projectionWindow.SyncProj4ProjectionForAll)
                        {
                            proj4StringForAll = projectionWindow.Proj4ProjectionParameters;
                        }
                    }
                    else
                    {
                        info.Layer.InitializeProj4Projection(string.Empty);
                    }
                }
            }
        }
internal static void SetInternalProjectionForRasterLayers ( IEnumerable < RasterLayerInfo > infos ) { string proj4StringForAll = string . Empty ; bool savePrjFileForAll = false ; foreach ( var info in infos ) { string currentProj4 = string . Empty ; info . Layer . Open ( ) ; if ( info . Layer . HasProjectionText ) { currentProj4 = info . Layer . GetProjectionText ( ) ; } if ( ! string . IsNullOrEmpty ( proj4StringForAll ) ) { info . Layer . InitializeProj4Projection ( proj4StringForAll ) ; if ( savePrjFileForAll ) { File . WriteAllText ( info . PrjFilePath , Proj4Projection . ConvertProj4ToPrj ( proj4StringForAll ) ) ; } } else if ( ! string . IsNullOrEmpty ( currentProj4 ) ) { string proj4 = currentProj4 ; if ( proj4 . Trim ( ) . Equals ( Proj4Projection . GetEpsgParametersString ( 4326 ) . Trim ( ) ) ) { if ( info . Layer . HasBoundingBox ) { if ( ! info . Layer . IsOpen ) info . Layer . Open ( ) ; if ( info . Layer . GetBoundingBox ( ) . Width > 361 ) { var result = System . Windows . Forms . MessageBox . Show ( GisEditor . LanguageManager . GetStringResource ( " " ) , GisEditor . LanguageManager . GetStringResource ( " " ) , System . Windows . Forms . MessageBoxButtons . YesNo ) ; if ( result == System . Windows . Forms . DialogResult . Yes ) { proj4 = Proj4Projection . GetGoogleMapParametersString ( ) ; } } } } info . Layer . InitializeProj4Projection ( proj4 ) ; } else if ( IsDecimalDegree ( info . Layer ) ) { info . Layer . InitializeProj4Projection ( Proj4Projection . GetEpsgParametersString ( 4326 ) ) ; } else { string description = GisEditor . LanguageManager . GetStringResource ( " " ) ; ProjectionWindow projectionWindow = new ProjectionWindow ( " " , description , " " ) ; if ( projectionWindow . ShowDialog ( ) . GetValueOrDefault ( ) ) { info . Layer . InitializeProj4Projection ( projectionWindow . Proj4ProjectionParameters ) ; savePrjFileForAll = true ; File . WriteAllText ( info . PrjFilePath , Proj4Projection . ConvertProj4ToPrj ( projectionWindow . Proj4ProjectionParameters ) ) ; if ( projectionWindow . SyncProj4ProjectionForAll ) { proj4StringForAll = projectionWindow . Proj4ProjectionParameters ; } } else { info . Layer . InitializeProj4Projection ( string . Empty ) ; } } } }
This method sets projection for raster layers.
This method sets projection for raster layers .
infos
IEnumerable<RasterLayerInfo>
None