use of org.geotools.data.simple.SimpleFeatureSource in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromHEAD.
@Test
public void testExportFromHEAD() throws Exception {
Feature[] points = new Feature[] { points1, points2, points3 };
for (Feature feature : points) {
insert(feature);
}
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setAll(true).call();
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath("HEAD:" + pointsName).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
use of org.geotools.data.simple.SimpleFeatureSource in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportWithAlterUsingDefaultFeatureType.
@Test
public void testExportWithAlterUsingDefaultFeatureType() throws Exception {
Feature[] points = new Feature[] { points2, points1B, points3 };
for (Feature feature : points) {
insert(feature);
}
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).setAlter(true).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), points.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, points));
}
use of org.geotools.data.simple.SimpleFeatureSource in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromTreeWithSeveralFeatureTypesUsingDefaultFeatureType.
@Test
public void testExportFromTreeWithSeveralFeatureTypesUsingDefaultFeatureType() throws Exception {
Feature[] points = new Feature[] { points2, points1B, points3 };
for (Feature feature : points) {
insert(feature);
}
Feature[] expectedPoints = new Feature[] { points2, points3 };
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).exportDefaultFeatureType().call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(featureCollection.size(), expectedPoints.length);
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, expectedPoints));
}
use of org.geotools.data.simple.SimpleFeatureSource in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testGetFeatureSourceString.
@Test
public void testGetFeatureSourceString() throws Exception {
try {
dataStore.getFeatureSource(RepositoryTestCase.linesName);
fail("Expected IOException");
} catch (IOException e) {
assertTrue(true);
}
SimpleFeatureSource source;
insertAndAdd(lines1);
commit();
source = dataStore.getFeatureSource(RepositoryTestCase.linesName);
assertTrue(source instanceof GeogigFeatureStore);
try {
dataStore.getFeatureSource(RepositoryTestCase.pointsName);
fail("Expected IOException");
} catch (IOException e) {
assertTrue(true);
}
insertAndAdd(points1);
commit();
source = dataStore.getFeatureSource(RepositoryTestCase.pointsName);
assertTrue(source instanceof GeogigFeatureStore);
}
use of org.geotools.data.simple.SimpleFeatureSource 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);
}
Aggregations