Search in sources :

Example 1 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class DiffBoundsTest method testReprojectToTargetBucketTree.

@Test
public void testReprojectToTargetBucketTree() throws Exception {
    final int leftCount = RevTree.NORMALIZED_SIZE_LIMIT * 2;
    final int rightCount = RevTree.NORMALIZED_SIZE_LIMIT * 3;
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String typeName = "newpoints";
    final DefaultProgressListener listener = new DefaultProgressListener();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, leftCount), listener, null, null);
    geogig.command(AddOp.class).call();
    workingTree.insert(typeName, new TestFeatureIterator(typeName, rightCount), listener, null, null);
    {
        // sanity check
        long diffFeatures = geogig.command(DiffCount.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD").call().featureCount();
        assertEquals(rightCount - leftCount, diffFeatures);
    }
    DiffBounds cmd = geogig.command(DiffBounds.class).setOldVersion("STAGE_HEAD").setNewVersion("WORK_HEAD");
    final CoordinateReferenceSystem nativeCrs = CRS.decode("EPSG:3857");
    final DiffSummary<BoundingBox, BoundingBox> diffInNativeCrs = cmd.setCRS(nativeCrs).call();
    CoordinateReferenceSystem targetcrs = CRS.decode("EPSG:4326", true);
    cmd.setCRS(targetcrs);
    DiffSummary<BoundingBox, BoundingBox> reprojected = cmd.call();
    assertEquals(targetcrs, reprojected.getLeft().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getRight().getCoordinateReferenceSystem());
    assertEquals(targetcrs, reprojected.getMergedResult().get().getCoordinateReferenceSystem());
    ReferencedEnvelope e = new ReferencedEnvelope(diffInNativeCrs.getRight());
    ReferencedEnvelope expected = e.transform(targetcrs, true);
    BoundingBox actual = reprojected.getRight();
    assertEquals(expected, actual);
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) BoundingBox(org.opengis.geometry.BoundingBox) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test)

Example 2 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class IndexTest method testWriteTree.

@Test
public void testWriteTree() throws Exception {
    insertAndAdd(points1);
    insertAndAdd(lines1);
    // this new root tree must exist on the repo db, but is not set as the current head. In
    // fact, it is headless, as there's no commit pointing to it. CommitOp does that.
    ObjectId newRootTreeId = geogig.command(WriteTree.class).setOldRoot(tree(repo.getHead().get().getObjectId())).call();
    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));
    // but the index staged root shall be pointing to it
    // assertEquals(newRootTreeId, index.getStaged().getId());
    RevTree tree = repo.getTree(newRootTreeId);
    // assertEquals(2, tree.size().intValue());
    String path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    // simulate a commit so the repo head points to this new tree
    ObjectInserter objectInserter = repo.newObjectInserter();
    List<ObjectId> parents = ImmutableList.of();
    RevCommit commit = new CommitBuilder(geogig.getPlatform()).setTreeId(newRootTreeId).setParentIds(parents).build();
    ObjectId commitId = commit.getId();
    objectInserter.insert(commit);
    Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(commitId).call();
    assertTrue(newHead.isPresent());
    WorkingTree workTree = repo.workingTree();
    workTree.delete(linesName, lines1.getIdentifier().getID());
    geogig.command(AddOp.class).call();
    // newRootTreeId
    newRootTreeId = geogig.command(WriteTree2.class).setOldRoot(tree(newRootTreeId)).call();
    // =
    // index.writeTree(newRootTreeId,
    // new
    // NullProgressListener());
    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));
    tree = repo.getTree(newRootTreeId);
    path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertFalse(repo.command(FindTreeChild.class).setParent(tree).setChildPath(path).call().isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) WorkingTree(org.locationtech.geogig.repository.WorkingTree) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectInserter(org.locationtech.geogig.storage.ObjectInserter) RevTree(org.locationtech.geogig.api.RevTree) WriteTree2(org.locationtech.geogig.api.plumbing.WriteTree2) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 3 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class IndexTest method testWriteEmptyPathAddAll.

@Test
public void testWriteEmptyPathAddAll() throws Exception {
    insert(lines1);
    WorkingTree workingTree = geogig.getRepository().workingTree();
    workingTree.createTypeTree(pointsName, pointsType);
    List<NodeRef> workHead = toList(geogig.command(LsTreeOp.class).setReference(Ref.WORK_HEAD).setStrategy(Strategy.DEPTHFIRST).call());
    assertEquals(3, workHead.size());
    Collection<NodeRef> filtered = Collections2.filter(workHead, new TreeNameFilter(pointsName));
    assertEquals(1, filtered.size());
    geogig.command(AddOp.class).call();
    List<NodeRef> indexHead = toList(geogig.command(LsTreeOp.class).setReference(Ref.STAGE_HEAD).setStrategy(Strategy.DEPTHFIRST).call());
    assertEquals(3, indexHead.size());
    filtered = Collections2.filter(indexHead, new TreeNameFilter(pointsName));
    assertEquals(1, filtered.size());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) Test(org.junit.Test)

Example 4 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class IndexTest method testAddEmptyTree.

@Test
public void testAddEmptyTree() throws Exception {
    WorkingTree workingTree = geogig.getRepository().workingTree();
    workingTree.createTypeTree(pointsName, pointsType);
    geogig.command(AddOp.class).setUpdateOnly(false).call();
    assertTrue(index.findStaged(pointsName).isPresent());
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) Test(org.junit.Test)

Example 5 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class OSMImportOpTest method testImportMultipleRules.

@Test
public void testImportMultipleRules() {
    final Mapping mapping;
    final File data = new File(getClass().getResource("ways.xml").getFile());
    {
        final File mappingsFile = new File(getClass().getResource("../cli/commands/mapping_multiple_rules.json").getFile());
        checkState(data.exists());
        checkState(mappingsFile.exists());
        mapping = Mapping.fromFile(mappingsFile.getAbsolutePath());
        checkState(2 == mapping.getRules().size(), "expected 2 rules, got %s", mapping.getRules().size());
    }
    geogig.command(OSMImportOp.class).setDataSource(data.getAbsolutePath()).setMapping(mapping).setNoRaw(true).call();
    WorkingTree workingTree = geogig.getContext().workingTree();
    List<NodeRef> featureTypeTrees = workingTree.getFeatureTypeTrees();
    assertEquals(2, featureTypeTrees.size());
    Set<String> expectedNames = newHashSet("osm_roads", "osm_roads_main");
    assertTrue(expectedNames.contains(featureTypeTrees.get(0).name()));
    assertTrue(expectedNames.contains(featureTypeTrees.get(1).name()));
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) File(java.io.File) Test(org.junit.Test)

Aggregations

WorkingTree (org.locationtech.geogig.repository.WorkingTree)54 Test (org.junit.Test)32 AddOp (org.locationtech.geogig.api.porcelain.AddOp)25 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 File (java.io.File)17 ArrayList (java.util.ArrayList)16 RevFeature (org.locationtech.geogig.api.RevFeature)15 Optional (com.google.common.base.Optional)12 SimpleFeature (org.opengis.feature.simple.SimpleFeature)12 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)11 NodeRef (org.locationtech.geogig.api.NodeRef)10 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)9 Name (org.opengis.feature.type.Name)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)7 Node (org.locationtech.geogig.api.Node)7 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5