Sunday, February 22, 2015

Print values of selected features in Feature Class Esri ArcObjects Snippets - Series

Esri ArcObjects Snippets - Series

Print values of selected features in Feature Class


 // display values of selected features in shape file (file system)  
      static void getselectedfeaturesvalueShp(IApplication app) {  
           IMxDocument mxDoc;  
           try {  
                mxDoc = (IMxDocument) app.getDocument();  
                int count = mxDoc.getActiveView().getFocusMap().getLayerCount();  
                for (int layerno = 0; layerno < count; layerno++) {  
                     if (mxDoc.getActiveView().getFocusMap().getLayer(layerno).isVisible()) {  
                          System.out.println("Layer " + layerno + " visible");  
                     }  
                }  
                Map map = (Map) mxDoc.getMaps().getItem(0);  
                MapSelection mapSelection = new MapSelection(map.getFeatureSelection());  
                mapSelection.reset();  
                IFeature feature = mapSelection.next();  
                while (feature != null) {  
                     int oid = (int) feature.getOID();  
                     System.out.println("OID of Selected feature = " + oid);  
                     int fieldcount = feature.getTable().getRow(oid).getFields().getFieldCount();  
                     System.out.println(" fieldcount = " + fieldcount);  
                     for (int q=0; q<fieldcount; q++){  
                          System.out.println("Field Name = "+ feature.getTable().getFields().getField(q).getName());  
                          System.out.println("Field Value = "+ feature.getTable().getRow(oid).getValue(q));  
                     }  
                     feature = mapSelection.next();       
                     System.out.println("***");                      
                }  
           } catch (AutomationException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           } catch (IOException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  
      }  



This code has been made using ESRI Resources and other Help Content and is provided here just for educational purpose.

No comments:

Post a Comment