/// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="poly">The Polygon.</param>
        /// <param name="output">The Raster.</param>
        /// <param name="progress">The progress handler.</param>
        public bool Execute(IFeatureSet poly, int noOfRow, int noOfCol, int selectionIndex, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (poly == null || output == null)
            {
                return false;
            }
            if (poly.FeatureType != FeatureTypes.Polygon)
                return false;

            //double CellSize = poly.Envelope.Width / 255;
            //int noOfRow = Convert.ToInt32(poly.Envelope.Height / CellSize);
            //int noOfCol = Convert.ToInt32(poly.Envelope.Width / CellSize);
            output=Raster.Create(output.Filename,"",noOfCol,noOfRow,1,typeof(int),new string[] { "" });

            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, poly.Envelope);

            output.Bounds=bound;

            output.NoDataValue = -1;
            int current, previous = 0;
            double area = 0.0, previousArea = 0.0;
            double hCellWidth = output.CellWidth / 2;
            double hCellHeight = output.CellHeight / 2;
            ICoordinate[] coordinateCell=new Coordinate[4];
            int polyIndex = -1;
            bool cover = false;
            //IEnvelope env=null;
            for (int i = 0; i < output.NumRows; i++)
            {
                current = Convert.ToInt32(i*100 / output.NumRows);
                //only update when increment in percentage
                if (current > previous+5)
                {
                    cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed");
                    previous = current;
                }

                for (int j = 0; j < output.NumColumns; j++)
                {
                    polyIndex = -1;
                    area = 0.0;
                    previousArea = 0.0;
                    cover=false;
                    ICoordinate cordinate=null;
                    cordinate = output.CellToProj(i, j);
                    //make the center of cell as point geometry
                    IPoint pt=new Point(cordinate);

                    for(int f=0;f<poly.Features.Count;f++)
                    {
                        if (selectionIndex == 0)
                        {
                            if (poly.Features[f].Covers(pt))
                            {
                                output.Value[i, j] = f;
                                cover = true;
                                break;
                            }
                            if (cancelProgressHandler.Cancel == true)
                                return false;
                        }
                        else //process area based selection
                        {
                            ICoordinate tempCo = new Coordinate(cordinate.X - hCellWidth, cordinate.Y - hCellHeight);
                            coordinateCell[0] = tempCo;
                            tempCo = new Coordinate(cordinate.X + hCellWidth, cordinate.Y - hCellHeight);
                            coordinateCell[1] = tempCo;
                            tempCo = new Coordinate(cordinate.X + hCellWidth, cordinate.Y + hCellHeight);
                            coordinateCell[2] = tempCo;
                            tempCo = new Coordinate(cordinate.X - hCellWidth, cordinate.Y + hCellHeight);
                            coordinateCell[3] = tempCo;

                            List<ICoordinate> ListCellCordinate = new List<ICoordinate>();
                            ListCellCordinate = coordinateCell.ToList<ICoordinate>();
                            IFeature cell = new Feature(FeatureTypes.Polygon, ListCellCordinate);
                            IFeature commonFeature=poly.Features[f].Intersection(cell);
                            if (commonFeature == null)
                                continue;
                            area=commonFeature.Area();
                            if (area > previousArea)
                            {
                                polyIndex = f;
                                cover = true;
                                previousArea = area;
                            }

                            if (cancelProgressHandler.Cancel == true)
                                return false;
                        }

                        
                    }
                    if (cover == true)
                    {
                        if (selectionIndex == 1)
                            output.Value[i, j] = polyIndex;
                    }
                    else
                        output.Value[i, j] = output.NoDataValue;
                }

            }
            //output.SaveAs(output.Filename);
            output.Save();
            //output.SaveAs(output.Filename);
            return true;
        }