001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/tools/shape/IndexShapeFile.java $
002 /*----------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/deegree/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 This library is free software; you can redistribute it and/or
012 modify it under the terms of the GNU Lesser General Public
013 License as published by the Free Software Foundation; either
014 version 2.1 of the License, or (at your option) any later version.
015
016 This library is distributed in the hope that it will be useful,
017 but WITHOUT ANY WARRANTY; without even the implied warranty of
018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 Lesser General Public License for more details.
020
021 You should have received a copy of the GNU Lesser General Public
022 License along with this library; if not, write to the Free Software
023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Application to index a shape file, using the R-tree algorithm.
026 Copyright (C) May 2003 by IDgis BV, The Netherlands - www.idgis.nl
027 ----------------------------------------*/
028
029 package org.deegree.tools.shape;
030
031 import java.io.File;
032
033 import javax.swing.JFileChooser;
034 import javax.swing.JFrame;
035 import javax.swing.filechooser.FileFilter;
036
037 import org.deegree.framework.file.FileMemory;
038
039 /**
040 * <p>
041 * IndexShapeFile is an application that can be used to index an ESRI ShapeFiles(tm). It indexes
042 * both the geometry and the alphanumeric attributes
043 * </p>
044 *
045 * <p>
046 * The application shows a file chooser with which the user can select a file. When a file is
047 * choosen the application opens it and shows the attributes. The user can now select the attributes
048 * that has to be indexed. Already indexed attributes are already selected and can be deselected.
049 * For alphanumeric attributes the user can indicate if the attribute is unique or not.
050 * </p>
051 *
052 * <p>
053 * After selecting the attributes the application creates the needed indexes and loops over all the
054 * features in the shape file. For every feature the application inserts the attributes in the right
055 * index. After looping over the features the application closes the shapefile and the created
056 * indexes and removes the indexes that are no longer needed (eg. the index for the attributes that
057 * are deselected).
058 * </p>
059 *
060 * <p>
061 * It is not possible to transform a unique index to a non-unique index or back.
062 * </p>
063 */
064 public class IndexShapeFile {
065
066 public static void main( String[] args )
067 throws Exception {
068 JFileChooser fileChooser = new JFileChooser();
069 fileChooser.setCurrentDirectory( FileMemory.getLastDirectory( "IndexShapeFile" ) );
070 fileChooser.setFileFilter( new ShapeFilter() );
071 fileChooser.setFileView( new ShapeView() );
072 if ( fileChooser.showOpenDialog( null ) == JFileChooser.APPROVE_OPTION ) {
073 IndexFrame indexFrame = new IndexFrame( fileChooser.getSelectedFile() );
074 indexFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
075 indexFrame.setVisible( true );
076 FileMemory.setLastDirectory( "IndexShapeFile", fileChooser.getSelectedFile() );
077 } else {
078 System.exit( 0 );
079 }
080 }
081
082 private static class ShapeFilter extends FileFilter {
083 public boolean accept( File f ) {
084 if ( f.isDirectory() )
085 return true;
086
087 String name = f.getName();
088 if ( name.length() > 4 ) {
089 return name.substring( name.length() - 4 ).equalsIgnoreCase( ".shp" );
090 }
091 return false;
092 }
093
094 public String getDescription() {
095 return "ESRI ShapeFiles";
096 }
097 }
098
099 }