示例數據路徑:C:\Program Files (x86)\ArcGIS\DeveloperKit10.1\Samples\data\StreamflowDateTime
大體效果:
代碼段解析:
1.查詢容差的獲取
pMxDoc = (IMxDocument)ArcMap.Application.Document;
// calculate tolerance rectangle to identify features inside it
int Tolerance = 0;
Tolerance = pMxDoc.SearchTolerancePixels;
IDisplayTransformation pDispTrans = null;
pDispTrans = pMxApp.Display.DisplayTransformation;
tagRECT pToleranceRect = new tagRECT();
pToleranceRect.left = X - Tolerance;
pToleranceRect.right = X + Tolerance;
pToleranceRect.top = Y - Tolerance;
pToleranceRect.bottom = Y + Tolerance;
IEnvelope pSearchEnvelope = null;
pSearchEnvelope = new EnvelopeClass();
pDispTrans.TransformRect(pSearchEnvelope, ref pToleranceRect, (int)(esriDisplayTransformationEnum.esriTransformPosition | esriDisplayTransformationEnum.esriTransformToMap));
通過IMxDocument.SearchTolerancePixels獲取像素容差,之後通過IDisplayTransformation接口,將鼠標點擊的平面座標x,y生成一個tagRect。
在之前的工作中,用到鼠標拾取要素之類的功能,通常的做法是獲取鼠標點的位置,按照一定距離緩衝之後進行查詢,這個一定距離是在代碼中寫死的,該功能只適用於某種業務場景,比如,一般緩衝0.5。這種查詢方式存在問題:對於投影座標,0.5的緩衝還算合適,可對於地理座標系,緩衝0.5代表的是緩衝0.5度,這時候空間查詢的範圍相當大。Sample中的查詢方式,通過讀取地圖中的查詢像素容差,再將像素容差轉換爲地圖圖形進行空間查詢。
2.要素拾取
IIdentify pIdentify = null;
pIdentify = (IIdentify)pMxDoc.FocusMap.get_Layer(0);
if (pIdentify == null)
{
MessageBox.Show("No layer");
return;
}
IArray pIDArray = null;
pIDArray = pIdentify.Identify(pSearchEnvelope);
在之前的工作中,用到鼠標拾取要素時,通常的做法是構建ISpatialFilter對象,以鼠標當前的位置進行空間查詢。Sample中通過IIdentify接口實現查詢,FeatureLayer等圖層對象都實現該接口,查詢結果爲IArray對象。
IArray對象中的具體對象爲IIdentifyObj對象(大體翻譯爲 圖層的被識別對象),該對象包含Flash()方法,可以用於實現對拾取對象的閃爍。
3.IDisplayTable接口 Provides access to members that work with the display table associated with a standalone table.
通常,使用IFeatureLayer.FeatureClass接口,獲取的Table對象,爲要素圖層數據源的表,
而使用IDisplayTable接口獲取的Table對象,包含Join的表。
官方幫助建議,如果想讓你的程序足夠通用,使用IDisplayTable接口。
4.IFeatureLayerDefinition接口,獲取圖層的選擇集,大致同ArcMap中的定義查詢功能。
5.獲取要素的Symbol,使用ILookupSymbol接口
ILookupSymbol pLookupSymbol = null;
pLookupSymbol = (ILookupSymbol)pGeoFeatureLayer.Renderer;
IFeature pFeature = null;
pFeature = (IFeature)pRowIDObj.Row;
IMarkerSymbol pSymbol = null;
pSymbol = (IMarkerSymbol)pLookupSymbol.LookupSymbol(false, pFeature);
6.IDataGraphWindow2 :Provides access to members that control the DataGraph Window. ESRI自帶的專題圖窗口