/// <summary> /// Creates a new instance of the frmAssignProjection class /// </summary> public frmReproject(MapWinGIS.Interfaces.IMapWin mapWin) { InitializeComponent(); if (mapWin == null) { throw new ArgumentException("No reference to MapWinGIS was passed"); } ProjectionDatabase database = mapWin.ProjectionDatabase as ProjectionDatabase; if (database == null) { throw new InvalidCastException("Invalid instance of projection database was passed"); } m_mapWin = mapWin; LayersControl1.Initialize(mapWin); if (ProjectionTreeView1.Initialize(database, mapWin)) { this.ProjectionTreeView1.RefreshList(); } this.LayersControl1.ControlType = LayersControl.CustomType.Projection; }
/// <summary> /// Creates a new instance of the frmAssignProjection class /// </summary> public frmAssignProjection(MapWinGIS.Interfaces.IMapWin mapWin) { InitializeComponent(); if (mapWin == null) { throw new NullReferenceException("No reference to MapWinGIS was passed"); } ProjectionDatabase database = mapWin.ProjectionDatabase as ProjectionDatabase; if (database == null) { throw new InvalidCastException("Invalid instance of projection database was passed"); } m_mapWin = mapWin; LayersControl1.Initialize(mapWin); LayersControl1.LayerAdded += delegate(string filename, DataGridView dgv, int rowIndex) { this.RefreshControlState(); }; LayersControl1.LayerRemoved += delegate() { this.RefreshControlState(); }; if (ProjectionTreeView1.Initialize(database, mapWin)) { this.ProjectionTreeView1.RefreshList(); } this.LayersControl1.ControlType = LayersControl.CustomType.Projection; this.RefreshControlState(); }
/// <summary> /// Creates a new instance of frmProjectionChooser class. /// It's assumed that database is read already. /// </summary> public frmChooseProjection(ProjectionDatabase database, MapWinGIS.Interfaces.IMapWin mapWin) { InitializeComponent(); if (projectionTreeView1.Initialize(database, mapWin)) { this.projectionTreeView1.RefreshList(); } }
/// <summary> /// Creates a new instance of the frmEnterProjection class /// </summary> public frmEnterProjection(CoordinateSystem coordSystem, IEnumerable <string> list, ProjectionDatabase database) { InitializeComponent(); m_existingList = list; m_coordinateSystem = coordSystem; m_database = database; }
/// <summary> /// Adds proj4 string for database /// </summary> private void btnUpdateDb_Click(object sender, EventArgs e) { ProjectionDatabase db = (ProjectionDatabase)m_mapWin.ProjectionDatabase; if (db != null) { db.UpdateProj4Strings(db.Name); } }
/// <summary> /// Initilizes tree view with the existing in-memory version of database /// </summary> public bool Initialize(ProjectionDatabase database, MapWinGIS.Interfaces.IMapWin mapWin) { m_mapWin = mapWin; // null is acceptable as well if (database.Name == "") { return(false); } this.m_database = database; return(true); }
/// <summary> /// Creates a new instance of frmProjectionMismatch class. ShowProjectionMismatch and ShowProjectionAbsence /// calls are needed to to the job. /// </summary> internal frmProjectionMismatch(ProjectionDatabase database) { InitializeComponent(); m_database = database; btnLayer.Click += delegate(object sender, EventArgs e) { frmProjectionCompare form = new frmProjectionCompare(m_projectProj, m_layerProj, m_database); form.ShowDialog(this); form.Dispose(); }; }
/// <summary> /// Initializes tree view /// </summary> /// <param name="databaseName">The name of MS Access database with projections</param> /// <returns></returns> public bool Initialize(string databaseName, MapWinGIS.Interfaces.IMapWin mapWin) { m_mapWin = mapWin; // null is acceptable as well try { m_database = new ProjectionDatabase(databaseName, new MapWinGIS.Data.SQLiteProvider()); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
/// <summary> /// Creates a new instance of frmProjectionManager class /// </summary> public frmProjectionManager(MapWinGIS.Interfaces.IMapWin mapWin) { InitializeComponent(); if (mapWin == null) { throw new NullReferenceException("No reference to MapWinGIS was passed"); } ProjectionDatabase database = mapWin.ProjectionDatabase as ProjectionDatabase; if (database == null) { throw new InvalidCastException("Invalid instance of projection database was passed"); } m_mapWin = mapWin; // initializing tree if (this.projectionTreeView1.Initialize(database, m_mapWin)) { int gcsCount, pcsCount; this.projectionTreeView1.RefreshList(out gcsCount, out pcsCount); lblGcsCount.Text = "Coordinate systems: " + gcsCount.ToString(); lblPcsCount.Text = "Projections: " + pcsCount.ToString(); } projectionTreeView1.CoordinateSystemSelected += new ProjectionTreeView.CoordinateSystemSelectedDelegate(projectionTreeView1_CoordinateSystemSelected); // initializing map projectionMap1.LoadStateFromExeName(Application.ExecutablePath); projectionMap1.CoordinatesChanged += new ProjectionMap.CoordinatesChangedDelegate(projectionMap1_CoordinatesChanged); // showing information on WGS 84 IEnumerable <GeographicCS> list = projectionTreeView1.CoordinateSystems.Where(cs => cs.Code == 4326); projectionTreeView1_CoordinateSystemSelected((Territory)list.First()); }
/// <summary> /// Creates a new instance of ProjectionViewer class /// </summary> public frmProjectionProperties(CoordinateSystem projection, ProjectionDatabase database) { InitializeComponent(); m_database = database; m_coordinateSystem = projection; listView1.MouseDoubleClick += delegate(object sender, MouseEventArgs e) { this.EditProjection(); }; listView1.SelectedIndexChanged += new EventHandler(listView1_SelectedIndexChanged); btnEdit.Click += delegate(object sender, EventArgs e) { this.EditProjection(); }; this.projectionMap1.LoadStateFromExeName(Application.ExecutablePath); this.projectionMap1.ShowVersionNumber = false; this.ShowProjection(projection); }
/// <summary> /// 创建一个frmProjectionCompare类的新实例 /// 构造函数 /// </summary> /// <param name="projectProj">项目投影</param> /// <param name="layerProj">图层投影</param> /// <param name="database">数据库</param> public frmProjectionCompare(MapWinGIS.GeoProjection projectProj, MapWinGIS.GeoProjection layerProj, ProjectionDatabase database) { InitializeComponent(); m_projectProj = projectProj; m_layerProj = layerProj; m_database = database; this.lblProject.Text = "项目: " + projectProj.Name; this.lblLayer.Text = "图层: " + layerProj.Name; this.txtProject.Text = projectProj.ExportToProj4(); this.txtLayer.Text = layerProj.ExportToProj4(); this.btnLayer.Click += delegate(object sender, EventArgs e) { this.ShowProjectionProperties(m_layerProj); }; this.btnProject.Click += delegate(object sender, EventArgs e) { this.ShowProjectionProperties(m_projectProj); }; }
/// <summary> /// Starts identification /// </summary> private void btnStart_Click(object sender, EventArgs e) { if (textBox1.Text == "") { Globals.MessageBoxInformation("No input projection is specified", "Enter projection"); return; } MapWinGIS.GeoProjection proj = new MapWinGIS.GeoProjection(); if (!proj.ImportFromProj4(textBox1.Text)) { if (!proj.ImportFromWKT(textBox1.Text)) { if (!proj.ImportFromESRI(textBox1.Text)) { Globals.MessageBoxInformation("The string can't be identified as one of the following formats: proj4, OGC WKT, ESRI WKT", "Invalid projection"); return; } } } ProjectionDatabase db = m_mapWin.ProjectionDatabase as ProjectionDatabase; if (db == null) { Globals.MessageBoxInformation("Projection database wasn't loaded", "Database inaccessible"); return; } listBox1.Items.Clear(); CoordinateSystem cs = db.GetCoordinateSystem(proj, ProjectionSearchType.UseDialects); if (cs != null) { // easy case - it was found by name listBox1.Items.Add(cs); Globals.MessageBoxExlamation("Projection was identified.", "Success"); return; } if (listBox1.Items.Count == 0 || !chkBreak.Checked) { Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { // difficult one MapWinGIS.GeoProjection projTest = new MapWinGIS.GeoProjection(); bool isSame = false; if (proj.IsGeographic) { foreach (GeographicCS gcs in db.GeographicCS) { if (projTest.ImportFromProj4(gcs.proj4)) { if (m_bounds != null) { isSame = projTest.get_IsSameExt(proj, m_bounds, 6); } else { isSame = projTest.get_IsSame(proj); } if (isSame) { listBox1.Items.Add(gcs); if (chkBreak.Checked) { break; } } } } } else if (proj.IsProjected) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); int count = 0; foreach (ProjectedCS pcs in db.ProjectedCS) { if (projTest.ImportFromProj4(pcs.proj4)) { count++; if (m_bounds != null) { isSame = projTest.get_IsSameExt(proj, m_bounds, 6); } else { isSame = projTest.get_IsSame(proj); } if (isSame) { listBox1.Items.Add(pcs); if (chkBreak.Checked) { break; } } } } } } finally { this.Cursor = oldCursor; } } if (listBox1.Items.Count == 0) { Globals.MessageBoxExlamation("Projection isn't present in the database", "Unknown projection"); } else { // Globals.MessageBoxExlamation("Projection wasn't identified. One of the listed projections could be the right one", "Results"); Globals.MessageBoxExlamation("Projection was identified. One of the listed projections should be the right one", "Results"); } }
/// <summary> /// 测试单层投影 /// </summary> /// <param name="layer">图层源(Shapefile或grid对象)</param> /// <param name="newLayer">输出新图层</param> /// <returns>返回测试结果</returns> public TestingResult TestLayer(LayerSource layer, out LayerSource newLayer) { if (layer == null) { throw new ArgumentException("空图层引用被通过"); } newLayer = null; MapWinGIS.GeoProjection projectProj = m_mapWin.Project.GeoProjection; MapWinGIS.GeoProjection layerProj = layer.Projection; bool isSame = projectProj.get_IsSameExt(layerProj, layer.Extents, 10); // 让我们看看我们是否有项目的投影的一种方言 if (!isSame && !projectProj.IsEmpty) { ProjectionDatabase db = (ProjectionDatabase)m_mapWin.ProjectionDatabase;//投影数据源 if (db != null) { CoordinateSystem cs = db.GetCoordinateSystem(projectProj, ProjectionSearchType.Enhanced);//坐标系统 if (cs != null) { db.ReadDialects(cs); foreach (string dialect in cs.Dialects) { MapWinGIS.GeoProjection projTemp = new MapWinGIS.GeoProjection(); if (!projTemp.ImportFromAutoDetect(dialect)) { continue; } if (layerProj.get_IsSame(projTemp)) { isSame = true; break; } } } } } // 投影中可以包含的文件的后缀名,让我们试着用正确的后缀搜索文件 if (!isSame) { if (CoordinateTransformation.SeekSubstituteFile(layer, projectProj, out newLayer)) { m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Substituted, newLayer.Filename); return(TestingResult.Substituted); } } if (!layer.Projection.IsEmpty) { if (projectProj.IsEmpty) { // 层具有投影,项目没有;分配到投影,不提示用户 // 让我们找个众所周知的投影与EPSG编码 ProjectionDatabase db = m_mapWin.ProjectionDatabase as ProjectionDatabase; if (db != null) { CoordinateSystem cs = db.GetCoordinateSystem(layerProj, ProjectionSearchType.UseDialects); if (cs != null) { MapWinGIS.GeoProjection proj = new MapWinGIS.GeoProjection(); if (proj.ImportFromEPSG(cs.Code)) { layerProj = proj; } } } m_mapWin.Project.GeoProjection = layerProj; return(TestingResult.Ok); } else if (isSame) { // 相同投影 return(TestingResult.Ok); } else { // 用户必须被提示 if (!m_usePreviousAnswerMismatch && !m_mapWin.ApplicationInfo.NeverShowProjectionDialog) { bool dontShow = false; bool useForOthers = false; ArrayList list = new ArrayList(); list.Add("Ignore mismatch"); list.Add("Reproject file"); //list.Add("Skip file"); // PM 2013-05-03: list.Add("Don't load the layer"); frmProjectionMismatch form = new frmProjectionMismatch((ProjectionDatabase)m_mapWin.ProjectionDatabase); int choice = form.ShowProjectionMismatch(list, (int)m_mapWin.ApplicationInfo.ProjectionMismatchBehavior, projectProj, layer.Projection, out useForOthers, out dontShow); form.Dispose(); if (choice == -1) { return(TestingResult.CancelOperation); } m_usePreviousAnswerMismatch = useForOthers; m_mapWin.ApplicationInfo.ProjectionMismatchBehavior = (ProjectionMismatchBehavior)choice; m_mapWin.ApplicationInfo.NeverShowProjectionDialog = dontShow; } MapWinGIS.Interfaces.ProjectionMismatchBehavior behavior = m_mapWin.ApplicationInfo.ProjectionMismatchBehavior; switch (behavior) { case ProjectionMismatchBehavior.Reproject: TestingResult result = CoordinateTransformation.ReprojectLayer(layer, out newLayer, projectProj, m_report); if (result == TestingResult.Ok || result == TestingResult.Substituted) { ProjectionOperaion oper = result == TestingResult.Ok ? ProjectionOperaion.Reprojected : ProjectionOperaion.Substituted; string newName = newLayer == null ? "" : newLayer.Filename; m_report.AddFile(layer.Filename, layer.Projection.Name, oper, newName); return(newName == layer.Filename ? TestingResult.Ok : TestingResult.Substituted); } else { m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.FailedToReproject, ""); return(TestingResult.Error); } case ProjectionMismatchBehavior.IgnoreMismatch: m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.MismatchIgnored, ""); return(TestingResult.Ok); case ProjectionMismatchBehavior.SkipFile: m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, ""); return(TestingResult.SkipFile); } } } else if (!projectProj.IsEmpty) // 图层投影是空的 { bool projectProjectionExists = !projectProj.IsEmpty; // 用户必须被提示 if (!m_usePreviousAnswerAbsence && !m_mapWin.ApplicationInfo.NeverShowProjectionDialog) { bool dontShow = false; bool useForOthers = false; ArrayList list = new ArrayList(); // 当在投影第一变体应排除 int val = projectProjectionExists ? 0 : 1; if (projectProjectionExists) { // PM 2013-05-03: //list.Add("Assign projection from project"); list.Add("Use the project's projection"); } // list.Add("Ignore the absence"); // list.Add("Skip the file"); list.Add("Ignore the missing of projection file"); list.Add("Don't load the layer"); frmProjectionMismatch form = new frmProjectionMismatch((ProjectionDatabase)m_mapWin.ProjectionDatabase); int choice = form.ShowProjectionAbsence(list, (int)m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior - val, projectProj, out useForOthers, out dontShow); form.Dispose(); if (choice == -1) { return(TestingResult.CancelOperation); } choice += val; m_usePreviousAnswerAbsence = useForOthers; m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior = (ProjectionAbsenceBehavior)choice; m_mapWin.ApplicationInfo.NeverShowProjectionDialog = dontShow; } // 当在项目没有投影,它不能分配层 ProjectionAbsenceBehavior behavior = m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior; if (!projectProjectionExists && m_mapWin.ApplicationInfo.ProjectionAbsenceBehavior == ProjectionAbsenceBehavior.AssignFromProject) { behavior = ProjectionAbsenceBehavior.IgnoreAbsence; } switch (behavior) { case ProjectionAbsenceBehavior.AssignFromProject: m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Assigned, ""); layer.Projection = projectProj; return(TestingResult.Ok); case ProjectionAbsenceBehavior.IgnoreAbsence: m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.AbsenceIgnored, ""); return(TestingResult.Ok); case ProjectionAbsenceBehavior.SkipFile: m_report.AddFile(layer.Filename, layer.Projection.Name, ProjectionOperaion.Skipped, ""); return(TestingResult.SkipFile); } } else { // 层没有投影,项目也没有,不在这里 } System.Diagnostics.Debug.Print("Invalid result in projection tester"); return(TestingResult.Ok); }