Search in sources :

Example 6 with MemoryDataStore

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);
    }
}
Also used : SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Test(org.junit.Test)

Example 7 with MemoryDataStore

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"));
    }
}
Also used : SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 8 with MemoryDataStore

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));
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Example 9 with MemoryDataStore

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));
}
Also used : SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) MemoryDataStore(org.geotools.data.memory.MemoryDataStore) Feature(org.opengis.feature.Feature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Example 10 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)

Aggregations

MemoryDataStore (org.geotools.data.memory.MemoryDataStore)20 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 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)6 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 IOException (java.io.IOException)3 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 FeatureSource (org.geotools.data.FeatureSource)2 QueryCapabilities (org.geotools.data.QueryCapabilities)2