Exemple #1
0
 /**
  * Create a schema
  *
  * @param names the names for the fields
  * @param types the types for the fields
  * @return
  */
 protected Schema createSchema(String names[], SimpleField.Type types[]) {
   Schema s = new Schema();
   for (int i = 0; i < names.length; i++) {
     SimpleField field = new SimpleField(names[i]);
     field.setType(types[i]);
     s.put(names[i], field);
   }
   return s;
 }
  @Test
  public void testSimple() throws Exception {
    Schema s1 = new Schema();
    SimpleField field = new SimpleField("category");
    field.setDisplayName("Category");
    field.setType(SimpleField.Type.STRING);
    s1.put(field);
    field = new SimpleField("subcategory");
    field.setDisplayName("Sub Category");
    field.setType(SimpleField.Type.STRING);
    s1.put(field);

    File test = createTemp("testxmlgdb", ".xml");
    FileOutputStream fos = new FileOutputStream(test);
    IGISOutputStream os = GISFactory.getOutputStream(DocumentType.XmlGDB, fos);
    os.write(s1);

    String names[] = {"hole", "distance"};
    Object values[];
    ContainerStart cs = new ContainerStart("Folder");
    cs.setName("One");
    os.write(cs);
    for (int i = 0; i < 3; i++) {
      values = new Object[2];
      values[0] = random.nextInt(18) + 1;
      values[1] = random.nextInt(40) * 10;
      Feature f = createFeature(Point.class, names, values);
      os.write(f);
    }
    os.write(new ContainerEnd());
    Map<String, Object> vmap = new HashMap<String, Object>();
    vmap.put("category", "building");
    vmap.put("subcategory", "house");

    cs = new ContainerStart("Folder");
    cs.setName("Two");
    os.write(cs);
    for (int i = 0; i < 10; i++) {
      Feature f = createFeature(Point.class, s1, vmap);
      os.write(f);
    }
    os.write(new ContainerEnd());
    cs = new ContainerStart("Folder");
    cs.setName("Three");
    os.write(cs);
    for (int i = 0; i < 10; i++) {
      Feature f = createFeature(Line.class, s1, vmap);
      os.write(f);
    }
    os.write(new ContainerEnd());
    cs = new ContainerStart("Folder");
    cs.setName("Four");
    os.write(cs);
    for (int i = 0; i < 10; i++) {
      Feature f = createFeature(LinearRing.class, s1, vmap);
      os.write(f);
    }
    os.write(new ContainerEnd());
    cs = new ContainerStart("Folder");
    cs.setName("Five");
    os.write(cs);
    for (int i = 0; i < 10; i++) {
      Feature f = createFeature(Polygon.class, s1, vmap);
      os.write(f);
    }
    os.write(new ContainerEnd());
    os.close();
    IOUtils.closeQuietly(fos);
  }