org.h2gis.functions.io.shp.internal

## Class ShapefileReader

- java.lang.Object
- - org.h2gis.functions.io.shp.internal.ShapefileReader

    public class ShapefileReader
    extends Object

The general use of this class is: `

     FileChannel in = new FileInputStream("thefile.dbf").getChannel();
     ShapefileReader r = new ShapefileReader( in ) while (r.hasNext()) { Geometry
     shape = (Geometry) r.nextRecord().shape() // do stuff } r.close();

` You don't have to immediately ask for the shape from the record. The record will contain the bounds of the shape and will only read the shape when the shape() method is called. This ShapefileReader.Record is the same object every time, so if you need data from the Record, be sure to copy it.

Author:
  jamesm, aaime, Ian Schneider

### Constructor Summary

Constructors
Constructor and Description
`ShapefileReader(FileChannel channel)` Creates a new instance of ShapeFile.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `close()` Clean up any resources.
`org.locationtech.jts.geom.Geometry` `geomAt(int offset)` Fetch the next record information.
`ShapefileHeader` `getHeader()` Get the header.
`static ShapefileHeader` `readHeader(ReadableByteChannel channel)` A short cut for reading the header from the given channel.
`void` `setHandler(ShapeHandler handler)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ShapefileReader

    public ShapefileReader(FileChannel channel)
                    throws IOException,
                           ShapefileException

Creates a new instance of ShapeFile.

Parameters:
  `channel` - The ReadableByteChannel this reader will use.
Throws:
  `IOException` - If problems arise.
  `ShapefileException` - If for some reason the file contains invalid records.

### Method Detail

#### readHeader

    public static ShapefileHeader readHeader(ReadableByteChannel channel)
                                      throws IOException

A short cut for reading the header from the given channel.

Parameters:
  `channel` - The channel to read from.
Returns:
  A ShapefileHeader object.
Throws:
  `IOException` - If problems arise.

#### getHeader

    public ShapefileHeader getHeader()

Get the header. Its parsed in the constructor.

Returns:
  The header that is associated with this file.

#### close

    public void close()
               throws IOException

Clean up any resources. Closes the channel.

Throws:
  `IOException` - If errors occur while closing the channel.

#### geomAt

    public org.locationtech.jts.geom.Geometry geomAt(int offset)
                                              throws IOException

Fetch the next record information.

Parameters:
  `offset` -
Returns:
  The record instance associated with this reader.
Throws:
  `IOException`

#### setHandler

    public void setHandler(ShapeHandler handler)

Parameters:
  `handler` - The handler to set.