Search in sources :

Example 86 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeoGigDataStoreTest method testGetSchemaString.

@Test
public void testGetSchemaString() throws Exception {
    try {
        dataStore.getSchema(RepositoryTestCase.linesName);
        fail("Expected IOException");
    } catch (IOException e) {
        assertTrue(true);
    }
    insertAndAdd(lines1);
    commit();
    SimpleFeatureType lines = dataStore.getSchema(RepositoryTestCase.linesName);
    assertEquals(super.linesType.getAttributeDescriptors(), lines.getAttributeDescriptors());
    try {
        dataStore.getSchema(RepositoryTestCase.pointsName);
        fail("Expected IOException");
    } catch (IOException e) {
        assertTrue(true);
    }
    insertAndAdd(points1);
    commit();
    SimpleFeatureType points = dataStore.getSchema(RepositoryTestCase.pointsName);
    assertEquals(super.pointsType, points);
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) IOException(java.io.IOException) Test(org.junit.Test)

Example 87 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class ReportMergeConflictsOpTest method testModifiedDefaultFeatureTypeInBothBranches.

@Test
public void testModifiedDefaultFeatureTypeInBothBranches() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    geogig.getRepository().workingTree().updateTypeTree(pointsName, modifiedPointsType);
    insert(points1B);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    String modifiedPointsTypeSpecB = "sp:String,ip:Integer,pp:Point:srid=4326,extraB:String";
    SimpleFeatureType modifiedPointsTypeB = DataUtilities.createType(pointsNs, pointsName, modifiedPointsTypeSpecB);
    geogig.getRepository().workingTree().updateTypeTree(pointsName, modifiedPointsTypeB);
    insert(points1B);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class).setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit).call();
    // the conflict in the feature type
    assertEquals(1, conflicts.getConflicts().size());
    // the change in the feature is the
    assertEquals(0, conflicts.getUnconflicted().size());
    // same, so no conflict
    Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class).setCommits(Lists.newArrayList(masterCommit, branchCommit)).call();
    assertTrue(hasConflicts.booleanValue());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ReportMergeScenarioOp(org.locationtech.geogig.api.plumbing.merge.ReportMergeScenarioOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 88 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class DescribeOp method _call.

/**
     * Describes a table from the data store that has been assigned.
     * 
     * @return a map that contains all properties and their types from the provided table
     */
@Override
protected Optional<Map<String, String>> _call() {
    if (dataStore == null) {
        throw new GeoToolsOpException(StatusCode.DATASTORE_NOT_DEFINED);
    }
    if (table == null || table.isEmpty()) {
        throw new GeoToolsOpException(StatusCode.TABLE_NOT_DEFINED);
    }
    Map<String, String> propertyMap = new HashMap<String, String>();
    boolean foundTable = false;
    List<Name> typeNames;
    try {
        typeNames = dataStore.getNames();
    } catch (Exception e) {
        throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_NAMES);
    }
    for (Name typeName : typeNames) {
        if (!table.equals(typeName.toString()))
            continue;
        foundTable = true;
        SimpleFeatureSource featureSource;
        try {
            featureSource = dataStore.getFeatureSource(typeName);
        } catch (Exception e) {
            throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
        }
        SimpleFeatureType featureType = featureSource.getSchema();
        Collection<PropertyDescriptor> descriptors = featureType.getDescriptors();
        for (PropertyDescriptor descriptor : descriptors) {
            propertyMap.put(descriptor.getName().toString(), descriptor.getType().getBinding().getSimpleName());
        }
    }
    if (!foundTable) {
        return Optional.absent();
    }
    return Optional.of(propertyMap);
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) HashMap(java.util.HashMap) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) Name(org.opengis.feature.type.Name)

Example 89 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class ExportDiffOp method addFidAttribute.

private static SimpleFeatureType addFidAttribute(RevFeatureType revFType) {
    SimpleFeatureType featureType = (SimpleFeatureType) revFType.type();
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.add("geogig_fid", String.class);
    for (AttributeDescriptor descriptor : featureType.getAttributeDescriptors()) {
        builder.add(descriptor);
    }
    builder.setName(featureType.getName());
    builder.setCRS(featureType.getCoordinateReferenceSystem());
    featureType = builder.buildFeatureType();
    return featureType;
}
Also used : SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 90 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class ExportDiffOp method getFeatures.

private static Iterator<SimpleFeature> getFeatures(Iterator<DiffEntry> diffs, final boolean old, final ObjectDatabase database, final ObjectId metadataId, final ProgressListener progressListener) {
    final SimpleFeatureType featureType = addFidAttribute(database.getFeatureType(metadataId));
    final RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
    final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
    Function<DiffEntry, SimpleFeature> asFeature = new Function<DiffEntry, SimpleFeature>() {

        @Override
        @Nullable
        public SimpleFeature apply(final DiffEntry input) {
            NodeRef nodeRef = old ? input.getOldObject() : input.getNewObject();
            if (nodeRef == null) {
                return null;
            }
            final RevFeature revFeature = database.getFeature(nodeRef.objectId());
            ImmutableList<Optional<Object>> values = revFeature.getValues();
            for (int i = 0; i < values.size(); i++) {
                String name = featureType.getDescriptor(i + 1).getLocalName();
                Object value = values.get(i).orNull();
                featureBuilder.set(name, value);
            }
            featureBuilder.set("geogig_fid", nodeRef.name());
            Feature feature = featureBuilder.buildFeature(nodeRef.name());
            feature.getUserData().put(Hints.USE_PROVIDED_FID, true);
            feature.getUserData().put(RevFeature.class, revFeature);
            feature.getUserData().put(RevFeatureType.class, revFeatureType);
            if (feature instanceof SimpleFeature) {
                return (SimpleFeature) feature;
            }
            return null;
        }
    };
    Iterator<SimpleFeature> asFeatures = Iterators.transform(diffs, asFeature);
    UnmodifiableIterator<SimpleFeature> filterNulls = Iterators.filter(asFeatures, Predicates.notNull());
    return filterNulls;
}
Also used : Optional(com.google.common.base.Optional) RevFeature(org.locationtech.geogig.api.RevFeature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Function(com.google.common.base.Function) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)152 SimpleFeature (org.opengis.feature.simple.SimpleFeature)78 IOException (java.io.IOException)47 Test (org.junit.Test)38 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)32 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)27 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)24 HashMap (java.util.HashMap)23 DataStore (org.geotools.data.DataStore)22 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)22 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)22 ObjectId (org.locationtech.geogig.api.ObjectId)20 ArrayList (java.util.ArrayList)18 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)18 Feature (org.opengis.feature.Feature)18 File (java.io.File)17 DefaultTransaction (org.geotools.data.DefaultTransaction)17 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)16 Transaction (org.geotools.data.Transaction)15 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)15