在java中绘制shapefile

时间:2015-04-28 21:54:34

标签: java shapefile

我想在java中读取shapefile然后绘制它。反正有没有读取shapefile并在java中绘制?你知道任何有用而简单的框架吗?

感谢。

1 个答案:

答案 0 :(得分:2)

您可以尝试Geotools。你可以从这段代码开始。

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