Exemple #1
0
        public bool contains_point(CPoint pt)
        {
            bool rt = false;

            double angle = 0;
            double dist = CJWDHelper.distance1(center.longitude, center.latitude, pt.longitude, pt.latitude, ref angle);

            if(dist < radius) {
                double deltAngle = 0;
                if(angle > azimuth) {
                    // angle is bigger
                    deltAngle = angle - azimuth;
                    if(deltAngle > 180) {
                        deltAngle = azimuth + 360 - angle;
                    }
                } else {
                    // angle is smaller
                    deltAngle = azimuth - angle;
                    if(deltAngle > 180) {
                        deltAngle = angle + 360 - azimuth;
                    }
                }
                if(deltAngle < angleExt / 2.0) {
                    // in angle span
                    rt = true;
                }
            }

            return rt;
        }
        private void calc_sector_covered_grid()
        {
            CPoint ct = new CPoint();

            string destTableName = "tbGridAreaOverlap_test";
            string deleteSql = @"delete from tbGridAreaOverlap_test where AreaGrandObjectName = 'GSM网扇区按半径'";
            deleteSql = deleteSql.Replace("tbGridAreaOverlap_test", destTableName);

            DBHelper.instatnce().exec(deleteSql);

            DataTable insertDT = new DataTable();
            insertDT.Columns.Add("GXID");
            insertDT.Columns.Add("GYID");
            insertDT.Columns.Add("AreaGrandObjectName");
            insertDT.Columns.Add("OverlapRatio");
            insertDT.Columns.Add("CellID");

            int indexCT = 0;
            foreach(var item in cellInfo)
            {
                double r = indexCT++ / (double)cellInfo.Count;
                LogHelper.instance().write("# compute process: " + r.ToString());
                string cellID = item.Key;

                string sql = @" declare @minLongitude float
                                declare @maxLongitude float
                                declare @minLatitude float
                                declare @maxLatitude float

                                set @minLongitude = minLongitude_V
                                set @maxLongitude = maxLongitude_V
                                set @minLatitude = minLatitude_V
                                set @maxLatitude = maxLatitude_V

                                SELECT [GXID],[GYID],[CLong],[CLat],[MaxLong],[MaxLat],[MinLong],[MinLat],[InNetCoverage],[GeoScene]
                                FROM tbGrid_test
                                where CLong <= @maxLongitude and CLong >= @minLongitude
                                and CLat <= @maxLatitude and CLat >= @minLatitude ";

                sql = sql.Replace("minLongitude_V", item.Value.minPos.longitude.ToString());
                sql = sql.Replace("minLatitude_V", item.Value.minPos.latitude.ToString());
                sql = sql.Replace("maxLongitude_V", item.Value.maxPos.longitude.ToString());
                sql = sql.Replace("maxLatitude_V", item.Value.maxPos.latitude.ToString());

                DataTable dt = new DataTable();
                DBHelper.instatnce().get_dataTable(ref dt, sql);

                foreach(DataRow dr in dt.Rows)
                {
                    string GXID = dr["GXID"].ToString();
                    string GYID = dr["GYID"].ToString();
                    string CLong = dr["CLong"].ToString();
                    string CLat = dr["CLat"].ToString();

                    double MaxLong = double.Parse(dr["MaxLong"].ToString());
                    double MaxLat = double.Parse(dr["MaxLat"].ToString());

                    double MinLong = double.Parse(dr["MinLong"].ToString());
                    double MinLat = double.Parse(dr["MinLat"].ToString());

                    int containsPtCount = 0;

                    ct.longitude = double.Parse(CLong);
                    ct.latitude = double.Parse(CLat);
                    if(item.Value.contains_point(ct))
                    { // 0 center pt
                        containsPtCount++;
                    }

                    ct.longitude = MinLong;
                    ct.latitude = MinLat;
                    if(item.Value.contains_point(ct))
                    { // 1 left bottom pt
                        containsPtCount++;
                    }

                    ct.longitude = MinLong;
                    ct.latitude = MaxLat;
                    if(item.Value.contains_point(ct))
                    { // 2 left top pt
                        containsPtCount++;
                    }

                    ct.longitude = MaxLong;
                    ct.latitude = MaxLat;
                    if(item.Value.contains_point(ct))
                    { // 3 right top pt
                        containsPtCount++;
                    }

                    ct.longitude = MaxLong;
                    ct.latitude = MinLat;
                    if(item.Value.contains_point(ct))
                    { // 4 right bottom pt
                        containsPtCount++;
                    }

                    if(containsPtCount > 0)
                    { // in pie
                        DataRow nr = insertDT.NewRow();

                        nr["GXID"] = GXID;
                        nr["GYID"] = GYID;
                        nr["AreaGrandObjectName"] = "GSM网扇区按半径";
                        nr["OverlapRatio"] = containsPtCount / (double)5.0;
                        nr["CellID"] = cellID;

                        insertDT.Rows.Add(nr);
                        //LogHelper.instance().write("# sector: " + cellID + ",(" + GXID + "," + GYID + ")", 0);

                        if(insertDT.Rows.Count > 1000) {
                            DBHelper.instatnce().batch_save_2_db(destTableName, ref insertDT);
                        }
                    }
                }

            }
            if(insertDT.Rows.Count > 0) {
                DBHelper.instatnce().batch_save_2_db(destTableName, ref insertDT);
            }
        }