Beispiel #1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a site variable with ecoregions.
        /// </summary>
        public ISiteVar <IEcoregion> CreateSiteVar(ILandscape landscape)
        {
            ISiteVar <IEcoregion>         siteVar = landscape.NewSiteVar <IEcoregion>();
            IInputRaster <EcoregionPixel> map     = rasterFactory.OpenRaster <EcoregionPixel>(path);

            Console.WriteLine("  reading in ecoregion from {0} ", path);
            using (map)
            {
                EcoregionPixel pixel = map.BufferPixel;
                foreach (Site site in landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    ushort mapCode = (ushort)pixel.MapCode.Value;
                    if (site.IsActive)
                    {
                        siteVar[site] = ecoregions.Find(mapCode);
                    }
                    if (!site.IsActive && ecoregions.Find(mapCode).Active)
                    {
                        String msg = String.Format("  Site not active and ecoregion is active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                        throw new ApplicationException(msg);
                        //Console.WriteLine("  Site not active");
                    }
                    if (site.IsActive && !ecoregions.Find(mapCode).Active)
                    {
                        String msg = String.Format("  Site is active and ecoregion is not active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                        throw new ApplicationException(msg);
                    }
                }
            }
            return(siteVar);
        }
Beispiel #2
0
        //---------------------------------------------------------------------

        public bool ReadValue()
        {
            if (disposed)
            {
                throw new System.InvalidOperationException("Object has been disposed.");
            }
            EcoregionPixel pixel = raster.BufferPixel;

            raster.ReadBufferPixel();
            pixelLocation = RowMajor.Next(pixelLocation, raster.Dimensions.Columns);
            ushort     mapCode   = (ushort)pixel.MapCode.Value;
            IEcoregion ecoregion = ecoregions.Find(mapCode);

            //Console.WriteLine("  reading in ecoregion {0} which is {1}", ecoregion.Name, ecoregion.Active);
            if (ecoregion != null)
            {
                return(ecoregion.Active);
            }

            string mesg      = string.Format("Error at map site {0}", pixelLocation);
            string innerMesg = string.Format("Unknown map code for ecoregion: {0}", mapCode);

            throw new MultiLineException(mesg, innerMesg);
        }