从ShapeFile读取数据

时间:2015-02-09 21:07:54

标签: java swing gis shapefile geotools

我是GIS领域的新手,我正在使用geotools来阅读/查看形状文件如何在不使用InfoTool的情况下如何阅读有关形状文件中某些点的数据,现在我能够阅读和查看shp文件,我可以使用InfoTool,缩放工具,等等

    private void openButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    JFileDataStoreChooser x = new JFileDataStoreChooser("shp");
    x.setAcceptAllFileFilterUsed(false);
    x.setFileSelectionMode(JFileDataStoreChooser.FILES_ONLY);

    int val = x.showOpenDialog(null);
    if ((val == JFileDataStoreChooser.CANCEL_OPTION) || (val == JFileDataStoreChooser.ERROR_OPTION)) {
        return;
    }

    File file = x.getSelectedFile();
    if (file == null) {
        return;
    }

    try {
        store = FileDataStoreFinder.getDataStore(file);
        featureSource = store.getFeatureSource();

        // Create a map content and add our shapefile to it
        MapContent map = null;

        if (mapPane.getMapContent() == null) {
            map = new MapContent();
            map.setTitle("Quickstart");
        } else {
            map = mapPane.getMapContent();
        }

        Style style;
        style = SLD.createSimpleStyle(featureSource.getSchema());
        FeatureLayer layer = new FeatureLayer(featureSource, style);

        map.addLayer(layer);
        mapPane.setMapContent(map);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);

    }
    }

我想做的是:

mapPane.addMouseListener(new MapMouseAdapter() {

        @Override
        public void onMouseClicked(MapMouseEvent ev) {
               // ev.getWorldPos();
               // get data from shape file if found about position
               // view this data 
               // JOptionPane.showMessageDialog(data);
            }
        }

    });

0 个答案:

没有答案