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);
}
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());
}
}
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);
}
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;
}
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;
}
Aggregations