Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public List <POIInfo> GetPoiInfos(string url)
        {
            List <POIInfo>  poiList = new List <POIInfo>();
            HttpWebResponse hwr     = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null);
            string          context = HttpHelper.GetResponseString(hwr);

            context = context.Substring(22, context.Length - 24);
            object t = JsonHelper.JsonDeserialize <object>(context);
            Dictionary <string, object> dicT     = t as Dictionary <string, object>;
            Dictionary <string, object> dicInfos = (dicT["content"] as object[])[0] as Dictionary <string, object>;

            object[] infos = dicInfos["uids"] as object[];
            if (infos.Length == 0)
            {
                return(poiList);
            }
            foreach (object i in infos.ToList())
            {
                Dictionary <string, object> icon = (i as Dictionary <string, object>)["icon"] as Dictionary <string, object>;
                object  x       = icon["x"];
                object  y       = icon["y"];
                object  ty      = (i as Dictionary <string, object>)["type"];
                object  name    = (i as Dictionary <string, object>)["name"];
                object  uid     = (i as Dictionary <string, object>)["uid"];
                double  doubleX = double.Parse(x.ToString());
                double  doubleY = double.Parse(y.ToString());
                string  id      = uid.ToString();
                POIInfo poiInfo = new POIInfo();
                poiInfo.name = name.ToString();
                poiInfo.type = ty.ToString();
                poiInfo.x    = doubleX;
                poiInfo.y    = doubleY;
                Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x);
                c          = CoordHelper.Gcj2Wgs(c.lon, c.lat);
                poiInfo.cx = c.lon;
                poiInfo.cy = c.lat;
                if (this.dicIDs.ContainsKey(id))
                {
                    continue;
                }
                else
                {
                    POIDeInfo poiDeInfo = this.GetDetailInfo(id);
                    Coord     coord     = this.coordProjection(doubleX, doubleY);
                    if (coord != null)
                    {
                        poiInfo.x = coord.lon;
                        poiInfo.y = coord.lat;
                    }
                    if (poiDeInfo != null)
                    {
                        poiInfo.phone   = poiDeInfo.phone;
                        poiInfo.type    = poiDeInfo.type;
                        poiInfo.address = poiDeInfo.address;
                    }
                }
                poiList.Add(poiInfo);
            }
            return(poiList);
        }
Exemplo n.º 2
0
            /// <summary>
            /// 获取中心点【火星坐标】
            /// </summary>
            /// <returns></returns>
            public Coord getGJC02Center()
            {
                if (string.IsNullOrEmpty(this.Center))
                {
                    return(null);
                }
                var m = this.Center.Split('|')[0];
                var x = double.Parse(m.Split(',')[0]);
                var y = double.Parse(m.Split(',')[1]);

                // 百度坐标转为火星坐标
                return(CoordHelper.BdDecrypt(y, x));
            }
Exemplo n.º 3
0
        private List <POIInfo> getKeywordPOI(string url)
        {
            List <POIInfo>              poiList = new List <POIInfo>();
            HttpWebResponse             hwr     = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", null);
            string                      context = HttpHelper.GetResponseString(hwr);
            object                      t       = JsonHelper.JsonDeserialize <object>(context);
            Dictionary <string, object> dicT    = t as Dictionary <string, object>;

            object[] dicInfos = dicT["uids"] as object[];
            for (int i = 0; i < dicInfos.Length; i++)
            {
                Dictionary <string, object> dic = dicInfos[i] as Dictionary <string, object>;
                POIInfo poiInfo = new POIInfo();
                object  objX    = dic["x"];
                object  objY    = dic["y"];
                object  objID   = dic["uid"];
                object  objName = dic["name"];
                if (objX != null && objY != null)
                {
                    double.TryParse(objX.ToString(), out poiInfo.x);
                    double.TryParse(objY.ToString(), out poiInfo.y);
                }
                if (objName != null)
                {
                    poiInfo.name = objName.ToString();
                }
                if (objID != null)
                {
                    string    id            = objID.ToString();
                    POIDeInfo poiDetailInfo = this.getDetailInfoKeyWord(id);
                    poiInfo.address = poiDetailInfo.address;
                    poiInfo.phone   = poiDetailInfo.phone;
                    poiInfo.type    = poiDetailInfo.type;
                }
                Coord coord = this.coordProjection(poiInfo.x, poiInfo.y);
                if (coord != null)
                {
                    poiInfo.x = coord.lon;
                    poiInfo.y = coord.lat;
                    Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x);
                    c          = CoordHelper.Gcj2Wgs(c.lon, c.lat);
                    poiInfo.cx = c.lon;
                    poiInfo.cy = c.lat;
                }
                poiList.Add(poiInfo);
            }
            return(poiList);
        }
Exemplo n.º 4
0
        private string PathConvert(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(string.Empty);
            }
            var paths = path.Split(';').ToList().Select(
                m =>
            {
                // var temp = m.Split(',');
                var lonlat = this.getBaiduPixLonlat(m);
                // CoordHelper.WebMercator2lonLat(new Coord(double.Parse(temp[0]), double.Parse(temp[1])));
                return(CoordHelper.BdDecrypt(lonlat.lat, lonlat.lon).ToString());
            }).ToArray();

            return(string.Join(";", paths));
        }
Exemplo n.º 5
0
            public string GetGJC02Bound()
            {
                if (string.IsNullOrEmpty(this.Bound))
                {
                    return(string.Empty);
                }
                var points = this.Bound.Split(';').Select(
                    m =>
                {
                    var x = double.Parse(m.Split(',')[0]);
                    var y = double.Parse(m.Split(',')[1]);

                    // 百度坐标转为火星坐标
                    return(CoordHelper.BdDecrypt(y, x).ToString());
                }).ToArray();

                return(String.Join(";", points));
            }
Exemplo n.º 6
0
        private Coord getBaiduLonlat(string i)
        {
            //if (string.IsNullOrEmpty(i))
            //{
            //    return new Coord(0, 0);
            //}
            //i = i.Split('|')[2];
            //i = i.Substring(0, i.Length - 1);
            //var lon = double.Parse(i.Split(',')[0]);
            //var lat = double.Parse(i.Split(',')[1]);
            //var lonlat = CoordHelper.WebMercator2lonLat(new Coord(lon, lat));
            i = i.Split('|')[2];
            i = i.Substring(0, i.Length - 1);
            var lonlat = this.getBaiduPixLonlat(i);

            lonlat = CoordHelper.BdDecrypt(lonlat.lat, lonlat.lon);
            return(lonlat);
            //  return CoordHelper.gcj2wgs(lonlat.lon, lonlat.lat);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 坐标转换
        /// </summary>
        /// <param name="lonlat">格式[x,y]或者[x|y]</param>
        /// <param name="project"></param>
        /// <returns></returns>
        public static Coord ProjectChange(string lonlat, ProjectConvert project)
        {
            if (string.IsNullOrEmpty(lonlat))
            {
                return(new Coord(0, 0));
            }
            try
            {
                double x = double.Parse(lonlat.Split('|', ',')[0]);
                double y = double.Parse(lonlat.Split('|', ',')[1]);
                switch (project)
                {
                case ProjectConvert.NONE:
                    return(new Coord(x, y));

                case ProjectConvert.GCJ_WGS:
                case ProjectConvert.GAODE84_WGS:
                    return(CoordHelper.Gcj2Wgs(x, y));

                case ProjectConvert.BAIDU_WGS:
                    var c = CoordHelper.BdDecrypt(y, x);
                    return(CoordHelper.Gcj2Wgs(c.lon, c.lat));

                case ProjectConvert.GAODE900913_WGS:
                    var g = CoordHelper.WebMercator2lonLat(new Coord(x, y));
                    return(CoordHelper.Gcj2Wgs(g.lon, g.lat));

                default:
                    return(new Coord(0, 0));
                }
            }
            catch (Exception)
            {
                Console.WriteLine(lonlat);
                return(new Coord());
            }
        }
Exemplo n.º 8
0
        private void DownPoIbyExtent(double x1, double y1, double x2, double y2, string keyWords, int index, int count)
        {
            for (int pindex = 0; pindex < 38; pindex++)
            {
                var keyWordsList = new List <string>();
                if (keyWords == string.Empty)
                {
                    keyWordsList.Add("美食$宾馆$购物$汽车$生活$结婚$丽人$金融$休闲娱乐$医疗");
                    keyWordsList.Add("旅游$教育$房地产$政府机构$公司企业$公交站$学校$小区");
                }
                else
                {
                    keyWordsList.Add(keyWords);
                }

                foreach (string keyword in keyWordsList)
                {
                    Random rd     = new Random();
                    int    kindex = rd.Next(0, this.keys.Length);
                    string url    = string.Format(
                        this.baiduPoiUrl,
                        keyword,
                        y1 + "," + x1 + "," + y2 + "," + x2,
                        pindex,
                        this.keys[kindex]);

                    try
                    {
                        HttpWebResponse ht = HttpHelper.CreateGetHttpResponse(
                            url,
                            1000,
                            "Opera/9.25 (Windows NT 6.0; U; en)",
                            null);
                        string ff        = HttpHelper.GetResponseString(ht);
                        var    detail    = JsonHelper.JsonDeserialize <object>(ff);
                        var    dicResult = detail as Dictionary <string, object>;
                        if (dicResult.ContainsKey("status") && dicResult["status"].ToString() != "0")
                        {
                            log.ErrorFormat("{0}请求失败,返回码:{1}", url, dicResult["status"]);
                            continue;
                        }
                        if (dicResult != null && dicResult.ContainsKey("results"))
                        {
                            object poiObjs = dicResult["results"];
                            var    pois    = poiObjs as object[];
                            if (pois.Length == 0)
                            {
                                if (this.DowningMessageEvent != null)
                                {
                                    this.DowningMessageEvent(index, count);
                                }
                                break;
                            }
                            foreach (object poi in pois)
                            {
                                var poiInfo = new POIInfo();
                                this.poiCount++;
                                var objects = poi as Dictionary <string, object>;
                                if (objects.ContainsKey("name") && objects["name"] != null)
                                {
                                    poiInfo.name = objects["name"].ToString();
                                }
                                if (objects.ContainsKey("location") && objects["location"] != null)
                                {
                                    var    dicxy   = objects["location"] as Dictionary <string, object>;
                                    string stringX = dicxy["lng"] != null ? dicxy["lng"].ToString() : "";
                                    string stringY = dicxy["lat"] != null ? dicxy["lat"].ToString() : "";
                                    double.TryParse(stringX, out poiInfo.x);
                                    double.TryParse(stringY, out poiInfo.y);
                                    Coord c = CoordHelper.BdDecrypt(poiInfo.y, poiInfo.x);
                                    c          = CoordHelper.Gcj2Wgs(c.lon, c.lat);
                                    poiInfo.cx = c.lon;
                                    poiInfo.cy = c.lat;
                                }
                                if (objects.ContainsKey("address") && objects["address"] != null)
                                {
                                    poiInfo.address = objects["address"].ToString();
                                }

                                if (objects.ContainsKey("telephone") && objects["telephone"] != null)
                                {
                                    poiInfo.phone = objects["telephone"].ToString();
                                }
                                if (this.DowningEvent != null)
                                {
                                    this.DowningEvent(poiInfo, index, count);
                                }
                            }
                        }
                        else
                        {
                            log.WarnFormat("请求{0} 出错", url);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat("请求{0} 出错:{1}", url, ex);
                    }
                }

                if (this.DowningMessageEvent != null)
                {
                    this.DowningMessageEvent(index, count);
                }
            }
        }