Example #1
0
        private void PopulateBuffer(IFeatureSet sf)
        {
            var buffer = sf.ExportSelection();

            Clear();
            _buffer = buffer;
            FeatureSetToSystemClipboard(buffer);
        }
        public static void ExportSelected(this IFeatureSet fs, IFileDialogService dialogService, ILayerService layerService)
        {
            if (fs == null)
            {
                throw new ArgumentNullException("fs");
            }
            if (dialogService == null)
            {
                throw new ArgumentNullException("dialogService");
            }
            if (layerService == null)
            {
                throw new ArgumentNullException("layerService");
            }

            if (fs.NumSelected == 0)
            {
                MessageService.Current.Info("No shapes are selected.");
                return;
            }

            string filename = string.Empty;

            dialogService.Title = "Select shapefile name to export selected shapes into";
            if (!dialogService.SaveFile(@"Shapefiles (*.shp)|*.shp", ref filename))
            {
                return;
            }

            var fsNew = fs.ExportSelection();

            if (fsNew != null)
            {
                if (!fsNew.SaveAsEx(filename, true))
                {
                    MessageService.Current.Warn("Failed to save shapefile: " + filename + ".");
                    return;
                }

                fsNew.Dispose();
            }
            else
            {
                MessageService.Current.Warn("Failed to export selection.");
                return;
            }

            if (MessageService.Current.Ask("Do you want to load the new shapefile?"))
            {
                bool result = layerService.AddLayersFromFilename(filename);
                if (!result)
                {
                    MessageService.Current.Warn("Failed to open exported shapefile: " + filename + ".");
                }
            }
        }