Пример #1
0
 private void OpenDatasource()
 {
     _datasource.Close();
     if (!OgrHelper.OpenDatasource(_datasource, _connection))
     {
         return;
     }
     PopulateList();
 }
Пример #2
0
        public static void ImportOgrLayer()
        {
            int layerHandle = App.Legend.SelectedLayer;

            if (layerHandle == -1)
            {
                return;
            }

            var sf = App.Map.get_Shapefile(layerHandle);

            if (sf == null)
            {
                MessageHelper.Info("Selected layer is not a vector layer.");
                return;
            }

            using (var form = new OgrConnectionForm())
            {
                if (form.ShowDialog(MainForm.Instance) == DialogResult.OK)
                {
                    var ds = new OgrDatasource();
                    if (!OgrHelper.OpenDatasource(ds, form.ConnectionParams))
                    {
                        return;
                    }

                    string layerName = App.Map.get_LayerName(layerHandle);
                    layerName = layerName.Replace(".", "_");

                    using (var importForm = new OgrImportShapefile(layerName))
                    {
                        if (importForm.ShowDialog(MainForm.Instance) == DialogResult.OK)
                        {
                            layerName = importForm.LayerName;
                            if (!ds.ImportShapefile(sf, layerName, "", tkShapeValidationMode.NoValidation))
                            {
                                MessageHelper.Warn("Failed to import shapefile: " + ds.GdalLastErrorMsg);
                            }
                            else
                            {
                                MessageHelper.Info("Layer was imported: " + layerName);
                            }
                        }
                    }
                }
            }
        }