Advertisement
kijato

OpenJump, BeanShell, MakeNewLayer

May 27th, 2019
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. //
  2. //import com.vividsolutions.jts.geom.*;
  3. //import com.vividsolutions.jump.feature.*;
  4. //import com.vividsolutions.jump.task.*;
  5. //import com.vividsolutions.jump.workbench.*;
  6.  
  7. MyClass() {
  8.   int ize = 8;
  9.    bar() { print("The '"+this.ize+"' is here!");  }
  10.   return this;
  11.   /*
  12.     my = MyClass();
  13.     print(my.ize);
  14.     my.bar();
  15.   */
  16. }
  17.  
  18.  
  19. {
  20.  
  21.   Random rand = new Random();
  22.  
  23.   randomString(int length) {
  24.       StringBuffer sb = new StringBuffer();
  25.       for (int i = 0 ; i < length ; i++) sb.append((char)(64 + 27.0*Math.random()));
  26.       return sb.toString();
  27.   }
  28.  
  29.  
  30.   schema = new FeatureSchema();
  31.   schema.addAttribute("id",AttributeType.BIGINT);
  32.   schema.addAttribute("name",AttributeType.STRING);
  33.   schema.addAttribute("geometry",AttributeType.GEOMETRY);
  34.   print("Attributes of schema:");
  35.   for ( name : schema.attributeNames ) {
  36.     print("  - "+name+" ["+schema.getAttributeType(name)+"]");
  37.   }
  38.  
  39.   dataset = new FeatureDataset(schema);
  40.   for (int i = 1 ; i < 6 ; i++) {
  41.     coord = new Coordinate(rand.nextInt(100*i),rand.nextInt(100*i),rand.nextInt(100*i));
  42.     geom = new GeometryFactory().createPoint(coord);
  43.     geom.setSRID(23700);
  44.     bf = new BasicFeature(schema);
  45.     bf.setGeometry(geom);
  46.     //bf.setUserData("id", rand.nextInt(100)); // don't work...
  47.     //bf.setUserData("name", randomString(5)); // don't work...
  48.     bf.setAttribute("id", rand.nextInt(1000));
  49.     bf.setAttribute("name", randomString(8));
  50.     dataset.add(bf);
  51.   }
  52.   print("Dataset size: "+dataset.size());
  53.   for ( f : dataset.getFeatures() ) {
  54.     print("  - "+f.getGeometry()+"\tid="+f.getAttribute(0)+"\tname="+f.getAttribute(1));
  55.   }
  56.   wc.layerManager.addLayer("DEMO","one point",dataset);
  57.   print("˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙");
  58.  
  59.   geoms = new ArrayList();
  60.   for (int i = 0; i < 5; i++) {
  61.     double x = rand.nextInt(100); double y = rand.nextInt(100); double z = rand.nextInt(100);
  62.     p = new Coordinate(x,y,z);
  63.     pt = new GeometryFactory().createPoint(p);
  64.     pt.setSRID(23700);
  65.     //pt.setAttribute("id", rand.nextInt(100));
  66.     //pt.setUserData("id", rand.nextInt(100));
  67.     geoms.add(pt);
  68.   }
  69.   FeatureCollection points = FeatureDatasetFactory.createFromGeometry(geoms,schema);   
  70.   print("dataset size: "+points.size()+" [...]");
  71.   wc.layerManager.addLayer("DEMO","more points",points);
  72.   print("˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙");
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement