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
- See Also:
- ShapefileReader.java
-
-
Constructor Summary
Constructors Constructor Description ShapefileReader(FileChannel channel)Creates a new instance of ShapeFile.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Clean up any resources.org.locationtech.jts.geom.GeometrygeomAt(int offset)Fetch the next record information.ShapefileHeadergetHeader()Get the header.static ShapefileHeaderreadHeader(ReadableByteChannel channel)A short cut for reading the header from the given channel.voidsetHandler(ShapeHandler handler)
-
-
-
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 IOExceptionClean 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 IOExceptionFetch 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.
-
-