use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class CloneOpTest method testCloneWithTags.
@Test
public void testCloneWithTags() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
List<RevTag> tags = Lists.newArrayList();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
RevTag tag = remoteGeogig.geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName(f.getIdentifier().getID()).call();
tags.add(tag);
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the remote has all of the tags
ImmutableList<RevTag> remoteTags = remoteGeogig.geogig.command(TagListOp.class).call();
assertEquals(tags.size(), remoteTags.size());
for (RevTag tag : tags) {
assertTrue(remoteTags.contains(tag));
}
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
/*
* This is commented out, since the clone operation does not clone tags yet This test
* verifies that no errors are raised when the repo to clone contains tags, but not to
* verify that tags are also cloned, since that is not supported
*
* I leave this dommented code here, to uncomment it once tag support is implemented for the
* clone operation
*
*
* // Make sure the local repository got all of the tags
*
* ImmutableList<RevTag> localTags = localGeogig.geogig.command(TagListOp.class).call();
*
* assertEquals(tags.size(), localTags.size());
*
* for (RevTag tag : tags) {
*
* assertTrue(localTags.contains(tag));
*
* }
*/
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class CreatePatchOpTest method testCreatePatchUsingIndex.
@Test
public void testCreatePatchUsingIndex() throws Exception {
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).setAll(true).call();
final String featureId = points1.getIdentifier().getID();
final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId, "changedProp", new Integer(1500), null);
insertAndAdd(modifiedFeature);
insertAndAdd(points3);
deleteAndAdd(points2);
delete(points3);
DiffOp op = geogig.command(DiffOp.class);
op.setCompareIndex(true);
Iterator<DiffEntry> diffs = op.call();
Patch patch = geogig.command(CreatePatchOp.class).setDiffs(diffs).call();
assertEquals(3, patch.count());
assertEquals(1, patch.getAddedFeatures().size());
assertEquals(1, patch.getRemovedFeatures().size());
assertEquals(1, patch.getModifiedFeatures().size());
assertEquals(RevFeatureTypeImpl.build(pointsType), patch.getFeatureTypes().get(0));
assertEquals(NodeRef.appendChild(pointsName, idP2), patch.getRemovedFeatures().get(0).getPath());
assertEquals(NodeRef.appendChild(pointsName, idP3), patch.getAddedFeatures().get(0).getPath());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class DiffOpTest method testSingleModification.
@Test
public void testSingleModification() throws Exception {
final ObjectId oldOid = insertAndAdd(points1);
final RevCommit insertCommit = geogig.command(CommitOp.class).setAll(true).call();
final String featureId = points1.getIdentifier().getID();
final Feature modifiedFeature = feature((SimpleFeatureType) points1.getType(), featureId, "changedProp", new Integer(1500), null);
final ObjectId newOid = insertAndAdd(modifiedFeature);
final RevCommit changeCommit = geogig.command(CommitOp.class).setAll(true).call();
List<DiffEntry> difflist = toList(diffOp.setOldVersion(insertCommit.getId()).setNewVersion(changeCommit.getId()).call());
assertNotNull(difflist);
assertEquals(1, difflist.size());
DiffEntry de = difflist.get(0);
String expectedPath = NodeRef.appendChild(pointsName, featureId);
assertEquals(expectedPath, de.newPath());
assertEquals(DiffEntry.ChangeType.MODIFIED, de.changeType());
assertEquals(oldOid, de.oldObjectId());
assertEquals(newOid, de.newObjectId());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class DiffOpTest method testReportRename.
@Test
public void testReportRename() throws Exception {
insertAndAdd(lines1);
final RevCommit commit1 = geogig.command(CommitOp.class).setAll(true).call();
Feature lines1B = feature(linesType, idL2, "StringProp2_1", new Integer(1000), "LINESTRING (1 1, 2 2)");
delete(lines1);
// insert(lines2);
WorkingTree workTree = repo.workingTree();
Name name = lines1.getType().getName();
String parentPath = name.getLocalPart();
@SuppressWarnings("unused") Node ref = workTree.insert(parentPath, lines1B);
geogig.command(AddOp.class).call();
RevCommit commit2 = geogig.command(CommitOp.class).setAll(true).call();
List<DiffEntry> diffs;
diffOp.setOldVersion(commit1.getId());
diffOp.setNewVersion(commit2.getId());
diffs = toList(diffOp.call());
// this is reported as an addition and a removal, with both
assertEquals(2, diffs.size());
// nodes pointing to same ObjectId
assertEquals(diffs.get(0).newObjectId(), diffs.get(1).oldObjectId());
assertEquals(diffs.get(1).newObjectId(), diffs.get(0).oldObjectId());
}
use of org.opengis.feature.Feature in project GeoGig by boundlessgeo.
the class ShpExportDiff method runInternal.
/**
* Executes the export command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
if (args.size() != 4) {
printUsage(cli);
throw new CommandFailedException();
}
String commitOld = args.get(0);
String commitNew = args.get(1);
String path = args.get(2);
String shapefile = args.get(3);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
File file = new File(shapefile);
if (file.exists() && !overwrite) {
throw new CommandFailedException("The selected shapefile already exists. Use -o to overwrite");
}
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.FALSE);
params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX.key, Boolean.FALSE);
ShapefileDataStore dataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
SimpleFeatureType outputFeatureType;
try {
outputFeatureType = getFeatureType(path, cli);
} catch (GeoToolsOpException e) {
cli.getConsole().println("No features to export.");
return;
}
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.add("geogig_fid", String.class);
for (AttributeDescriptor descriptor : outputFeatureType.getAttributeDescriptors()) {
builder.add(descriptor);
}
builder.setName(outputFeatureType.getName());
builder.setCRS(outputFeatureType.getCoordinateReferenceSystem());
outputFeatureType = builder.buildFeatureType();
dataStore.createSchema(outputFeatureType);
final String typeName = dataStore.getTypeNames()[0];
final SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
if (!(featureSource instanceof SimpleFeatureStore)) {
throw new CommandFailedException("Could not create feature store.");
}
final SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
Function<Feature, Optional<Feature>> function = getTransformingFunction(dataStore.getSchema());
ExportDiffOp op = cli.getGeogig().command(ExportDiffOp.class).setFeatureStore(featureStore).setPath(path).setOldRef(commitOld).setNewRef(commitNew).setUseOld(old).setTransactional(false).setFeatureTypeConversionFunction(function);
try {
op.setProgressListener(cli.getProgressListener()).call();
} catch (IllegalArgumentException iae) {
throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
} catch (GeoToolsOpException e) {
file.delete();
switch(e.statusCode) {
case MIXED_FEATURE_TYPES:
throw new CommandFailedException("Error: The selected tree contains mixed feature types.", e);
default:
throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
}
}
cli.getConsole().println(path + " exported successfully to " + shapefile);
}
Aggregations