public class ShapeFile extends ShapeUtils
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_RECORD_BUFFER_SIZE
A default record size.
|
protected ESRIBoundingBox |
fileBounds
Holds the bounds of the file (four doubles).
|
protected long |
fileLength
Holds the length of the file, in bytes.
|
protected int |
fileShapeType
Holds the shape type of the file.
|
protected int |
fileVersion
Holds the version of the file, as an int.
|
protected byte[] |
header
The buffer that holds the 100 byte header.
|
protected java.io.RandomAccessFile |
raf
The read/write class for shape files.
|
protected byte[] |
recBuf
A buffer for the current record's data.
|
protected byte[] |
recHdr
A buffer for current record's header.
|
static int |
SHAPE_FILE_CODE
A Shape File's magic number.
|
static int |
SHAPE_FILE_VERSION
The currently handled version of Shape Files.
|
DBF_ATTRIBUTE, DBF_AUTOINCREMENT, DBF_BINARY, DBF_CHARACTER, DBF_DATE, DBF_DOUBLE, DBF_FLOAT, DBF_LOGICAL, DBF_LONG, DBF_MEMO, DBF_NUMERIC, DBF_OLE, DBF_TIMESTAMP, DBF_TYPE_AUTOINCREMENT, DBF_TYPE_BINARY, DBF_TYPE_CHARACTER, DBF_TYPE_DATE, DBF_TYPE_DOUBLE, DBF_TYPE_FLOAT, DBF_TYPE_LOGICAL, DBF_TYPE_LONG, DBF_TYPE_MEMO, DBF_TYPE_NUMERIC, DBF_TYPE_OLE, DBF_TYPE_TIMESTAMP, PARAM_DBF, PARAM_SHP, PARAM_SHX, SHAPE_BOUNDS_ATTRIBUTE, SHAPE_DBF_DASHPATTERN, SHAPE_DBF_DASHPHASE, SHAPE_DBF_DESCRIPTION, SHAPE_DBF_FILLCOLOR, SHAPE_DBF_INFO_ATTRIBUTE, SHAPE_DBF_LINECOLOR, SHAPE_DBF_LINEWIDTH, SHAPE_DBF_SELECTCOLOR, SHAPE_FILE_HEADER_LENGTH, SHAPE_FILE_RECORD_HEADER_LENGTH, SHAPE_INDEX_ATTRIBUTE, SHAPE_MAX_MEASURE_ATTRIBUTE, SHAPE_MAX_Z_ATTRIBUTE, SHAPE_MEASURE_ATTRIBUTE, SHAPE_MIN_MEASURE_ATTRIBUTE, SHAPE_MIN_Z_ATTRIBUTE, SHAPE_TYPE_ARC, SHAPE_TYPE_MULTIPATCH, SHAPE_TYPE_MULTIPOINT, SHAPE_TYPE_MULTIPOINTM, SHAPE_TYPE_MULTIPOINTZ, SHAPE_TYPE_NULL, SHAPE_TYPE_POINT, SHAPE_TYPE_POINTM, SHAPE_TYPE_POINTZ, SHAPE_TYPE_POLYGON, SHAPE_TYPE_POLYGONM, SHAPE_TYPE_POLYGONZ, SHAPE_TYPE_POLYLINE, SHAPE_TYPE_POLYLINEM, SHAPE_TYPE_POLYLINEZ, SHAPE_Z_ATTRIBUTE
Constructor and Description |
---|
ShapeFile(java.io.File file)
Construct a
ShapeFile from the given File . |
ShapeFile(java.lang.String name)
Construct a
ShapeFile from a file name. |
Modifier and Type | Method and Description |
---|---|
void |
add(ESRIRecord r)
Adds a record to the end of this file.
|
void |
close()
Closes the shape file and disposes of resources.
|
ESRIBoundingBox |
getBoundingBox()
Returns the bounding box of this shape file.
|
long |
getFileLength()
Returns the length of the file in bytes.
|
int |
getFileVersion()
Returns the version of the file.
|
ESRIRecord |
getNextRecord()
Returns the next record from the shape file as an
ESRIRecord . |
int |
getShapeType()
Returns the shape type of the file.
|
protected void |
initHeader()
Reads or writes the header of a Shape file.
|
static void |
main(java.lang.String[] args)
The driver for the command line interface.
|
protected void |
readHeader()
Reads and parses the header of the file.
|
void |
setShapeType(int newShapeType)
Sets the shape type of the file.
|
void |
verify(boolean repair,
boolean verbose)
Verifies the contents of a shape file.
|
protected void |
verifyRecordBuffer(int size)
Verifies that the record buffer is big enough to hold the given number of
bytes.
|
protected void |
writeHeader()
Writes a blank header into the shape file.
|
getStringForType, readBEInt, readBox, readLEDouble, readLEInt, readLEInt, readLELong, readPoint, writeBEInt, writeBox, writeLEDouble, writeLEInt, writeLELong, writePoint
public static final int SHAPE_FILE_CODE
public static final int SHAPE_FILE_VERSION
public static final int DEFAULT_RECORD_BUFFER_SIZE
protected java.io.RandomAccessFile raf
protected byte[] header
protected long fileLength
protected int fileVersion
protected int fileShapeType
protected ESRIBoundingBox fileBounds
protected byte[] recHdr
protected byte[] recBuf
public ShapeFile(java.lang.String name) throws java.io.IOException
ShapeFile
from a file name.java.io.IOException
- if something goes wrong opening or reading the
file.public ShapeFile(java.io.File file) throws java.io.IOException
ShapeFile
from the given File
.file
- A file object representing an ESRI Shape Filejava.io.IOException
- if something goes wrong opening or reading the
file.protected void initHeader() throws java.io.IOException
After this function runs, the file pointer is set to byte 100, the first byte of the first record in the file.
java.io.IOException
- if something goes wrong reading or writing the
shape fileprotected void writeHeader() throws java.io.IOException
java.io.IOException
- if something goes wrong writing the shape fileprotected void readHeader() throws java.io.IOException
java.io.IOException
- if something goes wrong reading the fileheader
,
fileVersion
,
fileLength
,
fileShapeType
,
fileBounds
public long getFileLength()
public int getFileVersion()
public int getShapeType()
public void setShapeType(int newShapeType) throws java.io.IOException, java.lang.IllegalArgumentException
Shape types are enumerated in the class ShapeUtils.
newShapeType
- the new shape typejava.io.IOException
- if something goes wrong writing the filejava.lang.IllegalArgumentException
- if file already has a shape typeShapeUtils
public ESRIBoundingBox getBoundingBox()
public ESRIRecord getNextRecord() throws java.io.IOException
ESRIRecord
.
Each successive call gets the next record. There is no way to go back a
record. When there are no more records, null
is returned.java.io.IOException
- if something goes wrong reading the filepublic void add(ESRIRecord r) throws java.io.IOException
r
- the record to be addedjava.io.IOException
- if something goes wrong writing to the filepublic void close() throws java.io.IOException
java.io.IOException
- if something goes wrong closing the filepublic void verify(boolean repair, boolean verbose) throws java.io.IOException
repair
- NOT CURRENTLY USED - would signal that the file should be
repaired if possibleverbose
- NOT CURRENTLY USED - would cause the verifier to display
progress and statusjava.io.IOException
- if something goes wrong reading or writing the fileprotected void verifyRecordBuffer(int size)
size
- the number of bytes the buffer needs to holdpublic static void main(java.lang.String[] args) throws java.io.IOException
See the file documentation for usage.
args
- the command line argumentsjava.io.IOException
- if something goes wrong reading or writing the fileCopyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details