shp_renderer.data
Class SHPDataLoader

java.lang.Object
  extended by shp_renderer.data.SHPDataLoader

public class SHPDataLoader
extends java.lang.Object

SHPDataLoader - This class can be used to load shapefiles (.shp). Provided with a File, this method reads, constructs and builds SHPMap objects fully loaded with all necessary geographic data for rendering a map.

Author:
Richard McKenna

Field Summary
static int MULTIPATCH
           
static int MULTIPOINT
           
static int MULTIPOINTM
           
static int MULTIPOINTZ
           
static int NULL_SHAPE
           
static int POINT
           
static int POINTM
           
static int POINTZ
           
static int POLYGON
           
static int POLYGONM
           
static int POLYGONZ
           
static int POLYLINE
           
static int POLYLINEM
           
static int POLYLINEZ
           
 
Constructor Summary
SHPDataLoader()
          This constructor only initializes the mask.
 
Method Summary
 double[] extract2DBoundingBox(java.io.DataInputStream dis)
          This helper method gets the bounding box data from the shapefile via the input stream argument and uses it to build and return a double array that represents it.
 SHPPolyType extractPolyType(java.io.DataInputStream dis, int shapeType)
          This method loads a poly type, which could be a polygon or a polyline, like for roads in a map.
 long[] initLongMasks()
          This method generates a mask for each bit to help switch endianness.
 SHPMap loadShapefile(java.io.File shapeFile)
          This method takes a file that represents a shapefile as an argument and returns a constructed, fully loaded SHPMap.
 char readCharByte(java.io.DataInputStream dis)
          This helps us read a char stored in a byte, ensuring we don't end up with negatively values characters.
 int readIntByte(java.io.DataInputStream dis)
          This method is for reading a byte from a data stream and treating it as an int, accounting for the fact that it should never be a negative number.
 double readLittleEndianDouble(java.io.DataInputStream dis)
          Helper method for reading a double as little endian and building a big endian double to use.
 int readLittleEndianInt(java.io.DataInputStream dis)
          Helper method for reading an int as little endian and building a big endian int to use.
 short readLittleEndianShort(java.io.DataInputStream dis)
          Helper method for reading a short as little endian and building a big endian short to use.
 long switchLongEndian(long bel)
          This helper method switches the endianness of a long.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_SHAPE

public static final int NULL_SHAPE
See Also:
Constant Field Values

POINT

public static final int POINT
See Also:
Constant Field Values

POLYLINE

public static final int POLYLINE
See Also:
Constant Field Values

POLYGON

public static final int POLYGON
See Also:
Constant Field Values

MULTIPOINT

public static final int MULTIPOINT
See Also:
Constant Field Values

POINTZ

public static final int POINTZ
See Also:
Constant Field Values

POLYLINEZ

public static final int POLYLINEZ
See Also:
Constant Field Values

POLYGONZ

public static final int POLYGONZ
See Also:
Constant Field Values

MULTIPOINTZ

public static final int MULTIPOINTZ
See Also:
Constant Field Values

POINTM

public static final int POINTM
See Also:
Constant Field Values

POLYLINEM

public static final int POLYLINEM
See Also:
Constant Field Values

POLYGONM

public static final int POLYGONM
See Also:
Constant Field Values

MULTIPOINTM

public static final int MULTIPOINTM
See Also:
Constant Field Values

MULTIPATCH

public static final int MULTIPATCH
See Also:
Constant Field Values
Constructor Detail

SHPDataLoader

public SHPDataLoader()
This constructor only initializes the mask. This loader class is used more for functionality than for storing data.

Method Detail

loadShapefile

public SHPMap loadShapefile(java.io.File shapeFile)
                     throws java.io.IOException
This method takes a file that represents a shapefile as an argument and returns a constructed, fully loaded SHPMap.

Parameters:
shapeFile - the shape file to be loaded.
Throws:
java.io.IOException

extract2DBoundingBox

public double[] extract2DBoundingBox(java.io.DataInputStream dis)
                              throws java.io.IOException
This helper method gets the bounding box data from the shapefile via the input stream argument and uses it to build and return a double array that represents it.

Parameters:
dis - The data input stream that will extract the bounding box from the file.
Throws:
java.io.IOException

extractPolyType

public SHPPolyType extractPolyType(java.io.DataInputStream dis,
                                   int shapeType)
                            throws java.io.IOException
This method loads a poly type, which could be a polygon or a polyline, like for roads in a map. We will only be using polygons.

Parameters:
dis - The data input stream that will extract the polygon type from the file.
shapeType - The shape Type.
Throws:
java.io.IOException

initLongMasks

public long[] initLongMasks()
This method generates a mask for each bit to help switch endianness.


readCharByte

public char readCharByte(java.io.DataInputStream dis)
                  throws java.io.IOException
This helps us read a char stored in a byte, ensuring we don't end up with negatively values characters.

Parameters:
dis - The data input stream that will read the character byte from teh file.
Throws:
java.io.IOException

readIntByte

public int readIntByte(java.io.DataInputStream dis)
                throws java.io.IOException
This method is for reading a byte from a data stream and treating it as an int, accounting for the fact that it should never be a negative number.

Parameters:
dis - The data input stream that will read the integer byte from the file.
Throws:
java.io.IOException

readLittleEndianInt

public int readLittleEndianInt(java.io.DataInputStream dis)
                        throws java.io.IOException
Helper method for reading an int as little endian and building a big endian int to use.

Parameters:
dis - The data input stream that will read the little endian int from the file.
Throws:
java.io.IOException

readLittleEndianShort

public short readLittleEndianShort(java.io.DataInputStream dis)
                            throws java.io.IOException
Helper method for reading a short as little endian and building a big endian short to use.

Parameters:
dis - The data input stream that will read the little endian short from the file.
Throws:
java.io.IOException

readLittleEndianDouble

public double readLittleEndianDouble(java.io.DataInputStream dis)
                              throws java.io.IOException
Helper method for reading a double as little endian and building a big endian double to use.

Parameters:
dis - The data input stream that will read the little endian double from the file.
Throws:
java.io.IOException

switchLongEndian

public long switchLongEndian(long bel)
This helper method switches the endianness of a long.

Parameters:
bel - The value that will get switched.