Example #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);
        }
Example #2
0
 /// <summary>
 /// 根据地址查询兴趣点信息
 /// </summary>
 /// <param name="url">地址</param>
 /// <returns>兴趣点信息</returns>
 private void GetPoiInfos(string url)
 {
     try
     {
         HttpWebResponse hwr     = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", GetCookies());
         string          context = HttpHelper.GetResponseString(hwr);
         object          t       = JsonHelper.JsonDeserialize <object>(context);
         object[]        xs      = t as object[];
         for (int i = 0; i < xs.Length; i++)
         {
             object   ps      = xs[i];
             object[] pps     = ps as object[];
             object[] objects = pps[4] as object[];
             for (int j = 0; j < objects.Length; j++)
             {
                 object[] oos = objects[j] as object[];
                 object[] xos = oos[0] as object[];
                 for (int k = 0; k < xos.Length; k++)
                 {
                     object[] obs  = xos[k] as object[];
                     string   name = (obs.Length > 0 && obs[0] != null) ? obs[0].ToString() : "";
                     string   id   = (obs.Length > 0 && obs[obs.Length - 1] != null) ? obs[obs.Length - 1].ToString() : "";
                     if (id != "")
                     {
                         POIInfo   poiInfo   = new POIInfo();
                         POIDeInfo poiDeInfo = this.getDetailInfo(id);
                         if (poiDeInfo == null || poiDeInfo.name == "")
                         {
                             continue;
                         }
                         poiInfo.name    = poiDeInfo.name;
                         poiInfo.address = poiDeInfo.address.Replace(",", "");
                         //poiInfo.address.Replace(",", "");
                         poiInfo.type  = poiDeInfo.type;
                         poiInfo.phone = poiDeInfo.phone;
                         poiInfo.x     = poiDeInfo.x;
                         poiInfo.y     = poiDeInfo.y;
                         Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y);
                         poiInfo.cx       = c.lon;
                         poiInfo.cy       = c.lat;
                         poiInfo.pName    = poiDeInfo.pName;
                         poiInfo.cName    = poiDeInfo.cName;
                         poiInfo.dName    = poiDeInfo.dName;
                         poiInfo.roadName = poiDeInfo.roadName;
                         this.POICount++;
                         if (this.DowningEvent != null)
                         {
                             this.DowningEvent(poiInfo, this.index, this.count);
                         }
                     }
                 }
             }
         }
     }
     catch { }
 }
