Search in sources :

Example 1 with MemoryDataStore

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);
    }
}
Also used : FeatureJSON(org.geotools.geojson.feature.FeatureJSON) FeatureCollection(org.geotools.feature.FeatureCollection) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataStore(org.geotools.data.DataStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 2 with MemoryDataStore

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());
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) FeatureSource(org.geotools.data.FeatureSource) QueryCapabilities(org.geotools.data.QueryCapabilities) Query(org.geotools.data.Query) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 3 with MemoryDataStore

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;
}
Also used : AbstractDataStoreFactory(org.geotools.data.AbstractDataStoreFactory) Serializable(java.io.Serializable) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString)

Example 4 with MemoryDataStore

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;
}
Also used : AbstractDataStoreFactory(org.geotools.data.AbstractDataStoreFactory) Serializable(java.io.Serializable) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Matchers.anyString(org.mockito.Matchers.anyString)

Example 5 with MemoryDataStore

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;
}
Also used : AbstractDataStoreFactory(org.geotools.data.AbstractDataStoreFactory) Serializable(java.io.Serializable) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

MemoryDataStore (org.geotools.data.memory.MemoryDataStore)22 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 Test (org.junit.Test)14 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)13 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)13 Feature (org.opengis.feature.Feature)11 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)9 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)9 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)8 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 AbstractDataStoreFactory (org.geotools.data.AbstractDataStoreFactory)4 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)4 Matchers.anyString (org.mockito.Matchers.anyString)4 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)4 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 File (java.io.File)2 DataStore (org.geotools.data.DataStore)2