Search in sources :

Example 56 with RevFeature

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);
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Function(com.google.common.base.Function) RevFeature(org.locationtech.geogig.api.RevFeature) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 57 with RevFeature

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]);
}
Also used : RevFeature(org.locationtech.geogig.api.RevFeature) Test(org.junit.Test)

Example 58 with RevFeature

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();
}
Also used : RevFeature(org.locationtech.geogig.api.RevFeature) OSMImportOp(org.locationtech.geogig.osm.internal.OSMImportOp) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) File(java.io.File) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 59 with RevFeature

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();
}
Also used : Optional(com.google.common.base.Optional) RevFeature(org.locationtech.geogig.api.RevFeature) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 60 with RevFeature

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());
}
Also used : RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) File(java.io.File) Test(org.junit.Test)

Aggregations

RevFeature (org.locationtech.geogig.api.RevFeature)89 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)46 Test (org.junit.Test)45 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)43 Optional (com.google.common.base.Optional)40 NodeRef (org.locationtech.geogig.api.NodeRef)32 File (java.io.File)24 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)24 ObjectId (org.locationtech.geogig.api.ObjectId)21 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21 ImmutableList (com.google.common.collect.ImmutableList)20 Feature (org.opengis.feature.Feature)20 List (java.util.List)19 RevObject (org.locationtech.geogig.api.RevObject)18 RevTree (org.locationtech.geogig.api.RevTree)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)16 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 ArrayList (java.util.ArrayList)15 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)15 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)15