Esempio n. 1
0
        /// <summary>
        /// Fires selection event for coordinate systems
        /// </summary>
        private void ProjectionTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node != null)
            {
                e.Node.SelectedImageIndex = e.Node.ImageIndex;
                switch (e.Node.ImageIndex)
                {
                case ICON_GLOBE:
                {
                    GeographicCS gcs = e.Node.Tag as GeographicCS;
                    FireGeographicCSSelected(gcs);
                    FireCoordinateSystemSelected((Territory)gcs);
                    break;
                }

                case ICON_MAP:
                {
                    ProjectedCS pcs = e.Node.Tag as ProjectedCS;
                    FireProjectedCSSelected(pcs);
                    FireCoordinateSystemSelected((Territory)pcs);
                    break;
                }
                }
            }
        }
Esempio n. 2
0
 internal void FireProjectedCSSelected(ProjectedCS pcs)
 {
     if (ProjectedCSSelected != null)
     {
         ProjectedCSSelected(pcs);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Fills treeview with CS which fall into specified bounds
        /// </summary>
        public bool RefreshList(BoundingBox extents, out int gcsCount, out int projCount)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();

            gcsCount  = 0;
            projCount = 0;

            if (m_database == null)
            {
                throw new Exception("No database was specified to populate tree view");
            }

            this.SuspendLayout();
            this.Nodes.Clear();

            // limits coordinate systems to those which fall into extents
            bool showFullExtents = extents.xMin == -180.0 && extents.xMax == 180.0 && extents.yMin == -90.0 && extents.yMax == 90.0;

            this.ApplyExtents(extents, out gcsCount, out projCount);

            // adding top-most nodes
            TreeNode nodeUnspecified = this.Nodes.Add(NODE_UNSPECIFIED_DATUMS, NODE_UNSPECIFIED_DATUMS, ICON_FOLDER);
            TreeNode nodeWorld       = this.Nodes.Add(NODE_WORLD, NODE_WORLD, ICON_FOLDER);

            // adding regions
            Hashtable dctRegions  = new Hashtable();
            var       listRegions = m_database.Regions.Where(r => r.ParentCode == 1);

            foreach (var region in listRegions)
            {
                TreeNode nodeRegion = nodeWorld.Nodes.Add(region.Code.ToString(), region.Name.ToString(), ICON_FOLDER);
                dctRegions.Add(region.Code, nodeRegion);
            }

            // local GCS
            var listRegions2 = m_database.Regions.Where(r => r.ParentCode > 1 && dctRegions.ContainsKey(r.ParentCode));

            foreach (var region in listRegions2)
            {
                TreeNode nodeRegion    = dctRegions[region.ParentCode] as TreeNode;
                TreeNode nodeSubregion = nodeRegion.Nodes.Add(region.Code.ToString(), region.Name.ToString(), ICON_FOLDER);
                dctRegions.Add(region.Code, nodeSubregion);

                var listCountries = region.Countries.Where(cn => cn.IsActive).Where(c => c.GeographicCS.Where(cs => cs.IsActive).Count() > 0);
                foreach (var country in listCountries)
                {
                    TreeNode nodeCountry = null;   // it's to difficult to determine whether the country should be shown

                    foreach (GeographicCS gcs in country.GeographicCS.Where(cs => cs.IsActive).OrderBy(gcs => gcs.Name))
                    {
                        // when extents are limited, no need to show global systems for each country
                        if (!showFullExtents && gcs.Type != GeographicalCSType.Local)
                        {
                            continue;
                        }

                        if (gcs.Type != GeographicalCSType.Local || m_dctLocalWithClassification.ContainsKey(gcs.Code))
                        {
                            List <ProjectedCS> projections = new List <ProjectedCS>();
                            foreach (int code in country.ProjectedCS)
                            {
                                ProjectedCS pcs = gcs.ProjectionByCode(code);
                                if (pcs != null && pcs.IsActive)
                                {
                                    projections.Add(pcs);
                                }
                            }

                            if (projections.Count() > 0)
                            {
                                // country node will be added only here
                                if (nodeCountry == null)
                                {
                                    nodeCountry = nodeSubregion.Nodes.Add(country.Code.ToString(), country.Name.ToString(), ICON_FOLDER);
                                }

                                TreeNode nodeGcs = nodeCountry.Nodes.Add(gcs.Code.ToString(), gcs.Name.ToString(), ICON_GLOBE);
                                nodeGcs.Tag = gcs;
                                this.AddProjections(nodeGcs, gcs, projections);
                            }
                        }
                        else
                        {
                            if (nodeCountry == null)
                            {
                                nodeCountry = nodeSubregion.Nodes.Add(country.Code.ToString(), country.Name.ToString(), ICON_FOLDER);
                            }

                            // local GCS should be added to country even if there is no projection specified
                            TreeNode nodeGcs = nodeCountry.Nodes.Add(gcs.Code.ToString(), gcs.Name.ToString(), ICON_GLOBE);
                            nodeGcs.Tag = gcs;

                            foreach (ProjectedCS pcs in gcs.Projections.OrderBy(cs => cs.Name))
                            {
                                TreeNode nodePcs = nodeGcs.Nodes.Add(pcs.Code.ToString(), pcs.Name.ToString(), ICON_MAP);
                                nodePcs.Tag = pcs;
                            }
                        }
                    }
                }
            }

            // regional GCS
            var list1 = m_database.GeographicCS.Where(cs => cs.Type == GeographicalCSType.Regional && cs.IsActive).OrderBy(cs => cs.Name);

            foreach (var gcs in list1)
            {
                TreeNode nodeRegion = dctRegions[gcs.RegionCode] as TreeNode;
                TreeNode nodeGcs    = nodeRegion.Nodes.Add(gcs.Code.ToString(), gcs.Name.ToString(), ICON_GLOBE);
                nodeGcs.Tag = gcs;
                this.AddProjections(nodeGcs, gcs, gcs.Projections.Where(cs => !cs.Local));
            }

            // global GCS
            var list2 = m_database.GeographicCS.Where(cs => cs.Type == GeographicalCSType.Global && cs.IsActive).OrderBy(cs => cs.Name);

            foreach (var gcs in list2)
            {
                TreeNode nodeParent = gcs.Scope == SCOPE_NOT_RECOMMENDED || gcs.Name.ToLower().StartsWith("unspecified") ? nodeUnspecified : nodeWorld;
                TreeNode nodeGcs    = nodeParent.Nodes.Add(gcs.Code.ToString(), gcs.Name.ToString(), ICON_GLOBE);
                nodeGcs.Tag = gcs;
                this.AddProjections(nodeGcs, gcs, gcs.Projections.Where(cs => !cs.Local));
            }

            this.RemoveEmptyChilds(nodeWorld);

            this.UpdateFavoriteList();

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 读取PCS的列表
        /// </summary>
        /// <returns></returns>
        private bool ReadPCS(ref List <ProjectedCS> list)
        {
            DbConnection conn = m_provider.CreateConnection(m_dbname); // new DbConnection(this.get_ConectionString());
            DbCommand    cmd  = conn.CreateCommand();

            cmd.CommandText = SQL_PCS;

            conn.Open();
            DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            int codeColumn     = ColumnIndexByName(reader, CMN_CS_CODE);
            int nameColumn     = ColumnIndexByName(reader, CMN_CS_NAME);
            int sourceColumn   = ColumnIndexByName(reader, CMN_CS_SOURCE);
            int leftColumn     = ColumnIndexByName(reader, CMN_CS_LEFT);
            int rightColumn    = ColumnIndexByName(reader, CMN_CS_RIGHT);
            int bottomColumn   = ColumnIndexByName(reader, CMN_CS_SOUTH);
            int topColumn      = ColumnIndexByName(reader, CMN_CS_NORTH);
            int areaNameColumn = ColumnIndexByName(reader, CMN_CS_AREA_NAME);
            int remarksColumn  = ColumnIndexByName(reader, CMN_CS_REMARKS);
            int scopeColumn    = ColumnIndexByName(reader, CMN_CS_SCOPE);
            int typeColumn     = ColumnIndexByName(reader, CMN_CS_PROJECTION);
            int localColumn    = ColumnIndexByName(reader, CMN_CS_LOCAL);
            int proj4Column    = ColumnIndexByName(reader, CMN_CS_Proj4);


            if (codeColumn == -1 || nameColumn == -1 || sourceColumn == -1 ||
                leftColumn == -1 || rightColumn == -1 || bottomColumn == -1 ||
                topColumn == -1 || areaNameColumn == -1 || remarksColumn == -1 ||
                scopeColumn == -1 || typeColumn == -1 || localColumn == -1 || proj4Column == -1)
            {
                MessageBox.Show("The expected field isn't found in the [Coordinate Systems] table", "Field not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ProjectedCS pcs = new ProjectedCS();
                    pcs.Code       = reader.GetInt32(codeColumn);
                    pcs.Name       = reader.GetString(nameColumn);
                    pcs.Left       = reader.GetDouble(leftColumn);
                    pcs.Right      = reader.GetDouble(rightColumn);
                    pcs.Top        = reader.GetDouble(topColumn);
                    pcs.Bottom     = reader.GetDouble(bottomColumn);
                    pcs.SourceCode = reader.GetInt32(sourceColumn);
                    pcs.Scope      = reader.GetString(scopeColumn);
                    pcs.AreaName   = reader.GetString(areaNameColumn);
                    pcs.proj4      = (!reader.IsDBNull(proj4Column)) ? reader.GetString(proj4Column) : "";

                    pcs.ProjectionType = (!reader.IsDBNull(typeColumn)) ? reader.GetString(typeColumn) : "";
                    pcs.Remarks        = (!reader.IsDBNull(remarksColumn)) ? reader.GetString(remarksColumn) : "";

                    pcs.Local = false;
                    if (!reader.IsDBNull(localColumn))
                    {
                        pcs.Local = reader.GetBoolean(localColumn);
                    }

                    list.Add(pcs);
                }
            }
            return(true);
        }