Hi,
I have selected a feature on Map , and i am trying to read the attribute of the selected feature .
But all attributes are null.
I am using
ArcGIS 10.4 Engine
Postgresql 9.4 64 bit
Following is my code snippet.
public void onMouseDown(IMapControlEvents2OnMouseDownEvent event) throws AutomationException, IOException {
double x = event.getMapX();
double y = event.getMapY();
if (event.getButton() == 1)
{
try {
selectFeaturesScreenPoint(mapBean.getMap(),event.getX(),event.getY(),20);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
public void selectFeaturesScreenPoint(IMap map, int x, int y, int pixelTol)throws Exception
{
tagRECT r[] = new tagRECT[1];
r[0]=new tagRECT();
// Construct a small rectangle out of the x,y coordinates' pixel
// tolerance.
r[0].left = x - pixelTol; // Upper left x, top left is 0,0.
r[0].top = y - pixelTol; // Upper left y, top left is 0,0.
r[0].right = x + pixelTol; // Lower right x, top left is 0,0.
r[0].bottom = y + pixelTol; // Lower right y, top left is 0,0.
// Transform the device rectangle into a geographic rectangle via the
// display transformation.
IEnvelope envelope = new Envelope();
IActiveView activeView = (IActiveView)map;
IDisplayTransformation displayXform = activeView.getScreenDisplay()
.getDisplayTransformation();
displayXform.transformRect(envelope, r, 100);
// 5 = esriTransformPosition + esriTransformToMap.
envelope.setSpatialReferenceByRef(map.getSpatialReference());
ISelectionEnvironment selectionEnv = new SelectionEnvironment();
selectionEnv.setCombinationMethod(esriSelectionResultEnum.esriSelectionResultNew);
map.selectByShape(envelope, selectionEnv, true);
activeView.refresh();
if(map.getSelectionCount()>0)
{
System.out.println("Item is selected ");
MapSelection mapSelection = new MapSelection(map.getFeatureSelection());
mapSelection.reset();
IFeature feature = mapSelection.next();
System.out.println("Selected Feature is "+feature.getFields().getFieldCount());
Fields fields = (Fields) feature.getFields();
int fieldCount = fields.getFieldCount();
// Go through each field and print to the console
for (int index = 0; index < fieldCount; index++) {
System.out.print( "\t" + " " +fields.getField(index).getDefaultValue());
}
}
}
Can anybody help me.