Example #3
0
 /// <summary>
 /// 根据地址获取兴趣点信息(关键字查询)
 /// </summary>
 /// <param name="url">地址</param>
 /// <returns></returns>
 private void getPoiInfosKeyWord(string url)
 {
     try
     {
         HttpWebResponse             hwr     = HttpHelper.CreateGetHttpResponse(url, 1000, "Opera/9.25 (Windows NT 6.0; U; en)", GetCookies());
         string                      context = HttpHelper.GetResponseString(hwr);
         object                      t       = JsonHelper.JsonDeserialize <object>(context);
         Dictionary <string, object> ts      = t as Dictionary <string, object>;
         if (ts.ContainsKey("tiles"))
         {
             object[] objs = ts["tiles"] as object[];
             Dictionary <string, object> ob = objs[0] as Dictionary <string, object>;
             object[] osx = ob["tile"] as object[];
             for (int i = 0; i < osx.Length; i++)
             {
                 POIInfo poiInfo = new POIInfo();
                 Dictionary <string, object> dicox = osx[i] as Dictionary <string, object>;
                 string id = dicox["id"].ToString();
                 poiInfo.name = dicox["name"].ToString();
                 POIDeInfo poiDeInfo = this.getDetailInfo(id);
                 if (poiDeInfo != null && poiDeInfo.name != "")
                 {
                     poiInfo.name    = poiDeInfo.name;
                     poiInfo.address = poiDeInfo.address;
                     poiInfo.type    = poiDeInfo.type;
                     poiInfo.phone   = poiDeInfo.phone;
                     poiInfo.x       = poiDeInfo.x;
                     poiInfo.y       = poiDeInfo.y;
                     Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y);
                     poiInfo.cx       = c.lon;
                     poiInfo.cy       = c.lat;
                     poiInfo.roadName = poiDeInfo.roadName;
                     poiInfo.pName    = poiDeInfo.pName;
                     poiInfo.cName    = poiDeInfo.cName;
                     poiInfo.dName    = poiDeInfo.dName;
                     poiInfo.address.Replace(",", "");
                     this.POICount++;
                     if (this.DowningEvent != null)
                     {
                         this.DowningEvent(poiInfo, this.index, this.count);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         log.ErrorFormat("请求{0} 出错:{1}", url, ex);
     }
 }
Example #4
0
 public string getWgsPath(int index)
 {
     if (index >= this.paths.Count)
     {
         return(string.Empty);
     }
     string[] wgspaths = paths[index].Replace(",", "|").Split(';').ToList().Select(
         m =>
     {
         var lonlat = CoordHelper.Gcj2Wgs(double.Parse(m.Split('|')[0]), double.Parse(m.Split('|')[1]));
         return(string.Format("{0}|{1}", lonlat.lon, lonlat.lat));
     }).ToArray();
     return(string.Join(";", wgspaths));
 }
Example #5
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);
        }
Example #6
0
        public Coord GetLocationByAddress(string address, string cityCode, bool jiupian)
        {
            string tempURL = string.Format(this.addressUrl, this.keys[System.DateTime.Now.Ticks % this.keys.Length], cityCode, address);

            try
            {
                System.Threading.Thread.Sleep(500);
                HttpWebResponse webresponse = HttpHelper.CreateGetHttpResponse(tempURL, 1000, null, null);
                string          context     = HttpHelper.GetResponseString(webresponse);
                object          resultObj   = JsonHelper.JsonDeserialize <object>(context);
                if (resultObj != null)
                {
                    Dictionary <string, object> resultDic = resultObj as Dictionary <string, object>;
                    if (resultDic != null && resultDic.ContainsKey("geocodes"))
                    {
                        object locationObj = resultDic["geocodes"];
                        if ((locationObj as object[]).Length > 0)
                        {
                            string   location = ((locationObj as object[])[0] as Dictionary <string, object>)["location"].ToString();
                            string[] xy       = location.Split(',');
                            if (xy.Length == 2)
                            {
                                Coord c = new Coord();
                                if (double.TryParse(xy[0], out c.lon) && double.TryParse(xy[1], out c.lat))
                                {
                                    if (jiupian)
                                    {
                                        c = CoordHelper.Gcj2Wgs(c.lon, c.lat);
                                    }
                                    return(c);
                                }
                                else
                                {
                                    return(null);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("请求{0} 出错:{1}", tempURL, ex);
            }
            return(null);
        }
Example #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());
            }
        }
Example #8
0
        /// <summary>
        /// 转换是否纠偏,只使用与火星坐标纠偏
        /// </summary>
        /// <param name="dataTable">数据表,如果是点表中含X,Y字段,如果是线和面,表中含有PATH字段</param>
        /// <param name="filePath">存储路径</param>
        /// <param name="geoType">数据类型,暂时支持简单的点线面</param>
        /// <param name="jiupian">是否纠偏[火星坐标转84坐标]</param>
        public static void SaveShpFile(DataTable dataTable, string filePath, wkbGeometryType geoType, ProjectConvert jiupian)
        {
            if (geoType == wkbGeometryType.wkbLineString || geoType == wkbGeometryType.wkbPolygon)
            {
                if (!dataTable.Columns.Contains("PATH"))
                {
                    return;
                }
            }
            else if (geoType == wkbGeometryType.wkbPoint)
            {
                if (!dataTable.Columns.Contains("X") || !dataTable.Columns.Contains("Y"))
                {
                    return;
                }
            }
            else
            {
                return;
            }
            // 为了支持中文路径,请添加下面这句代码
            OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
            // 为了使属性表字段支持中文,请添加下面这句
            OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "");

            string strVectorFile = filePath;

            // 注册所有的驱动
            Ogr.RegisterAll();

            //创建数据,这里以创建ESRI的shp文件为例
            string strDriverName = "ESRI Shapefile";
            int    count         = Ogr.GetDriverCount();
            Driver oDriver       = Ogr.GetDriverByName(strDriverName);

            if (oDriver == null)
            {
                log.ErrorFormat("{0}驱动不可用!\n", strVectorFile);
                Console.WriteLine("{0}驱动不可用!\n", strVectorFile);
                return;
            }

            // 创建数据源
            DataSource oDS = oDriver.CreateDataSource(strVectorFile, null);

            if (oDS == null)
            {
                log.ErrorFormat("创建矢量文件{0}失败!\n", strVectorFile);
                Console.WriteLine("创建矢量文件【%s】失败!\n", strVectorFile);
                return;
            }
            string strwkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";

            OSGeo.OSR.SpatialReference srs = new OSGeo.OSR.SpatialReference(strwkt);
            // 创建图层,创建一个多边形图层,这里没有指定空间参考,如果需要的话,需要在这里进行指定
            Layer oLayer = oDS.CreateLayer("test", null, geoType, null);

            if (oLayer == null)
            {
                Console.WriteLine("图层创建失败!\n");
                return;
            }
            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                if (dataTable.Columns[i].ColumnName == "PATH")
                {
                    continue;
                }
                string    columnName = dataTable.Columns[i].ColumnName;
                FieldDefn oFieldName = new FieldDefn(columnName, FieldType.OFTString);
                oFieldName.SetWidth(255);
                oLayer.CreateField(oFieldName, 1);
            }
            FeatureDefn oDefn = oLayer.GetLayerDefn();

            foreach (DataRow row in dataTable.Rows)
            {
                if ((geoType == wkbGeometryType.wkbPolygon || geoType == wkbGeometryType.wkbLineString) && string.IsNullOrEmpty(row["PATH"].ToString()))
                {
                    continue;
                }
                // 创建Multi要素
                Feature oFeatureMulty = new Feature(oDefn);
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    if (geoType == wkbGeometryType.wkbPolygon || geoType == wkbGeometryType.wkbLineString)
                    {
                        if (dataTable.Columns[i].ColumnName == "PATH")
                        {
                            continue;
                        }
                    }
                    string name = row[i] != null ? row[i].ToString() : "";
                    if (!string.IsNullOrEmpty(name))
                    {
                        try
                        {
                            //oFeatureMulty.SetField(dataTable.Columns[i].ColumnName,name);
                            var value = name.Trim().Replace("'", "").Replace(",", "");
                            if (value.Length > 255)
                            {
                                value = value.Substring(0, 250);
                            }
                            oFeatureMulty.SetField(i, value);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }
                if (geoType == wkbGeometryType.wkbPolygon || geoType == wkbGeometryType.wkbLineString)
                {
                    string path = row["PATH"] != null ? row["PATH"].ToString() : "";
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }
                    var                geoCount        = path.Split('|').Length;
                    wkbGeometryType    newGeometryType = geoType;
                    OSGeo.OGR.Geometry geo1            = new OSGeo.OGR.Geometry(geoType);
                    if (geoType == wkbGeometryType.wkbPolygon)
                    {
                        if (geoCount > 1)
                        {
                            geo1 = new OSGeo.OGR.Geometry(wkbGeometryType.wkbMultiPolygon);
                            for (int i = 0; i < geoCount; i++)
                            {
                                var temp   = path.Split('|')[i];
                                var points = temp.Split(';');
                                OSGeo.OGR.Geometry innGeometry = new Geometry(wkbGeometryType.wkbLinearRing);
                                for (int j = 0; j < points.Length; j++)
                                {
                                    var c = ProjectChange(points[j], jiupian);
                                    innGeometry.AddPoint_2D(c.lon, c.lat);
                                }
                                var polygon = new Geometry(wkbGeometryType.wkbPolygon);
                                polygon.AddGeometry(innGeometry);
                                geo1.AddGeometry(polygon);
                            }
                        }
                        else
                        {
                            geo1 = new OSGeo.OGR.Geometry(wkbGeometryType.wkbPolygon);
                            for (int i = 0; i < geoCount; i++)
                            {
                                var temp   = path.Split('|')[i];
                                var points = temp.Split(';');
                                OSGeo.OGR.Geometry innGeometry = new Geometry(wkbGeometryType.wkbLinearRing);
                                for (int j = 0; j < points.Length; j++)
                                {
                                    var c = ProjectChange(points[j], jiupian);
                                    innGeometry.AddPoint_2D(c.lon, c.lat);
                                }
                                geo1.AddGeometry(innGeometry);
                            }
                        }
                    }
                    else
                    {
                        if (geoCount > 1)
                        {
                            geo1 = new OSGeo.OGR.Geometry(wkbGeometryType.wkbMultiLineString);
                            for (int i = 0; i < geoCount; i++)
                            {
                                var temp   = path.Split('|')[i];
                                var points = temp.Split(';');
                                OSGeo.OGR.Geometry innGeometry = new Geometry(wkbGeometryType.wkbLinearRing);
                                for (int j = 0; j < points.Length; j++)
                                {
                                    var c = ProjectChange(points[j], jiupian);
                                    innGeometry.AddPoint_2D(c.lon, c.lat);
                                }
                                geo1.AddGeometry(innGeometry);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < geoCount; i++)
                            {
                                var temp   = path.Split('|')[i];
                                var points = temp.Split(';');
                                geo1 = new OSGeo.OGR.Geometry(wkbGeometryType.wkbLinearRing);
                                for (int j = 0; j < points.Length; j++)
                                {
                                    var c = ProjectChange(points[j], jiupian);
                                    geo1.AddPoint_2D(c.lon, c.lat);
                                }
                            }
                        }
                    }



                    //if (geoType == wkbGeometryType.wkbLineString)
                    //{
                    //    for (int i = 0; i < ps.Length; i++)
                    //    {
                    //        var c = ProjectChange(ps[i], jiupian);
                    //        geo1.AddPoint_2D(c.lon, c.lat);
                    //    }
                    //}
                    //else if (geoType == wkbGeometryType.wkbPolygon)
                    //{
                    //    List<int> indexs = new List<int>();
                    //    indexs.Add(0);
                    //    for (int i = 0; i < ps.Length; i++)
                    //    {
                    //        if (ps[i].Split('|', ',').Length > 2)
                    //        {
                    //            indexs.Add(i);
                    //        }
                    //    }
                    //    indexs.Add(ps.Length - 1);
                    //    if (indexs.Count == 2)
                    //    {
                    //        OSGeo.OGR.Geometry outGeo = new OSGeo.OGR.Geometry(OSGeo.OGR.wkbGeometryType.wkbLinearRing);
                    //        for (int i = 0; i < ps.Length; i++)
                    //        {

                    //            var c = ProjectChange(ps[i], jiupian);
                    //            outGeo.AddPoint_2D(c.lon, c.lat);
                    //        }

                    //        var c1 = ProjectChange(ps[0], jiupian);
                    //        outGeo.AddPoint_2D(c1.lon, c1.lat);

                    //        geo1.AddGeometryDirectly(outGeo);
                    //    }
                    //    else
                    //    {
                    //        for (int j = 0; j < indexs.Count - 1; j++)
                    //        {
                    //            OSGeo.OGR.Geometry outGeo = new OSGeo.OGR.Geometry(OSGeo.OGR.wkbGeometryType.wkbLinearRing);
                    //            Coord sc = new Coord();
                    //            int first = indexs[j];
                    //            int end = indexs[j + 1];
                    //            for (int i = first; i < end + 1; i++)
                    //            {
                    //                if (i == first && first != 0)
                    //                {

                    //                    var c = ProjectChange(ps[i], jiupian);
                    //                    outGeo.AddPoint(c.lon, c.lat,0);
                    //                }
                    //                else
                    //                {

                    //                    if (jiupian != ProjectConvert.NONE)
                    //                    {
                    //                        var c = ProjectChange(ps[i], jiupian);
                    //                        outGeo.AddPoint(c.lon, c.lat,0);
                    //                    }
                    //                    else
                    //                    {
                    //                        double x = double.Parse(ps[i].Split('|', ',')[0]);
                    //                        double y = double.Parse(ps[i].Split('|', ',')[1]);
                    //                        if (i == first)
                    //                        {
                    //                            sc.lon = x;
                    //                            sc.lat = y;
                    //                        }
                    //                        outGeo.AddPoint(x, y, 0);
                    //                    }

                    //                }
                    //            }
                    //            outGeo.AddPoint(sc.lon, sc.lat, 0);
                    //            geo1.AddGeometryDirectly(outGeo);
                    //        }
                    //    }
                    //}
                    oFeatureMulty.SetGeometry(geo1);
                }
                else if (geoType == wkbGeometryType.wkbPoint)
                {
                    OSGeo.OGR.Geometry geo1    = new OSGeo.OGR.Geometry(wkbGeometryType.wkbPoint);
                    string             xstring = row["X"] != null ? row["X"].ToString() : "";
                    string             ystring = row["Y"] != null ? row["Y"].ToString() : "";
                    double             x       = double.Parse(xstring);
                    double             y       = double.Parse(ystring);
                    Coord c = CoordHelper.Gcj2Wgs(x, y);
                    geo1.AddPoint(c.lon, c.lat, 0);
                    oFeatureMulty.SetGeometry(geo1);
                }
                oLayer.CreateFeature(oFeatureMulty);
            }
            oLayer.Dispose();
            oDS.Dispose();
        }
Example #9
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);
                }
            }
        }
