Search in sources :

Example 61 with Feature

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));
         * 
         * }
         */
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 62 with Feature

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());
}
Also used : DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) Feature(org.opengis.feature.Feature) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 63 with Feature

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());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 64 with Feature

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) Node(org.locationtech.geogig.api.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) Name(org.opengis.feature.type.Name) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Example 65 with Feature

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);
}
Also used : Serializable(java.io.Serializable) ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) ExportDiffOp(org.locationtech.geogig.geotools.plumbing.ExportDiffOp) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) Feature(org.opengis.feature.Feature) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) ShapefileDataStoreFactory(org.geotools.data.shapefile.ShapefileDataStoreFactory) File(java.io.File)

Aggregations

Feature (org.opengis.feature.Feature)128 Test (org.junit.Test)90 RevCommit (org.locationtech.geogig.api.RevCommit)52 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)43 SimpleFeature (org.opengis.feature.simple.SimpleFeature)38 ObjectId (org.locationtech.geogig.api.ObjectId)35 RevFeature (org.locationtech.geogig.api.RevFeature)32 NodeRef (org.locationtech.geogig.api.NodeRef)29 LinkedList (java.util.LinkedList)27 LogOp (org.locationtech.geogig.api.porcelain.LogOp)23 Ref (org.locationtech.geogig.api.Ref)21 RefParse (org.locationtech.geogig.api.plumbing.RefParse)19 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)18 ArrayList (java.util.ArrayList)16 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)16 RevObject (org.locationtech.geogig.api.RevObject)16 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Function (com.google.common.base.Function)13 Optional (com.google.common.base.Optional)12 HashMap (java.util.HashMap)12