AE C# 图片和文本标注(通过查询)
2016-03-16 19:37
656 查看
查询数据后,图形标注
if (myds1V.Tables[0].Rows.Count > 0)
{
IActiveView pActiveView = (IActiveView)this.axMapControl1.Map;
this.axMapControl1.Map.ClearSelection();
pActiveView.Refresh();
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
ILayer pLayer = this.axMapControl1.Map.get_Layer(0);
if (pLayer.Name=="jx-xian")
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilterClass();
IEnvelope pEnvelope = new EnvelopeClass();
IRgbColor rgbColor = new RgbColorClass();
IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass();
// IPoint pPoint = new PointClass();
string fileName = "iconimg\\ico\\point.png";
pictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG, fileName);
pictureMarkerSymbol.Angle = 0;
pictureMarkerSymbol.BitmapTransparencyColor = rgbColor;
pictureMarkerSymbol.Size = 32;
pictureMarkerSymbol.XOffset = 0;
pictureMarkerSymbol.YOffset = 0;
for (int rn = 0; rn < myds1V.Tables[0].Rows.Count; rn++)
{
try
{
pQueryFilter.WhereClause = "名称 =" + "'" + myds1V.Tables[0].Rows[rn][1].ToString().Trim() + "'";
IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; //用来记录最终的结果,由于用户可能在不关闭此窗口的情况下进行
int iSelectedFeaturesCount = pFeatureSelection.SelectionSet.Count;//SelectionSet:The selected set of features.
esriSelectionResultEnum selectMethod;//用来记录处理结果的方法,用在用whereclause查询的地方
selectMethod = esriSelectionResultEnum.esriSelectionResultNew;
pFeatureSelection.SelectFeatures(pQueryFilter, selectMethod, false);//执行查询
//如果本次查询后,查询的结果数目没有改变,则认为本次查询没有产生新的结果
if (pFeatureSelection.SelectionSet.Count != 0)
{
IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while (pFeature != null)
{
// geometry = pFeature.ShapeCopy;
pEnvelope.Union(pFeature.Extent);
double mapX, mapY;
mapX = (pFeature.Extent.XMax + pFeature.Extent.XMin) / 2;
mapY = (pFeature.Extent.YMax + pFeature.Extent.YMin) / 2;
IPoint pPoint = new PointClass();
pPoint.PutCoords(mapX, mapY);
IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass();
pPictureMarkerSymbol.Size = 20;
pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG, fileName);
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pPictureMarkerSymbol as IMarkerSymbol;
IElement pElement = (IElement)pMarkerElement;
pElement.Geometry = pPoint;
pGraphicsContainer.AddElement(pElement, 0);
axMapControl1.FlashShape(pFeature.Shape, 3, 500, null);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
pFeature = pEnumFeature.Next();
}
}
}
catch (Exception ex)
{
MessageBox.Show("您的查询语句可能有误,请检查 | " + ex.Message);
return;
}
}
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
FrmEditSpecimen frmEditSpec = new FrmEditSpecimen(myds);
frmEditSpec.Show();
}
查询数据后,图形或文本标注
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
namespace GIS_Demo1
{
public partial class PropertyQueryFrm : Form
{
public IMapControl2 pMapControl;
public IMap pMap;
public int iLayerIndex;
public int iFieldIndex;
public PropertyQueryFrm(IMapControl2 pFMapControl)
{
pMapControl = pFMapControl;
pMap = pFMapControl.Map;
InitializeComponent();
}
private void PropertyQueryFrm_Load(object sender, EventArgs e)
{
ILayer pLayer;
for (int i = 0; i < pMap.LayerCount; i++)
{
pLayer = pMap.get_Layer(i);
clbLayers.Items.Add(pLayer.Name);
}
}
//属性查图
private void btnQuery_Click(object sender, EventArgs e)
{
int ct = 0;
if (clbLayers.Items.Count <= 0)
{
MessageBox.Show("请先加入待选择查询的图层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
for (int i = 0; i < clbLayers.Items.Count; i++)
{
if (clbLayers.GetItemChecked(i))
{
ct = ct + 1;
}
}
if (ct <= 0)
{
MessageBox.Show("请选择查询的图层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
IActiveView pActiveView = (IActiveView)pMap;
pMap.ClearSelection();
pActiveView.Refresh();
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureLayer pFeatureLayer;
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
for (int i = 0; i < clbLayers.Items.Count; i++)
{
if (clbLayers.GetItemChecked(i))
{
//iLayerIndex = clbLayers.Items.IndexOf(i);
pFeatureLayer = (IFeatureLayer)pMap.get_Layer(i);
if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
{
IFields pFields = pFeatureLayer.FeatureClass.Fields;
IField pField = pFields.get_Field(iFieldIndex);
pQueryFilter.WhereClause = lblFieldList.Text + "='" + txbValue.Text + "'";
IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
double mapX, mapY;
mapX = (pFeature.Extent.XMax + pFeature.Extent.XMin) / 2;
mapY = (pFeature.Extent.YMax + pFeature.Extent.YMin) / 2;
IPoint pPoint = new PointClass();
pPoint.PutCoords(mapX, mapY);
IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass();
pPictureMarkerSymbol.Size = 20;
pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, "E:\\资料文档\\GIS Demo1\\image\\TPieceOptDN1.bmp");
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pPictureMarkerSymbol as IMarkerSymbol;
IElement pElement = (IElement)pMarkerElement;
pElement.Geometry = pPoint;
//pMapControl.CenterAt(pPoint);
pGraphicsContainer.AddElement(pElement, 0);
pMapControl.FlashShape(pFeature.Shape, 3, 500, null);
//pMap.SelectFeature(pFeatureLayer, pFeature);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
pFeature = pFeatureCursor.NextFeature();
}
}
else
{
IFields pFields = pFeatureLayer.FeatureClass.Fields;
IField pField = pFields.get_Field(iFieldIndex);
pQueryFilter.WhereClause = lblFieldList.Text + "='" + txbValue.Text + "'";
IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
pMapControl.FlashShape(pFeature.Shape, 3, 500, null);
//pMapControl.CenterAt(pPoint);
pMap.SelectFeature(pFeatureLayer, pFeature);
pFeature = pFeatureCursor.NextFeature();
}
}
}
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
IMap pMap = pMapControl.Map;
IActiveView pActiveView = (IActiveView)pMap;
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
pMap.ClearSelection();
pActiveView.Refresh();
}
}
}
if (myds1V.Tables[0].Rows.Count > 0)
{
IActiveView pActiveView = (IActiveView)this.axMapControl1.Map;
this.axMapControl1.Map.ClearSelection();
pActiveView.Refresh();
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
ILayer pLayer = this.axMapControl1.Map.get_Layer(0);
if (pLayer.Name=="jx-xian")
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
IQueryFilter pQueryFilter = new QueryFilterClass();
IEnvelope pEnvelope = new EnvelopeClass();
IRgbColor rgbColor = new RgbColorClass();
IPictureMarkerSymbol pictureMarkerSymbol = new PictureMarkerSymbolClass();
// IPoint pPoint = new PointClass();
string fileName = "iconimg\\ico\\point.png";
pictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG, fileName);
pictureMarkerSymbol.Angle = 0;
pictureMarkerSymbol.BitmapTransparencyColor = rgbColor;
pictureMarkerSymbol.Size = 32;
pictureMarkerSymbol.XOffset = 0;
pictureMarkerSymbol.YOffset = 0;
for (int rn = 0; rn < myds1V.Tables[0].Rows.Count; rn++)
{
try
{
pQueryFilter.WhereClause = "名称 =" + "'" + myds1V.Tables[0].Rows[rn][1].ToString().Trim() + "'";
IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; //用来记录最终的结果,由于用户可能在不关闭此窗口的情况下进行
int iSelectedFeaturesCount = pFeatureSelection.SelectionSet.Count;//SelectionSet:The selected set of features.
esriSelectionResultEnum selectMethod;//用来记录处理结果的方法,用在用whereclause查询的地方
selectMethod = esriSelectionResultEnum.esriSelectionResultNew;
pFeatureSelection.SelectFeatures(pQueryFilter, selectMethod, false);//执行查询
//如果本次查询后,查询的结果数目没有改变,则认为本次查询没有产生新的结果
if (pFeatureSelection.SelectionSet.Count != 0)
{
IEnumFeature pEnumFeature = axMapControl1.Map.FeatureSelection as IEnumFeature;
IFeature pFeature = pEnumFeature.Next();
while (pFeature != null)
{
// geometry = pFeature.ShapeCopy;
pEnvelope.Union(pFeature.Extent);
double mapX, mapY;
mapX = (pFeature.Extent.XMax + pFeature.Extent.XMin) / 2;
mapY = (pFeature.Extent.YMax + pFeature.Extent.YMin) / 2;
IPoint pPoint = new PointClass();
pPoint.PutCoords(mapX, mapY);
IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass();
pPictureMarkerSymbol.Size = 20;
pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPicturePNG, fileName);
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pPictureMarkerSymbol as IMarkerSymbol;
IElement pElement = (IElement)pMarkerElement;
pElement.Geometry = pPoint;
pGraphicsContainer.AddElement(pElement, 0);
axMapControl1.FlashShape(pFeature.Shape, 3, 500, null);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
pFeature = pEnumFeature.Next();
}
}
}
catch (Exception ex)
{
MessageBox.Show("您的查询语句可能有误,请检查 | " + ex.Message);
return;
}
}
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
FrmEditSpecimen frmEditSpec = new FrmEditSpecimen(myds);
frmEditSpec.Show();
}
查询数据后,图形或文本标注
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
namespace GIS_Demo1
{
public partial class PropertyQueryFrm : Form
{
public IMapControl2 pMapControl;
public IMap pMap;
public int iLayerIndex;
public int iFieldIndex;
public PropertyQueryFrm(IMapControl2 pFMapControl)
{
pMapControl = pFMapControl;
pMap = pFMapControl.Map;
InitializeComponent();
}
private void PropertyQueryFrm_Load(object sender, EventArgs e)
{
ILayer pLayer;
for (int i = 0; i < pMap.LayerCount; i++)
{
pLayer = pMap.get_Layer(i);
clbLayers.Items.Add(pLayer.Name);
}
}
//属性查图
private void btnQuery_Click(object sender, EventArgs e)
{
int ct = 0;
if (clbLayers.Items.Count <= 0)
{
MessageBox.Show("请先加入待选择查询的图层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
for (int i = 0; i < clbLayers.Items.Count; i++)
{
if (clbLayers.GetItemChecked(i))
{
ct = ct + 1;
}
}
if (ct <= 0)
{
MessageBox.Show("请选择查询的图层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
IActiveView pActiveView = (IActiveView)pMap;
pMap.ClearSelection();
pActiveView.Refresh();
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureLayer pFeatureLayer;
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
for (int i = 0; i < clbLayers.Items.Count; i++)
{
if (clbLayers.GetItemChecked(i))
{
//iLayerIndex = clbLayers.Items.IndexOf(i);
pFeatureLayer = (IFeatureLayer)pMap.get_Layer(i);
if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
{
IFields pFields = pFeatureLayer.FeatureClass.Fields;
IField pField = pFields.get_Field(iFieldIndex);
pQueryFilter.WhereClause = lblFieldList.Text + "='" + txbValue.Text + "'";
IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
double mapX, mapY;
mapX = (pFeature.Extent.XMax + pFeature.Extent.XMin) / 2;
mapY = (pFeature.Extent.YMax + pFeature.Extent.YMin) / 2;
IPoint pPoint = new PointClass();
pPoint.PutCoords(mapX, mapY);
IPictureMarkerSymbol pPictureMarkerSymbol = new PictureMarkerSymbolClass();
pPictureMarkerSymbol.Size = 20;
pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, "E:\\资料文档\\GIS Demo1\\image\\TPieceOptDN1.bmp");
IMarkerElement pMarkerElement = new MarkerElementClass();
pMarkerElement.Symbol = pPictureMarkerSymbol as IMarkerSymbol;
IElement pElement = (IElement)pMarkerElement;
pElement.Geometry = pPoint;
//pMapControl.CenterAt(pPoint);
pGraphicsContainer.AddElement(pElement, 0);
pMapControl.FlashShape(pFeature.Shape, 3, 500, null);
//pMap.SelectFeature(pFeatureLayer, pFeature);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
pFeature = pFeatureCursor.NextFeature();
}
}
else
{
IFields pFields = pFeatureLayer.FeatureClass.Fields;
IField pField = pFields.get_Field(iFieldIndex);
pQueryFilter.WhereClause = lblFieldList.Text + "='" + txbValue.Text + "'";
IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
pMapControl.FlashShape(pFeature.Shape, 3, 500, null);
//pMapControl.CenterAt(pPoint);
pMap.SelectFeature(pFeatureLayer, pFeature);
pFeature = pFeatureCursor.NextFeature();
}
}
}
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
IMap pMap = pMapControl.Map;
IActiveView pActiveView = (IActiveView)pMap;
IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pActiveView;
pGraphicsContainer.DeleteAllElements();
pMap.ClearSelection();
pActiveView.Refresh();
}
}
}
相关文章推荐
- CLR----公共语言运行时
- C# IntPtr转换为Byte[]
- NET(C#)接入Dubbo服务,Zookeeper作为Dubbo服务的注册中心,实现thrift协议访问接口(3)
- c#中的结构
- C#时间戳转换
- C# 添加FormClosing事件
- C# 简单邮件群发通用类
- C#之DataSet和DataTable
- C#解leetcode 18. 4Sum
- C#使用DevExpress与panel的加载
- C# 获取某月的第一天和最后一天
- C#成魔之路<15> 注册表技术
- C# 性能优化
- C#循环使用File.Copy造成电脑死机
- C# DataTable转实体 通用方法
- c# 操作xml之xmlReader
- C#中MessageBox用法大全
- 【笔记】《C#大学教程》- 第11章 异常处理
- C#中枚举
- C# 截取字符串某个字符分割的最后一部分