示例#1
0
        public void ParseDetailReservoir(string web, string uid, DateTime baseTime)
        {
            if (web.Length < 100)
            {
                return;
            }
            string removeStr = @"


<svg>
	"    ;

            web = web.Remove(0, removeStr.Length);
            web = web.Replace(@"</svg>", "");
            web = web.Replace(@"?>", @"?><root>");
            web = web + @"</root>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(web);
            XmlNodeList listNode = doc.SelectNodes("/root/g/polyline/@points");
            List <HydrologicalRecord> tempList = new List <HydrologicalRecord>();

            if (listNode[0] != null)
            {
                string   levelData  = listNode[0].Value;
                string[] levelArray = levelData.Split(' ');

                foreach (string l in levelArray)
                {
                    string[] pair = l.Split(',');
                    try
                    {
                        double             addHour = double.Parse(pair[0]);
                        double             level   = ((int)(double.Parse(pair[1]) * 100 + 0.5)) / 100.0;
                        HydrologicalRecord r       = new HydrologicalRecord();
                        r.isKey        = false;
                        r.Time         = baseTime.AddHours(addHour);
                        r.L            = level;
                        r.Station      = new HydrologyStation();
                        r.Station.Uid  = uid;
                        r.Station.Type = "水库站";
                        tempList.Add(r);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (listNode[1] != null)
            {
                string   levelData  = listNode[1].Value;
                string[] levelArray = levelData.Split(' ');
                foreach (string l in levelArray)
                {
                    string[] pair = l.Split(',');
                    try
                    {
                        double             addHour = double.Parse(pair[0]);
                        double             flow    = ((int)(double.Parse(pair[1]) * 100 + 0.5)) / 100.0;
                        HydrologicalRecord r       = tempList.Find(item => item.Time.Equals(baseTime.AddHours(addHour)));
                        if (r != null)
                        {
                            r.Q = flow;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            this.listDetailRecord.AddRange(tempList);
        }
示例#2
0
        public void Parse()
        {
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

            try
            {
                HttpWebResponse response      = (HttpWebResponse)myReq.GetResponse();
                Stream          receiveStream = response.GetResponseStream();
                StreamReader    readStream    = new StreamReader(receiveStream, Encoding.UTF8);
                string          text          = readStream.ReadToEnd();
                response.Close();
                readStream.Close();
                JArray jsonArr = JArray.Parse(text);

                for (int i = 0; i < jsonArr.Count; i++)
                {
                    HydrologicalRecord data   = new HydrologicalRecord();
                    JObject            obTemp = JObject.Parse(jsonArr[i].ToString());
                    //解析站点
                    data.Station.Uid                  = obTemp["POI_OID"].Value <string>();
                    data.Station.Name                 = obTemp["POI_NAME"].Value <string>();
                    data.Station.Longitude            = obTemp["POI_LON"].Value <double>();
                    data.Station.Latitude             = obTemp["POI_LAT"].Value <double>();
                    data.Station.River                = obTemp["POI_RVNM"].Value <string>();
                    data.Station.HydrographicNet      = obTemp["POI_HNNM"].Value <string>();
                    data.Station.Basin                = obTemp["POI_BSNM"].Value <string>();
                    data.Station.AdministrativeRegion = obTemp["POI_ADDV"].Value <string>();
                    data.Station.Address              = obTemp["POI_ADDRESS"].Value <string>();
                    data.Station.Type                 = obTemp["POI_TYPE"].Value <string>();
                    if (data.Station.Type.Equals("河道站"))
                    {
                        riverCount++;
                    }
                    else if (data.Station.Type.Equals("水库站"))
                    {
                        reservoirCount++;
                    }
                    else if (data.Station.Type.Equals("潮位站"))
                    {
                        tideCount++;
                    }

                    //解析数据
                    try
                    {
                        data.L = obTemp["L"].Value <double>();
                    }
                    catch (InvalidCastException)
                    {
                        data.L = Double.NaN;
                    }

                    try
                    {
                        data.Q = obTemp["Q"].Value <double>();
                    }
                    catch (InvalidCastException)
                    {
                        data.Q = Double.NaN;
                    }

                    try
                    {
                        data.Wl1 = obTemp["WL1"].Value <double>();
                    }
                    catch (InvalidCastException)
                    {
                        data.Wl1 = Double.NaN;
                    }

                    try
                    {
                        data.Wl2 = obTemp["WL2"].Value <double>();
                    }
                    catch (InvalidCastException)
                    {
                        data.Wl2 = Double.NaN;
                    }

                    try
                    {
                        data.Time = obTemp["TM"].Value <DateTime>();
                    }
                    catch (InvalidCastException)
                    {
                        //Ticks 为0
                    }

                    listHydr.Add(data);
                }

                LogHelper.WriteLog(typeof(AllHydroParse), "地图水情数据爬取解析成功,河道站:" + riverCount + " ,水库站:" + reservoirCount + " ,潮位站:" + tideCount);
            }
            catch (WebException ex)
            {
                LogHelper.WriteLog(typeof(AllHydroParse), ex);
            }
        }