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);
}
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());
}
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());
}
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());
}
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()));
}
Aggregations