コード例 #1
0
        /// <summary>
        /// 2019/3/1
        /// 将加速栅格转为地理坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="grid"></param>
        /// <param name="gridxy"></param>
        /// <param name="gridz"></param>
        /// <returns></returns>
        public void PointGridXYZ(ref Point p, Grid3D grid, int agridsize, int agridVsize)
        {
            double half = 0.5 * agridsize;

            p.X = oX + grid.gxid * agridsize + half;
            p.Y = oY + grid.gyid * agridsize + half;
            p.Z = (grid.gzid + 0.5) * agridVsize;
        }
コード例 #2
0
        /// <summary>
        /// 空间点(大地坐标)所在的立体网格
        /// </summary>
        public void PointXYZToGrid3D1(Point p, ref Grid3D grid)
        {
            double dy = p.Y - oY;
            double dx = p.X - oX;

            grid.gxid = (int)(Math.Floor(dx / ggridsize));
            grid.gyid = (int)(Math.Floor(dy / ggridsize));
        }
コード例 #3
0
 private bool Init()
 {
     this.isCalc     = true;
     this.cur        = new Grid3D();
     this.line       = new Line();
     this.gridlength = GridHelper.getInstance().getAGridSize();
     this.vgridsize  = GridHelper.getInstance().getAGridVSize();
     return(!(this.gridlength < 0 || this.vgridsize < 0));
 }
コード例 #4
0
        /// <summary>
        /// 指定步长下栅格的中心地理坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="grid"></param>
        /// <param name="gridxy"></param>
        /// <param name="gridz"></param>
        /// <returns></returns>
        public Point Grid2CenterXY(Grid3D grid, int gridxy)
        {
            Point  p    = new Point();
            double half = 0.5 * gridxy;

            p.X = oX + grid.gxid * gridxy + half;
            p.Y = oY + grid.gyid * gridxy + half;
            return(p);
        }
コード例 #5
0
        /*
         * /// <summary>
         * /// 空间点(经纬度)所在的立体网格
         * /// </summary>
         * /// <param name="p"></param>
         * /// <param name="grid"></param>
         * /// <returns></returns>
         * public bool PointLLHToGrid3D(Point p, ref Grid3D grid)
         * {
         *  bool ret = p.Z > 0.0 && LngLatToGGrid(p.Lng, p.Lat, ref grid.gxid, ref grid.gyid);
         *  if (ret)
         *  {
         *      grid.gzid = (int)Math.Ceiling(p.Z / gheight);
         *  }
         *  return ret;
         * }
         */

        /// <summary>
        /// 空间点(大地坐标)所在的立体网格
        /// </summary>
        /// <param name="p"></param>
        /// <param name="grid"></param>
        /// <returns></returns>
        public bool PointXYZToGrid3D(Point p, ref Grid3D grid)
        {
            bool ret = p.Z > 0.0 && XYToGGrid(p.X, p.Y, ref grid.gxid, ref grid.gyid);

            if (ret)
            {
                grid.gzid = (int)Math.Ceiling(p.Z / gheight);
            }
            return(ret);
        }
コード例 #6
0
 private bool Init()
 {
     this.isCalc      = false;
     this.cur         = new Grid3D();
     this.distance    = 0.0;
     this.line        = new Line();
     this.gridlength  = GridHelper.getInstance().getGGridSize();
     this.vgridsize   = GridHelper.getInstance().getGHeight();
     this.gbaseheight = GridHelper.getInstance().getGBaseHeight();
     return(!(this.gridlength < 0 || this.vgridsize < 0 || this.gbaseheight < 0));
 }
コード例 #7
0
        /*
         * /// <summary>
         * /// 返回点(经纬度坐标)在加速栅格中距离左下角的距离坐标,单位米
         * /// </summary>
         * /// <param name="p"></param>
         * /// <param name="ingrid"></param>
         * /// <returns></returns>
         * public bool PointLLHInAccGrid(Point p, ref Point ingrid)
         * {
         *  bool ret;
         *  Grid3D grid = new Grid3D();
         *  if (ret = PointLLHToAccGrid(p, ref grid))
         *  {
         *      ingrid.X = CJWDHelper.distance(minlong, p.Lat, p.Lng, p.Lat) * 1000.0 - agridsize * grid.gxid;
         *      ingrid.Y = CJWDHelper.distance(p.Lng, minlat, p.Lng, p.Lat) * 1000.0 - agridsize * grid.gyid;
         *      ingrid.Z = p.Z - agridvsize * (grid.gzid - 1);
         *  }
         *  //Console.WriteLine(ret);
         *  return ret;
         * }
         */

        /// <summary>
        /// 返回点(大地坐标)在加速栅格中距离左下角的距离坐标,单位米
        /// </summary>
        /// <param name="p"></param>
        /// <param name="ingrid"></param>
        /// <returns></returns>
        public bool PointXYZInAccGrid(Point p, ref Point ingrid)
        {
            bool   ret;
            Grid3D grid = new Grid3D();

            if (ret = PointXYZToAccGrid(p, ref grid))
            {
                ingrid.X = p.X - oX - agridsize * grid.gxid;
                ingrid.Y = p.Y - oY - agridsize * grid.gyid;
                ingrid.Z = p.Z - agridvsize * (grid.gzid - 1);
            }
            return(ret);
        }
コード例 #8
0
        /*
         * /// <summary>
         * /// 空间点(经纬度)在立体网格内部距离左下角距离坐标,单位米
         * /// </summary>
         * /// <param name="p"></param>
         * /// <param name="ingrid"></param>
         * /// <returns></returns>
         * public bool PointLLHInGrid3D(Point p, ref Point ingrid)
         * {
         *  Grid3D grid = new Grid3D();
         *  bool ret = PointLLHToGrid3D(p, ref grid);
         *  if (ret)
         *  {
         *
         *      ingrid.X = CJWDHelper.distance(minlong, p.Lat, p.Lng, p.Lat) * 1000.0 - ggridsize * grid.gxid;
         *      ingrid.Y = CJWDHelper.distance(p.Lng, minlat, p.Lng, p.Lat) * 1000.0 - ggridsize * grid.gyid;
         *      ingrid.Z = p.Z - gheight * (grid.gzid - 1);
         *  }
         *  return ret;
         * }
         */

        /// <summary>
        /// 空间点(大地坐标)在立体网格内部距离左下角距离坐标,单位米
        /// </summary>
        /// <param name="p"></param>
        /// <param name="ingrid"></param>
        /// <returns></returns>
        public bool PointXYZInGrid3D(Point p, ref Point ingrid)
        {
            Grid3D grid = new Grid3D();
            bool   ret  = PointXYZToGrid3D(p, ref grid);

            if (ret)
            {
                ingrid.X = p.X - oX - ggridsize * grid.gxid;
                ingrid.Y = p.Y - oY - ggridsize * grid.gyid;
                ingrid.Z = p.Z - gheight * (grid.gzid - 1);
            }
            return(ret);
        }
コード例 #9
0
 /// <summary>
 /// 返回大地坐标点所在的地面网格,以区域左下角为原点
 /// </summary>
 /// <param name="lng"></param>
 /// <param name="lat"></param>
 /// <param name="gxid"></param>
 /// <param name="gyid"></param>
 /// <returns></returns>
 public bool XYZToGGrid(Point p, ref Grid3D grid3D)
 {
     if (checkXYZInGrid(p.X, p.Y, 0))
     {
         //同划分网格一致
         double dy = p.Y - oY;
         double dx = p.X - oX;
         grid3D.gxid = (int)Math.Floor(dx / ggridsize);
         grid3D.gyid = (int)Math.Floor(dy / ggridsize);
         grid3D.gzid = (int)Math.Floor(p.Z / gheight);
         return(true);
     }
     return(false);
 }
