NVS Shapefile library Version 3.2
NVision Solutions, Inc.

com.nvs.shapefile
Class Shapefile

java.lang.Object
  |
  +--com.nvs.shapefile.Shapefile

public class Shapefile
extends java.lang.Object

The Shapefile class represents an ESRI shapefile

Author:
Zack Watts
NVisionSolutions, Inc.

Field Summary
static int FIELDTYPE_CHARACTER
          Field type value of a string record field ('C')
static int FIELDTYPE_DATE
          Field type value of a string record field ('D')
static int FIELDTYPE_FLOAT
          Field type value of a string record field ('F')
static int FIELDTYPE_LOGICAL
          Field type value of a string record field ('L')
static int FIELDTYPE_NUMBER
          Field type value of a string record field ('N')
static int SHAPETYPE_MULTIPOINT
          Shape type value of a MultiPoint shapefile type descriptor (8)
static int SHAPETYPE_POINT
          Shape type value of a Point shapefile type descriptor (1)
static int SHAPETYPE_POLYGON
          Shape type value of a Polygon shapefile type descriptor (5)
static int SHAPETYPE_POLYLINE
          Shape type value of a PolyLine shapefile type descriptor (3)
 
Constructor Summary
Shapefile()
          Creates a new Shapefile with no shapes, no type, and a BoundingBox with all values set to zero.
Shapefile(java.io.InputStream mainInput, java.io.InputStream indexInput, java.io.InputStream recordsInput)
          Constructs a new Shapefile object by reading the specified streams
Shapefile(int type)
          Creates a new Shapefile with the specified type, no shapes, and a BoundingBox with all values set to zero.
Shapefile(java.lang.String fileName)
          Constructs a new Shapefile object by reading the specified file
If the index and/or records files cannot be found, no exception is
thrown.
 
Method Summary
 void addShapeObject(com.nvs.shapefile.ShapeObject obj)
          Adds the specified ShapeObject to this Shapefile
 void computeExtents()
          Computes the minimum extents for this Shapefile and sets its BoundingBox to them
 com.nvs.shapefile.BoundingBox getBoundingBox()
          Returns the BoundingBox of this Shapefile
 com.nvs.shapefile.ShapeObject getShapeObject(int index)
          Returns the ShapeObject at the specified index
 int getShapeObjectCount()
          Returns the number of ShapeObjects in this Shapefile
 java.util.ArrayList getShapeObjects()
          Returns all ShapeObjects in this Shapefile
 com.nvs.shapefile.TableDescription getTableDescription()
          Returns this Shapefile's TableDescription
 int getType()
          Returns the type of this Shapefile
 java.util.ArrayList getWarningMessages()
          Returns an ArrayList of Strings representing warning messages that have occured in read/write operations
 void removeShapeObject(int index)
          Removes the ShapeObject at the specified index
 void setBoundingBox(com.nvs.shapefile.BoundingBox box)
          Sets the BoundingBox of this Shapefile
 void setShapeObjects(java.util.Collection collection)
          Sets the ShapeObjects in this Shapefile to those in the specified collection
 void setTableDescription(com.nvs.shapefile.TableDescription tableDesc)
          Sets the TableDescription for this Shapefile
 void setType(int type)
          Sets the type of this Shapefile
 void write(java.io.OutputStream mainOutput, java.io.OutputStream indexOutput, java.io.OutputStream recordsOutput)
          Writes this shapefile to the specified streams
 void write(java.lang.String fileName)
          Writes this Shapefile
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHAPETYPE_POINT

public static final int SHAPETYPE_POINT
Shape type value of a Point shapefile type descriptor (1)

See Also:
Constant Field Values

SHAPETYPE_MULTIPOINT

public static final int SHAPETYPE_MULTIPOINT
Shape type value of a MultiPoint shapefile type descriptor (8)

See Also:
Constant Field Values

SHAPETYPE_POLYLINE

