ArcEngine 栅格数据另存结果空白

软件版本:ArcEngine10.2.2
测试数据:链接:https://pan.baidu.com/s/1o8mmaXO 密码:e8rg
0.png

操作步骤:
1.加载测试数据TAS_IPAS_IBC_20171204162303721.tif(注:该图层有五个波段)
2.调用ISaveas2 接口另存为jpg数据
1.png

输出结果:输出的结果识别像素值为4095
2.png

代码:
		/// <summary>
/// 执行另存
/// </summary>
/// <param name="bSetRepresentationType"></param>
/// <param name="representationType"></param>
/// <param name="bUseMessagebox"></param>
/// <returns></returns>
public bool SaveAs(bool bSetRepresentationType = false, rstRepresentationType representationType = rstRepresentationType.DT_ATHEMATIC, bool bUseMessagebox = true)
{
object objValue = m_checkedCmbBand.EditValue;
if (objValue == null)
{
XtraMessageBox.Show(AppMessage.MSG0070, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (string.IsNullOrEmpty(m_sOutputPath))
{
XtraMessageBox.Show(AppMessage.MSG0067, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}

FileInfo fileInfo = new FileInfo(m_sOutputPath);
if (fileInfo.Exists)
{
if (XtraMessageBox.Show(AppMessage.MSG0170, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
fileInfo.Delete();
}
else
{
return false;
}
}

IRaster raster = m_raster;
//获取输出波段
string bandNames = objValue.ToString().Split(',');
if (bandNames.Length != m_bandList.Count)
{
IRaster newRaster = ((m_raster as IRaster2).RasterDataset as IRasterDataset3).CreateRaster();
IRasterProps newRasterProps = newRaster as IRasterProps;
newRasterProps.Width = (m_raster as IRasterProps).Width;
newRasterProps.Height = (m_raster as IRasterProps).Height;
IRasterBandCollection newBandColl = newRaster as IRasterBandCollection;
IRasterBandCollection originBandColl = (m_raster as IRaster2).RasterDataset as IRasterBandCollection;
for (int i = 0; i < originBandColl.Count; i++)
{
IRasterBand band = originBandColl.Item(i);
foreach (string sBandName in bandNames)
{
if (sBandName.Trim() == band.Bandname)
{
newBandColl.AppendBand(band);
break;
}
}
}
raster = newRaster;
}
//选择重采样类型
SetResamplingMethod(raster, m_cmbResamplingType);
//设置像素类型
SetPixelType(raster, m_cmbPixelType);
//设置图像连续性
if (bSetRepresentationType)
{
SetRepresentationType(raster, representationType);
}

DevExpress.Utils.WaitDialogForm dlg = new DevExpress.Utils.WaitDialogForm(AppMessage.MSG0073, AppMessage.MSG0000);
IWorkspace workspace = null;
string sResult = AppMessage.MSG0074;
HTES.TAS.Log.Logger logger = new TAS.Log.Logger();
try
{
dlg.Owner = m_frm;
dlg.TopMost = false;
string sFormat = m_cmbOutputType.Text;
ISaveAs2 saveAs = raster as ISaveAs2;
if (!saveAs.CanSaveAs(sFormat))
{
XtraMessageBox.Show(AppMessage.MSG0075, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
IWorkspaceFactory worksapceFactory = new RasterWorkspaceFactoryClass();
workspace = worksapceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(m_sOutputPath), 0);
IDataset dataset = saveAs.SaveAs(System.IO.Path.GetFileName(m_sOutputPath), workspace, sFormat);
Marshal.ReleaseComObject(dataset);
return true;
}
catch (Exception ep)
{
sResult = AppMessage.MSG0076;
logger.Log(HTES.TAS.DB.Model.LogLevel.Error, HTES.TAS.DB.Model.EventType.UserManagement, m_frm.Text, ep);
return false;
}
finally
{
if (workspace != null)
{
Marshal.ReleaseComObject(workspace);
}
dlg.Close();
if (bUseMessagebox)
{
XtraMessageBox.Show(sResult, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

private void SetResamplingMethod(IRaster raster, ComboBoxEdit cmbResamplingType)
{
if (cmbResamplingType == null)
{
return;
}
switch ((ResamplingMethod)cmbResamplingType.SelectedIndex)
{
case ResamplingMethod.NEARSET:
raster.ResampleMethod = rstResamplingTypes.RSP_NearestNeighbor;
break;
case ResamplingMethod.BILINEAR:
raster.ResampleMethod = rstResamplingTypes.RSP_BilinearInterpolation;
break;
case ResamplingMethod.CUBIC:
raster.ResampleMethod = rstResamplingTypes.RSP_CubicConvolution;
break;
case ResamplingMethod.Majority:
raster.ResampleMethod = rstResamplingTypes.RSP_Majority;
break;
}
}

private void SetPixelType(IRaster raster, ComboBoxEdit cmbPixelType)
{
if (cmbPixelType == null)
{
return;
}
IRasterProps rasterProps = raster as IRasterProps;
switch ((PixelType)cmbPixelType.SelectedIndex)
{
case PixelType.Pt_char:
rasterProps.PixelType = rstPixelType.PT_CHAR;
rasterProps.NoDataValue = 127;
break;
case PixelType.Pt_uchar:
rasterProps.PixelType = rstPixelType.PT_UCHAR;
rasterProps.NoDataValue = 128;
break;
case PixelType.Pt_short:
rasterProps.PixelType = rstPixelType.PT_SHORT;
break;
case PixelType.Pt_ushort:
rasterProps.PixelType = rstPixelType.PT_USHORT;
break;
case PixelType.Pt_long:
rasterProps.PixelType = rstPixelType.PT_LONG;
break;
case PixelType.Pt_ulong:
rasterProps.PixelType = rstPixelType.PT_ULONG;
break;
case PixelType.Pt_float32:
rasterProps.PixelType = rstPixelType.PT_FLOAT;
break;
case PixelType.Pt_float64:
rasterProps.PixelType = rstPixelType.PT_DOUBLE;
break;
}
}

private void SetRepresentationType(IRaster raster, rstRepresentationType rasterRepresentationType)
{
IRasterBandCollection rasterBandColl = (raster as IRaster2).RasterDataset as IRasterBandCollection;
if (rasterBandColl == null)
{
return;
}
for (int i = 0; i < rasterBandColl.Count; i++)
{
rasterBandColl.Item(i).RepresentationType = rasterRepresentationType;
}
}

问题:
不知道是我代码哪儿写错了,输出的结果不对
已邀请:

朱新颖

赞同来自:

1,存储在GDB中试试
2,最好不要有中文路径,并且文件名称最好字母或下划线开头

石羽

赞同来自:

利用LayerExport可能会比较方便,原来的问题应该直接用rasterdataset对象进行saveas,我印象中create raster得到的raster只有三波段,通常只用来显示

要回复问题请先登录注册