首页 / 浏览问题 / 组件GIS / 问题详情
iObjects导出专题图。
588EXP 2017年01月11日
用户需要把多个专题图导出为CAD数据集并合并为一个数据集,用户代码如下,导出不成功,请问以下代码需要怎么修改?

public void export2DMap2Cad()
        {
            //生成临时内存数据集
            DatasourceConnectionInfo info = new DatasourceConnectionInfo();

            // 设置数据源位置为内存中,类型为UDB
            info.Server = ":memory:";
            info.EngineType = EngineType.UDB;
            info.Alias = "tmp_mem_ds_2DCAD";
            string dsName = "CADTmp";
            Datasource mem_ds = null;
            if (!this.workspace.Datasources.Contains(info.Alias))
                mem_ds = this.workspace.Datasources.Create(info);
            else
            {
                //mem_ds = parameter.workspace.Datasources.Open(info);
                mem_ds = this.workspace.Datasources[info.Alias];
            }
            if (mem_ds.Datasets.Contains(dsName))
            {
                mem_ds.Datasets.Delete(dsName);
            }
                            DatasetVectorInfo tmpCad = new DatasetVectorInfo();
                tmpCad.Type = DatasetType.CAD;
                tmpCad.Name = dsName;
                DatasetVector dataset = mem_ds.Datasets.Create(tmpCad);
                String outDatasetName = mem_ds.Datasets.GetAvailableDatasetName(dsName);

            //遍历Layer合并到数据集
            foreach (Layer layer in mapControl.Map.Layers)
            {
                try
                {
                    layer.ThemeToDatasetVector(mem_ds, outDatasetName);
                }
                catch (Exception e)
                {
                   
                }
            }
            //将数据集导出到CAD
            this.ExportToDXF(mem_ds, dsName);
            //删除不用的数据集
            mem_ds.Datasets.Delete(dsName);
        }

        public void ExportToDXF(Datasource datasource, string layername)
        {
            SaveFileDialog m_fileDialog;
            try
            {
                m_fileDialog = new SaveFileDialog();
                m_fileDialog.Filter = "dxf files(*.dxf)|*.dxf|dwg files(*.dwg)|*.dwg|All files(*.*)|*.*";
                //点了保存按钮进入
                if (m_fileDialog.ShowDialog() == DialogResult.OK)
                {
                    m_fileDialog.FilterIndex = 1;
                    //保存对话框是否记忆上次打开的目录
                    m_fileDialog.RestoreDirectory = true;
                    string localFilePath = m_fileDialog.FileName.ToString(); //获得文件路径
                    string aLastName = localFilePath.Substring(localFilePath.LastIndexOf(".") + 1, (localFilePath.Length - localFilePath.LastIndexOf(".") - 1));
                    // Datasource datasource = parameter.workspace.Datasources[0];                                        
                    if (aLastName == "dxf")
                    {
                        DatasetVector datasetVector = (DatasetVector)datasource.Datasets[layername];
                        // 2.构建DXF导出设置对象,设置导出文件路径,设置要导出的数据集。
                        ExportSettingDXF exportSettingDXF = new ExportSettingDXF();
                        exportSettingDXF.TargetFilePath = localFilePath;
                        exportSettingDXF.SourceData = datasetVector;
                        exportSettingDXF.TargetFileType = FileType.DXF;
                        // 3.构建DataExport对象,设置导出设置对象。
                        DataExport dataExport = new DataExport();
                        ExportSettings exportSettings = dataExport.ExportSettings;
                        exportSettings.Add(exportSettingDXF);
                        // 4.执行导出。
                        ExportResult result = dataExport.Run();
                        result.ToString();
                    }
                    else if (aLastName == "dwg")
                    {
                        DatasetVector datasetVector = (DatasetVector)datasource.Datasets[layername];
                        // 2.构建DXF导出设置对象,设置导出文件路径,设置要导出的数据集。
                        ExportSettingDWG exportSettingDWG = new ExportSettingDWG();
                        exportSettingDWG.TargetFilePath = localFilePath;
                        exportSettingDWG.SourceData = datasetVector;
                        exportSettingDWG.TargetFileType = FileType.DWG;
                        // 3.构建DataExport对象,设置导出设置对象。
                        DataExport dataExport = new DataExport();
                        ExportSettings exportSettings = dataExport.ExportSettings;
                        exportSettings.Add(exportSettingDWG);
                        // 4.执行导出。
                        ExportResult result = dataExport.Run();
                        result.ToString();
                    }
                    else
                    {
                        DatasetVector datasetVector = (DatasetVector)datasource.Datasets[layername];
                        // 2.构建DXF导出设置对象,设置导出文件路径,设置要导出的数据集。
                        ExportSettingDWG exportSettingDWG = new ExportSettingDWG();
                        exportSettingDWG.TargetFilePath = localFilePath;
                        exportSettingDWG.SourceData = datasetVector;
                        exportSettingDWG.TargetFileType = FileType.DWG;
                        // 3.构建DataExport对象,设置导出设置对象。
                        DataExport dataExport = new DataExport();
                        ExportSettings exportSettings = dataExport.ExportSettings;
                        exportSettings.Add(exportSettingDWG);
                        // 4.执行导出。
                        ExportResult result = dataExport.Run();
                        result.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

1个回答

//遍历Layer合并到数据集

foreach (Layer layer in mapControl.Map.Layers)
            {
                try
                {
                    DatasetVector datasetCAD = layer.ThemeToDatasetVector(mem_ds, outDatasetName);
                    if (datasetCAD !=null)
                    {
                        Recordset recordset=datasetCAD.GetRecordset(false,CursorType.Static);
                        dataset.Append(recordset);
                        recordset.Dispose();
                        mem_ds.Datasets.Delete(outDatasetName);
                        datasetCAD.Close();
                    }
                }
                catch (Exception e)
                {

                }
            }

这段代码修改一下

2EXP 2017年01月11日
你好,能不能具体帮忙改下代码?

修改的代码如上,ThemeToDatasetVector方法是把专题图图层转为CAD数据集,你要把所有的CAD用Append方法追加到一个数据集,然后在导出。

你好,根据你的方法把以上代码替换后,还是不成功,我们这边的客户为这个问题纠结1个多月了,麻烦你做个工作空间和调试成功的工程源码一起打包给我吧(718760045@qq.com),用户组件是iObject 8.1,多谢了!
代码测试过,没有问题。请检查地图中是否有单值专题图、分段专题图等专题图。调试程序看哪一步有问题。急用的话把数据发我2739150464@qq.com邮箱,我看下。下周一我会在我们资源中心上传范例,到时候你可以下载下来看下。
数据已发邮箱,谢谢!
...