I have new in ArcGis Dev. I am trying to create a tool. In the tool when cliked on the feature it will tell you about the XY point of the feature and the name of the feature. I am getting the XY. When I am trying to get the feature Name like if I click on Structure it will show the message "NE.Structure".
Apart structure, all the features I am getting null exception("System.NUllReferenceException occured in the dll but not handled by user code") and 2ndly what I tried is selecting the feature which I think is changing the map state. Can anyone please help. Here is what I tried
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add MapControl.OnMouseDown implementation
screenPoint = new ESRI.ArcGIS.Geometry.Point();
screenPoint.X = X;
screenPoint.Y = Y;
IScreenDisplay screenDisplay = (m_application.Document as IMxDocument).ActiveView.ScreenDisplay;
mapPoint = screenDisplay.DisplayTransformation.ToMapPoint(X,Y);
IMxDocument pMxDoc = (IMxDocument)m_application.Document;
IMap pMap = (IMap)pMxDoc.FocusMap;
mapPoint.SpatialReference = pMap.SpatialReference;
IEnvelope env = new EnvelopeClass() as IEnvelope;
// env.PutCoords(mapPoint.X, mapPoint.Y, mapPoint.X, mapPoint.Y);
ITopologicalOperator pTopOp = mapPoint as ITopologicalOperator;
ISpatialFilter pSpatFlt = new SpatialFilterClass();
pSpatFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
pSpatFlt.Geometry = pTopOp.Buffer(10);
ESRI.ArcGIS.esriSystem.UID pFeatLayerUID = new ESRI.ArcGIS.esriSystem.UIDClass();
pFeatLayerUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; /* refer http:// help.arcgis.com/EN/sdk/10.0/ArcObjects_NET/componenthelp/index.html#/Layers_Property/001200000m9t000000/ */
IEnumLayer pEnumLayer = pMap.get_Layers(pFeatLayerUID, true);
ILayer pThisLayer = pEnumLayer.Next();
//IGeometry selectionGeometry = (mapPoint as ITopologicalOperator).Buffer(100); // make a buffer
pMap.SelectByShape(mapPoint, (m_application as IMxApplication).SelectionEnvironment, false);
IFeatureLayer pThisFeatLayer = pThisLayer as IFeatureLayer;
IEnumFeature enumFeatures = (IEnumFeature)pMap.FeatureSelection;
IFeature thisFeature = enumFeatures.Next();
do
{
IGeometry thisGeom = thisFeature.ShapeCopy;
IFeatureCursor pFtCur = pThisFeatLayer.Search(pSpatFlt,true);
IFeature pFt = pFtCur.NextFeature();
IFeatureClass fC = (IFeatureClass)pFt.Class;
MessageBox.Show(fC.AliasName.ToString());
thisFeature = enumFeatures.Next();
} while (thisFeature != null);
MessageBox.Show("X position is " + mapPoint.X.ToString() + "Y position is :" + mapPoint.Y.ToString());
}
}
The exception I am getting is like :
This above error is coming in this line # IFeatureClass fC = (IFeatureClass)pFt.Class;
You asked me what I mean by changing the map state. In case user already selected any feature or an area, in that if my tool is trying to select the clicked feature, I am afraid it would deselect the user selection.