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