public static final int SHAPETYPE_POLYLINE
Shape type value of a PolyLine shapefile type descriptor (3)

See Also:
Constant Field Values

SHAPETYPE_POLYGON

public static final int SHAPETYPE_POLYGON
Shape type value of a Polygon shapefile type descriptor (5)

See Also:
Constant Field Values

FIELDTYPE_CHARACTER

public static final int FIELDTYPE_CHARACTER
Field type value of a string record field ('C')

See Also:
Constant Field Values

FIELDTYPE_NUMBER

public static final int FIELDTYPE_NUMBER
Field type value of a string record field ('N')

See Also:
Constant Field Values

FIELDTYPE_FLOAT

public static final int FIELDTYPE_FLOAT
Field type value of a string record field ('F')

See Also:
Constant Field Values

FIELDTYPE_DATE

public static final int FIELDTYPE_DATE
Field type value of a string record field ('D')

See Also:
Constant Field Values

FIELDTYPE_LOGICAL

public static final int FIELDTYPE_LOGICAL
Field type value of a string record field ('L')

See Also:
Constant Field Values
Constructor Detail

Shapefile

public Shapefile()
Creates a new Shapefile with no shapes, no type, and a BoundingBox with all values set to zero.


Shapefile

public Shapefile(int type)
Creates a new Shapefile with the specified type, no shapes, and a BoundingBox with all values set to zero.
Legal type values are:
Shapefile.SHAPETYPE_POINT
Shapefile.SHAPETYPE_MULTIPOINT
Shapefile.SHAPETYPE_POLYGON
Shapefile.SHAPETYPE_POLYLINE


Shapefile

public Shapefile(java.lang.String fileName)
          throws InvalidFileException,
                 java.io.IOException
Constructs a new Shapefile object by reading the specified file
If the index and/or records files cannot be found, no exception is
thrown. Instead, no attempt is made to read them and a warning message
is added to the warnings collection available through
getWarningMessages().

Parameters:
fileName - The first part of the file to be read
cities.shp would be specified as "cities". The ".shp", ".shx" and ".dbf" extensions are added automatically, all in lower case.
Throws:
java.io.FileNotFoundException - if the main file (.shp) cannot be found
InvalidFileException - when the specified shapefile is invalid
java.io.IOException

Shapefile

public Shapefile(java.io.InputStream mainInput,
                 java.io.InputStream indexInput,
                 java.io.InputStream recordsInput)
          throws InvalidFileException,
                 java.io.IOException
Constructs a new Shapefile object by reading the specified streams

Parameters:
mainInput - The InputStream associated with the ".shp" file
indexInput - The InputStream associated with the ".shx" file
This parameter may be null. In the case that it is null, reading of
the index file will be forgone and a warning message noting it will
be added to the warning messages collection.
recordsInput - The InputStream associated with the ".dbf" file
This parameter may be null. In the case that it is null, reading of
the records file will be forgone and a warning message noting it will
be added to the warning messages collection.
Throws:
InvalidFileException - when the specified shapefile is invalid
java.io.IOException - when there's an IO problem with the streams
Method Detail

getShapeObjectCount

public int getShapeObjectCount()
Returns the number of ShapeObjects in this Shapefile

Returns:
int the number of ShapeObjects in this Shapefile

write

public void write(java.lang.String fileName)
           throws java.io.IOException
Writes this Shapefile

Parameters:
fileName - The first part of the file to be written
cities.shp would be specified as "cities". The ".shp", ".shx" and ".dbf" extensions are added automatically, all in lower case.
Throws:
java.io.IOException - when there is a problem writing the file

write

public void write(java.io.OutputStream mainOutput,
                  java.io.OutputStream indexOutput,
                  java.io.OutputStream recordsOutput)
           throws java.io.IOException
Writes this shapefile to the specified streams