コード例 #10
0
        /// <summary>
        /// 在指定步长下空间点(大地坐标)所对应的栅格坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="grid"></param>
        /// <param name="gridxy"></param>
        /// <param name="gridz"></param>
        /// <returns></returns>
        public bool PointXYZGrid(Point p, ref Grid3D grid, int gridxy, int gridz)
        {
            bool ret = p.Z >= 0.0 && checkXYZInGrid(p.X, p.Y, 0);

            if (ret)
            {
                //同划分网格一致
                double dy = p.Y - oY;
                double dx = p.X - oX;
                grid.gxid = dx == 0 ? 0 : Convert.ToInt32(Math.Ceiling(dx / gridxy)) - 1;
                grid.gyid = dy == 0 ? 0 : Convert.ToInt32(Math.Ceiling(dy / gridxy)) - 1;
                grid.gzid = p.Z == 0 ? 0 : Convert.ToInt32(Math.Ceiling(p.Z / gridz)) - 1;
            }
            return(ret);
        }
コード例 #11
0
        /// <summary>
        /// 获取中心点在范围内的地面栅格中心点
        /// </summary>
        /// <returns></returns>
        public static int constructGGrids(ref Geometric.Point p1, ref Geometric.Point p2,
                                          ref Geometric.Point p3, ref Geometric.Point p4)
        {
            //Console.WriteLine("{0}", 1);
            ggrids = new Dictionary <string, Point>();

            Hashtable ht = new Hashtable();

            Grid3D gid1 = new Grid3D(), gid2 = new Grid3D(), gid3 = new Grid3D(), gid4 = new Grid3D();

            GridHelper.getInstance().PointXYZToGrid3D1(p1, ref gid1);
            GridHelper.getInstance().PointXYZToGrid3D1(p2, ref gid2);
            GridHelper.getInstance().PointXYZToGrid3D1(p3, ref gid3);
            GridHelper.getInstance().PointXYZToGrid3D1(p4, ref gid4);

            //Console.WriteLine("from: {0}", from * 180 / Math.PI);
            //Console.WriteLine("to: {0}", to * 180 / Math.PI);
            //Console.WriteLine("alpha: {0}", alpha * 180 / Math.PI);
            //Console.WriteLine("theta: {0}", theta * 180 / Math.PI);

            ht["x1"] = gid1.gxid;
            ht["x2"] = gid2.gxid;
            ht["x3"] = gid3.gxid;
            ht["x4"] = gid4.gxid;
            ht["y1"] = gid1.gyid;
            ht["y2"] = gid2.gyid;
            ht["y3"] = gid3.gyid;
            ht["y4"] = gid4.gyid;
            DataTable grids = IbatisHelper.ExecuteQueryForDataTable("getGroundGridsCenter", ht);
            //Console.WriteLine("{0}", grids.Rows.Count);
            double x, y, z;
            int    gxid, gyid;
            string key;

            for (int i = 0, cnt = grids.Rows.Count; i < cnt; i++)
            {
                gxid = Convert.ToInt32(grids.Rows[i]["GXID"]);
                gyid = Convert.ToInt32(grids.Rows[i]["GYID"]);
                x    = Convert.ToDouble(grids.Rows[i]["CX"]);
                y    = Convert.ToDouble(grids.Rows[i]["CY"]);
                z    = Convert.ToDouble(grids.Rows[i]["Dem"]);
                key  = string.Format("{0},{1}", gxid, gyid);
                ggrids.Add(key, new Point(x, y, z));
            }
            return(ggrids.Count);
        }
