Exemple #1
0
        /// <summary>
        /// POI 数据填充区号
        /// </summary>

        public void WritePoiDirect()
        {
            var tables = this.GetTables("poi");

            var dbHelper   = new DbHelper(this.con);
            var connection = new NpgsqlConnection(this.con);

            connection.Open();
            var command = connection.CreateCommand();

            command.CommandType = CommandType.Text;

            foreach (KeyValuePair <string, ProviceCity> keyValuePair in this.dictionary)
            {
                var provice  = keyValuePair.Value.Provice;
                var cityName = keyValuePair.Value.City;
                var table    = keyValuePair.Value.CityPinyin + "_poi";
                if (!tables.Contains(table))
                {
                    continue;
                }
                dbHelper.AddColumn("districtname", table);
                Console.WriteLine(cityName);
                var cityList = CityConfig.GetInstance().GetCityByName(cityName);
                if (cityList.Count != 1)
                {
                    Console.WriteLine(string.Format("{0}重复", cityName));
                    continue;
                }
                var code = cityList[0].baiduCode;
                if (cityName == "长沙")
                {
                    code = "158";
                }
                var districts = new Dictionary <string, string>(); // code name
                command.CommandText = string.Format(
                    "SELECT area_code,area_name,gid FROM CITY WHERE parent_code = '{0}'",
                    code);
                var read = command.ExecuteReader(CommandBehavior.CloseConnection);
                while (read.Read())
                {
                    districts[read.GetInt32(2).ToString()] = read.GetString(1);
                }
                read.Close();

                var sql = @" UPDATE {0} set districtName = '{1}' WHERE GID IN  (
                                            SELECT m.gid FROM {0} as m  , city as c
                                            where st_intersects(st_setsrid(m.geom,4326),st_setsrid(c.geom,4326))   and c.gid = {2}
                                            )  ";

                districts.Keys.ToList().ForEach(
                    m =>
                {
                    command.CommandText = (string.Format(sql, table, districts[m], m));
                    command.ExecuteNonQuery();
                });
            }
        }
Exemple #2
0
        public void PoiExpand()
        {
            var table = this.Poi;

            this.AddPinYin(table);
            var connection = new NpgsqlConnection(this.con);

            connection.Open();
            var command = connection.CreateCommand();

            var dbHelper = new DbHelper(this.con);

            dbHelper.AddColumn("districtname", table);
            Console.WriteLine(this.City);
            var cityName = City;
            var cityList = CityConfig.GetInstance().GetCityByName(cityName);

            if (cityList.Count != 1)
            {
                Console.WriteLine(string.Format("{0}重复", cityName));
                return;
            }
            var code = cityList[0].baiduCode;

            if (cityName == "长沙")
            {
                code = "158";
            }
            var districts = new Dictionary <string, string>(); // code name

            command.CommandText = string.Format(
                "SELECT area_code,area_name,gid FROM CITY WHERE parent_code = '{0}'",
                code);
            var read = command.ExecuteReader();

            while (read.Read())
            {
                districts[read.GetInt32(2).ToString()] = read.GetString(1);
            }
            read.Close();

            var sql = @" UPDATE {0} set districtName = '{1}' WHERE GID IN  (
                                            SELECT m.gid FROM {0} as m  , city as c
                                            where st_intersects(st_setsrid(m.geom,4326),st_setsrid(c.geom,4326))   and c.gid = {2}
                                            )  ";

            districts.Keys.ToList().ForEach(
                m =>
            {
                command.CommandText = (string.Format(sql, table, districts[m], m));
                command.ExecuteNonQuery();
            });
            connection.Close();
        }
        //private int timeOut = 2000;
        /// <summary>
        /// 下载百度行政区划图
        /// </summary>
        /// <param name="name">下载城市名称,可以是全国,省,市,县</param>
        /// <param name="areaCode"></param>
        /// <param name="type">名称所属类型,属于国家,还是省,市,区 ,县</param>
        public void DownAdminDivision(string name, string areaCode, CityType type)
        {
            switch (type)
            {
            case CityType.Country:
                List <Province> provinces = CityConfig.GetInstance().Countryconfig.countries;
                int             index     = 1;
                int             count     = 1;
                foreach (Province p in provinces)
                {
                    count++;
                    foreach (City c in p.cities)
                    {
                        count++;
                        count += c.districts.Count;
                    }
                }
                this.DownPositions(name, "", type, index, count, "");
                foreach (Province p in provinces)
                {
                    index++;
                    this.DownPositions(p.name, p.areacode, CityType.Province, index, count, p.baiduCode);
                    foreach (City c in p.cities)
                    {
                        index++;
                        this.DownPositions(c.name, c.areacode, CityType.City, index, count, c.baiduCode);
                    }
                }
                break;

            case CityType.Province:
                int pindex = 1;
                int pcount = 1;
                this.DownPositions(name, areaCode, CityType.Province, pindex, pcount, "");
                List <City> cities = CityConfig.GetCitiesByProvinceName(name);
                foreach (City c in cities)
                {
                    pcount++;
                    pcount += c.districts.Count;
                }
                foreach (City c in cities)
                {
                    pindex++;
                    this.DownPositions(c.name, c.areacode, CityType.City, pindex, pcount, c.baiduCode);
                    foreach (District d in c.districts)
                    {
                        pindex++;
                        this.DownPositions(d.name, c.areacode, CityType.District, pindex, pcount, d.baiduCode);
                    }
                }
                break;

            case CityType.City:
                List <District> districts = CityConfig.GetDistrictsByCityName(name);
                int             cindex    = 1;
                int             ccount    = 1 + districts.Count;
                if (!name.Contains("市") && !name.Contains("自治"))
                {
                    name = name + "市";
                }
                this.DownPositions(name, "", type, cindex, ccount, "");
                foreach (District d in districts)
                {
                    cindex++;
                    this.DownPositions(d.name, d.areacode, CityType.District, cindex, ccount, d.baiduCode);
                }
                break;

            case CityType.District:
                this.DownPositions(name, areaCode, CityType.District, 1, 1, "");
                break;
            }
            if (this.AdminDivisionDownedEvent != null)
            {
                this.AdminDivisionDownedEvent();
            }
        }