Advertisement
kijato

OpenJump, Beanshell - getAttribute(s)Stats

May 19th, 2020
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. {
  2.   import com.vividsolutions.jump.workbench.ui.*;
  3.   import java.util.*;
  4.  
  5.   Layer layer = wc.getLayerManager().getLayer("teszt");
  6.   if (layer == null) { print ("Layer not found"); return; }
  7.  
  8.   FeatureSchema schema = layer.getFeatureCollectionWrapper().getFeatureSchema();
  9.  
  10.  
  11.   //int zData = schema.getAttributeIndex("LAYER");
  12.   //print("\nLAYER index: " + zData + " (" + schema.getAttributeType("LAYER") + ")");
  13.  
  14.  
  15.   //print("Attributes of schema:");
  16.   //for(int i=0;i<schema.getAttributeCount();i++){
  17.   //  print("   "+i+" "+schema.getAttributeName(i));
  18.   //}
  19.  
  20.  
  21.   Hashtable keys = new Hashtable();
  22.   Iterator iter = layer.getFeatureCollectionWrapper().iterator();
  23.   String layerName = "LAYER";
  24.   int layerIndex = schema.getAttributeIndex(layerName);
  25.   while ( iter.hasNext() ) {
  26.     BasicFeature bf = (BasicFeature)iter.next();
  27.     if(!keys.containsKey(bf.getAttribute(layerIndex))){
  28.       keys.put(bf.getAttribute(layerIndex),1);
  29.     } else {
  30.       keys.put( bf.getAttribute(layerIndex), keys.get(bf.getAttribute(layerIndex))+1);
  31.     }
  32.   }
  33.   print("Statistics of '" + layerName + "' attributes:\n" + keys);
  34.  
  35.  
  36.   Hashtable attributes = new Hashtable();
  37.   for(int i=0;i<schema.getAttributeCount();i++){
  38.     print("   "+i+" "+schema.getAttributeName(i)+ " (" + schema.getAttributeType("LAYER") + ")");
  39.     if(!attributes.containsKey(schema.getAttributeName(i))){
  40.       attributes.put(schema.getAttributeName(i),new Hashtable());
  41.     }
  42.     Hashtable keys = new Hashtable();
  43.     Iterator iter = layer.getFeatureCollectionWrapper().iterator();
  44.     while ( iter.hasNext() ) {
  45.       BasicFeature bf = (BasicFeature)iter.next();
  46.       if(bf.getAttribute(i)!=null){
  47.         if(!keys.containsKey(bf.getAttribute(i))){
  48.             keys.put(bf.getAttribute(i),1);
  49.         } else {
  50.           keys.put( bf.getAttribute(i), keys.get(bf.getAttribute(i))+1);
  51.         }
  52.       }
  53.     }
  54.     print(keys);
  55.     keys.clear();
  56.   }
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement