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