Arc Toolbar
Having got our model working, we'll now just rank our outputs and list them.
Here's the code for the rest of the Button's onClick method. If you put this after the code you have, it should work,
but you may have to think through the scope of the outputFeatures2 variable and try-catch blocks. You may also need to
change the name of outputFeatures2
to whichever variable contains the final intersected results layer name.
You'll also need an init
method, as we had last practical, to set up an
instance variable, app
, at the top of the class. Again, make sure you understand what
it is doing. You can also find it split into useful chunks in the Code Cookbook.
IMxDocument mxDocument = (IMxDocument)app.getDocument(); IMap map = mxDocument.getFocusMap(); ILayer layer = null; for (int i=0; i < map.getLayerCount(); i++) { layer = map.getLayer(i); if (layer.getName().equals(outputFeatures2.substring(outputFeatures2.lastIndexOf("\\") + 1))) { break; } } IAttributeTable pAttributeTable = (IAttributeTable) layer; ITable table = pAttributeTable.getAttributeTable(); ITableSort tableSort = new TableSort(); tableSort.setTableByRef(table); tableSort.setFields("Join_Count"); tableSort.setAscending("Join_Count", false); tableSort.sort(null); ICursor iCursor = tableSort.getRows(); IRow row = iCursor.nextRow(); String results = ""; int countField = row.getFields().findField("Join_Count"); int addressField = row.getFields().findField("ADDRESS"); while (row != null) { results = results + row.getValue(countField) + " " + row.getValue(addressField) + "\n"; row = iCursor.nextRow(); } JOptionPane.showMessageDialog(null, results);
Once you've got that working, we're done!