Example #1
0
        private void AddFolderToMap()
        {
            var folder = GetSelectedItem <IFolderItem>();

            if (folder != null)
            {
                _layerService.BeginBatch();

                try
                {
                    foreach (var item in folder.SubItems)
                    {
                        var file = item as IFileItem;
                        if (file != null)
                        {
                            _layerService.AddLayersFromFilename(file.Filename);
                        }
                    }
                }
                finally
                {
                    _layerService.EndBatch();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles output generated by GDAL utilities. The location of output
        /// is specified by OutputLayerInfo.Filename;
        /// </summary>
        public bool HandleGdalOutput(OutputLayerInfo outputInfo)
        {
            if (File.Exists(outputInfo.Filename))
            {
                outputInfo.DatasourcePointer = new DatasourcePointer(outputInfo.Filename);

                if (outputInfo.AddToMap)
                {
                    // don't report error if layer isn't added to the map
                    // user might cancel it because of projection mismatch
                    _layerService.AddLayersFromFilename(outputInfo.Filename);
                }

                return(true);
            }

            return(false);
        }
        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 + ".");
                }
            }
        }
        private void RestoreLayers(MapWin4Project project, string path)
        {
            if (project.MapwinGis == null || project.MapwinGis.Layers == null)
            {
                Logger.Current.Info("Failed to find Layers node in the legacy project file.");
                return;
            }

            var layers = project.MapwinGis.Layers;
            int step   = 0;
            int count  = layers.Count;

            foreach (var xmlLayer in layers)
            {
                step++;
                FireProgressChanged(step, count, "Loading layer: " + xmlLayer.LayerName);

                if (string.IsNullOrWhiteSpace(xmlLayer.Filename))
                {
                    Logger.Current.Info("Failed to load layer: " + (xmlLayer.LayerName ?? ""));
                    continue;
                }

                string filename = Path.Combine(path, xmlLayer.Filename);
                if (!File.Exists(filename))
                {
                    Logger.Current.Info("Layer isn't found: " + filename);
                    continue;
                }

                if (_layerService.AddLayersFromFilename(filename))
                {
                    var layer = _context.Layers.ItemByHandle(_layerService.LastLayerHandle);

                    if (layer == null)
                    {
                        continue;
                    }
                    layer.Name = xmlLayer.LayerName;

                    string state = xmlLayer.SerializeToXml();
                    layer.Deserialize(state);
                }
                else if (_layerService.Aborted)
                {
                    return;
                }
            }
        }
Example #5
0
        private void MapFileDropped(object sender, FileDroppedEventArgs e)
        {
            if (TryParseTmsProviderFromDroppedFilename(e.Filename))
            {
                return;
            }

            if (e.Filename.ToLower().EndsWith(".mwproj") ||
                e.Filename.ToLower().EndsWith(".mwprj"))
            {
                _projectService.Open(e.Filename, false);
                return;
            }

            _layerService.AddLayersFromFilename(e.Filename);
            int handle = _layerService.LastLayerHandle;
            _map.ZoomToLayer(handle);
        }