The Rural Technology Initiative ceased operations in 2011. This site is maintained as an archive of works from RTI collaborators from 2000 to 2011 and is no longer updated. RTI's successor and remaining staff can be found at NRSIG.org


     
 
   
Search the RTI Website
 
Click to go to the Precision Forestry Cooperative website
Click to go to the RTI Home page
Click to go to the About RTI page
Click to go to the RTI Projects page
Click to go to the RTI Publications page
Click to go to the RTI Tools page
Click to go to the RTI Geographic Information Systems page
Click to go to the RTI Streaming Video Directory
Click to go to the RTI Training page
Click to go to the RTI Contacts page
Click to go to the RTI Image Archive
Click to go to the RTI Site Map
Click to go to the RTI Links page


Appendix C

GEN2ASC.EXE

 

The following bit of java code was written by to facilitate the processing of multiple ASCII (X, Y, Z) files into Arc Info Generate format. The program creates a small interface that allows window control of selecting files. In any given folder select as many files as desired of the correct format and the files will be formatted automatically and the new files will be placed in the same directory with a "txt_l" extension.

/*
* @(#)asc2gen.java
* Matthew Walsh
* March 12, 2003
*
* Reads files in format "x, y, z" and creates an Arc Generate file
*
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class asc2gen extends JFrame {
private JPanel buttonPanel;
private datman data;
private JButton function3;

public asc2gen() {
super("Ascii(x,y,z) to Generate");
data = new datman(); // instantiate the data controler

function3 = new JButton( "Convert Files" );
function3.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e)
{
data.openFile();
}
}
);

buttonPanel = new JPanel();
buttonPanel.setLayout( new GridLayout(2,4) );
buttonPanel.add( function3);

Container c = getContentPane();
c.add( buttonPanel, BorderLayout.SOUTH );

setSize( 580, 700);
show();
}

public static void main(String args[]) {
asc2gen app = new asc2gen();

app.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}

/*
* @author Matthew Walsh
* @(#)datman.java 03/04/03
*
* Handles the reading of X,Y,Z format ascii data and writing ArcInfo Generate files.
*/

import java.io.*;
import java.util.*;
import javax.swing.*;

class datman {
public String x, y, z;
public int numCommands=0, curCommand=0;
private BufferedReader input;
private BufferedWriter output;
private JFileChooser fd;

public datman() {

fd = new JFileChooser();
fd.setFileSelectionMode( JFileChooser.FILES_ONLY );
fd.setMultiSelectionEnabled(true);
}

/**
* Calls JFileChooser and handles which methods to call in order to
* read the files.
*/
public void openFile( )
{
String stRead = ""; // Line strings for running StringTokenizer
String stCurToken = ""; // string containing current token for parsing.
String theCommand = "";

int result = fd.showOpenDialog( null );

// check for cancel button
if ( result == JFileChooser.CANCEL_OPTION ){
return;
}

File filelist[] = fd.getSelectedFiles();

for (int k = 0; k < filelist.length; k++) {
File fileName = (File) filelist[k];

if (fileName == null || fileName.getName().equals("")){
JOptionPane.showMessageDialog( null, "Invalid File Name", "Invalid File
name", JOptionPane.ERROR_MESSAGE );
}
else {
// open the file
try {
if (numCommands != 0)
this.closeFile();

input = new BufferedReader(new FileReader (fileName),
10240);
// JOptionPane.showMessageDialog( null, fileName.getName(),
" File Name", JOptionPane.INFORMATION_MESSAGE );

output = new BufferedWriter(new
FileWriter(fileName.getName()+ "_l"), 10485760);

for (int i = 0; i < fileName.length(); i++) {

stRead = input.readLine();
StringTokenizer st = new StringTokenizer(stRead,
" ");
x = st.nextToken();
y = st.nextToken();
z = st.nextToken();
// System.out.println("x: " + x + " y: " + y + " z: " +
z);
output.write("1 " + x + " " + y + " " + z);
output.newLine();
// output.flush();
}

output.write("END");
output.flush();
output.close();

}
catch (IOException e ) {
JOptionPane.showMessageDialog( null, "Error Opening File",
" Error", JOptionPane.ERROR_MESSAGE );

}
catch (NullPointerException e) {
// placed here just to catch the times when the program
attempts to read too far.
System.out.println("Null Point error in data reading");
try {

output.write("END");
output.flush();
output.close();
} catch (IOException f) {
System.out.println("Null Point error on the second
try/catch");
}
}
}
}

}
/**
* Closes the data files and removes the data from memory.
*/
public void closeFile( )
{
try {
input.close();

this.numCommands = 0;
this.curCommand = 0;

}
catch (IOException ex){
JOptionPane.showMessageDialog(null, "Error closing file", "Error",
JOptionPane.ERROR_MESSAGE );
System.exit(1);
}
}
}

 
School of Environmental and Forest Sciences
USDA Forest Service State & Private Forestry
WSU Cooperative Extension
The Rural Technology Home Page is provided by the College of Forest Resources. For more information, please contact the Rural Technology Initiative, University of Washington Box 352100 Seattle, WA 98195, (206) 543-0827. © 2000-2004, University of Washington, Rural Technology Initiative, including all photographs and images unless otherwise noted. To view the www.ruraltech.org privacy policy, click here.
Last Updated 10/13/2022 11:34:38 AM