Beispiel #1
0
        private async Task ImportSQLite(string file)
        {
            Gis.IMapWindow window = null;

            Model.Geometry.SpatiaLite.Database db = new Model.Geometry.SpatiaLite.Database(file);
            List <IFeatureSet> dataset            = null;

            bool ok = true;
            await Task.Run(() =>
            {
                ok = db.TryLoadSpatialDataset(out dataset);
            });

            if (!ok)
            {
                MessageBox.Show("Unable to load spatial dataset from file '" + file + "': " + db.ErrorMessage);
                return;
            }

            SetProgress(50);

            var mapGroup = new Gis.DotSpatialMapGroup();

            mapGroup.MapGroup            = CreateMapGroup(dataset);
            mapGroup.MapGroup.LegendText = Path.GetFileNameWithoutExtension(file);

            window = mapFactory.CreateMapWindow();
            window.Attach(this.container);
            window.AddMapGroup(mapGroup);

            SetProgress(100);

            window.Show(Window.DockingState.Document);

            this.dataset = dataset;
        }
Beispiel #2
0
        public bool ImportSQLite(string filePath, string name, bool addedFromProjectLoad)
        {
            Model.Geometry.SpatiaLite.Database db = new Model.Geometry.SpatiaLite.Database(filePath);
            List <IFeatureSet> dataset            = null;

            bool ok = true;

            ok = db.TryLoadSpatialDataset(out dataset);

            if (!ok)
            {
                MessageBox.Show("Unable to load spatial dataset from file '" + filePath + "': " + db.ErrorMessage);
                return(false);
            }

            DotSpatial.Controls.MapGroup mapGroup = new DotSpatial.Controls.MapGroup();
            mapGroup.LegendText       = name;
            mapGroup.SelectionEnabled = true;

            foreach (var fs in dataset)
            {
                var mapLayer = GetMapLayerFromFeatureSet(fs);
                mapLayer.SelectionEnabled = true;
                //group.Layers.Add(layer);
                mapGroup.Layers.Add(mapLayer);
                mapLayer.SetParentItem(mapGroup);
                var id = Guid.NewGuid().ToString();
                //this.idMapLayer[id] = mapLayer;
                //this.idMapLayerInverse[mapLayer] = id;
                mapGroup.Layers[mapGroup.Layers.Count - 1].LegendText = fs.Name;
            }

            foreach (var layer in mapGroup.Layers)
            {
                //if (!layer.Projection.Equals(this.map.MapFrame.Projection))
                // If we don't reproject upon load for every layer, then the layers don't display properly.
                layer.Reproject(this.map.MapFrame.Projection);

                IMapFeatureLayer fl = layer as IMapFeatureLayer;
                if (fl != null)
                {
                    //LayerAdded(fl);
                }
            }

            this.map.Layers.Add(mapGroup);
            //var id = Guid.NewGuid().ToString();
            //this.idMapGroupInverse[mapGroup] = id;
            //this.idMapGroup[id] = mapGroup;

            mapGroup.IsExpanded = false;
            //if (!this.mapSymbolHelper.LoadSymbology(mg, file, this))
            //{
            //  return false;
            //}

            if (!addedFromProjectLoad)
            {
                this.projectMgr.SetProperty(Section_Layers, name, filePath);
            }

            return(true);
        }