use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromWrongFeatureType.
@Test
public void testExportFromWrongFeatureType() throws Exception {
MemoryDataStore dataStore = new MemoryDataStore(pointsType);
final String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
try {
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).call();
fail();
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromTreeWithSeveralFeatureTypesUsingNonexistantTypeId.
@Test
public void testExportFromTreeWithSeveralFeatureTypesUsingNonexistantTypeId() 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;
try {
geogig.command(ExportOp.class).setFeatureStore(featureStore).setPath(pointsName).setFilterFeatureTypeId(ObjectId.forString("fake")).call();
fail();
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().contains("filter feature type"));
}
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromWorkingTree.
@Test
public void testExportFromWorkingTree() throws Exception {
Feature[] points = new Feature[] { points1, points2, 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).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.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class ExportOpTest method testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId.
@Test
public void testExportFromTreeWithSeveralFeatureTypesUsingFeatureTypeId() throws Exception {
Feature[] points = new Feature[] { points2, points1B, points3 };
for (Feature feature : points) {
insert(feature);
}
Feature[] expectedPoints = new Feature[] { points1B };
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).setFilterFeatureTypeId(RevFeatureTypeImpl.build(modifiedPointsType).getId()).call();
featureSource = dataStore.getFeatureSource(typeName);
featureStore = (SimpleFeatureStore) featureSource;
SimpleFeatureCollection featureCollection = featureStore.getFeatures();
assertEquals(expectedPoints.length, featureCollection.size());
SimpleFeatureIterator features = featureCollection.features();
assertTrue(collectionsAreEqual(features, expectedPoints));
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class AbstractGeoJsonCommand method getDataStore.
protected DataStore getDataStore(String geoJSON) throws FileNotFoundException, IOException {
try {
File geoJsonfile = new File(geoJSON);
checkParameter(geoJsonfile.exists(), "File does not exist '%s'", geoJsonfile);
InputStream in = new FileInputStream(geoJsonfile);
FeatureJSON fjson = new FeatureJSON();
@SuppressWarnings("rawtypes") FeatureCollection fc = fjson.readFeatureCollection(in);
@SuppressWarnings("unchecked") DataStore dataStore = new MemoryDataStore(fc);
return dataStore;
} catch (IOException ioe) {
throw new CommandFailedException("Error opening GeoJSON: " + ioe.getMessage(), ioe);
}
}
Aggregations