/// <summary> /// 导入为Wor /// Import to Wor /// </summary> public void ImportToWor() { try { m_dataImport.ImportSettings.Clear(); ImportSettingWOR worSetting = new ImportSettingWOR(); worSetting.ImportMode = ImportMode.Overwrite; worSetting.SourceFilePath = @"..\..\SampleData\DataExchange\WorImport\Jingjin.wor"; worSetting.TargetDatasource = m_desDatasource; worSetting.TargetWorkspace = m_workspace; m_dataImport.ImportSettings.Add(worSetting); m_dataImport.Run(); m_mapControl.Map.Close(); m_mapControl.Map.Open(m_workspace.Maps[0]); m_mapControl.Map.ViewEntire(); m_mapControl.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
internal static ImportResult ImportShpToDatasource(string filePath, Datasource datasource, string targetTableName) { ImportSettingSHP importSettingSHP = new ImportSettingSHP(); importSettingSHP.IsAttributeIgnored = false; importSettingSHP.IsImportAs3D = false; //设置当同名数据集存在时导入的模式,如果存在名字冲突,则覆盖(Overwrite) importSettingSHP.ImportMode = ImportMode.Overwrite; //设置需要导入的数据路径信息 importSettingSHP.SourceFilePath = filePath; //设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码 importSettingSHP.SourceFileCharset = Charset.ANSI; //设置要导入的目标数据源 importSettingSHP.TargetDatasource = datasource; //设置目标数据集名称 importSettingSHP.TargetDatasetName = targetTableName; importSettingSHP.TargetEncodeType = EncodeType.None; DataImport importer = new DataImport(); importer.ImportSettings.Add(importSettingSHP); //数据导入mysql数据库 ImportResult result = importer.Run(); return(result); }
/// <summary> ///udb中导入shp /// </summary> /// <param name="importPath"></param> public string ImportShp(string importPath, DatasourceConnectionInfo info) { try { string name = importPath.Substring(importPath.LastIndexOf("\\")+1); //wks.Datasources.Open(info); // 1. 构建数据源连接对象。 // info.Database = @"G:\数据转换\测试数据\Test\text.udb";数据库型 //DatasourceConnectionInfo info = new DatasourceConnectionInfo(); //info.Server = sourceUDB;//如@"G:\数据转换\测试数据\Test\text.udb"; ImportSettingSHP importSettingSHP = new ImportSettingSHP(); importSettingSHP.ImportMode = ImportMode.Overwrite;//可复写 importSettingSHP.SourceFilePath = importPath; importSettingSHP.TargetDatasourceConnectionInfo = info; //importSettingSHP.IsAttributeIgnored = false; // 3. 获取导入设置对象的导入信息集合(ImportDataInfos),设置目标数据集的名字。默认为原名 //ImportDataInfo dataInfos = importSettingSHP.GetTargetDataInfos(""); //importSettingSHP.SetTargetDataInfos(dataInfos); // 4. 构建数据导入类对象(DataImport),构建并设置导入设置对象集合。 DataImport import1 = new DataImport(); ImportSettings settings = import1.ImportSettings; settings.Add(importSettingSHP); ImportResult dd = import1.Run(); i++; if (dd.FailedSettings.Length != 0) return "【shp数据导入】" + name + "导入失败!请检查数据是否含有有效记录。\t\n"; return null; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }
public void ImportToShp() { //-------------数据库打开工作空间 workspace1 = new SuperMap.Data.Workspace(); workspace1.Open(gkfqd.Common.Tool.GetConnectionInfo()); importDatasource = workspace1.Datasources[gkfqd.Common.Tool.GetWorkspaceDataDatasources()]; dataImport = new DataImport(); try { dataImport.ImportSettings.Clear(); //ImportSettingSHP shpSetting = new ImportSettingSHP(); ImportSettingBMP bmpSetting = new ImportSettingBMP(); bmpSetting.ImportMode = ImportMode.Overwrite; string str = System.IO.Directory.GetCurrentDirectory(); //复制选择文件到临时文件夹,目的是重命名文件,导入到数据库指定文件中 String targetPath = str + "\\tempFolder\\temp_gkfqd01.bmp"; bmpSetting.SourceFilePath = targetPath; bmpSetting.TargetDatasource = importDatasource; dataImport.ImportSettings.Add(bmpSetting); dataImport.Run(); mapControl1.Map.ViewEntire(); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); MessageBox.Show(ex.Message); } }
private void ImportShpDirectly(string filePath) { Workspace workspace = new Workspace(); DatasourceConnectionInfo info = new DatasourceConnectionInfo(); //mysql数据源 //设置数据源连接的引擎类型 info.EngineType = EngineType.MySQL; //设置数据库连接字符串 info.Server = server; info.Database = database; info.User = userName; info.Password = password; info.Driver = driver; info.IsAutoConnect = true; info.Alias = "MySQL"; //不能为空 // 打开数据库数据源 //超图sdk不能直接连接空数据库,需要使用Create方法新建数据库,才有超图“系统表” Datasource datasource = workspace.Datasources.Open(info); if (datasource != null) { ImportSettingSHP importSettingSHP = new ImportSettingSHP(); importSettingSHP.IsAttributeIgnored = false; importSettingSHP.IsImportAs3D = false; //设置当同名数据集存在时导入的模式,如果存在名字冲突,则覆盖(Overwrite) importSettingSHP.ImportMode = ImportMode.Overwrite; //设置需要导入的数据路径信息 importSettingSHP.SourceFilePath = filePath; //设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码 importSettingSHP.SourceFileCharset = Charset.ANSI; //设置要导入的目标数据源 importSettingSHP.TargetDatasource = datasource; //设置目标数据集名称 importSettingSHP.TargetDatasetName = targetTableName; importSettingSHP.TargetEncodeType = EncodeType.None; DataImport importer = new DataImport(); importer.ImportSettings.Add(importSettingSHP); //数据导入mysql数据库 ImportResult result = importer.Run(); if (result.FailedSettings.Length == 0) { Console.WriteLine($"导入{filePath}成功!"); } else { Console.WriteLine($"导入{filePath}失败!"); } } // 释放工作空间资源 info.Dispose(); workspace.Dispose(); }
/// <summary> /// 导入为shp /// </summary> public void ImportToShp() { //-------------数据库打开工作空间 workspace1 = new SuperMap.Data.Workspace(); /* WorkspaceconnectionInfo workspaceconnectionInfo = new WorkspaceconnectionInfo(); * workspaceconnectionInfo.Type = WorkspaceType.Oracle; * workspaceconnectionInfo.Server = "ORCL"; * workspaceconnectionInfo.Database = ""; * workspaceconnectionInfo.Name = "workspace"; * workspaceconnectionInfo.User = "******"; * workspaceconnectionInfo.Password = "******"; * workspace1.Open(workspaceconnectionInfo);*/ workspace1.Open(gkfqd.Common.Tool.GetConnectionInfo()); importDatasource = workspace1.Datasources[gkfqd.Common.Tool.GetWorkspaceDataDatasources()]; dataImport = new DataImport(); try { dataImport.ImportSettings.Clear(); ImportSettingSHP shpSetting = new ImportSettingSHP(); shpSetting.ImportMode = ImportMode.Overwrite; string str = System.IO.Directory.GetCurrentDirectory(); //复制选择文件到临时文件夹,目的是重命名文件,导入到数据库指定文件中 String targetPath = str + "\\tempFolder\\temp_gkfqd.shp"; shpSetting.SourceFilePath = targetPath; shpSetting.TargetDatasource = importDatasource; dataImport.ImportSettings.Add(shpSetting); dataImport.Run(); importResultShp = importDatasource.Datasets["temp_gkfqd"] as DatasetVector; mapControl1.Map.Workspace = workspace1; mapControl1.Map.Layers.Clear(); mapControl1.Map.Layers.Add(importResultShp, true); mapControl1.Map.ViewEntire(); mapControl1.Map.Refresh(); } catch (Exception ex) { Trace.WriteLine(ex.Message); MessageBox.Show(ex.Message); } RefreshDataGridView(); }
/// <summary> /// 导入为Dwg /// </summary> public void ImportToDwg() { //----------- this.fileWorkspace = new SuperMap.Data.Workspace(); //打开工作空间及地图 WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"..\..\template\temp.smwu"); fileWorkspace.Open(conInfo); dataImport = new DataImport(); // m_srcDatasource = fileWorkspace.Datasources["temp"]; importDatasource = fileWorkspace.Datasources["temp"]; //---------- try { dataImport.ImportSettings.Clear(); ImportSettingDWG dwgSetting = new ImportSettingDWG(); dwgSetting.ImportMode = ImportMode.Append; //dwgSetting.SourceFilePath = @"..\..\SampleData\DataExchange\DwgImport\Polyline.dwg"; dwgSetting.SourceFilePath = imgPath; dwgSetting.TargetDatasource = importDatasource; dwgSetting.ImportingAsCAD = true; dataImport.ImportSettings.Add(dwgSetting); dataImport.Run(); DatasetVector importResult = importDatasource.Datasets["Polyline"] as DatasetVector; this.mapControl1.Map.Workspace = fileWorkspace; mapControl1.Map.Layers.Clear(); mapControl1.Map.Layers.Add(importResult, true); mapControl1.Map.ViewEntire(); mapControl1.Map.Refresh(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
public string ImportCSV(string targetName,string importPath, DatasourceConnectionInfo info) { try { ImportSettingCSV importSettingCSV = new ImportSettingCSV(); importSettingCSV.ImportMode = ImportMode.Overwrite;//可复写 importSettingCSV.FirstRowIsField = true; importSettingCSV.SourceFilePath = importPath; importSettingCSV.TargetDatasourceConnectionInfo = info; importSettingCSV.TargetDatasetName = targetName; DataImport import1 = new DataImport(); import1.ImportSettings.Add(importSettingCSV); ImportResult dd= import1.Run();//.GetSucceedDatasetNames(importSettingCSV); if(dd.FailedSettings.Length!=0) return "【属性表导入】"+targetName+"导入失败!请检查数据是否含有有效记录。\t\n"; return null; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }
public void ImportTIFFTest(string importPath, string sourceUDB) { try { // 1. 构建数据源连接对象。 DatasourceConnectionInfo info = new DatasourceConnectionInfo(); info.Server = sourceUDB; WorkspaceConnectionInfo ConnectionInfo = new WorkspaceConnectionInfo(sourceUDB); SuperMap.Data.Workspace wps = new SuperMap.Data.Workspace(); wps.Create(ConnectionInfo); Datasources ds = wps.Datasources; //ds.Open(info); Datasource dss = ds.Create(info); // new Datasource(); //dss.Connect(); // 2. 构建SHP导入设置对象(ImportSettingSHP),设置数据源,设置导入数据路径。 ImportSettingTIF importSettingTIF = new ImportSettingTIF(); importSettingTIF.ImportMode = ImportMode.Overwrite;//可复写 importSettingTIF.SourceFilePath = importPath; importSettingTIF.TargetDatasourceConnectionInfo = info; importSettingTIF.ImportingAsGrid = true;//栅格数据集形式 // 3. 获取导入设置对象的导入信息集合(ImportDataInfos),设置目标数据集的名字。 // ImportDataInfo dataInfos = importSettingSHP.GetTargetDataInfos(""); //importSettingSHP.SetTargetDataInfos(dataInfos); // 4. 构建数据导入类对象(DataImport),构建并设置导入设置对象集合。 PrjCoordSys prj = new PrjCoordSys(); prj.Type = PrjCoordSysType.SphereMercator; importSettingTIF.TargetPrjCoordSys = prj;//设置了参考投影,还需改变其投影转换 //prj.GeoCoordSys.FromXML(readXML()) DataImport import1 = new DataImport(); ImportSettings settings = import1.ImportSettings; settings.Add(importSettingTIF); import1.Run(); try { int m = importPath.LastIndexOf('\\'); string dsName = importPath.Substring(m + 1); int n = dsName.LastIndexOf('.'); string dsname = dsName.Substring(0, n); Datasets datasets = dss.Datasets; Dataset m_processDataset = datasets[dsname]; PrjCoordSys prj1 = new PrjCoordSys(); prj1.FromXML(readXML(@"G:\移动风险监测\参考坐标\CGCS_2000.xml")); Boolean result = CoordSysTranslator.Convert(m_processDataset, prj1, new CoordSysTransParameter(), CoordSysTransMethod.GeocentricTranslation); } catch (Exception ex) { MessageBox.Show(ex.Message); } i++; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// udb中导入tiff /// </summary> /// <param name="importPath"></param> public string ImportTIFF(string importPath, DatasourceConnectionInfo info) { try { string name = importPath.Substring(importPath.LastIndexOf("\\") + 1); // 1. 构建数据源连接对象。 //DatasourceConnectionInfo info = new DatasourceConnectionInfo(); //info.Server = sourceUDB; // 2. 构建SHP导入设置对象(ImportSettingSHP),设置数据源,设置导入数据路径。 //info.Password = "******"; ImportSettingTIF importSettingTIF = new ImportSettingTIF(); //m_workspace.Datasources.Open(info); importSettingTIF.ImportMode = ImportMode.Overwrite;//可复写 importSettingTIF.SourceFilePath = importPath; importSettingTIF.TargetDatasourceConnectionInfo = info; importSettingTIF.ImportingAsGrid = true;//栅格数据集形式 // 3. 获取导入设置对象的导入信息集合(ImportDataInfos),设置目标数据集的名字。 // ImportDataInfo dataInfos = importSettingSHP.GetTargetDataInfos(""); //importSettingSHP.SetTargetDataInfos(dataInfos); // 4. 构建数据导入类对象(DataImport),构建并设置导入设置对象集合。 //string prjRef = @"G:\移动风险监测\参考坐标\CGCS_2000.xml"; PrjCoordSys prj = new PrjCoordSys(); // prj.FromFile(prjRef, PrjFileType.SuperMap); prj.Type = PrjCoordSysType.SphereMercator; importSettingTIF.TargetPrjCoordSys = prj;//设置了参考投影,还需改变其投影转换 DataImport import1 = new DataImport(); ImportSettings settings = import1.ImportSettings; settings.Add(importSettingTIF); ImportResult dd= import1.Run(); i++; if (dd.FailedSettings.Length != 0) return "【tif数据导入】" + name + "导入失败!请检查数据是否有效。\t\n"; return null; } catch (Exception ex) { MessageBox.Show(ex.Message); return null; } }
public override void Run() { try { //// WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(@"D:\Program Files (x86)\SuperMap\SuperMap iDesktop 7C\SampleData\World\World.smwu"); // WorkspaceControl workspaceControl // = SuperMap.Desktop.Application.ActiveApplication.MainForm.DockBarManager[typeof(WorkspaceControlManager)].Control as WorkspaceControl; // if (workspaceControl != null) // { // workspaceControl.ResourcesNodeVisible = false; // workspaceControl.LayoutsNodeVisible = false; // //workspaceControl.WorkspaceTree.Workspace.Open(conInfo); // WorkspaceConnectionInfo conInfo1 = new WorkspaceConnectionInfo(@"..\..\Default.smwu"); // //workspaceControl.WorkspaceTree.Workspace.Create(conInfo1); // //workspaceControl.WorkspaceTree.Workspace.Close(); // //workspaceControl.WorkspaceTree.Workspace.Dispose(); // bool dd= workspaceControl.WorkspaceTree.Workspace.Open(conInfo1); // workspaceControl.WorkspaceTree.Workspace.Datasources.Create() // //workspaceControl.Update(); // //workspaceControl.WorkspaceTree.WorkspaceNode.Nodes.Add("dafsaf"); // // workspaceControl.WorkspaceTree.Update(); // } // System.Windows.Forms.MessageBox.Show("LoadImageCtrlAction"); //IFormMap activeMapForm = Application.ActiveForm as IFormMap; //MapControl activeMap = activeMapForm.MapControl; //IFormManager dd= Application.ActiveApplication.MainForm.FormManager; //for (int i = 0; i < dd.Count; i++) //{ //} WorkspaceControl workspaceControl = SuperMap.Desktop.Application.ActiveApplication.MainForm.DockBarManager[typeof(WorkspaceControlManager)].Control as WorkspaceControl; Datasource targetDatasource; DatasourceConnectionInfo dataSourceConnectionInfo = new DatasourceConnectionInfo(); dataSourceConnectionInfo.Server = @"..\..\Default"; if (workspaceControl != null) { workspaceControl.ResourcesNodeVisible = false; workspaceControl.LayoutsNodeVisible = false; Form1 form1 = new Form1(); form1.Show(); try { bool isExist = workspaceControl.WorkspaceTree.Workspace.Datasources.Contains(dataSourceConnectionInfo.Alias); if (isExist) { targetDatasource = workspaceControl.WorkspaceTree.Workspace.Datasources[dataSourceConnectionInfo.Alias]; } else { targetDatasource = workspaceControl.WorkspaceTree.Workspace.Datasources.Open(dataSourceConnectionInfo); } } catch (Exception ex1) { targetDatasource = workspaceControl.WorkspaceTree.Workspace.Datasources.Create(dataSourceConnectionInfo); } OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "影像文件(*.tif)|*.*"; ofd.ValidateNames = true; ofd.CheckPathExists = true; ofd.CheckFileExists = true; ofd.ShowHelp = true; //ofd.HelpRequest += ofd_HelpRequest; if (ofd.ShowDialog() == DialogResult.OK) { string strFileName = ofd.FileName; //其他代码 DataImport m_dataImport = new DataImport(); m_dataImport.ImportSettings.Clear(); //ImportSettingIMG imgSetting = new ImportSettingIMG(); //imgSetting.ImportMode = ImportMode.Overwrite; //imgSetting.SourceFilePath = @"..\..\SampleData\DataExchange\ImgImport\Multibands.img"; //imgSetting.TargetDatasource = m_desDatasource; //imgSetting.MultiBandImportMode = MultiBandImportMode.MultiBand; //m_dataImport.ImportSettings.Add(imgSetting); //m_dataImport.Run(); //DatasetImage importResult = m_desDatasource.Datasets["Multibands"] as DatasetImage; //LayerSettingImage layerSetting = new LayerSettingImage(); //layerSetting.DisplayBandIndexes = new Int32[] { 3, 2, 1 }; //layerSetting.DisplayColorSpace = ColorSpaceType.RGB; ImportSettingTIF importSetingTif = new ImportSettingTIF(); importSetingTif.ImportMode = ImportMode.Overwrite; importSetingTif.SourceFilePath = strFileName; PrjCoordSys prgCoord = importSetingTif.GetSourcePrjCoordSys(); Charset pCharset = importSetingTif.SourceFileCharset; ImportDataInfos importDataInfoTif = importSetingTif.GetTargetDataInfos(""); importSetingTif.SetTargetDataInfos(importDataInfoTif); //ImportDataInfoTIF importDataInfoTif1 = null; importSetingTif.TargetDatasource = targetDatasource; m_dataImport.ImportSettings.Add(importSetingTif); m_dataImport.Run(); } } } catch (Exception ex) { SuperMap.Desktop.Application.ActiveApplication.Output.Output(ex.StackTrace); } }