//---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="landscapeDimensions">
 /// The dimensions of the landscape.
 /// </param>
 protected Enumerator(Dimensions landscapeDimensions)
     : base()
 {
     ResetLocationAndIndex();
     rows = landscapeDimensions.Rows;
     columns = landscapeDimensions.Columns;
 }
コード例 #2
0
        public void Init()
        {
            List<IEcoregionParameters> ecoregionParms = new List<IEcoregionParameters>();
            ecoregionParms.Add(new Parameters("eco0", "Ecoregion A", 0, true));
            ecoregionParms.Add(new Parameters("eco11", "Ecoregion B", 11, false));
            ecoregionParms.Add(new Parameters("eco222", "Ecoregion C", 222, true));
            ecoregionParms.Add(new Parameters("eco3333", "Ecoregion D", 3333, false));
            ecoregionParms.Add(new Parameters("eco-65535", "Ecoregion E", 65535, true));

            dataset = new Dataset(ecoregionParms);
            rasterFactory = new RasterFactory();

            //  Initialize 8-bit ecoregion data
            ecoregions8Bit = new byte[,] {
                {   0,   0,  11, 222,  11 },
                {   0,  11,  11, 222,  11 },
                {   0,  11,  11, 222, 222 },
                {  11,  11,  11, 222, 222 },
                {  11,  11, 222, 222, 222 },
                {  11,  11, 222, 222, 222 }
            };
            dims8Bit = new Dimensions(ecoregions8Bit.GetLength(0),
                                      ecoregions8Bit.GetLength(1));
            rasterFactory.SetData(path8Bit, ecoregions8Bit);

            //  Initialize 16-bit ecoregion data
            ecoregions16Bit = new ushort[,] {
                {   0,   0,  11, 222,  11,  3333,     0 },
                {   0,  11,  11, 222,  11,  3333, 65535 },
                {   0,  11,  11, 222, 222,  3333, 65535 },
                {  11,  11,  11, 222, 222,  3333, 65535 },
                {  11,  11, 222, 222, 222,  3333, 65535 },
                {  11,  11, 222, 222, 222, 65535, 65535 },
                {   0,   0, 222, 222, 222, 65535, 65535 }
            };
            dims16Bit = new Dimensions(ecoregions16Bit.GetLength(0),
                                       ecoregions16Bit.GetLength(1));
            rasterFactory.SetData(path16Bit, ecoregions16Bit);
        }
コード例 #3
0
        //---------------------------------------------------------------------

        ///<summary>
        /// Run the plug-in at a particular timestep.
        ///</summary>
        public override void Run()
        {
            ModelCore.UI.WriteLine("Processing landscape for wind events ...");

            SiteVars.Event.SiteValues = null;
            SiteVars.Severity.ActiveSiteValues = 0;

            int eventCount = 0;
            foreach (ActiveSite site in PlugIn.ModelCore.Landscape) {
                Event windEvent = Event.Initiate(site, Timestep);
                if (windEvent != null) {
                    LogEvent(PlugIn.ModelCore.CurrentTime, windEvent);
                    eventCount++;
                }
            }
            ModelCore.UI.WriteLine("  Wind events: {0}", eventCount);

            //  Write wind severity map
            string path = MapNames.ReplaceTemplateVars(mapNameTemplate, PlugIn.modelCore.CurrentTime);
            Dimensions dimensions = new Dimensions(modelCore.Landscape.Rows, modelCore.Landscape.Columns);
            using (IOutputRaster<BytePixel> outputRaster = modelCore.CreateRaster<BytePixel>(path, dimensions))
            {
                BytePixel pixel = outputRaster.BufferPixel;
                foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) {
                    if (site.IsActive) {
                        if (SiteVars.Disturbed[site])
                            pixel.MapCode.Value = (byte) (SiteVars.Severity[site] + 1);
                        else
                            pixel.MapCode.Value = 1;
                    }
                    else {
                        //  Inactive site
                        pixel.MapCode.Value = 0;
                    }
                    outputRaster.WriteBufferPixel();
                }
            }
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="landscapeDimensions">
 /// The dimensions of the landscape.
 /// </param>
 protected Collection(Dimensions landscapeDimensions)
 {
     this.landscapeDimensions = landscapeDimensions;
 }
        public void Run()
        {
            Console.WriteLine("Running the example LANDIS-II extension...");

            Console.WriteLine("Ecoregion codes:");
            foreach (Site site in core.Landscape.AllSites) {
                Console.Write("  {0}", core.EcoregionCodes[site]);
                if (site.Location.Column == core.Landscape.Columns)
                    Console.WriteLine();
            }
            Console.WriteLine();

            short[,] data = new short[90,140];
            int rows    = data.GetLength(0);
            int columns = data.GetLength(1);
            Dimensions dimensions = new Dimensions(rows, columns);

            for (int r = 0; r < rows; ++r) {
                for (int c = 0; c < columns; ++c)
                    data[r, c] = (short) ((c * 100) + r);
            }

            string rasterPath = "slope-aspect.img";

            using (IOutputRaster<SlopeAspectPixel> outputRaster = core.CreateRaster<SlopeAspectPixel>(rasterPath, dimensions))
            {
                SlopeAspectPixel pixel = outputRaster.BufferPixel;
                for (int row = 0; row < rows; ++row) {
                    for (int column = 0; column < columns; ++column) {
                        pixel.Slope.Value  = (float)(data[row, column] / 100.0);
                        pixel.Aspect.Value = data[row, column];
                        outputRaster.WriteBufferPixel();
                    }
                }
            }

            Console.WriteLine("Opening input raster \"{0}\":", rasterPath);
            // Have to use pixel with two float bands because GDAL allows only
            // one shared data type across all the raster bands when creating
            // a raster.
            //
            // TO DO: Consider changing spatial library's API so that all the
            //        bands in an input or output raster have the same type.
            using (IInputRaster<SlopeAspectPixel_float> inputRaster = core.OpenRaster<SlopeAspectPixel_float>(rasterPath))
            {
                Console.WriteLine("  Dimensions: {0}", inputRaster.Dimensions);

                SlopeAspectPixel_float pixel = inputRaster.BufferPixel;
                int slopeErrors = 0;
                int aspectErrors = 0;
                for (int row = 1; row <= inputRaster.Dimensions.Rows; ++row) {
                    for (int column = 1; column <= inputRaster.Dimensions.Columns; ++column) {
                        inputRaster.ReadBufferPixel();

                        // Check the actual slope and aspect values to expected values
                        float expectedSlope = (float)(data[row-1, column-1] / 100.0);
                        if (pixel.Slope.Value != expectedSlope) {
                            Console.WriteLine("({0}, {1}) : expected Slope ({2}) not = actual Slope ({3})", row, column, expectedSlope, pixel.Slope.Value);
                            slopeErrors++;
                        }
                        float expectedAspect = data[row-1, column-1];
                        if (pixel.Aspect.Value != expectedAspect) {
                            Console.WriteLine("({0}, {1}) : expected Aspect ({2}) not = actual Aspect ({3})", row, column, expectedAspect, pixel.Aspect.Value);
                            aspectErrors++;
                        }
                    }
                }
                Console.WriteLine("# of mismatched slope values: {0}", slopeErrors);
                Console.WriteLine("# of mismatched aspect values: {0}", aspectErrors);
            }
        }