The
IlvTigerDataSource class is a data source that reads TIGER/Line files.
This data source is filtered so that only selected features can be
read from the file, the others being ignored. These features can be
supplied in code as an array of strings or can be retrieved from a
IlvFeatureSelectorPanel configured with the
TigerFeaturesEN.txt
file.
This file contains the list of the Census Feature Class Codes (
CFCCs) and a description of the corresponding
features. Use the following lines to supply the CFCCs in the code:
try {
IlvTigerDataSource source = new IlvTigerDataSource(filename);
source.setManager(manager);
source.setCFCCCodeList(new String[]{"A41"});
source.start();
} catch (Exception e) {
e.printStackTrace();
}
To retrieve the CFCC codes from an IlvFeatureSelectiorPanel
,
you can use the following code, which creates, instantiates and starts
a TIGER/Line data source with the selected features:
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
final IlvFeatureSelectorPanel spanel = new IlvFeatureSelectorPanel(manager, "TigerFeaturesEN.txt");
JButton button = new JButton("OK");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Vector src = new Vector();
IlvFeatureSelectorPanel.Feature[] features = spanel.getSelectedFeatures();
ArrayList cfccCodes = new ArrayList();
if (features != null) {
for (int j = 0; j < features.length; j++) {
IlvFeatureSelectorPanel.Feature currentFeature = features[j];
IlvFeatureSelectorPanel.Feature currentChild;
int nChildren = currentFeature.getChildCount();
if (nChildren != 0) {// major
for (int i = 0; i < currentFeature.getChildCount(); i++) {
currentChild = (IlvFeatureSelectorPanel.Feature) currentFeature.getChildAt(i);
cfccCodes.add(currentChild.getMajorCode() + currentChild.getMinorCode());
}
} else {
cfccCodes.add(currentFeature.getMajorCode() + currentFeature.getMinorCode());
}
}
}
String[] s = (String[])cfccCodes.toArray(new String[0]);
try {
source = new IlvTigerDataSource(filename);
source.setManager(manager);
source.setCFCCCodeList(s);
source.start();
} catch (Exception e1) {
e1.printStackTrace(); }
}});
panel.add(button, BorderLayout.SOUTH);
JScrollPane pane = new JScrollPane(spanel);
panel.add(pane, BorderLayout.CENTER);
JFrame f = new JFrame();
f.getContentPane().add(panel);
f.pack();
f.setVisible(true);