在ArcGlobe三维环境中进行数据查询(.net)
分享
最近在研究ArcGlobe开发,写了个小程序,其中有一个功能是在ArcGlobe中进行数据查询,现在把主要代码贴出来。
文章来源:http://blog.csdn.net/sydbc/article/details/17791143
/// <summary>
/// 查询功能
/// </summary>
/// <paramname=”sender”></param>
/// <paramname=”e”></param>
private void BtnOK_Click(objectsender, EventArgs e)
{
try
{
//图层名称
String LayerName = this.CbxLayer.Text;
//查询条件
String SearchText = this.TbxName.Text;
if (SearchText == String.Empty)
{
MessageBox.Show(“查询条件不允许为空!”, “错误”, MessageBoxButtons.OK, MessageBoxIcon.Error);
TbxName.Focus();
//清空数据列表
this.dg1.DataSource = null;
//跳出查询
return;
}
//当前视图
IScene scene = this.axGlobeControl1.Globe.GlobeDisplay.Scene;
//查询器
IQueryFilter pQueryFilter = new QueryFilterClass();
IActiveView pActiveView;
pActiveView = (IActiveView)scene;
//清空当前视图
scene.ClearSelection();
IFeatureLayer pFeatureLayer;
pFeatureLayer = (IFeatureLayer)scene.get_Layer(GetLayerId(LayerName, scene));
//判断要查询的图层
if (LayerName == “堤防”)
{
//查询条件
pQueryFilter.WhereClause = “XMMC like “%” + SearchText + “%”";
}
else if (LayerName == “险工险段”)
{
//查询条件
pQueryFilter.WhereClause = “BZ like “%” + SearchText + “%”";
}
……
IFeatureCursor pFeatureCursor;
//查询
pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature;
pFeature = pFeatureCursor.NextFeature();
IFields pFields = pFeatureCursor.Fields;
int fieldIndex = 0;
int fieldIndexName = 0;
if (LayerName == “堤防”)
{
fieldIndex = pFields.FindField(“NAME”);
fieldIndexName = pFields.FindField(“XMMC”);
}
else if (LayerName == “险工险段”)
{
fieldIndex = pFields.FindField(“NAME”);
fieldIndexName = pFields.FindField(“BZ”);
}
……
pfeat = pFeature;
if (pFeature == null)
{
MessageBox.Show(“您所查询的结果不存在!”);
TbxName.Select();
TbxName.Focus();
this.dg1.DataSource = null;
return;
}
//绑定DataTable
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn();
dc1.ColumnName = “工程代码”;
DataColumn dc2 = new DataColumn();
dc2.ColumnName = “工程名称”;
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
string Code = String.Empty;
string Name = String.Empty;
while (pFeature != null)
{
//scene.SelectFeature(pFeatureLayer, pFeature);
Code = pFeature.get_Value(fieldIndex) as string;
Name = pFeature.get_Value(fieldIndexName) as string;
DataRow dr = dt.NewRow();
dr[0] = Code;
dr[1] = Name;
dt.Rows.Add(dr);
pFeature = pFeatureCursor.NextFeature();
}
//绑定列表
this.dg1.DataSource = dt.DefaultView;
}
catch
{
MessageBox.Show(“异常!”, “错误”, MessageBoxButtons.OK, MessageBoxIcon.Error);
this.dg1.DataSource = null;
}
}
文章来源:http://blog.csdn.net/sydbc/article/details/17791143
0 个评论
推荐内容
相关问题
- 运用ArcGIS利用大数据中哪些数据对公园可达性进行分析?
- 怎样用arcgis对已经矢量化的不同时期同一地区的土地利用图像进行时空变化分析?
- arcgis Api for java script 4.4部署离线环境
- ArcGIS Runtime SDK for Android加载本地影像时,如何对RGB波段进行调整?
- arcgis中栅格数据怎么进行批量裁剪?
- 三维模型在pro中呈現沒問題上传至portal後模型無法完整呈現(包括破圖、材質遺失)?
- arcgis api for js中三维的TileLayer默认会显示在MapImageLayer的下面且显示顺序无法调整吗
- javascript api for gis 开发环境配置
- CityEngine做的三维环境可以在移动端显示吗?
- 按照行政区,对图斑进行编号
- 各位大佬,一个属性表里面的不同的两行怎么根据一个字段进行求和