コード例 #12
0
        /// <summary>
        /// 从数据库表tbGrid3D中取出所有符合条件的数据,并以GXID,GYID,GZID排序,组成空间网格集合
        /// </summary>
        /// <returns></returns>
        public static void constructGrid3D(ref Geometric.Point p1, ref Geometric.Point p2,
                                           ref Geometric.Point p3, ref Geometric.Point p4)
        {
            Hashtable para = new Hashtable();

            Grid3D gid1 = new Grid3D(), gid2 = new Grid3D(), gid3 = new Grid3D(), gid4 = new Grid3D();

            GridHelper.getInstance().PointXYZToGrid3D1(p1, ref gid1);
            GridHelper.getInstance().PointXYZToGrid3D1(p2, ref gid2);
            GridHelper.getInstance().PointXYZToGrid3D1(p3, ref gid3);
            GridHelper.getInstance().PointXYZToGrid3D1(p4, ref gid4);

            para["x1"] = gid1.gxid;
            para["x2"] = gid2.gxid;
            para["x3"] = gid3.gxid;
            para["x4"] = gid4.gxid;
            para["y1"] = gid1.gyid;
            para["y2"] = gid2.gyid;
            para["y3"] = gid3.gyid;
            para["y4"] = gid4.gyid;
            DataTable dt = IbatisHelper.ExecuteQueryForDataTable("GetBuildingGrid3D1", para);

            //Console.WriteLine(string.Format("{0} {1} {3}  {4} {5} {6} {7}", gid1.gxid, gid2.gxid, gid3.gxid, gid4.gxid, gid1.gyid, gid2.gyid, gid3.gyid, gid4.gyid);
            for (int i = 0; i < dt.Rows.Count; i++)//按行遍历DataTable
            {
                int buildingid = Convert.ToInt32(dt.Rows[i][0].ToString());
                //gxid,gyid,gzid
                string value = dt.Rows[i][1].ToString() + "," + dt.Rows[i][2].ToString() + "," + dt.Rows[i][3].ToString();
                if (bgrid3d.ContainsKey(buildingid))
                {
                    bgrid3d[buildingid].Add(value);
                }
                else
                {
                    List <string> list = new List <string>();
                    list.Add(value);
                    bgrid3d.Add(buildingid, list);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// 构建建筑物底面点数据和中心点以及高度数据,顶面所有点
        /// </summary>
        public static void constructBuildingData(ref Geometric.Point p1, ref Geometric.Point p2,
                                                 ref Geometric.Point p3, ref Geometric.Point p4)
        {
            DateTime t0, t1, t2, t3;

            t0 = DateTime.Now;

            Hashtable ht = new Hashtable();

            Grid3D gid1 = new Grid3D(), gid2 = new Grid3D(), gid3 = new Grid3D(), gid4 = new Grid3D();

            GridHelper.getInstance().PointXYZToGrid3D1(p1, ref gid1);
            GridHelper.getInstance().PointXYZToGrid3D1(p2, ref gid2);
            GridHelper.getInstance().PointXYZToGrid3D1(p3, ref gid3);
            GridHelper.getInstance().PointXYZToGrid3D1(p4, ref gid4);

            ht["x1"] = gid1.gxid;
            ht["x2"] = gid2.gxid;
            ht["x3"] = gid3.gxid;
            ht["x4"] = gid4.gxid;
            ht["y1"] = gid1.gyid;
            ht["y2"] = gid2.gyid;
            ht["y3"] = gid3.gyid;
            ht["y4"] = gid4.gyid;

            DataTable dt = IbatisHelper.ExecuteQueryForDataTable("GetBuildingCenter", ht);

            int    bid;
            double x, y, z, altitude;

            for (int i = 0; i < dt.Rows.Count; i++)//按行遍历DataTable
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                if (bid > maxID)
                {
                    maxID = bid;
                }
                if (bid < minID)
                {
                    minID = bid;
                }
                x        = Convert.ToDouble(dt.Rows[i]["BCenterX"]);
                y        = Convert.ToDouble(dt.Rows[i]["BCenterY"]);
                z        = Convert.ToDouble(dt.Rows[i]["BHeight"]);
                altitude = Convert.ToDouble(dt.Rows[i]["BAltitude"]); // 地形
                buildingCenter.Add(bid, new Point(x, y, 0));
                buildingHeight.Add(bid, z + altitude);                // 地形
                buildingAltitude.Add(bid, altitude);                  // 地形
            }

            t1 = DateTime.Now;

            dt = IbatisHelper.ExecuteQueryForDataTable("GetBuildingVertex", ht);
            List <Point> vcollection;
            Point        t;

            //string path = @"f:\t2.txt";
            //StreamWriter sw = File.CreateText(path);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                x   = Convert.ToDouble(dt.Rows[i]["VertexX"]);
                y   = Convert.ToDouble(dt.Rows[i]["VertexY"]);
                t   = new Point(x, y, 0);

                if (buildingVertex.ContainsKey(bid))
                {
                    buildingVertex[bid].Add(t);
                }
                else
                {
                    vcollection = new List <Point>();
                    vcollection.Add(t);
                    buildingVertex.Add(bid, vcollection);
                }
            }
            //sw.Close();
            t2 = DateTime.Now;

            dt = IbatisHelper.ExecuteQueryForDataTable("getBuildingTopVertex", ht);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                x   = Convert.ToDouble(dt.Rows[i]["CX"]);
                y   = Convert.ToDouble(dt.Rows[i]["CY"]);
                z   = buildingHeight[bid];
                t   = new Point(x, y, z);

                //sw.Write(bid + ": " + c.X + " " + c.Y + "\n");

                if (buildingTopVertex.ContainsKey(bid))
                {
                    buildingTopVertex[bid].Add(t);
                }
                else
                {
                    vcollection = new List <Point>();
                    vcollection.Add(t);
                    buildingTopVertex.Add(bid, vcollection);
                }
            }
            //sw.Close();
            t3 = DateTime.Now;

            Console.WriteLine(string.Format("建筑物底面中心:{0}秒", (t1 - t0).TotalMilliseconds / 1000));
            Console.WriteLine(string.Format("建筑物底面顶点:{0}秒", (t2 - t1).TotalMilliseconds / 1000));
            Console.WriteLine(string.Format("建筑物顶面顶点:{0}", (t3 - t2).TotalMilliseconds / 1000));
        }
コード例 #14
0
        /// <summary>
        /// 获取空间直线经过的下一个加速栅格
        /// </summary>
        /// <returns></returns>
        public Grid3D getNextCrossAccGrid()
        {
            if (!this.isCalc || this.cur == null)
            {
                return(null);
            }
            Grid3D ret  = new Grid3D(this.cur);
            double ttx  = Math.Round(this.tx, 3);
            double tty  = Math.Round(this.ty, 3);
            double ttz  = Math.Round(this.tz, 3);
            bool   flag = false;//是否计算完成

            //先经过x方向栅格
            if (!flag && ttx <= tty && ttx <= ttz)
            {
                this.cur.gxid += this.stepx;
                if (this.cur.gxid < this.mingxid || this.cur.gxid > this.maxgxid)
                {
                    this.isCalc    = false;
                    this.cur.gxid -= this.stepx;//还原更改,继续计算
                    return(ret);
                }
                else
                {
                    this.tx += this.dx;
                    flag     = true;
                }
            }
            //先经过y方向栅格
            if (!flag && tty <= ttx && tty <= ttz)
            {
                this.cur.gyid += this.stepy;
                if (this.cur.gyid < this.mingyid || this.cur.gyid > this.maxgyid)
                {
                    this.isCalc    = false;
                    this.cur.gyid -= this.stepy;
                    return(ret);
                }
                else
                {
                    this.ty += this.dy;
                    flag     = true;
                }
            }
            //先经过z方向栅格
            if (!flag && ttz <= ttx && ttz <= tty)
            {
                this.cur.gzid += this.stepz;
                if (this.cur.gzid < 1 || this.cur.gzid > 3)
                {
                    this.isCalc    = false;
                    this.cur.gzid -= this.stepz;
                    return(ret);
                }
                else
                {
                    this.tz += this.dz;
                    flag     = true;
                }
            }
            return(ret);
        }
