using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.GeoAnalyst;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
/*
* 表面分析 ArcEngine + C#
* 2011.3.10 xyj
* wxuyongjun@163
*
* */
namespace SpatialAnalysis.Surface_Analysis
{
class SurfaceCommonFunction
{
/// <summary>
/// 创建等值线
/// </summary>
/// <param name="raster"></param>栅格集
/// <param name="contourList"></param>等值间隔
/// <param name="smooth"></param>是否平滑
/// <param name="maxDeviation"></param>平滑的最大背离值 
/// <param name="contourLineClass"></param>等值线矢量要素集
/// <param name="pGeoDataset"></param>地理要素集
public static void CreateRasterContour(IRaster raster, double[] contourList, bool smooth, double maxDeviation, out IFeatureClass contourLineClass, out IGeoDataset pGeoDataset)
{
RasterSurfaceOpClass class2 = new RasterSurfaceOpClass();
object missing = System.Type.Missing;
object contoursArray = contourList;
IGeoDataset geoDataset = raster as IGeoDataset;
pGeoDataset = class2.ContourList(geoDataset, ref contoursArray);
contourLineClass = pGeoDataset as IFeatureClass;
IFields fields = contourLineClass.Fields;
IField[] fieldArray = new IField[fields.FieldCount];
for (int i = 0; i < fields.FieldCount; i++)
{
fieldArray[i] = _Field(i);
}
if (smooth)
{
IFeatureCursor o = contourLineClass.Search(null, false);
if (o != null)
{
IFeature feature = o.NextFeature();
for (int j = 0; feature != null; j++)
{
IPolyline shape = feature.Shape as IPolyline;
shape.Smooth(maxDeviation);
feature.Shape = shape;
feature.Store();
feature = o.NextFeature();
}
System .Runtime .InteropServices .  Marshal.ReleaseComObject(o);
}
else
{
System .Windows .Forms .  MessageBox.Show("生成的等值线条数为 0");
}
}
}
/// <summary>
/// 创建坡度集
/// </summary>
/// <param name="raster"></param>栅格数据
/// <param name="zFactor"></param>拉伸系数
/// <param name="type"></param>记
录类型{度,百分比}
/// <param name="pGeoDataset"></param>坡度集
public static void  CreateRasterSlope(IRaster raster, float zFactor,int type, out IGeoDataset pGeoDataset)
{
try
{
RasterSurfaceOpClass class2 = new RasterSurfaceOpClass();
object o = zFactor;
IGeoDataset geoDataset = raster as IGeoDataset;
//坡度记录方式{ 度,上升的百分比}
esriGeoAnalysisSlopeEnum geoType;
//如果为1,则记录为增长百分比
if (type == 1)
{
geoType = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise;
}
else //默认用度来记录
{
geoType = esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees;
}
//坡度提取
pGeoDataset = class2.Slope(geoDataset, geoType, ref o);
}
catch (Exception ex)
{
pGeoDataset = null;
System.Windows.Forms.MessageBox.Show("坡度提取错误,原因:"+ex.Message , "错误提示");
}
}
/// <summary>
/// 坡向计算
/// </summary>
/// <param name="raster"></param>高程数据
/// <param name="pGeoDataset"></param>结果数据集
public static void CreateRasterAspect(IRaster raster, out IGeoDataset pGeoDataset)
param name
{
try
{
RasterSurfaceOpClass class2 = new RasterSurfaceOpClass();               
IGeoDataset geoDataset = raster as IGeoDataset;
//坡向提取
pGeoDataset = class2.Aspect (geoDataset );
}
catch (Exception ex)
{
pGeoDataset = null;
System.Windows.Forms.MessageBox.Show("坡向提取错误,原因:" + ex.Message, "错误提示");
}
}
// <summary>
/// 获取所有的格网图层
/// </summary>
/// <param name="pMapControl"></param>
/// <returns></returns>
public static  IArray GetRasterLyrs(IMapControl2 pMapControl)
{
try
{
//ESRI图层数组
ESRI.ArcGIS.esriSystem.IArray array = new ArrayClass();
//遍历地图,出所有的栅格数据图层
for (int i = 0; i <= (pMapControl.Map.LayerCount - 1); i++)
{
ILayer layer = _Layer(i);
if (layer is IRasterLayer)
{
array.Add(_Layer(i));
}
else if (layer is IGroupLayer)
{
ICompositeLayer layer2 = layer as ICompositeLayer;
for (int j = 0; j < layer2.Count; j++)
{
ILayer unk = _Layer(j);
if (unk is IRasterLayer)
{
array.Add(unk);
}
}
}
}
return array;
}
catch
{
return null;
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。