Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * Create a feature with a number of data elements in the extended data. This method will not use
  * a schema.
  *
  * @param geoclass the class of the geometry objects to create
  * @param schema the schema
  * @param valuemap the valuemap, not <code>null</code>
  * @return the new instance
  */
 protected Feature createFeature(
     Class<? extends Geometry> geoclass, Schema schema, Map<String, Object> valuemap) {
   if (schema == null) {
     throw new IllegalArgumentException("schema should never be null");
   }
   if (valuemap == null) {
     throw new IllegalArgumentException("valuemap should never be null");
   }
   Feature f = createBasicFeature(geoclass);
   f.setSchema(schema.getId());
   for (String key : schema.getKeys()) {
     SimpleField field = schema.get(key);
     Object value = valuemap.get(key);
     f.putData(field, value != null ? value : ObjectUtils.NULL);
   }
   return f;
 }
  @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);
  }