Search in sources :

Example 1 with ShapefileFeatureStore

use of org.geotoolkit.data.shapefile.ShapefileFeatureStore in project geotoolkit by Geomatys.

the class CreateShapefileDemo method main.

public static void main(String[] args) throws Exception {
    // create a featurestore toward the wanted path
    final ShapefileFeatureStore store = new ShapefileFeatureStore(URI.create("file:/tmp/test.shp"));
    // create the feature type needed
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("River");
    ftb.addAttribute(Point.class).setName("the_geom").setCRS(CommonCRS.WGS84.geographic());
    ftb.addAttribute(String.class).setName("name");
    final FeatureType type = ftb.build();
    // add this model in the datastore
    store.createFeatureType(type);
    // create and store a feature
    final List<Feature> features = new ArrayList<>();
    final Feature f = type.newInstance();
    f.setPropertyValue("the_geom", org.geotoolkit.geometry.jts.JTS.getFactory().createPoint(new Coordinate(15, 20)));
    f.setPropertyValue("name", "long river");
    features.add(f);
    store.addFeatures(type.getName().toString(), features);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) ShapefileFeatureStore(org.geotoolkit.data.shapefile.ShapefileFeatureStore) Feature(org.opengis.feature.Feature)

Example 2 with ShapefileFeatureStore

use of org.geotoolkit.data.shapefile.ShapefileFeatureStore in project geotoolkit by Geomatys.

the class CPGFileTest method testReadUTF8.

/**
 * Test reading a shapefile with an UTF-8 cpg file.
 *
 * @throws DataStoreException
 */
@Test
public void testReadUTF8() throws DataStoreException, MalformedURLException, URISyntaxException {
    final URL url = CPGFileTest.class.getResource("/org/geotoolkit/test-data/shapes/utf8.shp");
    final ShapefileFeatureStore store = new ShapefileFeatureStore(url.toURI());
    try (final FeatureReader reader = store.getFeatureReader(new Query(store.getName()))) {
        Assert.assertTrue(reader.hasNext());
        final Feature feature = reader.next();
        Assert.assertEquals("&éè\"'(-_çà)=@%$*:test", feature.getProperty("text").getValue());
    }
}
Also used : Query(org.geotoolkit.storage.feature.query.Query) ShapefileFeatureStore(org.geotoolkit.data.shapefile.ShapefileFeatureStore) FeatureReader(org.geotoolkit.storage.feature.FeatureReader) Feature(org.opengis.feature.Feature) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ShapefileFeatureStore

use of org.geotoolkit.data.shapefile.ShapefileFeatureStore in project geotoolkit by Geomatys.

the class IndexedShapefileDataStoreFactoryTest method testCreateNewDataStore.

/*
     * Test method for
     * 'org.geotoolkit.data.shapefile.indexed.IndexedShapefileDataStoreFactory.createNewDataStore(Map)'
     */
@Test
public void testCreateNewDataStore() throws Exception {
    ShapefileFeatureStore ds1 = testCreateDataStore(true, false);
    ShapefileFeatureStore ds2 = testCreateDataStore(true, true);
    assertNotSame(ds1, ds2);
}
Also used : ShapefileFeatureStore(org.geotoolkit.data.shapefile.ShapefileFeatureStore) Test(org.junit.Test)

Example 4 with ShapefileFeatureStore

use of org.geotoolkit.data.shapefile.ShapefileFeatureStore in project geotoolkit by Geomatys.

the class Styles method createPolygonContext.

public static MapLayers createPolygonContext(MutableStyle style) throws DataStoreException, URISyntaxException, MalformedURLException {
    MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
    context.setIdentifier("demo context");
    context.setTitle("demo context");
    DataStore store;
    FeatureSet fs;
    store = new ShapefileFeatureStore(Styles.class.getResource("/data/world/city.shp").toURI());
    fs = (FeatureSet) store.findResource("city");
    if (style == null) {
        style = SF.style(SF.polygonSymbolizer(SF.stroke(Color.BLACK, 0), SF.fill(SF.literal(new Color(0f, 0.5f, 0.2f, 1f)), FF.literal(0.3f)), null));
    }
    MapLayer layer = MapBuilder.createLayer(fs);
    layer.setStyle(style);
    layer.setAbstract("city");
    layer.setTitle("city");
    context.getComponents().add(layer);
    return context;
}
Also used : DataStore(org.apache.sis.storage.DataStore) MapLayer(org.apache.sis.portrayal.MapLayer) FeatureSet(org.apache.sis.storage.FeatureSet) ShapefileFeatureStore(org.geotoolkit.data.shapefile.ShapefileFeatureStore) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 5 with ShapefileFeatureStore

use of org.geotoolkit.data.shapefile.ShapefileFeatureStore in project geotoolkit by Geomatys.

the class Styles method createWorldContext.

// ////////////////////////////////////////////////////////////////////
// SAMPLE DATA ///////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public static MapLayers createWorldContext(MutableStyle style) throws DataStoreException, URISyntaxException, MalformedURLException {
    MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
    context.setIdentifier("demo context");
    context.setTitle("demo context");
    DataStore store;
    FeatureSet fs;
    store = new ShapefileFeatureStore(Styles.class.getResource("/data/world/Countries.shp").toURI());
    fs = (FeatureSet) store.findResource("Countries");
    if (style == null) {
        style = SF.style(SF.polygonSymbolizer(SF.stroke(Color.BLACK, 0), SF.fill(SF.literal(new Color(0f, 0.5f, 0.2f, 1f)), FF.literal(0.3f)), null));
    }
    MapLayer layer = MapBuilder.createLayer(fs);
    layer.setStyle(style);
    layer.setAbstract("world background");
    layer.setTitle("world background");
    context.getComponents().add(layer);
    return context;
}
Also used : DataStore(org.apache.sis.storage.DataStore) MapLayer(org.apache.sis.portrayal.MapLayer) FeatureSet(org.apache.sis.storage.FeatureSet) ShapefileFeatureStore(org.geotoolkit.data.shapefile.ShapefileFeatureStore) MapLayers(org.apache.sis.portrayal.MapLayers)

Aggregations

ShapefileFeatureStore (org.geotoolkit.data.shapefile.ShapefileFeatureStore)8 Test (org.junit.Test)3 URL (java.net.URL)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2 DataStore (org.apache.sis.storage.DataStore)2 FeatureSet (org.apache.sis.storage.FeatureSet)2 Query (org.geotoolkit.storage.feature.query.Query)2 Feature (org.opengis.feature.Feature)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 AbstractTestCaseSupport (org.geotoolkit.data.shapefile.AbstractTestCaseSupport)1 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)1 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 FeatureType (org.opengis.feature.FeatureType)1