Esempio n. 1
0
 internal void FireGeographicCSSelected(GeographicCS gcs)
 {
     if (GeographicCSSelected != null)
     {
         GeographicCSSelected(gcs);
     }
 }
Esempio n. 2
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. 3
0
        /// <summary>
        /// 链接GCS到countries
        /// </summary>
        private void LinkGCSToCountry()
        {
            DbConnection conn = m_provider.CreateConnection(m_dbname); //new OleDbConnection(this.get_ConectionString());
            DbCommand    cmd  = conn.CreateCommand();

            cmd.CommandText = SQL_CS_BY_COUNTRY;//"SELECT * FROM [Country by Coordinate System] WHERE [REGION] = 0";

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

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    int codeCountry = reader.GetInt32(0);
                    if (m_dctCountries.ContainsKey(codeCountry))
                    {
                        Country country = (Country)m_dctCountries[codeCountry];

                        string projType = reader.GetString(2);
                        if (projType == CS_TYPE_GEOGRAPHIC_2D)
                        {
                            int codeGcs = reader.GetInt32(1);
                            if (m_dctGCS.ContainsKey(codeGcs))
                            {
                                GeographicCS gcs = (GeographicCS)m_dctGCS[codeGcs];
                                country.GeographicCS.Add(gcs);
                            }
                        }
                        else if (projType == CS_TYPE_PROJECTED)
                        {
                            int codePCS = reader.GetInt32(1);
                            country.ProjectedCS.Add(codePCS);
                        }
                    }
                }
            }

            // 应该为每个国家添加的全球CS
            var listGlobalCS = m_listGCS.Where(gcs => gcs.AreaCode == CODE_AREA_WORLD);

            foreach (Country country in m_listCountries)
            {
                foreach (var gcs in listGlobalCS)
                {
                    country.GeographicCS.Add(gcs);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 链接GCS到Region
        /// </summary>
        private void LinkGCSToRegion()
        {
            DbConnection conn = m_provider.CreateConnection(m_dbname);//创建数据库链接
            DbCommand    cmd  = conn.CreateCommand();

            cmd.CommandText = SQL_GCS_BY_REGION;//"SELECT * FROM [Country by Coordinate System] WHERE [REGION] <> 0";
            conn.Open();
            DbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    int codeGcs = reader.GetInt32(1);
                    if (m_dctGCS.ContainsKey(codeGcs))
                    {
                        GeographicCS gcs = (GeographicCS)m_dctGCS[codeGcs];
                        gcs.Type       = GeographicalCSType.Regional;
                        gcs.RegionCode = reader.GetInt32(0);;
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 读取GCS列表
        /// </summary>
        private bool ReadGCS(ref List <GeographicCS> list)
        {
            DataTable dt = this.get_Table(SQL_GCS, false);

            if (dt == null)
            {
                throw new Exception("mwGRS query wansn't found in the database: " + m_dbname);
            }

            foreach (DataRow row in dt.Rows)
            {
                GeographicCS gcs = new GeographicCS();
                gcs.Code     = int.Parse(row[CMN_CS_CODE].ToString());
                gcs.Name     = row[CMN_CS_NAME].ToString();
                gcs.Left     = this.ParseDouble(row[CMN_CS_LEFT]);
                gcs.Right    = this.ParseDouble(row[CMN_CS_RIGHT]);
                gcs.Top      = this.ParseDouble(row[CMN_CS_NORTH]);
                gcs.Bottom   = this.ParseDouble(row[CMN_CS_SOUTH]);
                gcs.AreaCode = int.Parse(row[CMN_CS_AREA_CODE].ToString());
                gcs.Scope    = (row[CMN_CS_SCOPE]).ToString();
                gcs.AreaName = (row[CMN_CS_AREA_NAME]).ToString();
                gcs.Remarks  = (row[CMN_CS_REMARKS]).ToString();
                gcs.proj4    = (row[CMN_CS_Proj4]).ToString();

                //设置GCS的类型
                gcs.Type = (gcs.Left != -180.0f || gcs.Bottom != -90.0f || gcs.Right != 180.0f || gcs.Top != 90.0f) ?
                           GeographicalCSType.Local : GeographicalCSType.Global;

                list.Add(gcs);

                // 添加到哈希表
                m_dctGCS.Add(gcs.Code, gcs);
            }

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Adding projections for a gcs node
        /// </summary>
        /// <param name="parentNode"></param>
        /// <param name="gcs"></param>
        /// <param name="projections"></param>
        private void AddProjections(TreeNode parentNode, GeographicCS gcs, IEnumerable <ProjectedCS> projections)
        {
            if (m_dctUsaStates.Contains(gcs.Code))
            {
                string[] states = { "Alaska",        "Alabama",        "Arkansas",     "Arizona",  "California",    "Colorado",     "Connecticut",  "District Columbia",
                                    "Delaware",      "Florida",        "Georgia",      "Hawaii",   "Iowa",          "Idaho",        "Illinois",     "Indiana",          "Kansas","Kentucky",
                                    "Louisiana",     "Massachusetts",  "Maryland",     "Maine",    "Michigan",      "Minnesota",    "Missouri",     "Mississippi",
                                    "Montana",       "North Carolina", "North Dakota", "Nebraska", "New Hampshire", "New Jersey",   "New Mexico",
                                    "Nevada",        "New York",       "Ohio",         "Oklahoma", "Oregon",        "Pennsylvania", "Rhode Island", "South Carolina",
                                    "South Dakota",  "Tennessee",      "Texas",        "Utah",     "Virginia",      "Vermont",      "Washington",   "Wisconsin",
                                    "West Virginia", "Wyoming" };

                Hashtable dctStatePCS = new Hashtable();
                TreeNode  nodeStates  = null;
                foreach (string state in states)
                {
                    var list = projections.Where(p => p.Name.Contains(state));
                    if (list.Count() > 0)
                    {
                        if (nodeStates == null)
                        {
                            nodeStates = parentNode.Nodes.Add("States", "States", ICON_FOLDER);
                        }

                        TreeNode nodeState = nodeStates.Nodes.Add(state, state, ICON_FOLDER);
                        foreach (ProjectedCS pcs in list)
                        {
                            TreeNode node = nodeState.Nodes.Add(pcs.Code.ToString(), pcs.Name, ICON_MAP);
                            node.Tag = pcs;
                            if (!dctStatePCS.ContainsKey(pcs.Code))
                            {
                                dctStatePCS.Add(pcs.Code, null);
                            }
                        }
                    }
                }

                // now process the rest as usual
                projections = projections.Where(p => !dctStatePCS.ContainsKey(p.Code));
            }

            if (gcs.Type != GeographicalCSType.Local || m_dctLocalWithClassification.ContainsKey(gcs.Code))
            {
                IEnumerable <string> uniqueTypes = projections.Select(cs => cs.ProjectionType).Distinct().OrderBy(t => t);
                if (uniqueTypes.Count() > 1)
                {
                    foreach (string type in uniqueTypes)
                    {
                        if (type != "")
                        {
                            TreeNode nodeType = parentNode.Nodes.Add(type.ToString(), type.ToString(), ICON_FOLDER);
                            var      projList = projections.Select(cs => cs).Where(c => c.ProjectionType == type);
                            foreach (var val in projList)
                            {
                                TreeNode nodePcs = nodeType.Nodes.Add(val.Code.ToString(), val.Name.ToString(), ICON_MAP);
                                nodePcs.Tag = val;
                            }
                        }
                    }
                }

                // adding projections with undefined type
                IEnumerable <ProjectedCS> list = uniqueTypes.Count() > 1 ?
                                                 projections.Where(c => c.ProjectionType == "").OrderBy(c => c.Name) : projections.OrderBy(c => c.Name);
                if (list.Count() > 0)
                {
                    foreach (ProjectedCS pcs in list)
                    {
                        TreeNode nodePcs = parentNode.Nodes.Add(pcs.Code.ToString(), pcs.Name.ToString(), ICON_MAP);
                        nodePcs.Tag = pcs;
                    }
                }
            }
            else
            {
                foreach (ProjectedCS pcs in projections)
                {
                    TreeNode nodePcs = parentNode.Nodes.Add(pcs.Code.ToString(), pcs.Name.ToString(), ICON_MAP);
                    nodePcs.Tag = pcs;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 查询数据库并填写GCS列表
        /// 有4个水平层次: Regions->Countries->GCS->PCS
        /// 连接信息:
        /// Regions->Countries (Countries.REGION_CODE on Region.REGION_cODE)
        /// Regions->GCS (mwGCSByRegion)
        /// Countries->GCS (mwGCSByCountry)
        /// GCS->PCS (PCS.SOUCRCE_CODE on GCS.CODE)
        /// </summary>
        public bool Read(string dbName)
        {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();

            m_dbname = dbName;

            // regions
            m_listRegions = new List <Region>(30);
            this.ReadRegions(ref m_listRegions);

            // countries
            m_listCountries = new List <Country>(300);
            this.ReadCountries(ref m_listCountries);

            // geographic CS
            m_listGCS = new List <GeographicCS>(800);
            this.ReadGCS(ref m_listGCS);

            // projected CS
            m_listPCS = new List <ProjectedCS>(3000);
            this.ReadPCS(ref m_listPCS);

            // 链接regions和countries
            foreach (Country country in m_listCountries)
            {
                if (m_dctRegions.ContainsKey(country.RegionCode))
                {
                    Region region = (Region)m_dctRegions[country.RegionCode];
                    region.Countries.Add(country);
                }
                else
                {
                    System.Diagnostics.Debug.Print("Specified region wasn't found: " + country.RegionCode);
                }
            }

            // 链接GCS到地区
            this.LinkGCSToRegion();

            // 链接GCS到country
            this.LinkGCSToCountry();

            // 链接PCS到GCS
            foreach (ProjectedCS pcs in m_listPCS)
            {
                if (m_dctGCS.ContainsKey(pcs.SourceCode))
                {
                    GeographicCS gcs = (GeographicCS)m_dctGCS[pcs.SourceCode];
                    gcs.Projections.Add(pcs);
                }
                else
                {
                    System.Diagnostics.Debug.Print("Source geographic CS for projected CS wasn't found: " + pcs.Code);
                }
            }

            // 读取方言
            this.RefreshDialects();

            return(true);
        }