Пример #1
0
        /// <summary>
        /// 查询布控
        /// </summary>
        /// <param name="data">坐标集合</param>
        public void QueryMarkArea(string data)
        {
            List <PointF> points    = new List <PointF>();
            object        pointList = JSONToObject <object>(data);
            Array         aPoint    = (Array)pointList;

            for (int i = 0; i < aPoint.Length; i++)
            {
                Dictionary <string, object> spoint = (Dictionary <string, object>)aPoint.GetValue(i);
                PointF PF = new PointF();
                foreach (KeyValuePair <string, object> kv in spoint)
                {
                    if (kv.Key == "lng")
                    {
                        PF.X = float.Parse(kv.Value.ToString());
                    }
                    else if (kv.Key == "lat")
                    {
                        PF.Y = float.Parse(kv.Value.ToString());
                    }
                }
                points.Add(PF);
            }
            PointF        center    = new PointF();
            PointF        maxCenter = new PointF();
            double        area      = 0;
            double        maxLength = 0;
            float         maxX      = 0;
            List <double> lengths   = new List <double>();
            int           s         = polyCentriod(points, points.Count, ref center, ref area);

            for (int i = 0; i < points.Count; i++)
            {
                double l = GetDistance(points[i].Y, points[i].X, center.Y, center.X);
                lengths.Add(l);
                if (l > maxLength)
                {
                    maxLength = l;
                    maxCenter = points[i];
                }
                if (points[i].X > maxX)
                {
                    maxX = points[i].X;
                }
            }
            double Maxl = Math.Sqrt(Math.Abs(maxCenter.X - center.X) * Math.Abs(maxCenter.X - center.X) + Math.Abs(maxCenter.Y - center.Y) * Math.Abs(maxCenter.Y - center.Y)) * 10000;

            string where1 = "sqrt(pow((x_values-" + center.X.ToString() + "),2)+pow((y_values-" + center.Y.ToString() + "),2))*10000 < " + Maxl.ToString();

            //DataTable dt = Dt_Station;// this.bll.GetStation();
            DataTable dtOut;

            if (Dt_Station != null)
            {
                dtOut = Dt_Station.Copy();
            }
            else
            {
                return;
            }
            PointF    QueryPoint = new PointF();
            Hashtable hs         = new Hashtable();

            for (int n = dtOut.Rows.Count - 1; n >= 0; n--)
            {
                if (dtOut.Rows[n]["xpoint"].ToString() != "")
                {
                    QueryPoint.X = float.Parse(dtOut.Rows[n]["xpoint"].ToString());
                    QueryPoint.Y = float.Parse(dtOut.Rows[n]["ypoint"].ToString());
                    if (!IsVisible(QueryPoint, points, maxX))
                    {
                        dtOut.Rows[n].Delete();
                        dtOut.AcceptChanges();
                    }
                }
                else
                {
                    dtOut.Rows[n].Delete();
                    dtOut.AcceptChanges();
                }
            }
            if (dtOut != null && dtOut.Rows.Count > 0)
            {
                showstation(dtOut);
                StoreKK.RemoveAll();
                StoreKK.DataSource = dtOut;
                StoreKK.DataBind();
                panelkk.Collapsed = false;
                Pantrack.Height   = 550;
            }
            else
            {
                //panelkk.Collapsed = true;
                Pantrack.Height = 240;
                StoreKK.RemoveAll();
                StoreKK.DataBind();
            }
        }
        /// <summary>
        /// 依据坐标点获取监测点
        /// </summary>
        /// <param name="xpos">x坐标</param>
        /// <param name="ypos">y坐标</param>
        /// <param name="r">半径</param>
        public void QueryMarkArea(string xpos, string ypos, int r)
        {
            try
            {
                PointF dot = new PointF();
                dot.X = float.Parse(xpos);
                dot.Y = float.Parse(ypos);
                DataTable dt = bll.GetStation();
                DataTable dtOut;
                if (dt != null)
                {
                    dtOut = dt.Copy();
                }
                else
                {
                    return;
                }
                PointF    QueryPoint = new PointF();
                Hashtable hs         = new Hashtable();
                double    l;
                for (int n = dtOut.Rows.Count - 1; n >= 0; n--)
                {
                    if (dtOut.Rows[n]["xpoint"].ToString() == "" || dtOut.Rows[n]["ypoint"].ToString() == "")
                    {
                        dtOut.Rows[n].Delete();
                        dtOut.AcceptChanges();
                        continue;
                    }
                    QueryPoint.X = float.Parse(dtOut.Rows[n]["xpoint"].ToString());
                    QueryPoint.Y = float.Parse(dtOut.Rows[n]["ypoint"].ToString());
                    l            = GetDistance(QueryPoint.X, QueryPoint.Y, dot.X, dot.Y);

                    if (l > r)
                    {
                        dtOut.Rows[n].Delete();
                        dtOut.AcceptChanges();
                    }
                }
                if (dtOut != null && dtOut.Rows.Count > 0)
                {
                    showstation(dtOut);
                    StoreKK.RemoveAll();
                    StoreKK.DataSource = dtOut;
                    StoreKK.DataBind();
                    panelkk.Collapsed = false;
                    Pantrack.Height   = 800;
                }
                else
                {
                    //panelkk.Collapsed = true;
                    Pantrack.Height = 240;
                    StoreKK.RemoveAll();
                    StoreKK.DataBind();
                }
            }
            catch (Exception ex)
            {
                ILog.WriteErrorLog(ex.Message);
                logManager.InsertLogError("CarStrandQuery.aspx-QueryMarkArea", ex.Message + ";" + ex.StackTrace, "QueryMarkArea has an exception");
            }
        }