|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectShapefileReader
public class ShapefileReader
The general use of this class is:
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.
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();
Nested Class Summary | |
---|---|
class |
ShapefileReader.Record
The reader returns only one Record instance in its lifetime. |
Constructor Summary | |
---|---|
ShapefileReader(ShpFiles shapefileFiles,
boolean strict,
boolean useMemoryMapped,
GeometryFactory gf)
Creates a new instance of ShapeFile. |
|
ShapefileReader(ShpFiles shapefileFiles,
boolean strict,
boolean useMemoryMapped,
GeometryFactory gf,
boolean onlyRandomAccess)
Creates a new instance of ShapeFile. |
Method Summary | |
---|---|
void |
close()
Clean up any resources. |
void |
disableShxUsage()
Disables .shx file usage. |
static int |
fill(ByteBuffer buffer,
ReadableByteChannel channel)
|
int |
getCount(int count)
Parses the shpfile counting the records. |
ShapefileHeader |
getHeader()
Get the header. |
void |
goTo(int offset)
Moves the reader to the specified byte offset in the file. |
boolean |
hasNext()
If there exists another record. |
String |
id()
An id for the reader. |
ShapefileReader.Record |
nextRecord()
Fetch the next record information. |
ShapefileReader.Record |
recordAt(int offset)
Sets the current location of the byteStream to offset and returns the next record. |
void |
setFlatGeometry(boolean flatGeometry)
|
void |
setHandler(ShapeHandler handler)
|
Object |
shapeAt(int offset)
Returns the shape at the specified byte distance from the beginning of the file. |
boolean |
supportsRandomAccess()
|
int |
transferTo(ShapefileWriter writer,
int recordNum,
double[] bounds)
Transfer (by bytes) the data at the current record to the ShapefileWriter. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ShapefileReader(ShpFiles shapefileFiles, boolean strict, boolean useMemoryMapped, GeometryFactory gf) throws IOException, ShapefileException
shapefileFiles
- The ReadableByteChannel this reader will use.strict
- True to make the header parsing throw Exceptions if the
version or magic number are incorrect.
IOException
- If problems arise.
ShapefileException
- If for some reason the file contains invalid records.public ShapefileReader(ShpFiles shapefileFiles, boolean strict, boolean useMemoryMapped, GeometryFactory gf, boolean onlyRandomAccess) throws IOException, ShapefileException
shapefileFiles
- The ReadableByteChannel this reader will use.strict
- True to make the header parsing throw Exceptions if the
version or magic number are incorrect.useMemoryMapped
- Wheter to enable memory mapping or notgf
- The geometry factory used to build the geometriesonlyRandomAccess
- When true sets up the reader to do exclusively read driven by goTo(x)
and thus avoids opening the .shx file
IOException
- If problems arise.
ShapefileException
- If for some reason the file contains invalid records.Method Detail |
---|
public void disableShxUsage() throws IOException
IOException
public static int fill(ByteBuffer buffer, ReadableByteChannel channel) throws IOException
IOException
public ShapefileHeader getHeader()
public void close() throws IOException
IOException
- If errors occur while closing the channel.public boolean supportsRandomAccess()
public boolean hasNext() throws IOException
IOException
public int transferTo(ShapefileWriter writer, int recordNum, double[] bounds) throws IOException
bounds
- double array of length four for transfering the bounds
into
IOException
public ShapefileReader.Record nextRecord() throws IOException
IOException
public void goTo(int offset) throws IOException, UnsupportedOperationException
offset
-
IOException
UnsupportedOperationException
public Object shapeAt(int offset) throws IOException, UnsupportedOperationException
offset
-
IOException
UnsupportedOperationException
public ShapefileReader.Record recordAt(int offset) throws IOException, UnsupportedOperationException
offset
- If using an shx file the offset would be: 2 *
(index.getOffset(i))
IOException
- thrown in a read error occurs
UnsupportedOperationException
- thrown if not a random access filepublic int getCount(int count) throws DataSourceException
DataSourceException
public void setHandler(ShapeHandler handler)
handler
- The handler to set.public String id()
FileReader
id
in interface FileReader
public void setFlatGeometry(boolean flatGeometry)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |