Reputation: 448
I would like to read a shapefile in java and then draw it. Are there anyway to read a shapefile and draw it in java? Do you know any useful and easy framework?
Thanks.
Upvotes: 1
Views: 1287
Reputation: 1919
You can try Geotools. You can start with this code.
public class Quickstart {
public static void main(String[] args) throws Exception {
File file = JFileDataStoreChooser.showOpenFile("shp", null);
if (file == null) {
return;
}
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
// Create a map content and add our shapefile to it
MapContent map = new MapContent();
map.setTitle("Quickstart");
Style style = SLD.createSimpleStyle(featureSource.getSchema());
Layer layer = new FeatureLayer(featureSource, style);
map.addLayer(layer);
// Display the map
JMapFrame.showMap(map);
}
}
Upvotes: 3