示例#1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance from an input grid of boolean values.
        /// </summary>
        /// <param name="activeSites">
        /// An input grid of boolean values where true values indicates active
        /// sites.
        /// </param>
        public Array2D(IInputGrid <bool> activeSites)
            : base(activeSites.Dimensions)
        {
            int rows    = activeSites.Rows;
            int columns = activeSites.Columns;

            indexes = new uint[rows, columns];
            uint count = 0;

            for (int row = 0; row < rows; ++row)
            {
                for (int column = 0; column < columns; ++column)
                {
                    uint dataIndex = InactiveSite.DataIndex;
                    if (activeSites.ReadValue())
                    {
                        count++;
                        dataIndex = count;
                    }
                    indexes[row, column] = dataIndex;
                }
            }
            ActiveLocationCount   = count;
            InactiveLocationCount = (rows * columns) - ActiveLocationCount;

#if LOG4NET
            if (isDebugEnabled)
            {
                log.Debug("Active Site Locations");
                log.Debug("");
                log.DebugFormat("Grid dimensions: {0}", activeSites.Dimensions);
                log.Debug("");

                StringBuilder line = new StringBuilder(8 * (int)columns);
                line.Append("Column:");
                for (int column = 1; column <= columns; column++)
                {
                    line.Append('\t').Append(column);
                }
                log.Debug(line.ToString());

                log.Debug("Row");
                for (int row = 0; row < rows; row++)
                {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < columns; column++)
                    {
                        line.Append('\t').Append(indexes[row, column]);
                    }
                    log.Debug(line.ToString());
                }
            }
