//---------------------------------------------------------------------

        public override void Run()
        {
            //if keyword == maxage
            foreach (ISpecies species in selectedSpecies)
            {
                string path = MapNameTemplates.ReplaceTemplateVars(mapNameTemplate, species.Name, modelCore.CurrentTime);
                modelCore.UI.WriteLine("   Writing maximum age map for {0} to {1} ...", species.Name, path);
                using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions))
                {
                    ShortPixel pixel = outputRaster.BufferPixel;
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (site.IsActive)
                        {
                            pixel.MapCode.Value = SiteVars.GetMaxAge(species, (ActiveSite)site);
                        }
                        else
                        {
                            pixel.MapCode.Value = 0;
                        }

                        outputRaster.WriteBufferPixel();
                    }
                }
            }

            WriteMapWithMaxAgeAmongAll();
        }
Exemple #2
0
        public static void InitializeMetadata(string speciesNameTemplate, IEnumerable <ISpecies> selectedSpecies)
        {
            ScenarioReplicationMetadata scenRep = new ScenarioReplicationMetadata()
            {
                RasterOutCellArea = PlugIn.ModelCore.CellArea,
                TimeMin           = PlugIn.ModelCore.StartTime,
                TimeMax           = PlugIn.ModelCore.EndTime,
            };

            Extension = new ExtensionMetadata(PlugIn.ModelCore)
                        //Extension = new ExtensionMetadata()
            {
                Name         = PlugIn.ExtensionName,
                TimeInterval = PlugIn.ModelCore.CurrentTime,
                ScenarioReplicationMetadata = scenRep
            };

            //---------------------------------------
            //          map outputs:
            //---------------------------------------

            foreach (ISpecies species in selectedSpecies)
            {
                OutputMetadata mapOut_max = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = "max_age_" + species.Name,
                    FilePath     = MapNameTemplates.ReplaceTemplateVars(speciesNameTemplate, species.Name, PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_max);
            }

            OutputMetadata mapOut_max_all = new OutputMetadata()
            {
                Type         = OutputType.Map,
                Name         = "AllSppMaxAge",
                FilePath     = MapNameTemplates.ReplaceTemplateVars(speciesNameTemplate, "AllSppMaxAge", PlugIn.ModelCore.CurrentTime),
                Map_DataType = MapDataType.Continuous,
                Visualize    = true,
                //Map_Unit = "categorical",
            };

            Extension.OutputMetadatas.Add(mapOut_max_all);



            //---------------------------------------
            MetadataProvider mp = new MetadataProvider(Extension);

            mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name);
        }
        //---------------------------------------------------------------------

        private void WriteMapWithMaxAgeAmongAll()
        {
            //    Maximum age map for all species
            string path = MapNameTemplates.ReplaceTemplateVars(mapNameTemplate, "AllSppMaxAge", modelCore.CurrentTime);

            modelCore.UI.WriteLine("   Writing maximum age map for all species to {0} ...", path);
            using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions))
            {
                ShortPixel pixel = outputRaster.BufferPixel;
                foreach (Site site in modelCore.Landscape.AllSites)
                {
                    if (site.IsActive)
                    {
                        pixel.MapCode.Value = SiteVars.GetMaxAge((ActiveSite)site);
                    }
                    else
                    {
                        pixel.MapCode.Value = 0;
                    }

                    outputRaster.WriteBufferPixel();
                }
            }
        }