public static string GetProj4ProjectionParameter(string prjPathFileName)
        {
            string proj4Parameter = string.Empty;

            try
            {
                if (!File.Exists(prjPathFileName))
                {
                    var projectionWindow = new ProjectionWindow();
                    if (projectionWindow.ShowDialog().GetValueOrDefault())
                    {
                        proj4Parameter = projectionWindow.Proj4ProjectionParameters;
                        File.WriteAllText(prjPathFileName, Proj4Projection.ConvertProj4ToPrj(projectionWindow.Proj4ProjectionParameters));
                    }
                }
                else
                {
                    string wkt = File.ReadAllText(prjPathFileName);
                    proj4Parameter = Proj4Projection.ConvertPrjToProj4(wkt);
                }
            }
            catch (Exception ex)
            {
                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
            }

            return(proj4Parameter);
        }
예제 #2
0
        private void ChooseProjectionClick(object sender, RoutedEventArgs e)
        {
            ProjectionWindow projectionWindow = new ProjectionWindow(GisEditor.ActiveMap.DisplayProjectionParameters, "Choose the projection you want to save", "");

            if (projectionWindow.ShowDialog().GetValueOrDefault())
            {
                string selectedProj4Parameter = projectionWindow.Proj4ProjectionParameters;
                if (!string.IsNullOrEmpty(selectedProj4Parameter))
                {
                    Proj4ProjectionParametersStringCore = selectedProj4Parameter;
                }
            }
        }
예제 #3
0
        private void ChooseInternalProjection(ReprojectionShpFileEntity entity)
        {
            var projectionWindow = new ProjectionWindow("", "", "Apply For All");

            if (projectionWindow.ShowDialog().GetValueOrDefault())
            {
                if (projectionWindow.SyncProj4ProjectionForAll)
                {
                    foreach (var shpEntity in SourceFiles)
                    {
                        shpEntity.InternalProjection             = projectionWindow.Proj4ProjectionParameters;
                        shpEntity.IsInternalProjectionDetermined = true;
                    }
                }
                else
                {
                    entity.InternalProjection             = projectionWindow.Proj4ProjectionParameters;
                    entity.IsInternalProjectionDetermined = true;
                }
            }
        }
        /// <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>
        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);
                    }
                }
            }
        }