#endif
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance from an input grid of boolean values.
        /// </summary>
        /// <param name="activeSites">
        /// An input grid of boolean values where true values indicates active
        /// sites.
        /// </param>
        public Array2D(IInputGrid<bool> activeSites)
            : base(activeSites.Dimensions)
        {
            int rows = activeSites.Rows;
            int columns = activeSites.Columns;

            indexes = new uint[rows, columns];
            uint count = 0;
            for (int row = 0; row < rows; ++row) {
                for (int column = 0; column < columns; ++column) {
                    uint dataIndex = InactiveSite.DataIndex;
                    if (activeSites.ReadValue()) {
                        count++;
                        dataIndex = count;
                    }
                    indexes[row, column] = dataIndex;
                }
            }
            ActiveLocationCount = count;
            InactiveLocationCount = (rows * columns) - ActiveLocationCount;

            #if LOG4NET
            if (isDebugEnabled) {
                log.Debug("Active Site Locations");
                log.Debug("");
                log.DebugFormat("Grid dimensions: {0}", activeSites.Dimensions);
                log.Debug("");

                StringBuilder line = new StringBuilder(8 * (int) columns);
                line.Append("Column:");
                for (int column = 1; column <= columns; column++)
                    line.Append('\t').Append(column);
                log.Debug(line.ToString());

                log.Debug("Row");
                for (int row = 0; row < rows; row++) {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < columns; column++)
                        line.Append('\t').Append(indexes[row, column]);
                    log.Debug(line.ToString());
                }
            }
            #endif
        }
        public void Map8Bit()
        {
            Map map = new Map(path8Bit, dataset);

            using (IInputGrid <bool> inputGrid = map.OpenAsInputGrid()) {
                Assert.AreEqual(dims8Bit.Rows, inputGrid.Dimensions.Rows);
                Assert.AreEqual(dims8Bit.Columns, inputGrid.Dimensions.Columns);

                for (int row = 0; row < dims8Bit.Rows; ++row)
                {
                    for (int column = 0; column < dims8Bit.Columns; ++column)
                    {
                        IEcoregion ecoregion = dataset.Find(ecoregions8Bit[row, column]);
                        Assert.AreEqual(ecoregion.Active, inputGrid.ReadValue());
                    }
                }
            }
        }
        public void Map16Bit()
        {
            Map map = new Map(path16Bit, dataset, rasterDriverMgr);

            using (IInputGrid <EcoregionCode> inputGrid = map.OpenAsInputGrid()) {
                Assert.AreEqual(dims16Bit.Rows, inputGrid.Dimensions.Rows);
                Assert.AreEqual(dims16Bit.Columns, inputGrid.Dimensions.Columns);

                for (int row = 0; row < dims16Bit.Rows; ++row)
                {
                    for (int column = 0; column < dims16Bit.Columns; ++column)
                    {
                        ushort        mapCode       = ecoregions16Bit[row, column];
                        IEcoregion    ecoregion     = dataset.Find(mapCode);
                        EcoregionCode ecoregionCode = inputGrid.ReadValue();
                        Assert.AreEqual(mapCode, (int)ecoregionCode);
                        Assert.AreEqual(ecoregion.Active, ecoregionCode.IsActive);
                    }
                }
            }
        }
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.firstActive = null;
			this.firstInactive = null;

			this.rows = activeSites.Rows;
			this.columns = activeSites.Columns;
			this.indexes = new uint[this.rows, this.columns];
			this.count = 0;

			for (uint row = 0; row < this.rows; ++row) {
				for (uint column = 0; column < this.columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						this.indexes[row, column] = this.count;
						if (this.firstActive == null)
							this.firstActive = new LocationAndIndex(new Location(row+1, column+1), this.count);
					}
					else {
						if (this.firstInactive == null)
							this.firstInactive = new LocationAndIndex(new Location(row+1, column+1), InactiveSiteDataIndex);
					}
				}  // for each column
			}  // for each row

			if (logger.IsDebugEnabled) {
				LogDebug("Active Site Map");
				LogDebug("");
				LogDebug("Input Grid: {0}", activeSites.Dimensions);
				LogDebug("");

				if (firstActive == null)
					LogDebug("First Active: null");
				else
					LogDebug("First Active: {0} {1}", firstActive.Location, firstActive.Index);
				if (firstInactive == null)
					LogDebug("First Inactive: null");
				else
					LogDebug("First Inactive: {0} {1}", firstInactive.Location, firstInactive.Index);
				LogDebug("");

				StringBuilder line = new StringBuilder(8 * (int) this.columns);
				line.Append("Column:");
				for (int column = 1; column <= this.columns; column++)
					line.Append('\t').Append(column);
				LogDebug(line.ToString());

				LogDebug("Row");
				for (int row = 0; row < this.rows; row++) {
					line.Remove(0, line.Length);
					line.Append(row + 1);
					for (int column = 0; column < this.columns; column++)
						line.Append('\t').Append(indexes[row, column]);
					LogDebug(line.ToString());
				}
			}
		}
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.firstActive = null;
			this.firstInactive = null;

			this.rowIntervals    = new List<Interval>();
			this.activeRows      = new List<ActiveRow>();
			this.columnIntervals = new List<Interval>();

			bool inRowInterval = false;
			Interval rowInterval = new Interval();
			for (uint row = 1; row <= activeSites.Rows; ++row) {
				uint colIntervalCount = 0;
				uint firstColIntervalIndex = 0;
				bool inColumnInterval = false;
				Interval columnInterval = new Interval();
				for (uint column = 1; column <= activeSites.Columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						if (! this.firstActive.HasValue)
							this.firstActive = new Location(row, column);

						if (inColumnInterval) {
							//  extend column interval
							columnInterval.End = column;
						}
						else {
							//  start a new column interval
							columnInterval = new Interval(column, column,
							                              count - 1);
							inColumnInterval = true;
							colIntervalCount++;
							if (colIntervalCount == 1)
								firstColIntervalIndex = (uint)
														columnIntervals.Count;
						}
					}
					else {
						// current site is inactive
						if (! this.firstInactive.HasValue)
							this.firstInactive = new Location(row, column);

						if (inColumnInterval) {
							//  end of current column interval
							this.columnIntervals.Add(columnInterval);
							inColumnInterval = false;
						}
					}
				}  // for each column

				// at end of current row
				if (colIntervalCount > 0) {
					//  current row is an active row
					if (inColumnInterval) {
						//  last column was active, so add its interval
						this.columnIntervals.Add(columnInterval);
					}
					this.activeRows.Add(new ActiveRow(colIntervalCount,
					                             	  firstColIntervalIndex));
					if (inRowInterval) {
						//  extend row interval
						rowInterval.End = row;
					}
					else {
						//	start a new row interval
						rowInterval = new Interval(row, row,
						                           (uint)(activeRows.Count-1));
						inRowInterval = true;
					}
				}
				else {
					//	current row is not an active row
					if (inRowInterval) {
						this.rowIntervals.Add(rowInterval);
						inRowInterval = false;
					}
				}
			}  // for each row

			if (inRowInterval) {
				//	last row was an active row, so add its row interval
				this.rowIntervals.Add(rowInterval);
			}

			if (logger.IsDebugEnabled) {
				LogDebug("Active Site Map");
				LogDebug("");
				LogDebug("Input Grid: {0}", activeSites.Dimensions);
				LogDebug("");
				LogDebug("Row Intervals");
				LogDebug("  index: start to end (index of start row in active rows");
				for (int i = 0; i < rowIntervals.Count; i++) {
					Interval interval = rowIntervals[i];
					LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
				}

				LogDebug("");
				LogDebug("Active Rows");
				LogDebug("  index: # column intervals, index of 1st column interval");
				for (int i = 0; i < activeRows.Count; i++) {
					ActiveRow activeRow = ActiveRows[i];
					LogDebug("  {0}: {1}, {2}", i, activeRow.IntervalCount, activeRow.FirstIntervalOffset);
				}

				LogDebug("");
				LogDebug("Column Intervals");
				LogDebug("  index: start to end (data index of start column");
				for (int i = 0; i < columnIntervals.Count; i++) {
					Interval interval = columnIntervals[i];
					LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
				}
			}
		}
		//---------------------------------------------------------------------

		private void Initialize(IInputGrid<bool> activeSites)
		{
			this.rowIntervals    = new List<Interval>();
			this.activeRows      = new List<ActiveRow>();
			this.columnIntervals = new List<Interval>();

			bool inRowInterval = false;
			Interval rowInterval = new Interval();
			for (uint row = 1; row <= activeSites.Rows; ++row) {
				uint colIntervalCount = 0;
				uint firstColIntervalIndex = 0;
				bool inColumnInterval = false;
				Interval columnInterval = new Interval();
				for (uint column = 1; column <= activeSites.Columns; ++column) {
					if (activeSites.ReadValue()) {
						this.count++;
						if (inColumnInterval) {
							//  extend column interval
							columnInterval.End = column;
						}
						else {
							//  start a new column interval
							columnInterval = new Interval(column, column,
							                              count - 1);
							inColumnInterval = true;
							colIntervalCount++;
							if (colIntervalCount == 1)
								firstColIntervalIndex = (uint)
														columnIntervals.Count;
						}
					}
					else {
						// current site is inactive
						if (inColumnInterval) {
							//  end of current column interval
							this.columnIntervals.Add(columnInterval);
							inColumnInterval = false;
						}
					}
				}  // for each column

				// at end of current row
				if (colIntervalCount > 0) {
					//  current row is an active row
					if (inColumnInterval) {
						//  last column was active, so add its interval
						this.columnIntervals.Add(columnInterval);
					}
					this.activeRows.Add(new ActiveRow(colIntervalCount,
					                             	  firstColIntervalIndex));
					if (inRowInterval) {
						//  extend row interval
						rowInterval.End = row;
					}
					else {
						//	start a new row interval
						rowInterval = new Interval(row, row,
						                           (uint)(activeRows.Count-1));
						inRowInterval = true;
					}
				}
				else {
					//	current row is not an active row
					if (inRowInterval) {
						this.rowIntervals.Add(rowInterval);
						inRowInterval = false;
					}
				}
			}  // for each row

			if (inRowInterval) {
				//	last row was an active row, so add its row interval
				this.rowIntervals.Add(rowInterval);
			}
		}
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.firstActive   = null;
            this.firstInactive = null;

            this.rowIntervals    = new List <Interval>();
            this.activeRows      = new List <ActiveRow>();
            this.columnIntervals = new List <Interval>();

            bool     inRowInterval = false;
            Interval rowInterval   = new Interval();

            for (uint row = 1; row <= activeSites.Rows; ++row)
            {
                uint     colIntervalCount      = 0;
                uint     firstColIntervalIndex = 0;
                bool     inColumnInterval      = false;
                Interval columnInterval        = new Interval();
                for (uint column = 1; column <= activeSites.Columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        if (!this.firstActive.HasValue)
                        {
                            this.firstActive = new Location(row, column);
                        }

                        if (inColumnInterval)
                        {
                            //  extend column interval
                            columnInterval.End = column;
                        }
                        else
                        {
                            //  start a new column interval
                            columnInterval = new Interval(column, column,
                                                          count - 1);
                            inColumnInterval = true;
                            colIntervalCount++;
                            if (colIntervalCount == 1)
                            {
                                firstColIntervalIndex = (uint)
                                                        columnIntervals.Count;
                            }
                        }
                    }
                    else
                    {
                        // current site is inactive
                        if (!this.firstInactive.HasValue)
                        {
                            this.firstInactive = new Location(row, column);
                        }

                        if (inColumnInterval)
                        {
                            //  end of current column interval
                            this.columnIntervals.Add(columnInterval);
                            inColumnInterval = false;
                        }
                    }
                }                  // for each column

                // at end of current row
                if (colIntervalCount > 0)
                {
                    //  current row is an active row
                    if (inColumnInterval)
                    {
                        //  last column was active, so add its interval
                        this.columnIntervals.Add(columnInterval);
                    }
                    this.activeRows.Add(new ActiveRow(colIntervalCount,
                                                      firstColIntervalIndex));
                    if (inRowInterval)
                    {
                        //  extend row interval
                        rowInterval.End = row;
                    }
                    else
                    {
                        //	start a new row interval
                        rowInterval = new Interval(row, row,
                                                   (uint)(activeRows.Count - 1));
                        inRowInterval = true;
                    }
                }
                else
                {
                    //	current row is not an active row
                    if (inRowInterval)
                    {
                        this.rowIntervals.Add(rowInterval);
                        inRowInterval = false;
                    }
                }
            }              // for each row

            if (inRowInterval)
            {
                //	last row was an active row, so add its row interval
                this.rowIntervals.Add(rowInterval);
            }

            if (logger.IsDebugEnabled)
            {
                LogDebug("Active Site Map");
                LogDebug("");
                LogDebug("Input Grid: {0}", activeSites.Dimensions);
                LogDebug("");
                LogDebug("Row Intervals");
                LogDebug("  index: start to end (index of start row in active rows");
                for (int i = 0; i < rowIntervals.Count; i++)
                {
                    Interval interval = rowIntervals[i];
                    LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
                }

                LogDebug("");
                LogDebug("Active Rows");
                LogDebug("  index: # column intervals, index of 1st column interval");
                for (int i = 0; i < activeRows.Count; i++)
                {
                    ActiveRow activeRow = ActiveRows[i];
                    LogDebug("  {0}: {1}, {2}", i, activeRow.IntervalCount, activeRow.FirstIntervalOffset);
                }

                LogDebug("");
                LogDebug("Column Intervals");
                LogDebug("  index: start to end (data index of start column");
                for (int i = 0; i < columnIntervals.Count; i++)
                {
                    Interval interval = columnIntervals[i];
                    LogDebug("  {0}: {1} to {2} ({3})", i, interval.Start, interval.End, interval.StartOffset);
                }
            }
        }
