public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException { final int count = in.readInt(); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = DataStreamValueSerializerV1.INSTANCE.decode(fieldType, in); builder.addValue(value); } RevFeature built = builder.build(); return built; }
@Test public void testNullFeature() throws Exception { try { RevFeatureBuilder.build((Feature) null); fail("expected IllegalStateException on null feature"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("No feature set")); } }
public RevFeature readFeature(@Nullable ObjectId id, DataInput in) throws IOException { final int count = readUnsignedVarInt(in); final RevFeatureBuilder builder = RevFeatureBuilder.builder(); for (int i = 0; i < count; i++) { final byte fieldTag = in.readByte(); final FieldType fieldType = FieldType.valueOf(fieldTag); Object value = valueEncoder.decode(fieldType, in); builder.addValueNoCopy(value); } RevFeature built = id == null ? builder.build() : builder.build(id); return built; }
@Test public void TestCatFeatureObject() { RevFeature feature = RevFeatureBuilder.build(points1); CharSequence desc = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(feature)) .call(); String[] lines = desc.toString().split("\n"); assertEquals(points1.getProperties().size() + 2, lines.length); assertEquals(FieldType.STRING.name() + "\tStringProp1_1", lines[2]); assertEquals(FieldType.INTEGER.name() + "\t1000", lines[3]); assertEquals(FieldType.POINT.name() + "\tPOINT (1 1)", lines[4]); }
@Override protected RevFeature read(ObjectId id, BufferedReader reader, TYPE type) throws IOException { Preconditions.checkArgument(TYPE.FEATURE.equals(type), "Wrong type: %s", type.name()); RevFeatureBuilder builder = RevFeatureBuilder.builder(); String line; while ((line = reader.readLine()) != null) { builder.addValue(parseAttribute(line)); } return builder.build(); }
private Node feature(ObjectStore db, String idPrefix, int index) { final String id = idPrefix + "." + index; final Feature feature; feature = super.feature(pointsType, id, id, index, point(index)); RevFeature revFeature = RevFeatureBuilder.build(feature); db.put(revFeature); Envelope bounds = (Envelope) feature.getBounds(); return Node.create(id, revFeature.getId(), ObjectId.NULL, TYPE.FEATURE, bounds); }
/** * Only for testing: allows to return a {@link RevFeature} with the specified id instead of the * one resulting from {@link HashObject} */ public static RevFeature featureForceId(ObjectId forceId, Object... rawValues) { RevFeatureBuilder builder = RevFeatureBuilder.builder().addAll(rawValues); RevFeature revFeature = builder.build(forceId); return revFeature; }
public FeatureInfo featureInfo(String treePath, Feature f) { final String path = NodeRef.appendChild(treePath, f.getIdentifier().getID()); RevFeature feature = RevFeatureBuilder.build(f); FeatureType type = f.getType(); RevFeatureType ftype = RevFeatureTypeBuilder.build(type); return FeatureInfo.insert(feature, ftype.getId(), path); }
public static RevFeature feature(Object... rawValues) { RevFeatureBuilder builder = RevFeatureBuilder.builder().addAll(rawValues); return builder.build(); }
@Test public void testRemoveFeaturePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addRemovedFeature(path, RevFeatureBuilder.build(points1), RevFeatureTypeBuilder.build(pointsType)); testPatch(patch); }
public static RevFeature createPointFeature(double x, double y, Object... extraAttribues) { RevFeatureBuilder builder = RevFeatureBuilder.builder(); builder.addValue(gf.createPoint(new Coordinate(x, y))); if (extraAttribues != null) { builder.addAll(Lists.newArrayList(extraAttribues)); } RevFeature feature = builder.build(); return feature; }
@Test public void testAddFeaturePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addAddedFeature(path, RevFeatureBuilder.build(points1), RevFeatureTypeBuilder.build(pointsType)); testPatch(patch); }
@Test public void testRevFeatureToString() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeatureBuilder.builder().addAll(values).build(); String featureString = feature.toString(); assertEquals("Feature[" + feature.getId().toString() + "; StringProp, 1000, POINT(1 1)]", featureString); } }
protected FeatureInfo featureInfo(SimpleFeatureType type, String id, Object... values) { RevFeature feature = RevFeatureBuilder.build(feature(type, id, values)); RevFeatureType ftype = RevFeatureTypeBuilder.build(type); repo.objectDatabase().put(ftype); String path = NodeRef.appendChild(type.getName().getLocalPart(), id); return FeatureInfo.insert(feature, ftype.getId(), path); }
@Test public void testRevFeatureConstructorAndAccessors() { List<Object> values = Lists.newArrayList("StringProp1_1", new Integer(1000), "POINT(1 1)"); RevFeature feature = RevFeatureBuilder.builder().addAll(values).build(); assertEquals(TYPE.FEATURE, feature.getType()); assertEquals(Lists.transform(values, (v) -> Optional.fromNullable(v)), feature.getValues()); }
public FeatureInfo featureInfo(String treePath, Feature f) { final String path = NodeRef.appendChild(treePath, f.getIdentifier().getID()); RevFeature feature = RevFeatureBuilder.build(f); FeatureType type = f.getType(); RevFeatureType ftype = RevFeatureTypeBuilder.build(type); repo.objectDatabase().put(ftype); return FeatureInfo.insert(feature, ftype.getId(), path); }
@Test public void testBuildEmpty() throws Exception { RevFeature emptyFeature = RevFeatureBuilder.builder().build(); assertNotNull(emptyFeature); assertTrue(emptyFeature.getValues().isEmpty()); assertEquals(ObjectId.valueOf("0aaf76f425c6e0f43a36197de768e67d9e035abb"), emptyFeature.getId()); }
@Test public void testRemoveFeaturePatch() throws Exception { insert(points1); Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addRemovedFeature(path, RevFeatureBuilder.build(points1), RevFeatureTypeBuilder.build(pointsType)); geogig.command(ApplyPatchOp.class).setPatch(patch).call(); RevTree root = repo.workingTree().getTree(); assertNotNull(root); Optional<Node> featureBlobId = findTreeChild(root, path); assertFalse(featureBlobId.isPresent()); }
@Test public void testRemovedFeatureDoesNotExists() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); patch.addRemovedFeature(path, RevFeatureBuilder.build(points1), RevFeatureTypeBuilder.build(pointsType)); try { geogig.command(ApplyPatchOp.class).setPatch(patch).call(); fail(); } catch (CannotApplyPatchException e) { assertTrue(true); } }
protected ObjectId insert(Repository repo, Feature f) throws Exception { final WorkingTree workTree = repo.workingTree(); Name name = f.getType().getName(); String parentPath = name.getLocalPart(); RevFeatureType type = RevFeatureTypeBuilder.build(f.getType()); repo.objectDatabase().put(type); String path = NodeRef.appendChild(parentPath, f.getIdentifier().getID()); FeatureInfo fi = FeatureInfo.insert(RevFeatureBuilder.build(f), type.getId(), path); workTree.insert(fi); return fi.getFeature().getId(); }