您的位置:首页 > 其它

由等高线生成TIN并由TIN生成坡度图【解决中文环境翻译差别的问题】(转载请注明出自博客园)

2010-02-02 15:18 645 查看
由等高线等生成TIN并生成坡度图的代码。在softline代码段对错误信息作了处理,不再使用“软线”,“软性线”,“柔性线”,“软断线”等固定翻译编写代码。

需要添加的引用

ESRI.ArcGIS.ADF;
ESRI.ArcGIS.Analyst3DTools;
ESRI.ArcGIS.Carto;
ESRI.ArcGIS.DataSourcesFile;
ESRI.ArcGIS.DataSourcesGDB;
ESRI.ArcGIS.esriSystem;
ESRI.ArcGIS.Geodatabase;
ESRI.ArcGIS.Geoprocessing;
ESRI.ArcGIS.Geoprocessor;

/// <summary>

/// 创建TIN

/// </summary>

/// <returns></returns>

private bool Createtin()

{////(转载请注明出自博客园)

string mdbPath = @"D:\TESTDATA\spacial data.mdb";

string layerName = "DGX";

string gcField = "BSGC";////高程字段名

string TinPath = @"D:\TESTDATA\TIN";////目标TIN路径

bool result = false;

IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();

if (pWorkspaceFactory != null)

{

pWorkspace = pWorkspaceFactory.OpenFromFile(mdbPath, 0);

////异常来自 HRESULT:0x80040228 解决办法:加license控件!!

}

IFeatureClass pFeatureClass_DGX = null;

IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

try

{

pFeatureClass_DGX = pFeatureWorkspace.OpenFeatureClass(layerName);

}

catch

{

pFeatureClass_DGX = null;

}

if (pFeatureClass_DGX == null)

{

return result;

}

CreateTin createTinProcess = new CreateTin();

createTinProcess.out_tin = TinPath;

createTinProcess.spatial_reference = (pFeatureClass_DGX as IGeoDataset).SpatialReference;

if (Directory.Exists(TinPath))

{////删除已经存在的TIN

Directory.Delete(TinPath, true);

}

else

{////创建存放TIN的文件夹

string parentPath = Directory.GetParent(TinPath).FullName;

if (!Directory.Exists(parentPath))

{

Directory.CreateDirectory(parentPath);

}

}

string message = "";

if (Execute(createTinProcess, out message))

{

IFeatureLayer layer = new FeatureLayerClass();

layer.FeatureClass = pFeatureClass_DGX;

layer.Name = pFeatureClass_DGX.AliasName;

GPUtilitiesClass gpUtil = new GPUtilitiesClass();

gpUtil.AddInternalLayer(layer as ILayer);

int index = -1;

index = pFeatureClass_DGX.Fields.FindField(gcField);

if (index >= 0)

{

IField field = pFeatureClass_DGX.Fields.get_Field(index);

string in_featuresPortion1 = layer.Name + " " + field.AliasName + " <None> ";

string in_featuresPortion2 = "softline";

EditTin editTinProcess = new EditTin();

editTinProcess.in_tin = TinPath;

for (int i = 0; i < 2; i++)

{

string in_features = in_featuresPortion1 + in_featuresPortion2 + " false ";

editTinProcess.in_features = in_features;

if (Execute(editTinProcess, out message))

{

result = true;////创建TIN成功

break;

}

else

{

string[] subMessages = message.Split(new char[] { '\n' });

string rightParaInfo = "ERROR 000800: The value is not a member of %s.";

if (subMessages[3] == rightParaInfo)

{

if (subMessages[4] == rightParaInfo)

{

if (subMessages[5] == rightParaInfo)

{

if (subMessages[6] == rightParaInfo)

{

}

else

{

////参数4错误

}

}

else

{

////处理由于中文环境或其他语言环境中softline翻译不同带来的问题

string paras = subMessages[5];

paras = paras.Replace("ERROR 000800: The value is not a member of", string.Empty).Trim(new char[] { '.' });

string[] parameters = paras.Split(new char[] { '|' });

if (parameters.Length == 3)

{

in_featuresPortion2 = parameters[2].Trim();

continue;

}

else

{

////未知错误

result = false;

throw new Exception(message);

}

}

}

else

{

////高程字段名称错误

}

}

else

{

////图层名称错误

}

result = false;

throw new Exception(message);

}

}

}

else

{

result = false;

}

}

else

{

result = false;

}

return result;

}

/// <summary>

/// 创建坡度图

/// </summary>

/// <returns></returns>

private bool CreateSlope()

{////(转载请注明出自博客园)

string tinPath = @"D:\TESTDATA\tin";////TIN路径

string classBreaksTablePath = @"D:\TESTDATA\class breaks table.txt";////分段表

string slopePath = @"D:\TESTDATA\pdt.shp";////坡度图路径

bool result = false;

List<string> fileList = new List<string>();

////可加入删除已存在坡度图的代码段

TinSlope tinSlopeProcess = new TinSlope();

tinSlopeProcess.in_tin = tinPath;

tinSlopeProcess.out_feature_class = slopePath;

tinSlopeProcess.units = "DEGREE";

tinSlopeProcess.class_breaks_table = classBreaksTablePath;

string message = "";

if (Execute(tinSlopeProcess, out message))

{

result = true;

}

else

{

result = false;

}

return result;

}

public bool Execute(IGPProcess GPProcess, out string message)

{////(转载请注明出自博客园)

message = "";

bool result = false;

IGeoProcessorResult ProcessorResult = null;

Geoprocessor Processor = new Geoprocessor();

ProcessorResult = (IGeoProcessorResult)Processor.Execute(GPProcess, null);

if (ProcessorResult != null && ProcessorResult.Status == esriJobStatus.esriJobSucceeded)

{

result = true;

}

else

{

result = false;

}

object obj = new object();

if (message != null)

{

if (Processor != null)

{

message = Processor.GetMessages(ref obj);

}

else

{

message = "";

}

}

return result;

}////(转载请注明出自博客园)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: