private void RemoveDatabaseLayer() { var layer = GetSelectedItem <IDatabaseLayerItem>(); if (layer != null) { var db = layer.Parent as IDatabaseItem; if (db != null) { var ds = new VectorDatasource(); if (ds.Open(db.Connection.ConnectionString)) { int layerIndex = ds.LayerIndexByName(layer.Name); if (MessageService.Current.Ask("Do you want to remove database layer: " + layer.Name + "?")) { if (!ds.DeleteLayer(layerIndex)) { MessageService.Current.Warn("Failed to remove layer."); } RefreshItem(db); } } } } }
/// <summary> /// Runs the tool. /// </summary> public override bool Run(ITaskHandle task) { string options = PrepareOptions(); var ds = new VectorDatasource(); if (ds.Open(Database.ConnectionString)) { if (InputLayer.Datasource.HasInvalidShapes()) { Log.Warn("Datasource has invalid shapes. Please run Fix tool before importing it.", null); return(false); } if (!ds.ImportLayer(InputLayer.Datasource, NewLayerName, options, ValidationMode.NoValidation)) { Log.Warn("Failed to import shapefile: " + ds.GdalLastErrorMsg, null); return(false); } Log.Info("Layer was imported: " + NewLayerName); return(true); } return(false); }
private bool HandleLayerMenu(string itemKey) { switch (itemKey) { case MenuKeys.AddWmsLayer: { var model = new WmsCapabilitiesModel(_context.Repository); _context.Container.Run <WmsCapabilitiesPresenter, WmsCapabilitiesModel>(model); return(true); } case MenuKeys.AddDatabaseLayer: var connection = _databaseService.PromptUserForConnection(); if (connection != null) { using (var ds = new VectorDatasource()) { var model = new DatabaseLayersModel(ds, connection); _context.Container.Run <DatabaseLayersPresenter, DatabaseLayersModel>(model); } } return(true); case MenuKeys.AddLayer: _layerService.AddLayer(DataSourceType.All); return(true); case MenuKeys.AddRasterLayer: _layerService.AddLayer(DataSourceType.Raster); return(true); case MenuKeys.AddVectorLayer: _layerService.AddLayer(DataSourceType.Vector); return(true); case MenuKeys.LayerClearSelection: var layer = _context.Legend.SelectedLayer; if (layer != null && layer.FeatureSet != null) { layer.FeatureSet.ClearSelection(); _context.Map.Redraw(); } return(true); case MenuKeys.ClearLayers: if (MessageService.Current.Ask("Do you wan't to remove all layers from the map?")) { _context.Legend.Layers.Clear(); } return(true); } return(false); }
public IEnumerable <string> GetSchemas() { using (var source = new VectorDatasource()) { if (source.Open(ConnectionString)) { foreach (var s in source.GetShemas()) { yield return(s); } } } }
private bool TestConnectionCore(string cs, ref string errorMessage) { using (var ds = new VectorDatasource()) { bool result = ds.Open(cs); if (!result) { errorMessage = ds.GdalLastErrorMsg; } return(result); } }
public DatabaseLayersModel(VectorDatasource ds, DatabaseConnection connection) { if (ds == null) { throw new ArgumentNullException("ds"); } if (connection == null) { throw new ArgumentNullException("connection"); } Datasource = ds; Connection = connection; }
// TODO Make more generic connection string // [Test] public void VectorDatasource() { const string connection = "PG:dbname=london host=localhost user=postgres password=1234"; var ds = new VectorDatasource(connection); foreach (VectorLayer layer in ds) { Debug.Print("Layer: " + layer.Name); } var lyr = ds.GetLayer(0); var fs = lyr.Data.Features; Debug.Print("Number of features: " + fs.Count()); int count = 0; foreach (var ft in fs) { Debug.Print("Feature: {0}; Number of points: {1}", count++, ft.Geometry.Points.Count); } }