//获取某个位置相对于栅格位置的坐标
        public RasterPositionValue Coordinate(IPoint point)
        {
            IRasterProps rasterProps = (IRasterProps)GetRaster();

            if (!Contains(rasterProps.Extent.Envelope, point))
            {
                return(null);
            }
            int    xIndex           = (int)((point.X - rasterProps.Extent.XMin) / rasterProps.MeanCellSize().X);
            int    yIndex           = (int)((rasterProps.Extent.YMax - point.Y) / rasterProps.MeanCellSize().Y);
            object readValue        = Read(xIndex, yIndex);
            RasterPositionValue res = new RasterPositionValue()
            {
                XIndex = xIndex, YIndex = yIndex
            };

            if (readValue != null)
            {
                res.HasValue    = true;
                res.RasterValue = Convert.ToSingle(readValue);
            }
            else
            {
                res.HasValue    = false;
                res.RasterValue = -1;
            }
            return(res);
        }
Exemple #2
0
        public RasterOp Calculator(Postion startPostion)
        {
            if (!Read(startPostion.XIndex, startPostion.YIndex).HasValue)
            {
                throw new ArgumentOutOfRangeException("起始位置不含有数据");
            }
            RasterPositionValue[,] cost = new RasterPositionValue[Width, Height];
            //初始化操作
            InitializeValues(cost);
            InitializeStart(startPostion, cost);
            //使用orderbag,是的每次取出的最小值
            OrderedBag <RasterPositionValue> bag = new OrderedBag <RasterPositionValue>();

            bag.Add(cost[startPostion.XIndex, startPostion.YIndex]);
            while (bag.Count != 0)
            {
                RasterPositionValue pos = bag.RemoveFirst();
                var postions            = Sourround(cost, pos);
                foreach (var postion in postions)
                {
                    double relativeCost = Read(postion.XIndex, postion.YIndex).GetValueOrDefault() * 0.5 +
                                          Read(postion.XIndex, postion.YIndex).GetValueOrDefault() * 0.5;
                    if (pos.XIndex != postion.XIndex && pos.YIndex != postion.YIndex)
                    {
                        relativeCost *= Math.Sqrt(2);
                    }
                    cost[postion.XIndex, postion.YIndex].Visited     = true;
                    cost[postion.XIndex, postion.YIndex].HasValue    = true;
                    cost[postion.XIndex, postion.YIndex].RasterValue = (float)relativeCost
                                                                       + cost[pos.XIndex, pos.YIndex].RasterValue;
                    bag.Add(cost[postion.XIndex, postion.YIndex]);
                }
            }
            return(Result(cost));
        }
Exemple #3
0
 private void InitializeValues(RasterPositionValue[,] cost)
 {
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             cost[i, j] = new RasterPositionValue()
             {
                 HasValue    = false,
                 Visited     = false,
                 RasterValue = 0,
                 XIndex      = i,
                 YIndex      = j
             };
         }
     }
 }
 //获取某个位置相对于栅格位置的坐标
 public RasterPositionValue Coordinate(IPoint point)
 {
     IRasterProps rasterProps = (IRasterProps) GetRaster();
     if (!Contains(rasterProps.Extent.Envelope, point))
         return null;
     int xIndex = (int)((point.X - rasterProps.Extent.XMin)/rasterProps.MeanCellSize().X);
     int yIndex = (int) ((rasterProps.Extent.YMax - point.Y)/rasterProps.MeanCellSize().Y);
     object readValue = Read(xIndex, yIndex);
     RasterPositionValue res = new RasterPositionValue(){XIndex = xIndex,YIndex=yIndex};
     if (readValue!=null)
     {
         res.HasValue = true;
         res.RasterValue = Convert.ToSingle(readValue);
     }
     else
     {
         res.HasValue = false;
         res.RasterValue = -1;
     }
     return res;
 }
Exemple #5
0
 private void InitializeValues(RasterPositionValue[,] cost)
 {
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             cost[i, j] = new RasterPositionValue()
             {
                 HasValue = false,
                 Visited = false,
                 RasterValue = 0,
                 XIndex = i,
                 YIndex = j
             };
         }
     }
 }