Parameters:
mainOutput - The InputStream associated with the ".shp" file
indexOutput - The InputStream associated with the ".shx" file
This parameter may be specified as null. If it is null, then writing
of the index file will be forgone and a warning noting the fact will
be appended to the warnings collection.
recordsOutput - The InputStream associated with the ".dbf" file
This parameter may be specified as null. If it is null, then writing
of the records file will be forgone and a warning noting the fact will
be appended to the warnings collection.
Throws:
java.io.IOException - when there's an IO problem with the streams

getType

public int getType()
Returns the type of this Shapefile

Returns:
int the type of this shapefile
legal types:
Shapefile.SHAPETYPE_POINT
Shapefile.SHAPETYPE_MULTIPOINT
Shapefile.SHAPETYPE_POLYGON
Shapefile.SHAPETYPE_POLYLINE

setType

public void setType(int type)
Sets the type of this Shapefile

Parameters:
type - the type of this shapefile as an int
legal types:
Shapefile.SHAPETYPE_POINT
Shapefile.SHAPETYPE_MULTIPOINT
Shapefile.SHAPETYPE_POLYGON
Shapefile.SHAPETYPE_POLYLINE

addShapeObject

public void addShapeObject(com.nvs.shapefile.ShapeObject obj)
                    throws InvalidShapeTypeException,
                           InvalidFieldNameException
Adds the specified ShapeObject to this Shapefile

Parameters:
obj - the ShapeObject to add
Throws:
InvalidShapeTypeException - when obj's type differs from this Shapefile's type
InvalidFieldNameException

removeShapeObject

public void removeShapeObject(int index)
                       throws java.lang.IndexOutOfBoundsException
Removes the ShapeObject at the specified index

Parameters:
index - the index of the ShapeObject to be removed
Throws:
java.lang.IndexOutOfBoundsException - when the index is out of bounds

getShapeObject

public com.nvs.shapefile.ShapeObject getShapeObject(int index)
                                             throws java.lang.IndexOutOfBoundsException
Returns the ShapeObject at the specified index

Parameters:
index - the desired index as an int
Returns:
ShapeObject the ShapeObject at the specified index
Throws:
java.lang.IndexOutOfBoundsException - when the index is out of bounds

getShapeObjects

public java.util.ArrayList getShapeObjects()
Returns all ShapeObjects in this Shapefile

Returns:
ArrayList all ShapeObjects in this Shapefile

setShapeObjects

public void setShapeObjects(java.util.Collection collection)
                     throws InvalidShapeTypeException,
                            InvalidFieldNameException
Sets the ShapeObjects in this Shapefile to those in the specified collection

Parameters:
collection - the ShapeObjects to be set as a collection
Throws:
InvalidShapeTypeException - when a ShapeObject is added with a different type than this Shapefile
InvalidFieldNameException

getBoundingBox

public com.nvs.shapefile.BoundingBox getBoundingBox()
Returns the BoundingBox of this Shapefile

Returns:
BoundingBox the BoundingBox of this Shapefile

setBoundingBox

public void setBoundingBox(com.nvs.shapefile.BoundingBox box)
Sets the BoundingBox of this Shapefile

Parameters:
box - the new bounding box of this Shapefile

setTableDescription

public void setTableDescription(com.nvs.shapefile.TableDescription tableDesc)
Sets the TableDescription for this Shapefile

Parameters:
tableDesc - The new TableDescription

computeExtents

public void computeExtents()
Computes the minimum extents for this Shapefile and sets its BoundingBox to them


getTableDescription

public com.nvs.shapefile.TableDescription getTableDescription()
Returns this Shapefile's TableDescription

Returns:
TableDescription this Shapefile's TableDescription

getWarningMessages

public java.util.ArrayList getWarningMessages()
Returns an ArrayList of Strings representing warning messages that have occured in read/write operations

Returns:
ArrayList Warning messages as an ArrayList of Strings

NVS Shapefile library Version 3.2
NVision Solutions, Inc.