Class 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
    See Also:
    ShapefileReader.java
    • 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.