コード例 #15
0
        /// <summary>
        /// 获取空间直线经过的下一个空间建筑物网格
        /// </summary>
        /// <param name="d">空间网格距离线段起点的距离</param>
        /// <returns></returns>
        public Grid3D getNextCrossGrid3D(ref double d)
        {
            if (!this.isCalc || this.cur == null)
            {
                return(null);
            }
            Grid3D ret = new Grid3D(this.cur);

            d = this.distance;
            double ttx  = Math.Round(this.tx, 3);
            double tty  = Math.Round(this.ty, 3);
            double ttz  = Math.Round(this.tz, 3);
            bool   flag = false;//是否计算完成

            //先经过x方向栅格
            if (!flag && ttx < tty && ttx < ttz)
            {
                this.cur.gxid += this.stepx;
                if (this.cur.gxid < 0 || this.cur.gxid > this.maxgxid)
                {
                    this.isCalc    = false;
                    this.cur.gxid -= this.stepx;//还原更改,继续计算
                    return(ret);
                }
                else
                {
                    this.distance = this.tx;
                    this.tx      += this.dx;
                    flag          = true;
                }
            }
            //先经过y方向栅格
            if (!flag && tty < ttx && tty < ttz)
            {
                this.cur.gyid += this.stepy;
                if (this.cur.gyid < 0 || this.cur.gyid > this.maxgyid)
                {
                    this.isCalc    = false;
                    this.cur.gyid -= this.stepy;
                    return(ret);
                }
                else
                {
                    this.distance = this.ty;
                    this.ty      += this.dy;
                    flag          = true;
                }
            }
            //先经过z方向栅格
            if (!flag && ttz < ttx && ttz < tty)
            {
                this.cur.gzid += this.stepz;
                if (this.cur.gzid < 1)
                {
                    this.isCalc    = false;
                    this.cur.gzid -= this.stepz;
                    return(ret);
                }
                else
                {
                    this.distance = this.tz;
                    this.tz      += this.dz;
                    flag          = true;
                }
            }
            //下一个点是线段终点
            if (!flag && (ttx < maxlength && tty < maxlength && ttz < maxlength))
            {
                if (!this.cur.Equals(ret))
                {
                    this.tx = this.ty = this.tz = maxlength + 10;
                }
            }
            if (!flag)
            {
                this.isCalc = false;
            }

            return(ret);
        }
コード例 #16
0
 public bool Equals(Grid3D g)
 {
     return(g != null && this.gxid == g.gxid && this.gyid == g.gyid && this.gzid == g.gzid);
 }
コード例 #17
0
 public Grid3D(Grid3D g)
 {
     this.gxid = g.gxid;
     this.gyid = g.gyid;
     this.gzid = g.gzid;
 }
コード例 #18
0
        /// <summary>
        /// 返回空间点所在的加速网格坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="gxid"></param>
        /// <param name="gyid"></param>
        /// <param name="gzid"></param>
        /// <returns></returns>
        //public bool PointLLHToAccGrid(Point p, ref Grid3D grid)
        //{
        //    return LngLatHeightToAccGrid(p.Lng, p.Lat, p.Z, ref grid.gxid, ref grid.gyid, ref grid.gzid);
        //}

        /// <summary>
        /// 返回空间点(大地坐标)所在的加速网格坐标
        /// </summary>
        /// <param name="p"></param>
        /// <param name="gxid"></param>
        /// <param name="gyid"></param>
        /// <param name="gzid"></param>
        /// <returns></returns>
        public bool PointXYZToAccGrid(Point p, ref Grid3D grid)
        {
            return(XYZToAccGrid(p.X, p.Y, p.Z, ref grid.gxid, ref grid.gyid, ref grid.gzid));
        }