iobject 使用镶嵌数据集的方法加载影像数据到图层,加载多个影像数据时报错

0 投票

使用产品:iobject.net 10i操作系统:win10 x64
数据类型:影像数据
问题详细描述:使用c#进行组件开发,加载影像数据时选择了先创建镶嵌数据集,在把镶嵌数据集加入到map里,但是加载单个影像数据不会出问题,多加载几个就报错
问题重现步骤: 1.加载多个影像数据

以下为报错提示:

以下是代码:

 private void btnImportDOM_Click(object sender, EventArgs e)
        {
            if (comDatasource.Text == "")
            {
                MessageBox.Show("请选择目标数据源!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (txtDatasets.Text == "")
            {
                MessageBox.Show("请设置源数据集名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (txtPrj2.Text == "")
            {
                MessageBox.Show("请设置坐标系!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            this.Cursor = Cursors.WaitCursor;
            labeltxt.Visible = true;

            DatasetMosaic pDatasetMosaic = CreateMosaic(prjCoordSys, SourceFilePath, txtDatasets.Text);
            AddDatasetMosaicToMAP(pDatasetMosaic, m_mapControl, true);

       
            this.Cursor = Cursors.Default;

            this.Close();

        }
        internal DatasetMosaic CreateMosaic(PrjCoordSys prj, string[] files, string datasetname)
        {
            DatasetMosaic datasetMosaic=null;
            if (m_workspace.Datasources.Count == 0)
            {
                MessageBox.Show("请先打开一个数据源");
                return null;
            }
            Datasource datasource = m_workspace.Datasources[0];

            if (datasource.Datasets.Contains(datasetname))
            {
                bool issuccessdelete = false;
                try
                {
                    issuccessdelete = datasource.Datasets.Delete(datasetname);
                }
                catch (Exception ex)
                {
                    bool aa = datasource.Datasets.Contains(datasetname);
                    if (!aa)
                    {
                        MessageBox.Show("当前数据源内已经不存在数据集:" + datasetname);
                    }
                }
            }           
          
            datasetMosaic = datasource.Datasets.CreateMosaic(datasetname, prj);
        
            if (datasetMosaic == null)
            {
                MessageBox.Show("数据集:" + datasetname + "创建失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return null;
            }

            //对镶嵌数据集的轮廓表扩充属性;
              bool AA = File.Exists(files[0]);
             datasetMosaic.AddFiles(files);

            String path = Path.GetDirectoryName(files[0]);           
            String overviewpath = path + "\\overview";
            //构建概视图
            String datasetMosaicOverviewPath = overviewpath + "\\" + datasetname + "\\";
            if (!System.IO.File.Exists(datasetMosaicOverviewPath))
            {
                DirectoryInfo directoryInfo = Directory.CreateDirectory(datasetMosaicOverviewPath);
            }
            bool buildOverview = datasetMosaic.BuildOverview(datasetMosaicOverviewPath, 5120, 5120, 3, true, 0);
            return datasetMosaic;
        }

        public static void AddDatasetMosaicToMAP(DatasetMosaic Dataset, MapControl mapControl, bool isEnsureVisible)//, Loading loadingform)
        {
            try
            {
                if (Dataset != null)
                {
                    mapControl.Map.Workspace = Dataset.Datasource.Workspace;
                    LayerMosaicGroup layerMosaicGroup = mapControl.Map.Layers.AddMosaicGroup(Dataset, true);
                    LayerMosaic layerMosaic = layerMosaicGroup.MosaicLayer;
                    LayerSettingImage layersetting = layerMosaic.SettingImage as LayerSettingImage;
                  //  layersetting.DisplayBandIndexes = new int[3] { 2, 1, 0 };
                    layersetting.DisplayBandIndexes = new int[3] { 0, 1, 2 };
                    if (Dataset.BandCount > 1)
                    {
                        layersetting.DisplayMode = ImageDisplayMode.Composite;
                    }
                    else
                    {
                        layersetting.DisplayMode = ImageDisplayMode.Stretched;
                    }
                    layersetting.DisplayColorSpace = ColorSpaceType.RGB;
                    layersetting.ImageInterpolationMode = ImageInterpolationMode.NearestNeighbor;

                    Dataset.BuildStatistics();

                    ImageStretchOption option = new ImageStretchOption();
                    if (Dataset.PixelFormat == PixelFormat.UBit8)
                    {
                        option.StretchType = ImageStretchType.None;
                    }
                    else
                    {
                        option.StretchType = ImageStretchType.StandardDeviation;
                    }
                    option.StandardDeviationStretchFactor = 1;

                    layersetting.ImageStretchOption = option;
                    layersetting.BackgroundColor = Color.FromArgb(0, 0, 0);
                    //layersetting.SpecialValueColor = Color.FromArgb(65535, 65535, 55537);
                    //layersetting.IsSpecialValueTransparent = true;
                    layersetting.IsBackgroundTransparent = true;
                    if (layerMosaicGroup.FootprintLayer != null)
                    {
                        layerMosaicGroup.FootprintLayer.IsVisible = false;
                        layerMosaicGroup.BoundaryLayer.IsVisible = false;
                    }
                    layerMosaicGroup[1].IsVisible = false;
                    if (isEnsureVisible)
                    {
                        mapControl.Map.EnsureVisible(layerMosaic);
                    }
                    mapControl.Map.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据加载失败" + ex.ToString(), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }

11月 24, 2020 分类:  140次浏览 | 用户: yzcccc (3 分)

1个回答

0 投票
你的意思是添加多个影像到一个镶嵌数据集中就报错?将这几个影像在桌面里面进行同样的操作,看会出现报错吗
11月 24, 2020 用户: 程逸诗 名扬四海 (4,378 分)
不是,我每次添加一个影像数据就会创建一个新的 XIANGQIAN 数据集
尝试过添加各种影像数据,都出现类似问题,然后将程序打包安装后加载影像数据闪退,没有报错信息
你好,问题解决了,我在测试的时候对同一个影像加载了多次,按道理是不应该加载多个同名影像的,所以应该算是我的操作失误
好的,解决了就好
...