01: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/tools/shape/IndexShapeFile.java $
02: /*
03:
04: This file is part of deegree.
05: Copyright (C) 2001-2008 by:
06: EXSE, Department of Geography, University of Bonn
07: http://www.giub.uni-bonn.de/deegree/
08: lat/lon GmbH
09: http://www.lat-lon.de
10:
11: This library is free software; you can redistribute it and/or
12: modify it under the terms of the GNU Lesser General Public
13: License as published by the Free Software Foundation; either
14: version 2.1 of the License, or (at your option) any later version.
15:
16: This library is distributed in the hope that it will be useful,
17: but WITHOUT ANY WARRANTY; without even the implied warranty of
18: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19: Lesser General Public License for more details.
20:
21: You should have received a copy of the GNU Lesser General Public
22: License along with this library; if not, write to the Free Software
23: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24:
25: Application to index a shape file, using the R-tree algorithm.
26: Copyright (C) May 2003 by IDgis BV, The Netherlands - www.idgis.nl
27: */
28:
29: package org.deegree.tools.shape;
30:
31: import java.io.File;
32:
33: import javax.swing.JFileChooser;
34: import javax.swing.JFrame;
35: import javax.swing.filechooser.FileFilter;
36:
37: import org.deegree.framework.file.FileMemory;
38:
39: /**
40: <p>IndexShapeFile is an application that can be used to index an ESRI ShapeFiles(tm).
41: It indexes both the geometry and the alphanumeric attributes</p>
42:
43: <p>The application shows a file chooser with which the user can select a file. When a file
44: is choosen the application opens it and shows the attributes. The user can now select the
45: attributes that has to be indexed. Already indexed attributes are already selected and can
46: be deselected. For alphanumeric attributes the user can indicate if the attribute is unique or not.</p>
47:
48: <p>After selecting the attributes the application creates the needed indexes and loops over all the
49: features in the shape file. For every feature the application inserts the attributes in the right index.
50: After looping over the features the application closes the shapefile and the created indexes and removes the indexes
51: that are no longer needed (eg. the index for the attributes that are deselected).</p>
52:
53: <p>It is not possible to transform a unique index to a non-unique index or back.</p>
54: */
55: public class IndexShapeFile {
56:
57: public static void main(String[] args) throws Exception {
58: JFileChooser fileChooser = new JFileChooser();
59: fileChooser.setCurrentDirectory(FileMemory
60: .getLastDirectory("IndexShapeFile"));
61: fileChooser.setFileFilter(new ShapeFilter());
62: fileChooser.setFileView(new ShapeView());
63: if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
64: IndexFrame indexFrame = new IndexFrame(fileChooser
65: .getSelectedFile());
66: indexFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
67: indexFrame.setVisible(true);
68: FileMemory.setLastDirectory("IndexShapeFile", fileChooser
69: .getSelectedFile());
70: } else {
71: System.exit(0);
72: }
73: }
74:
75: private static class ShapeFilter extends FileFilter {
76: public boolean accept(File f) {
77: if (f.isDirectory())
78: return true;
79:
80: String name = f.getName();
81: if (name.length() > 4) {
82: return name.substring(name.length() - 4)
83: .equalsIgnoreCase(".shp");
84: }
85: return false;
86: }
87:
88: public String getDescription() {
89: return "ESRI ShapeFiles";
90: }
91: }
92:
93: }
|