Example #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();
                });
            }
        }
Example #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();
        }
Example #3
0
    public void Init(CityInventory cityInventory, CityConfig cityConfig, UnityAction <Building> onHoverBuilding = null, UnityAction <Building> onHoverEndBuilding = null)
    {
        CityInventory = cityInventory;
        CityConfig    = cityConfig;

        OnHoverBuilding    = onHoverBuilding;
        OnHoverEndBuilding = onHoverEndBuilding;
        CityInventory.RefreshInventoryGrids();
        CityInventory.RefreshConflictAndIsolation();

        CityEditAreaIndicator.Init(CityInventory);
        cityInventoryGirdMatrix = new CityInventoryGrid[cityInventory.Columns, cityInventory.Rows];

        while (rockPosSet.Count < 2)
        {
            rockPosSet.Add(new GridPos(Random.Range(0, CityInventory.Columns / 2), Random.Range(0, CityInventory.Rows / 2)));
        }
        while (rockPosSet.Count < 4)
        {
            rockPosSet.Add(new GridPos(Random.Range(CityInventory.Columns / 2, CityInventory.Columns), Random.Range(0, CityInventory.Rows / 2)));
        }
        while (rockPosSet.Count < 6)
        {
            rockPosSet.Add(new GridPos(Random.Range(0, CityInventory.Columns / 2), Random.Range(CityInventory.Rows / 2, CityInventory.Rows)));
        }
        while (rockPosSet.Count < 8)
        {
            rockPosSet.Add(new GridPos(Random.Range(CityInventory.Columns / 2, CityInventory.Columns), Random.Range(CityInventory.Rows / 2, CityInventory.Rows)));
        }
        while (rockPosSet.Count < 10)
        {
            rockPosSet.Add(new GridPos(Random.Range(CityInventory.Columns / 3 * 1, CityInventory.Columns / 3 * 2), Random.Range(CityInventory.Rows / 3 * 1, CityInventory.Rows / 3 * 2)));
        }

        PerlinRandomOffset = new Vector2(Random.Range(-99872.3213f, 344.1239123f), Random.Range(-12312.1231f, 39291.1231f));
        for (int col = 0; col < cityInventory.Columns; col++)
        {
            for (int row = 0; row < cityInventory.Rows; row++)
            {
                CityInventoryGrid grid = cityInventory.CreateCityInventoryGrid(CityInventoryGridContainer);
                grid.transform.localPosition = new Vector3((col - cityInventory.Columns / 2) * cityInventory.GridSize, 0, (row - cityInventory.Rows / 2) * cityInventory.GridSize);
                TerrainType tt = GenerateTerrainByPerlinNoise(col, row);
                grid.Init(new GridPos(col, row), CityInventory, tt);
                cityInventoryGirdMatrix[col, row] = grid;
            }
        }

        CityInventory.OnAddItemSucAction    = OnAddBuildingSuc;
        CityInventory.OnRemoveItemSucAction = OnRemoveBuildingSuc;
        GridShown = false;

        RefreshBuildingCoverMaskMatrix(false);
    }
Example #4
0
        private void cmbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string provinceName = (cmbProvince.SelectedItem as ComboBoxItem).Text;

            cmbCity.Items.Clear();
            string      name   = (cmbProvince.SelectedItem as ComboBoxItem).Text;
            List <City> cities = CityConfig.GetCitiesByProvinceName(name);

            foreach (City c in cities)
            {
                ComboBoxItem item1 = new ComboBoxItem();
                item1.Text = c.name;
                item1.Tag  = c.areacode;
                cmbCity.Items.Add(item1);
            }
            if (cmbCity.Items.Count > 0)
            {
                cmbCity.SelectedIndex = 0;
            }
        }
Example #5
0
        private void cmbProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            string provinceName = cmbProvince.SelectedItem.ToString();

            if (provinceName == "全国")
            {
                cmbCity.Items.Clear();
                ComboBoxItem item = new ComboBoxItem();
                item.Text = "全部";
                item.Tag  = "";
                cmbCity.Items.Add(item);
            }
            else
            {
                cmbCity.Items.Clear();
                ComboBoxItem item = new ComboBoxItem();
                item.Text = "全部";
                item.Tag  = "";
                cmbCity.Items.Add(item);
                string      name   = cmbProvince.SelectedItem.ToString();
                List <City> cities = CityConfig.GetCitiesByProvinceName(name);
                foreach (City c in cities)
                {
                    ComboBoxItem item1 = new ComboBoxItem();
                    item1.Text = c.name;
                    item1.Tag  = c.areacode;
                    cmbCity.Items.Add(item1);
                }
                if (cmbCity.Items.Count == 2)//直辖市
                {
                    cmbCity.Items.Remove(cmbCity.Items[0]);
                }
            }
            if (cmbCity.Items.Count > 0)
            {
                cmbCity.SelectedIndex = 0;
            }
        }
Example #6
0
        public City(long seed, RantEngine rant, CityConfig config)
        {
            _seed = seed;
            _rant = rant;
            _updateQueue = new UpdateQueue(this);

            citizenCache = new SeedCache<CitizenInfo>(CITIZEN_CACHE_CAPACITY, s => new CitizenInfo(this, s));

            var data = rant.DoPackaged("sp/city", seed);

            Name = data["name"];
            int year, month, day;
            if (!(
                    int.TryParse(data["year"], out year) &&
                    int.TryParse(data["month"], out month) &&
                    int.TryParse(data["day"], out day)))
            {
                year = 1990;
                month = 4;
                day = 1;
            }
            StartingTime = CurrentTime = new DateTime(year, month, day);
        }
