public static string GenerateTemporaryImageFile(GridLayer layer, string filenamePrefix, Color lowcolor, Color highcolor, Color novaluecolor, double cutoff = 0, int intervals = 256)
        {
            var filename = TempFileManager.NewTempFilename("bmp", filenamePrefix);

            CreateImageFileFromGrid(layer, filename, lowcolor, highcolor, novaluecolor, cutoff, intervals);
            var image = LayerImageGenerator.GetImageForLayer(layer, lowcolor, highcolor, novaluecolor, cutoff, intervals);

            TempFileManager.Attach(filename + "w");
            return(filename);
        }
        private void StartSingleModel()
        {
            var points = pointSets.PointSets;

            if (points == null || points.Count() == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            int totalPoints = 0;

            points.ForEach((set) => {
                totalPoints += set.Count();
            });

            if (totalPoints == 0)
            {
                ErrorMessage.Show("There are no training points to model from!");
                return;
            }

            if (_layerFilenames.Count == 0)
            {
                ErrorMessage.Show("There are no environmental grid layers specified!");
                return;
            }

            _currentModel = _singleModelOptions.cmbModelType.SelectedItem as DistributionModel;
            if (_currentModel != null)
            {
                _currentModel.ProgressObserver = this;

                btnStart.IsEnabled = false;
                btnStop.IsEnabled  = true;

                JobExecutor.QueueJob(() => {
                    try {
                        var layers = _layerFilenames.Select((mm) => {
                            ProgressMessage(string.Format("Loading grid layer {0}", mm.Name));
                            return(new GridLayer(mm.Name));
                        }).ToList();

                        ProgressMessage("Running model...");

                        var result = _currentModel.RunModel(layers, points);

                        if (_currentModel.IsCancelled)
                        {
                            MessageBox.Show("Model cancelled", "Model cancelled", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }

                        this.InvokeIfRequired(() => {
                            ProgressMessage("Saving file...");
                            result.SaveToGRDFile(_singleModelOptions.txtFilename.Text);

                            if (_singleModelOptions.chkGenerateImage.IsChecked == true)
                            {
                                ProgressMessage("Preparing map...");
                                string imageFilename = SystemUtils.ChangeExtension(_singleModelOptions.txtFilename.Text, "bmp");
                                TempFileManager.Attach(imageFilename);
                                double cutoff = _singleModelOptions.CutOff;
                                int intervals = _singleModelOptions.Intervals;
                                ShowGridLayerInMap(result, intervals, cutoff, _singleModelOptions, imageFilename);
                            }
                        });
                        ProgressMessage("Model complete.");
                    } catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                    } finally {
                        this.InvokeIfRequired(() => {
                            btnStart.IsEnabled = true;
                            btnStop.IsEnabled  = false;
                        });
                        _currentModel = null;
                    }
                });
            }
        }