Ejemplo n.º 1
0
        /// <summary>
        /// 测试一个类型是由拓展形成的图层的单层投影
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="newName">输出新的文件名</param>
        /// <returns>返回测试结果</returns>
        public TestingResult TestLayer(string filename, out string newName)
        {
            newName = filename;
            LayerSource layer = new LayerSource(filename, this as MapWinGIS.ICallback); //打开指定文件的图层

            if (layer.Type == LayerSourceType.Undefined)                                //图层类型是没有定义的
            {
                string message = layer.GetErrorMessage();
                if (message == "")
                {
                    message = "Unspecified error";
                }

                MessageBox.Show("Invalid datasource: " + message.ToLower() + Environment.NewLine + filename, m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(TestingResult.Error);
            }
            else
            {
                LayerSource   newLayer = null;
                TestingResult result   = this.TestLayer(layer, out newLayer);
                if (result == TestingResult.Substituted)
                {
                    newName = newLayer.Filename;
                    newLayer.Close();
                }

                layer.Close();
                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Does the reprojection work
        /// </summary>
        private void DoReprojection(IEnumerable <string> filenames, MapWinGIS.GeoProjection projection, bool inPlace)
        {
            frmTesterReport report = new frmTesterReport();

            report.InitProgress(projection);
            List <string> files = new List <string>();

            int count = 0;  // number of successfully reprojected shapefiles

            foreach (string filename in filenames)
            {
                LayerSource layer    = new LayerSource(filename);
                LayerSource layerNew = null;

                if (projection.get_IsSame(layer.Projection))
                {
                    report.AddFile(layer.Filename, projection.Name, ProjectionOperaion.SameProjection, "");
                    files.Add(layer.Filename);
                }
                else
                {
                    TestingResult result = CoordinateTransformation.ReprojectLayer(layer, out layerNew, projection, report);
                    if (result == TestingResult.Ok || result == TestingResult.Substituted)
                    {
                        ProjectionOperaion oper    = result == TestingResult.Ok ? ProjectionOperaion.Reprojected : ProjectionOperaion.Substituted;
                        string             newName = layerNew == null ? "" : layerNew.Filename;
                        report.AddFile(layer.Filename, layer.Projection.Name, oper, newName);
                        files.Add(newName == "" ? layer.Filename : newName);
                        count++;
                    }
                    else
                    {
                        ProjectionOperaion operation = result == TestingResult.Error ? ProjectionOperaion.FailedToReproject : ProjectionOperaion.Skipped;
                        report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, "");
                    }
                }

                layer.Close();
                if (layerNew != null)
                {
                    layerNew.Close();
                }
            }
            report.ShowReport(projection, "Reprojection results:", ReportType.Loading);

            IEnumerable <string> names = m_mapWin.Layers.Select(l => l.FileName);

            names = files.Except(names);

            if (count > 0)
            {
                if (projection.get_IsSame(m_mapWin.Project.GeoProjection))
                {
                    if (names.Count() > 0)
                    {
                        if (MessageBox.Show("Do you want to add layers to the project?", m_mapWin.ApplicationInfo.ApplicationName,
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            m_mapWin.Layers.StartAddingSession();

                            foreach (string filename in names)
                            {
                                m_mapWin.Layers.Add(filename);
                            }
                            m_mapWin.Layers.StopAddingSession();
                        }
                    }
                    else
                    {
                        MessageBox.Show("No files to add to the map.",
                                        m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Chosen projection is different from the project one. The layers can't be added to map.",
                                    m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("No files to add to the map.",
                                m_mapWin.ApplicationInfo.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }