How to load data from a Shape File directly

From OpenJUMP Wiki
Revision as of 18:32, 27 May 2010 by Mentaer (talk | contribs) (Created page with 'An example that allows to load data stored in a Shapefile directly, without any GUI interactions: <pre> String filename= "data/tigerline/2009_us_state/tl_2009_us_state.shp"; Sha…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

An example that allows to load data stored in a Shapefile directly, without any GUI interactions:

String filename= "data/tigerline/2009_us_state/tl_2009_us_state.shp";
ShapefileReader reader = new ShapefileReader();
FeatureCollection fc = reader.read(new DriverProperties(filename));
List<Feature> features = fc.getFeatures();

The list of features can then be parsed and modified. You can also add the FeatureCollection as layer in OpenJUMP using:

context.addLayer(StandardCategoryNames.RESULT, "myLayerName" , fc ); 

Note, the context is a PlugInContext available in a PlugIn class.