使用产品: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;
}
}