Example #7
0
        private void cmbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbDistrict.Items.Clear();
            ComboBoxItem item = new ComboBoxItem();

            item.Text = "全部";
            item.Tag  = "";
            cmbDistrict.Items.Add(item);
            string          name      = cmbCity.SelectedItem.ToString();
            List <District> districts = CityConfig.GetDistrictsByCityName(name);

            foreach (District d in districts)
            {
                ComboBoxItem item1 = new ComboBoxItem();
                item1.Text = d.name;
                item1.Tag  = d.areacode;
                cmbDistrict.Items.Add(item1);
            }
            if (cmbDistrict.Items.Count > 0)
            {
                cmbDistrict.SelectedIndex = 0;
            }
        }
        //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();
            }
        }
Example #9
0
    public List <Road> Generate(Road prevSegment, RoadMap roadMap)
    {
        var newRoads = new List <Road>();

        if (prevSegment.severed)
        {
            return(newRoads);
        }

        if (segFactory == null)
        {
            Initialize();
        }
        Road continueStraight = segFactory.CreateRoad(
            prevSegment.end,
            prevSegment.transform.localRotation,
            prevSegment.length,
            prevSegment.t + 1,
            prevSegment.type
            );
        float straightPop = Heatmap.Value(continueStraight.end);

        if (prevSegment.type == RoadType.Highway)
        {
            // generate a random deviation and compare to going straight,
            // chosing the road that leads to the highest population
            float newAngle = prevSegment.transform.localEulerAngles.y + CityConfig.RandomStraightAngle();

            Road randomStraight = segFactory.CreateRoad(
                prevSegment.end,
                Quaternion.Euler(prevSegment.transform.localEulerAngles.x, newAngle, 0),
                prevSegment.length,
                prevSegment.t + 1,
                prevSegment.type
                );

            float randomPop = Heatmap.Value(randomStraight.end);
            float roadPop;
            Road  straight;
            if (randomPop > straightPop)
            {
                newRoads.Add(randomStraight);
                roadPop  = randomPop;
                straight = randomStraight;
                DestroyImmediate(continueStraight.gameObject);
            }
            else
            {
                newRoads.Add(continueStraight);
                roadPop  = straightPop;
                straight = continueStraight;
                DestroyImmediate(randomStraight.gameObject);
            }

            // highway branches off highway
            if (roadPop > CityConfig.HIGHWAY_BRANCH_POPULATION_THRESHOLD)
            {
                Junction j = null;
                if (Random.value < CityConfig.HIGHWAY_BRANCH_PROBABILITY)
                {
                    Road leftRoad = AddBranch(
                        prevSegment,
                        straight,
                        j,
                        prevSegment.transform.localEulerAngles.y - 90 + CityConfig.RandomBranchAngle(),
                        prevSegment.length,
                        prevSegment.t + 1,
                        prevSegment.type
                        );
                    newRoads.Add(leftRoad);
                }
                if (Random.value < CityConfig.HIGHWAY_BRANCH_PROBABILITY)
                {
                    Road rightRoad = AddBranch(
                        prevSegment,
                        straight,
                        j,
                        prevSegment.transform.localEulerAngles.y + 90 + CityConfig.RandomBranchAngle(),
                        prevSegment.length,
                        prevSegment.t + 1,
                        prevSegment.type
                        );
                    newRoads.Add(rightRoad);
                }
            }
        }
        else if (straightPop > CityConfig.STREET_BRANCH_POPULATION_THRESHOLD)
        {
            // do not delete continueStraight
            newRoads.Add(continueStraight);
        }
        else
        {
            DestroyImmediate(continueStraight.gameObject);
        }

        // street branches off either highway or streets
        if (straightPop > CityConfig.STREET_BRANCH_POPULATION_THRESHOLD)
        {
            int t = (prevSegment.type == RoadType.Highway) ? CityConfig.STREET_FROM_HIGHWAY_DELAY : 1;

            Junction j = null;
            if (Random.value < CityConfig.STREET_BRANCH_PROBABILITY)
            {
                Road leftRoad = AddBranch(
                    prevSegment,
                    continueStraight,
                    j,
                    prevSegment.transform.localEulerAngles.y - 90 + CityConfig.RandomBranchAngle(),
                    CityConfig.STREET_SEGMENT_LENGTH,
                    prevSegment.t + t,
                    RoadType.Street
                    );
                newRoads.Add(leftRoad);
            }
            if (Random.value < CityConfig.STREET_BRANCH_PROBABILITY)
            {
                Road leftRoad = AddBranch(
                    prevSegment,
                    continueStraight,
                    j,
                    prevSegment.transform.localEulerAngles.y + 90 + CityConfig.RandomBranchAngle(),
                    CityConfig.STREET_SEGMENT_LENGTH,
                    prevSegment.t + t,
                    RoadType.Street
                    );
                newRoads.Add(leftRoad);
            }
        }

        // set up links between roads
        foreach (Road r in newRoads)
        {
            r.Parent = prevSegment;
            prevSegment.next.Add(new Road.Neighbour(r, true));
            foreach (Road r_other in newRoads)
            {
                if (r_other.id != r.id)
                {
                    r.prev.Add(new Road.Neighbour(r_other, false));
                }
            }
        }

        return(newRoads);
    }