查询数据后,图形标注
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
{
}