示例#9
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.rowIntervals    = new List <Interval>();
            this.activeRows      = new List <ActiveRow>();
            this.columnIntervals = new List <Interval>();

            bool     inRowInterval = false;
            Interval rowInterval   = new Interval();

            for (uint row = 1; row <= activeSites.Rows; ++row)
            {
                uint     colIntervalCount      = 0;
                uint     firstColIntervalIndex = 0;
                bool     inColumnInterval      = false;
                Interval columnInterval        = new Interval();
                for (uint column = 1; column <= activeSites.Columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        if (inColumnInterval)
                        {
                            //  extend column interval
                            columnInterval.End = column;
                        }
                        else
                        {
                            //  start a new column interval
                            columnInterval = new Interval(column, column,
                                                          count - 1);
                            inColumnInterval = true;
                            colIntervalCount++;
                            if (colIntervalCount == 1)
                            {
                                firstColIntervalIndex = (uint)
                                                        columnIntervals.Count;
                            }
                        }
                    }
                    else
                    {
                        // current site is inactive
                        if (inColumnInterval)
                        {
                            //  end of current column interval
                            this.columnIntervals.Add(columnInterval);
                            inColumnInterval = false;
                        }
                    }
                }                  // for each column

                // at end of current row
                if (colIntervalCount > 0)
                {
                    //  current row is an active row
                    if (inColumnInterval)
                    {
                        //  last column was active, so add its interval
                        this.columnIntervals.Add(columnInterval);
                    }
                    this.activeRows.Add(new ActiveRow(colIntervalCount,
                                                      firstColIntervalIndex));
                    if (inRowInterval)
                    {
                        //  extend row interval
                        rowInterval.End = row;
                    }
                    else
                    {
                        //	start a new row interval
                        rowInterval = new Interval(row, row,
                                                   (uint)(activeRows.Count - 1));
                        inRowInterval = true;
                    }
                }
                else
                {
                    //	current row is not an active row
                    if (inRowInterval)
                    {
                        this.rowIntervals.Add(rowInterval);
                        inRowInterval = false;
                    }
                }
            }              // for each row

            if (inRowInterval)
            {
                //	last row was an active row, so add its row interval
                this.rowIntervals.Add(rowInterval);
            }
        }
