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);
}
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class WorkingTreeTest method testInsertPagingFeatureSource.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testInsertPagingFeatureSource() throws Exception {
assertEquals(2, super.getGeogig().getPlatform().availableProcessors());
final List<SimpleFeature> features = ImmutableList.of((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3);
MemoryDataStore store = new MemoryDataStore();
store.addFeatures(features);
final QueryCapabilities caps = mock(QueryCapabilities.class);
when(caps.isOffsetSupported()).thenReturn(true);
FeatureSource source = new ForwardingFeatureSource(store.getFeatureSource(pointsName)) {
@Override
public QueryCapabilities getQueryCapabilities() {
return caps;
}
@Override
public FeatureCollection getFeatures(Query query) throws IOException {
Integer startIndex = query.getStartIndex();
if (startIndex == null) {
return super.getFeatures();
}
int toIndex = (int) Math.min((long) startIndex + query.getMaxFeatures(), features.size());
List<SimpleFeature> result = features.subList(startIndex, toIndex);
return DataUtilities.collection(result);
}
};
assertTrue(source.getQueryCapabilities().isOffsetSupported());
String treePath = "target_typename";
workTree.insert(treePath, source, Query.ALL, LISTENER);
assertEquals(3, workTree.countUnstaged(treePath).featureCount());
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class TestHelper method createFactoryWithGetNamesException.
public static AbstractDataStoreFactory createFactoryWithGetNamesException() throws Exception {
MemoryDataStore testDataStore = mock(MemoryDataStore.class);
when(testDataStore.getNames()).thenThrow(new IOException());
when(testDataStore.getTypeNames()).thenThrow(new RuntimeException());
when(testDataStore.getSchema(anyString())).thenThrow(new IOException());
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(testDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class TestHelper method createEmptyTestFactory.
public static AbstractDataStoreFactory createEmptyTestFactory() throws Exception {
MemoryDataStore testDataStore = new MemoryDataStore();
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(testDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
use of org.geotools.data.memory.MemoryDataStore in project GeoGig by boundlessgeo.
the class TestHelper method createFactoryWithGetFeatureSourceException.
public static AbstractDataStoreFactory createFactoryWithGetFeatureSourceException() throws Exception {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.setCRS(CRS.decode("EPSG:4326"));
builder.add("geom", Point.class);
builder.add("label", String.class);
builder.setName("table1");
SimpleFeatureType type = builder.buildFeatureType();
SimpleFeatureTypeBuilder builder2 = new SimpleFeatureTypeBuilder();
builder2.setCRS(CRS.decode("EPSG:4326"));
builder2.add("geom", Point.class);
builder2.add("name", String.class);
builder2.setName("table2");
SimpleFeatureType type2 = builder2.buildFeatureType();
GeometryFactory gf = new GeometryFactory();
SimpleFeature f1 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 8)), "feature1" }, null);
SimpleFeature f2 = SimpleFeatureBuilder.build(type, new Object[] { gf.createPoint(new Coordinate(5, 4)), "feature2" }, null);
SimpleFeature f3 = SimpleFeatureBuilder.build(type2, new Object[] { gf.createPoint(new Coordinate(3, 2)), "feature3" }, null);
MemoryDataStore testDataStore = new MemoryDataStore();
testDataStore.addFeature(f1);
testDataStore.addFeature(f2);
testDataStore.addFeature(f3);
MemoryDataStore spyDataStore = spy(testDataStore);
when(spyDataStore.getFeatureSource("table1")).thenThrow(new IOException("Exception"));
final AbstractDataStoreFactory factory = mock(AbstractDataStoreFactory.class);
when(factory.createDataStore(anyMapOf(String.class, Serializable.class))).thenReturn(spyDataStore);
when(factory.canProcess(anyMapOf(String.class, Serializable.class))).thenReturn(true);
return factory;
}
Aggregations