Search in sources :

Example 16 with FeatureStore

use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.

the class ShapefileQuadTreeReadWriteTest method test.

private void test(final FeatureType type, final FeatureCollection one, final File tmp, final ShapefileProvider maker, final boolean memorymapped) throws IOException, MalformedURLException, Exception {
    FeatureStore s;
    s = createDataStore(maker, tmp.toURI().toURL(), memorymapped);
    s.createFeatureType(type);
    Session session = s.createSession(true);
    session.addFeatures(type.getName().toString(), one);
    session.commit();
    s = createDataStore(new ShapefileProvider(), tmp.toURI().toURL(), true);
    GenericName typeName = s.getNames().iterator().next();
    FeatureCollection two = s.createSession(true).getFeatureCollection(new Query(typeName));
    // copy values, order is not tested here.
    Collection<Feature> cone = new ArrayList<>();
    Collection<Feature> ctwo = new ArrayList<>();
    FeatureStoreUtilities.fill(one, cone);
    FeatureStoreUtilities.fill(two, ctwo);
// one.containsAll(two);
// two.containsAll(one);
}
Also used : GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session) ShapefileProvider(org.geotoolkit.data.shapefile.ShapefileProvider)

Example 17 with FeatureStore

use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.

the class ShapefileQuadTreeReadWriteTest method test.

void test(final String f) throws Exception {
    // ShapeTestData.url(f)
    // File file = copyShapefiles(f); // Work on File rather than URL from
    // // JAR.
    FeatureStore s = createDataStore(new ShapefileProvider(), ShapeTestData.url(f), true);
    GenericName typeName = s.getNames().iterator().next();
    FeatureType type = s.getFeatureType(typeName.toString());
    FeatureCollection one = s.createSession(true).getFeatureCollection(new Query(typeName));
    ShapefileProvider maker = new ShapefileProvider();
    test(type, one, getTempFile(), maker, false);
    test(type, one, getTempFile(), maker, true);
}
Also used : FeatureType(org.opengis.feature.FeatureType) GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) ShapefileProvider(org.geotoolkit.data.shapefile.ShapefileProvider)

Example 18 with FeatureStore

use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.

the class AbstractModelTests method testDataStore.

@Test
public void testDataStore() {
    final FeatureStore store = getDataStore();
    assertNotNull(store);
}
Also used : FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Test(org.junit.Test)

Example 19 with FeatureStore

use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.

the class AbstractModelTests method testSchemaCreation.

@Test
public void testSchemaCreation() throws Exception {
    final FeatureStore store = getDataStore();
    final List<Class> geometryBindings = getSupportedGeometryTypes();
    final List<Class> bindinds = getSupportedAttributTypes();
    FeatureTypeBuilder sftb = new FeatureTypeBuilder();
    final Session session = store.createSession(true);
    for (final Class geomType : geometryBindings) {
        // create the schema ------------------------------------------------
        final String name = "testname";
        sftb = new FeatureTypeBuilder();
        sftb.setName(name);
        sftb.addAttribute(geomType).setName("att_geometry").setCRS(CommonCRS.WGS84.geographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
        for (int i = 0; i < bindinds.size(); i++) {
            sftb.addAttribute(bindinds.get(i)).setName("att" + i);
        }
        final FeatureType sft = sftb.build();
        // add listeners
        StorageCountListener storeListen = new StorageCountListener();
        StorageCountListener sessionListen = new StorageCountListener();
        store.addListener(StoreEvent.class, storeListen);
        session.addListener(StoreEvent.class, sessionListen);
        store.createFeatureType(sft);
        final FeatureType type = store.getFeatureType(name);
        assertNotNull(type);
        assertTrue(FeatureTypeExt.equalsIgnoreConvention(sft, type));
        // check listeners
        // assertEquals(1, storeListen.numManageEvent);
        // assertEquals(1, sessionListen.numManageEvent);
        // assertEquals(0, storeListen.numContentEvent);
        // assertEquals(0, sessionListen.numContentEvent);
        // assertNotNull(storeListen.lastManagementEvent);
        // assertNotNull(sessionListen.lastManagementEvent);
        // assertNull(storeListen.lastContentEvent);
        // assertNull(sessionListen.lastContentEvent);
        // assertEquals(StorageManagementEvent.Type.ADD, storeListen.lastManagementEvent.getType());
        // assertEquals(StorageManagementEvent.Type.ADD, sessionListen.lastManagementEvent.getType());
        // assertEquals(name, storeListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
        // assertEquals(name, sessionListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
        // assertEquals(sft, storeListen.lastManagementEvent.getNewFeatureType());
        // assertEquals(sft, sessionListen.lastManagementEvent.getNewFeatureType());
        // assertEquals(null, storeListen.lastManagementEvent.getOldFeatureType());
        // assertEquals(null, sessionListen.lastManagementEvent.getOldFeatureType());
        store.removeListener(StoreEvent.class, storeListen);
        session.removeListener(StoreEvent.class, sessionListen);
        // delete the created schema ----------------------------------------
        GenericName nsname = null;
        for (GenericName n : store.getNames()) {
            if (n.tip().toString().equalsIgnoreCase(name)) {
                nsname = n;
                break;
            }
        }
        assertNotNull(nsname);
        readAndWriteTest(store, nsname);
        // add listeners
        storeListen = new StorageCountListener();
        sessionListen = new StorageCountListener();
        store.addListener(StoreEvent.class, storeListen);
        session.addListener(StoreEvent.class, sessionListen);
        store.deleteFeatureType(nsname.toString());
        // check listeners
        // assertEquals(1, storeListen.numManageEvent);
        // assertEquals(1, sessionListen.numManageEvent);
        // assertEquals(0, storeListen.numContentEvent);
        // assertEquals(0, sessionListen.numContentEvent);
        // assertNotNull(storeListen.lastManagementEvent);
        // assertNotNull(sessionListen.lastManagementEvent);
        // assertNull(storeListen.lastContentEvent);
        // assertNull(sessionListen.lastContentEvent);
        // assertEquals(StorageManagementEvent.Type.DELETE, storeListen.lastManagementEvent.getType());
        // assertEquals(StorageManagementEvent.Type.DELETE, sessionListen.lastManagementEvent.getType());
        // assertEquals(name, storeListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
        // assertEquals(name, sessionListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
        // assertEquals(null, storeListen.lastManagementEvent.getNewFeatureType());
        // assertEquals(null, sessionListen.lastManagementEvent.getNewFeatureType());
        // assertEquals(sft, storeListen.lastManagementEvent.getOldFeatureType());
        // assertEquals(sft, sessionListen.lastManagementEvent.getOldFeatureType());
        store.removeListener(StoreEvent.class, storeListen);
        session.removeListener(StoreEvent.class, sessionListen);
        try {
            store.getFeatureType(nsname.toString());
            throw new Exception("Should have raised an error.");
        } catch (DataStoreException ex) {
        // ok
        }
    }
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) GenericName(org.opengis.util.GenericName) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) DataStoreException(org.apache.sis.storage.DataStoreException) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 20 with FeatureStore

use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.

the class PostgisDemo method main.

public static void main(String[] args) throws DataStoreException {
    Demos.init();
    System.out.println(PostgresProvider.PARAMETERS_DESCRIPTOR);
    final Parameters parameters = Parameters.castOrWrap(PostgresProvider.PARAMETERS_DESCRIPTOR.createValue());
    parameters.getOrCreate(PostgresProvider.HOST).setValue("hote");
    parameters.getOrCreate(PostgresProvider.PORT).setValue(5432);
    parameters.getOrCreate(PostgresProvider.DATABASE).setValue("base");
    parameters.getOrCreate(PostgresProvider.USER).setValue("user");
    parameters.getOrCreate(PostgresProvider.PASSWORD).setValue("secret");
    final FeatureStore store = (FeatureStore) DataStores.open(parameters);
    final MapLayers context = MapBuilder.createContext();
    for (GenericName n : store.getNames()) {
        System.out.println(store.getFeatureType(n.toString()));
        final FeatureSet col = store.createSession(true).getFeatureCollection(new Query(n));
        final MapLayer layer = MapBuilder.createLayer(col);
        layer.setStyle(RandomStyleBuilder.createRandomVectorStyle(col.getType()));
        context.getComponents().add(layer);
    }
// FXMapFrame.show(context);
}
Also used : GenericName(org.opengis.util.GenericName) Parameters(org.apache.sis.parameter.Parameters) Query(org.geotoolkit.storage.feature.query.Query) MapLayer(org.apache.sis.portrayal.MapLayer) FeatureSet(org.apache.sis.storage.FeatureSet) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

FeatureStore (org.geotoolkit.storage.feature.FeatureStore)28 GenericName (org.opengis.util.GenericName)11 AbstractFeatureStore (org.geotoolkit.storage.feature.AbstractFeatureStore)10 Query (org.geotoolkit.storage.feature.query.Query)9 DataStoreException (org.apache.sis.storage.DataStoreException)8 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)6 Test (org.junit.Test)6 FeatureType (org.opengis.feature.FeatureType)6 Session (org.geotoolkit.storage.feature.session.Session)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 Parameters (org.apache.sis.parameter.Parameters)3 ShapefileProvider (org.geotoolkit.data.shapefile.ShapefileProvider)3 Feature (org.opengis.feature.Feature)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2