示例#10
0
        //---------------------------------------------------------------------

        private void Initialize(IInputGrid <bool> activeSites)
        {
            this.firstActive   = null;
            this.firstInactive = null;

            this.rows    = activeSites.Rows;
            this.columns = activeSites.Columns;
            this.indexes = new uint[this.rows, this.columns];
            this.count   = 0;

            for (uint row = 0; row < this.rows; ++row)
            {
                for (uint column = 0; column < this.columns; ++column)
                {
                    if (activeSites.ReadValue())
                    {
                        this.count++;
                        this.indexes[row, column] = this.count;
                        if (this.firstActive == null)
                        {
                            this.firstActive = new LocationAndIndex(new Location(row + 1, column + 1), this.count);
                        }
                    }
                    else
                    {
                        if (this.firstInactive == null)
                        {
                            this.firstInactive = new LocationAndIndex(new Location(row + 1, column + 1), InactiveSiteDataIndex);
                        }
                    }
                }          // for each column
            }              // for each row

            if (logger.IsDebugEnabled)
            {
                LogDebug("Active Site Map");
                LogDebug("");
                LogDebug("Input Grid: {0}", activeSites.Dimensions);
                LogDebug("");

                if (firstActive == null)
                {
                    LogDebug("First Active: null");
                }
                else
                {
                    LogDebug("First Active: {0} {1}", firstActive.Location, firstActive.Index);
                }
                if (firstInactive == null)
                {
                    LogDebug("First Inactive: null");
                }
                else
                {
                    LogDebug("First Inactive: {0} {1}", firstInactive.Location, firstInactive.Index);
                }
                LogDebug("");

                StringBuilder line = new StringBuilder(8 * (int)this.columns);
                line.Append("Column:");
                for (int column = 1; column <= this.columns; column++)
                {
                    line.Append('\t').Append(column);
                }
                LogDebug(line.ToString());

                LogDebug("Row");
                for (int row = 0; row < this.rows; row++)
                {
                    line.Remove(0, line.Length);
                    line.Append(row + 1);
                    for (int column = 0; column < this.columns; column++)
                    {
                        line.Append('\t').Append(indexes[row, column]);
                    }
                    LogDebug(line.ToString());
                }
            }
        }