Ejemplo n.º 1
0
  @Test
  public void testUpdate() throws Exception {
    GeoGitDataset states = ws.get("states");
    Set<String> abbrs =
        Sets.newHashSet(
            Iterables.transform(
                states.cursor(new VectorQuery()),
                new Function<Feature, String>() {
                  @Override
                  public String apply(Feature input) {
                    String abbr = (String) input.get("STATE_ABBR");
                    assertNotNull(abbr);
                    assertNotEquals(abbr, abbr.toLowerCase());

                    return abbr.toLowerCase();
                  }
                }));

    Transaction tx = states.transaction(null);
    Cursor<Feature> c = states.cursor(new VectorQuery().update().transaction(tx));
    for (Feature f : c) {
      f.put("STATE_ABBR", ((String) f.get("STATE_ABBR")).toLowerCase());
      c.write();
    }
    tx.commit();

    assertEquals(49, abbrs.size());
    for (Feature f : ws.get("states").cursor(new VectorQuery())) {
      abbrs.remove(f.get("STATE_ABBR"));
    }

    assertTrue(abbrs.isEmpty());
  }
Ejemplo n.º 2
0
  @Test
  public void testCreate() throws Exception {
    Schema widgets =
        new SchemaBuilder("widgets")
            .field("shape", Polygon.class)
            .field("name", String.class)
            .field("cost", Double.class)
            .schema();

    GeoGitDataset data = ws.create(widgets);
    assertEquals(0, data.count(new VectorQuery()));

    GeomBuilder gb = new GeomBuilder();

    Transaction tx = data.transaction(null);
    Cursor<Feature> c = data.cursor(new VectorQuery().append().transaction(tx));

    Feature f = c.next();
    f.put("shape", gb.point(0, 0).toPoint().buffer(10));
    f.put("name", "bomb");
    f.put("cost", 1.99);
    c.write();

    f = c.next();
    f.put("shape", gb.points(0, 0, 1, 1).toLineString().buffer(1));
    f.put("name", "dynamite");
    f.put("cost", 2.99);
    c.write();

    f = c.next();
    f.put("shape", gb.points(-5, 5, 5, 5, 2, -2, 3, -5, -3, -5, -2, -2, -5, 5).ring().toPolygon());
    f.put("name", "anvil");
    f.put("cost", 3.99);

    c.write();
    tx.commit();

    data = ws.get("widgets");
    assertEquals(3, data.count(new VectorQuery()));

    c = data.cursor(new VectorQuery().filter("name = 'bomb'"));
    assertTrue(c.hasNext());
    assertEquals(1.99, c.next().get("cost"));
  }
Ejemplo n.º 3
0
  void doAddPoints() throws Exception {
    GeoGitDataset points = ws.get("point");

    Transaction tx = points.transaction(null);
    Cursor<Feature> c = points.cursor(new VectorQuery().append().transaction(tx));

    Feature f = c.next();
    f.put("geometry", new GeomBuilder().point(-114, 51).toPoint());
    f.put("name", "Calgary");
    f.put("pop", 1214839l);
    c.write();

    f = c.next();
    f.put("geometry", new GeomBuilder().point(-123, 49).toPoint());
    f.put("name", "Vancouver");
    f.put("pop", 2313328l);
    c.write();

    tx.commit();
  }