Example #1
0
        public void ReadShpFileTest()
        {
            ShpOperator target   = new ShpOperator(); // TODO: 初始化为适当的值
            string      fileName = TestDataDir + "\\province.shp";
            bool        expected = true;              // TODO: 初始化为适当的值
            bool        actual;

            actual = target.ReadShpFile(fileName);

            Assert.AreEqual(expected, actual);
            // Assert.Inconclusive("验证此测试方法的正确性。");
        }
Example #2
0
        /// <summary>
        /// 创建边界
        /// </summary>
        /// <returns></returns>
        private bool CreateBorder()
        {
            ShpOperator shpOper = new ShpOperator();

            shpOper.ReadShpFile(m_provinceShpFile);

            int polygonCnt = shpOper.Polygons.Count;

            float gridStep = 0.005f;

            RectangleF lonlatBox = FixLonLatBox();

            int widthPts  = (int)(lonlatBox.Width / gridStep) + 1;
            int heightPts = (int)(lonlatBox.Height / gridStep) + 1;

            DatasetInfo lonInfo = m_L1DataFile.LongitudeInfo;

            float[, ,] lon = m_L1DataFile.Longitude;
            float[, ,] lat = m_L1DataFile.Latitude;
            DatasetInfo latInfo = m_L1DataFile.LatitudeInfo;

            GridPt[,] grid = new GridPt[widthPts, heightPts];

            for (int ystart = 0; ystart < lonInfo.row; ystart++)
            {
                for (int xstart = 0; xstart < lonInfo.col; xstart++)
                {
                    int xIndex = (int)((lon[0, ystart, xstart] - lonlatBox.X) / gridStep);
                    int yIndex = (int)((lat[0, ystart, xstart] - lonlatBox.Y) / gridStep);

                    grid[xIndex, yIndex].Y = ystart;
                    grid[xIndex, yIndex].X = xstart;
                }
            }


            for (int i = 0; i < polygonCnt; i++)
            {
                Polygon_shape shape = shpOper.Polygons[i];

                RectangleF shapeRect = new RectangleF();
                shapeRect.X      = (float)shape.Box[0];
                shapeRect.Y      = (float)shape.Box[1];
                shapeRect.Height = (float)shape.Box[3] - (float)shape.Box[1];
                shapeRect.Width  = (float)shape.Box[2] - (float)shape.Box[0];

                if (lonlatBox.IntersectsWith(shapeRect))
                {
                    //return true;
                    List <Point> polygonPts = new List <Point>();
                    for (int j = 0; j < shape.NumPoints; j++)
                    {
                        //if(shape.Points[j])
                        int xIndex = (int)((shape.Points[j].X - lonlatBox.X) / gridStep);
                        int yIndex = (int)((shape.Points[j].Y - lonlatBox.Y) / gridStep);

                        if (xIndex <= 0 || yIndex <= 0 || xIndex >= widthPts || yIndex >= heightPts)
                        {
                            continue;
                        }

                        if (grid[xIndex, yIndex].X == 0 && grid[xIndex, yIndex].Y == 0)
                        {
                            continue;
                        }

                        polygonPts.Add(new Point(grid[xIndex, yIndex].X, grid[xIndex, yIndex].Y));
                        //m_PolygonPts.

                        //grid[xIndex,yIndex]
                    }

                    if (polygonPts.Count > 3)
                    {
                        m_PolygonPts.Add(polygonPts.ToArray());
                    }
                }

                //shape.
            }


            m_BorderImgWidth  = latInfo.col;
            m_BorderImgHeight = latInfo.row;
            return(false);
        }
Example #3
0
 public void ShpOperatorConstructorTest()
 {
     ShpOperator target = new ShpOperator();
     // Assert.Inconclusive("TODO: 实现用来验证目标的代码");
 }