Example #10
0
        private void DownPoiInfobyExtent(double x1, double y1, double x2, double y2, string keyWord, int curentIndex, int count)
        {
            keyWord = !String.IsNullOrEmpty(keyWord) ? keyWord : "汽车|摩托|餐饮|购物|生活|体育|医疗|住宿|风景|住宅|政府|科教|交通|金融|公司|行政地名|自然地名|小区|学校";
            for (int pindex = 1; pindex < 21; pindex++)
            {
                string tempUrl = string.Format(
                    this.poiUrl,
                    keyWord,
                    pindex,
                    string.Join("|", new[] { x1.ToString(), y1.ToString(), x2.ToString(), y2.ToString() }));
                try
                {
                    HttpWebResponse ht = HttpHelper.CreateGetHttpResponse(
                        tempUrl,
                        1000,
                        "Opera/9.25 (Windows NT 6.0; U; en)",
                        null);
                    string ff     = HttpHelper.GetResponseString(ht);
                    object detail = JsonHelper.JsonDeserialize <object>(ff);
                    Dictionary <string, object> dicResult = detail as Dictionary <string, object>;
                    //{errcode:30000,errmsg:"Denied",data:{host:"wangsu.traffitor.amap.com"}}
                    if (dicResult != null && dicResult.ContainsKey("status") && dicResult.ContainsKey("status").ToString() != "1")
                    {
                        log.WarnFormat("请求{0}出现错误,详细:{1}", tempUrl, ff);
                        continue;
                    }
                    if (dicResult != null && dicResult["status"] != null && dicResult["status"].ToString() == "1")
                    {
                        object   poiObjs = dicResult["list"];
                        object[] pois    = poiObjs as object[];
                        if (pois.Length == 0)
                        {
                            break;
                        }
                        else
                        {
                            for (int i = 0; i < pois.Length; i++)
                            {
                                POIInfo poiInfo = new POIInfo();
                                this.POICount++;
                                Dictionary <string, object> objects = pois[i] as Dictionary <string, object>;

                                poiInfo.name = objects["name"] != null ? objects["name"].ToString() : "";
                                if (objects["address"] is Array)
                                {
                                    string   address   = "";
                                    object[] addresses = objects["tel"] as object[];
                                    for (int j = 0; j < addresses.Length; j++)
                                    {
                                        if (address != "")
                                        {
                                            address = address + ";" + addresses[j] != null ? addresses[j].ToString() : "";
                                        }
                                        else
                                        {
                                            address = addresses[j] != null ? addresses[j].ToString() : "";
                                        }
                                    }
                                }
                                else
                                {
                                    poiInfo.address = objects["address"] != null ? objects["address"].ToString() : "";
                                }
                                poiInfo.address.Replace(",", "");
                                string tel = "";
                                if (objects["tel"] is Array)
                                {
                                    object[] otels = objects["tel"] as object[];
                                    for (int j = 0; j < otels.Length; j++)
                                    {
                                        if (tel != "")
                                        {
                                            tel = tel + ";" + otels[j] != null ? otels[j].ToString() : "";
                                        }
                                        else
                                        {
                                            tel = otels[j] != null ? otels[j].ToString() : "";
                                        }
                                    }
                                }
                                else
                                {
                                    tel = objects["tel"] != null ? objects["tel"].ToString() : "";
                                }
                                poiInfo.type  = objects["type"] != null ? objects["type"].ToString() : "";
                                poiInfo.phone = tel;


                                string str_longitude = objects["longitude"].ToString();
                                string str_latitude  = objects["latitude"].ToString();

                                double.TryParse(str_longitude, out poiInfo.x);
                                double.TryParse(str_latitude, out poiInfo.y);

                                Coord c = CoordHelper.Gcj2Wgs(poiInfo.x, poiInfo.y);
                                poiInfo.cx = c.lon;
                                poiInfo.cy = c.lat;

                                if (objects.ContainsKey("templateData"))
                                {
                                    var templateData = (Dictionary <string, object>)objects["templateData"];
                                    if (templateData.ContainsKey("aoi"))
                                    {
                                        var aoi      = ((Dictionary <string, object>)objects["templateData"])["aoi"].ToString();
                                        var tempAois = aoi.Split('_').ToList().Select(
                                            m => CoordHelper.Gcj2Wgs(
                                                double.Parse(m.Split(',')[0]),
                                                double.Parse(m.Split(',')[1])).ToString()).ToArray();
                                        poiInfo.aoi = string.Join("_", tempAois);
                                    }
                                }

                                if (this.DowningEvent != null)
                                {
                                    this.DowningEvent(poiInfo, curentIndex, count);
                                }
                                if (this.DowningMessageEvent != null)
                                {
                                    this.DowningMessageEvent(curentIndex, count);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.ErrorFormat("请求{0} 出错:{1}", url, ex);
                    Console.WriteLine(ex.Message);
                }
                System.Threading.Thread.Sleep(500);
            }
        }
Example #11
0
        public void downLoadRoadCrossByCityName(string cityName)
        {
            string        code      = this.getCodeByCityName(cityName);
            List <string> roadNames = CityRoadConfig.GetInstance().GetRoadNamesByCityName(cityName);

            if (roadNames.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("没有" + cityName + "的道路信息,等待后续路网库更新");
            }
            int i = 0;

            foreach (string name in roadNames)
            {
                i++;
                int    index    = i % this.keys.Length;
                string realName = name;
                if (name.Contains("-"))
                {
                    realName = realName.Split('-')[1];
                }
                string tempUrl = string.Format(urlCross, code, keys[index], realName);
                string context = HttpHelper.GetRequestContent(tempUrl);
                if (string.IsNullOrEmpty(context))
                {
                    continue;
                }
                object t = JsonHelper.JsonDeserialize <object>(context);
                Dictionary <string, object> dicRoot = t as Dictionary <string, object>;
                if (dicRoot != null && dicRoot["status"].ToString() == "1")
                {
                    object[] roadsObjs = dicRoot["roadinters"] as object[];
                    if (roadsObjs != null && roadsObjs.Length > 0)
                    {
                        for (int j = 0; j < roadsObjs.Length; j++)
                        {
                            Dictionary <string, object> dicRoadCross = roadsObjs[j] as Dictionary <string, object>;
                            if (dicRoadCross != null)
                            {
                                RoadCrossModel roadCrossModel = new RoadCrossModel();
                                roadCrossModel.id = dicRoadCross["id"] != null ? dicRoadCross["id"].ToString() : "";
                                //roadCrossModel.first_id = dicRoadCross["first_id"] != null
                                //                              ? dicRoadCross["first_id"].ToString()
                                //                              : "";
                                roadCrossModel.first_name = dicRoadCross["first_name"] != null
                                                                ? dicRoadCross["first_name"].ToString()
                                                                : "";
                                //roadCrossModel.second_id = dicRoadCross["second_id"] != null
                                //                               ? dicRoadCross["second_id"].ToString()
                                //                               : "";
                                roadCrossModel.second_name = dicRoadCross["second_name"] != null
                                                                 ? dicRoadCross["second_name"].ToString()
                                                                 : "";
                                string localtionXY = dicRoadCross["location"] != null
                                                         ? dicRoadCross["location"].ToString()
                                                         : "";
                                string[] xy = localtionXY.Split(',');
                                if (xy.Length == 2)
                                {
                                    double.TryParse(xy[0], out roadCrossModel.x);
                                    double.TryParse(xy[1], out roadCrossModel.y);

                                    var coor = CoordHelper.Gcj2Wgs(roadCrossModel.x, roadCrossModel.y);
                                    roadCrossModel.wgs_x = coor.lon;
                                    roadCrossModel.wgs_y = coor.lat;
                                }
                                if (roadCrossModel.x > 0 && roadCrossModel.y > 0)
                                {
                                    if (this.roadCrossDowningHandler != null)
                                    {
                                        this.roadCrossDowningHandler(roadCrossModel, i, roadNames.Count);
                                    }
                                }
                            }
                        }
                    }
                }
                System.Threading.Thread.Sleep(50);
            }
            if (this.downOverHandler != null)
            {
                this.downOverHandler();
            }
        }