Problem importing miscellaneous shape files (and solution)

From: Lonnie D. Goad <LGoad@optimetrics.org>
Date: Mon Aug 26 2002 - 13:37:41 EDT

Hello all,
        I had downloaded some Tiger Map Data from
www.geographynetwork.com/data/tiger2000 and was attempting to add it via
EsriPlugin and PlugInLayer when I received a NumberFormatException
followed by a NullPointerException. Troubleshooting revealed that there
was a problem reading the .dbf file. Further testing resulted in my
finding the problem in DbfInputStream.readData() method. The problem
being that if the column being read is of TYPE_NUMERIC, each field in
that column is converted to a Double, and if the field is empty the
NumberFormatException is thrown and the model is never created. Below
is the original method first, followed by the changed method.

****************
*** ORIGINAL ***
****************
    public void readData() throws IOException {
        _leis.skipBytes(2);
        _records = new ArrayList();
        for (int r=0; r <= _rowCount - 1; r++) {
            ArrayList record = new ArrayList();
            for (int c = 0; c <= _columnCount - 1; c++) {
                int length = _lengths[c];
                int type = _types[c];
                if(type == DbfTableModel.TYPE_NUMERIC){
                    String cell = _leis.readString(length);
                    record.add(c, new Double(cell));
                }
                else{
                    String cell = _leis.readString(length);
                    record.add(c, cell);
                }
            }
            _records.add(record);
            _leis.skipBytes(1);
        }
    }

*******************
*** WITH CHANGE ***
*******************
    public void readData() throws IOException {
        _leis.skipBytes(2);
        _records = new ArrayList();
        for (int r=0; r <= _rowCount - 1; r++) {
            ArrayList record = new ArrayList();
            for (int c = 0; c <= _columnCount - 1; c++) {
                int length = _lengths[c];
                int type = _types[c];
                if(type == DbfTableModel.TYPE_NUMERIC){
                    String cell = _leis.readString(length);
                    try
                    {
                                record.add(c, new Double(cell));
                        }
                        catch (NumberFormatException nfe)
                        {
                                record.add(c, null);
                        }
                }
                else{
                    String cell = _leis.readString(length);
                    record.add(c, cell);
                }
            }
            _records.add(record);
            _leis.skipBytes(1);
        }
    }

P.S. www.geographynetwork.com has a lot of cool data files in shapefile
format and registration is free

************************
Lonnie Goad - Programmer
OptiMetrics Inc.
2107 Laurel Bush Rd. Suite 209
Bel Air, Md. 21015
LGoad@OptiMetrics.org
http://www.OptiMetrics.org
(410)569-6081 ext: 105
fax: (410)569-6083

--
[To unsubscribe to this list send an email to "majdart@bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Aug 26 13:38:24 2002

This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:33 EDT