001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_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>IndexShapeFile is an application that can be used to index an ESRI ShapeFiles(tm). 041 It indexes both the geometry and the alphanumeric attributes</p> 042 043 <p>The application shows a file chooser with which the user can select a file. When a file 044 is choosen the application opens it and shows the attributes. The user can now select the 045 attributes that has to be indexed. Already indexed attributes are already selected and can 046 be deselected. For alphanumeric attributes the user can indicate if the attribute is unique or not.</p> 047 048 <p>After selecting the attributes the application creates the needed indexes and loops over all the 049 features in the shape file. For every feature the application inserts the attributes in the right index. 050 After looping over the features the application closes the shapefile and the created indexes and removes the indexes 051 that are no longer needed (eg. the index for the attributes that are deselected).</p> 052 053 <p>It is not possible to transform a unique index to a non-unique index or back.</p> 054 */ 055 public class IndexShapeFile { 056 057 public static void main( String[] args ) throws Exception { 058 JFileChooser fileChooser = new JFileChooser(); 059 fileChooser.setCurrentDirectory( FileMemory.getLastDirectory( "IndexShapeFile" ) ); 060 fileChooser.setFileFilter( new ShapeFilter() ); 061 fileChooser.setFileView( new ShapeView() ); 062 if ( fileChooser.showOpenDialog( null ) == JFileChooser.APPROVE_OPTION ) { 063 IndexFrame indexFrame = new IndexFrame( fileChooser.getSelectedFile() ); 064 indexFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); 065 indexFrame.setVisible( true ); 066 FileMemory.setLastDirectory( "IndexShapeFile", fileChooser.getSelectedFile() ); 067 } else { 068 System.exit( 0 ); 069 } 070 } 071 072 private static class ShapeFilter extends FileFilter { 073 public boolean accept( File f ) { 074 if ( f.isDirectory() ) 075 return true; 076 077 String name = f.getName(); 078 if ( name.length() > 4 ) { 079 return name.substring( name.length() - 4 ).equalsIgnoreCase( ".shp" ); 080 } 081 return false; 082 } 083 084 public String getDescription() { 085 return "ESRI ShapeFiles"; 086 } 087 } 088 089 }