How to load data from a Shape File directly

From OpenJUMP Wiki
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.

For other examples, and also on how to load image files by code check out this email thread:
http://www.mail-archive.com/jump-pilot-devel@lists.sourceforge.net/msg07498.html