use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class ExportOp method alter.
private Iterator<SimpleFeature> alter(Iterator<SimpleFeature> plainFeatures, final ObjectId targetFeatureTypeId) {
final RevFeatureType targetType = stagingDatabase().getFeatureType(targetFeatureTypeId);
Function<SimpleFeature, SimpleFeature> alterFunction = new Function<SimpleFeature, SimpleFeature>() {
@Override
public SimpleFeature apply(SimpleFeature input) {
final RevFeatureType oldFeatureType;
oldFeatureType = (RevFeatureType) input.getUserData().get(RevFeatureType.class);
final ObjectId metadataId = oldFeatureType.getId();
if (targetType.getId().equals(metadataId)) {
return input;
}
final RevFeature oldFeature;
oldFeature = (RevFeature) input.getUserData().get(RevFeature.class);
ImmutableList<PropertyDescriptor> oldAttributes = oldFeatureType.sortedDescriptors();
ImmutableList<PropertyDescriptor> newAttributes = targetType.sortedDescriptors();
ImmutableList<Optional<Object>> oldValues = oldFeature.getValues();
List<Optional<Object>> newValues = Lists.newArrayList();
for (int i = 0; i < newAttributes.size(); i++) {
int idx = oldAttributes.indexOf(newAttributes.get(i));
if (idx != -1) {
Optional<Object> oldValue = oldValues.get(idx);
newValues.add(oldValue);
} else {
newValues.add(Optional.absent());
}
}
RevFeature newFeature = RevFeatureImpl.build(ImmutableList.copyOf(newValues));
FeatureBuilder featureBuilder = new FeatureBuilder(targetType);
SimpleFeature feature = (SimpleFeature) featureBuilder.build(input.getID(), newFeature);
return feature;
}
};
return Iterators.transform(plainFeatures, alterFunction);
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class CatObjectTest method TestCatFeatureObject.
@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]);
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class OSMMapTest method testMappingExcludingFeaturesWithMissingTag.
@Test
public void testMappingExcludingFeaturesWithMissingTag() throws Exception {
// import and check
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
cli.execute("osm", "import", file.getAbsolutePath());
cli.execute("add");
cli.execute("commit", "-m", "message");
GeoGIG geogig = cli.newGeoGIG();
Optional<RevTree> tree = geogig.command(RevObjectParse.class).setRefSpec("HEAD:node").call(RevTree.class);
assertTrue(tree.isPresent());
assertTrue(tree.get().size() > 0);
tree = geogig.command(RevObjectParse.class).setRefSpec("HEAD:way").call(RevTree.class);
assertTrue(tree.isPresent());
assertTrue(tree.get().size() > 0);
// map
String mappingFilename = OSMMapTest.class.getResource("mapping_exclude_missing_tag.json").getFile();
File mappingFile = new File(mappingFilename);
cli.execute("osm", "map", mappingFile.getAbsolutePath());
// check that a feature was correctly mapped
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:namedhighways/2059114068").call(RevFeature.class);
assertTrue(revFeature.isPresent());
// check that a feature was correctly ignored
revFeature = geogig.command(RevObjectParse.class).setRefSpec("HEAD:namedhighways/81953612").call(RevFeature.class);
assertFalse(revFeature.isPresent());
geogig.close();
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class OSMUnmapTest method testUnMapping.
@Test
public void testUnMapping() throws Exception {
cli.execute("osm", "unmap", "busstops");
GeoGIG geogig = cli.newGeoGIG();
Optional<RevTree> tree = geogig.command(RevObjectParse.class).setRefSpec("HEAD:node").call(RevTree.class);
assertTrue(tree.isPresent());
assertTrue(tree.get().size() > 0);
Optional<RevFeature> unmapped = geogig.command(RevObjectParse.class).setRefSpec("HEAD:node/507464799").call(RevFeature.class);
assertTrue(unmapped.isPresent());
ImmutableList<Optional<Object>> values = unmapped.get().getValues();
assertEquals("POINT (7.1959361 50.739397)", values.get(6).get().toString());
assertEquals("VRS:gemeinde:BONN|VRS:ortsteil:Hoholz|VRS:ref:68566|bus:yes|highway:bus_stop|name:Gielgen|public_transport:platform", values.get(3).get().toString());
geogig.close();
}
use of org.locationtech.geogig.api.RevFeature in project GeoGig by boundlessgeo.
the class OSMAplyDiffOpTest method testApplyChangesetWithMissingNode.
@Test
public void testApplyChangesetWithMissingNode() throws Exception {
String filename = getClass().getResource("nodes_for_changeset2.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
long unstaged = geogig.getRepository().workingTree().countUnstaged("node").count();
assertTrue(unstaged > 0);
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/2059114068").call(RevFeature.class);
assertTrue(revFeature.isPresent());
revFeature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:node/269237867").call(RevFeature.class);
assertFalse(revFeature.isPresent());
String changesetFilename = getClass().getResource("changeset_missing_nodes.xml").getFile();
OSMReport report = geogig.command(OSMApplyDiffOp.class).setDiffFile(new File(changesetFilename)).call().get();
assertEquals(1, report.getUnpprocessedCount());
assertEquals(4, report.getCount());
revFeature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:way/51502277").call(RevFeature.class);
assertTrue(revFeature.isPresent());
revFeature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:way/31347480").call(RevFeature.class);
assertFalse(revFeature.isPresent());
}
Aggregations