Exemple #6
0
 private  void InitializeStart(Postion startPostion,RasterPositionValue[,] cost)
 {
     //startPostion.HasValue = true;
     //startPostion.RasterValue = 0;
     //startPostion.Visited = true;
     cost[startPostion.XIndex, startPostion.YIndex].HasValue = true;
     cost[startPostion.XIndex, startPostion.YIndex].Visited = true;
     cost[startPostion.XIndex, startPostion.YIndex].RasterValue = 0;
 }
Exemple #7
0
 private bool VisistedValid(RasterPositionValue[,] cost,Postion pos)
 {
     //return ValueValid(pos.XIndex, pos.YIndex)
     //    &&!cost[pos.XIndex,pos.YIndex].Visited;    
     return pos.XIndex >= 0 && pos.XIndex < Width
            && pos.YIndex >= 0 && pos.YIndex < Height
            && _raster[pos.XIndex, pos.YIndex].HasValue
            && cost[pos.XIndex, pos.YIndex].Visited == false;
 }
Exemple #8
0
 public IEnumerable<Postion> Sourround(RasterPositionValue[,] cost,
     Postion postion)
 {
     if (VisistedValid(cost, postion.LeftTop()))
         yield return postion.LeftTop();
     if (VisistedValid(cost, postion.Top()))
         yield return postion.Top();
     if (VisistedValid(cost, postion.RightTop()))
         yield return postion.RightTop();
     if (VisistedValid(cost, postion.Right()))
         yield return postion.Right();
     if (VisistedValid(cost, postion.RightButtom()))
         yield return postion.RightButtom();
     if (VisistedValid(cost, postion.Buttom()))
         yield return postion.Buttom();
     if (VisistedValid(cost, postion.LeftButtom()))
         yield return postion.LeftButtom();
     if (VisistedValid(cost, postion.Left()))
         yield return postion.Left();
 }
Exemple #9
0
 private RasterOp Result(RasterPositionValue[,] cost)
 {
     float?[,] raster = new float?[Width, Height];
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             if (cost[i, j].Visited)
             {
                 raster[i, j] = cost[i, j].RasterValue;
             }
             else
             {
                 raster[i, j] = null;
             }
         }
     }
     return new RasterOp(raster);
 }
Exemple #10
0
 public RasterOp Calculator(Postion startPostion)
 {
     if (!Read(startPostion.XIndex,startPostion.YIndex).HasValue)
         throw new ArgumentOutOfRangeException("起始位置不含有数据");
     RasterPositionValue[,] cost=new RasterPositionValue[Width,Height];
     //初始化操作
     InitializeValues(cost);
     InitializeStart(startPostion,cost);
     //使用orderbag,是的每次取出的最小值
     OrderedBag<RasterPositionValue> bag=new OrderedBag<RasterPositionValue>();
     bag.Add(cost[startPostion.XIndex,startPostion.YIndex]);
     while (bag.Count!=0)
     {
         RasterPositionValue pos = bag.RemoveFirst();
         var postions = Sourround(cost, pos);
         foreach (var postion in postions)
         {
             double relativeCost = Read(postion.XIndex, postion.YIndex).GetValueOrDefault() * 0.5 +
                                  Read(postion.XIndex, postion.YIndex).GetValueOrDefault()*0.5;
             if (pos.XIndex!=postion.XIndex&&pos.YIndex!=postion.YIndex)
             {
                 relativeCost *= Math.Sqrt(2);
             }
             cost[postion.XIndex, postion.YIndex].Visited = true;
             cost[postion.XIndex, postion.YIndex].HasValue = true;
             cost[postion.XIndex, postion.YIndex].RasterValue = (float) relativeCost
                 +cost[pos.XIndex,pos.YIndex].RasterValue;
             bag.Add(cost[postion.XIndex, postion.YIndex]);
         }
     }
     return Result(cost);
 }