由等高线生成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;
}////(转载请注明出自博客园)
需要添加的引用
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;
}////(转载请注明出自博客园)
相关文章推荐
- Ubuntu server 中文环境乱码问题的解决办法(转载)
- java 生成EXCEL 解决中文乱码问题(只供自己后面寻找方便)【转载悠悠的BOLG】
- java解压多目录Zip文件(解决中文乱码问题)--转载
- 解决Mantis中文环境下CSV导出乱码问题
- 中文乱码解决问题(转载)
- 如何解决Python中利用Wordcloud无法生成中文词云的问题?
- 解决dwr1.0版本在jdk1.3环境下中文问题
- tomcat8.0环境下解决get方法中文参数乱码问题
- 多域环境下people picker查找不到用户问题的解决(转载jianyi)
- TOMCAT中文问题,解决(全)(转载)
- 解决Ubuntu环境下vim和QT中文输入问题
- [转]解决linux下sqldeveloper 中文环境显示乱码的问题
- 在linux mint 18环境下解决wine安装软件中文乱码的问题
- 使用cygwin在windows上模拟unix环境,解决不能显示中文的问题
- 解决Mac环境下vim中文乱码&转码问题
- windows环境下Mysql中文乱码问题解决方法
- 如何解决在Win7,VS2012环境中生成的c++程序在XP上提示“XXXX.exe不是有效的Win32应用程序”的问题
- Mysql 中文乱码问题 windows环境下解决
- 使用cygwin在windows上模拟unix环境,解决不能显示中文的问题
- [转载]Word——Word中Visio图无法打印中文问题解决方法