de.fhg.igd.earth.model.input.shapefile
Class ShapeUtils

java.lang.Object
  extended byde.fhg.igd.earth.model.input.shapefile.ShapeUtils
Direct Known Subclasses:
DBaseFile, ESRIPoly, ESRIRecord, ShapeFile

public class ShapeUtils
extends Object

Title : Earth Copyright : Copyright (c) 2001 Organisation : IGD FhG

Version:
: 1.0
Author:
: Werner Beutel

Field Summary
private static byte[] leiBuffer
          A buffer for reading/writing little endian ints.
static int SHAPE_FILE_HEADER_LENGTH
          The length of a shape file header in bytes.
static int SHAPE_FILE_HEADER_LENGTH_DB
           
static int SHAPE_FILE_RECORD_HEADER_LENGTH
          The length of a shape file record header in bytes.
static int SHAPE_TYPE_ARC
          The indicator for an arc (polyline) shape type.
static int SHAPE_TYPE_MULTIPOINT
          The indicator for a multipoint shape type.
static int SHAPE_TYPE_NULL
          The indicator for a null shape type.
static int SHAPE_TYPE_POINT
          The indicator for a point shape type.
static int SHAPE_TYPE_POLYGON
          The indicator for a polygon shape type.
static int SHAPE_TYPE_POLYLINE
          The indicator for a polyline (arc) shape type.
 
Constructor Summary
ShapeUtils()
           
 
Method Summary
static int readBEInt(byte[] b, int off)
          Reads a big endian integer.
static ESRIBoundingBox readBox(byte[] b, int off)
          Reads a bounding box record.
static double readLEDouble(byte[] b, int off)
          Reads a little endian double.
static int readLEInt(byte[] b, int off)
          Reads a little endian integer.
static int readLEInt(RandomAccessFile in)
          Reads a little endian int from the current location of the given file.
static long readLELong(byte[] b, int off)
          Reads a little endian 8 byte integer.
static ESRIPoint readPoint(byte[] b, int off)
          Reads a point record.
static int writeBEInt(byte[] b, int off, int val)
          Writes the given integer to the given buffer at the given location in big endian format.
static int writeBox(byte[] b, int off, ESRIBoundingBox box)
          Writes the given bounding box to the given buffer at the given location.
static int writeLEDouble(byte[] b, int off, double val)
          Writes the given double to the given buffer at the given location in little endian format.
static int writeLEInt(byte[] b, int off, int val)
          Writes the given integer to the given buffer at the given location in little endian format.
static int writeLELong(byte[] b, int off, long val)
          Writes the given long to the given buffer at the given location in little endian format.
static int writePoint(byte[] b, int off, ESRIPoint point)
          Writes the given point to the given buffer at the given location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHAPE_FILE_HEADER_LENGTH

public static final int SHAPE_FILE_HEADER_LENGTH
The length of a shape file header in bytes. (100)

See Also:
Constant Field Values

SHAPE_FILE_HEADER_LENGTH_DB

public static final int SHAPE_FILE_HEADER_LENGTH_DB
See Also:
Constant Field Values

SHAPE_FILE_RECORD_HEADER_LENGTH

public static final int SHAPE_FILE_RECORD_HEADER_LENGTH
The length of a shape file record header in bytes. (8)

See Also:
Constant Field Values

SHAPE_TYPE_NULL

public static final int SHAPE_TYPE_NULL
The indicator for a null shape type. (0)

See Also:
Constant Field Values

SHAPE_TYPE_POINT

public static final int SHAPE_TYPE_POINT
The indicator for a point shape type. (1)

See Also:
Constant Field Values

SHAPE_TYPE_ARC

public static final int SHAPE_TYPE_ARC
The indicator for an arc (polyline) shape type. (3)

See Also:
Constant Field Values

SHAPE_TYPE_POLYLINE

public static final int SHAPE_TYPE_POLYLINE
The indicator for a polyline (arc) shape type. (3). NOTE: ESRI decided to rename the `arc' type as the `polyline' type as of their July 1998 Shapefile Technical Description paper. Maybe they should rename Arc/Info as Polyline/Info?...

See Also:
Constant Field Values

SHAPE_TYPE_POLYGON

public static final int SHAPE_TYPE_POLYGON
The indicator for a polygon shape type. (5)

See Also:
Constant Field Values

SHAPE_TYPE_MULTIPOINT

public static final int SHAPE_TYPE_MULTIPOINT
The indicator for a multipoint shape type. (8)

See Also:
Constant Field Values

leiBuffer

private static byte[] leiBuffer
A buffer for reading/writing little endian ints.

Constructor Detail

ShapeUtils

public ShapeUtils()
Method Detail

readBEInt

public static int readBEInt(byte[] b,
                            int off)
Reads a big endian integer.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the int resides
Returns:
the int read from the buffer at the offset location

readLEInt

public static int readLEInt(byte[] b,
                            int off)
Reads a little endian integer.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the int resides
Returns:
the int read from the buffer at the offset location

readLEInt

public static int readLEInt(RandomAccessFile in)
                     throws IOException
Reads a little endian int from the current location of the given file. Synchronized for thread-safe access to leiBuffer.

Parameters:
in - an input file
Returns:
the int read from the file
Throws:
IOException

readLELong

public static long readLELong(byte[] b,
                              int off)
Reads a little endian 8 byte integer.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the long resides
Returns:
the long read from the buffer at the offset location

readLEDouble

public static double readLEDouble(byte[] b,
                                  int off)
Reads a little endian double.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the double resides
Returns:
the double read from the buffer at the offset location

readPoint

public static ESRIPoint readPoint(byte[] b,
                                  int off)
Reads a point record. A point record is a double representing the x value and a double representing a y value.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the int resides
Returns:
the point read from the buffer at the offset location

readBox

public static ESRIBoundingBox readBox(byte[] b,
                                      int off)
Reads a bounding box record. A bounding box is four double representing, in order, xmin, ymin, xmax, ymax.

Parameters:
b - the raw data buffer
off - the offset into the buffer where the int resides
Returns:
the point read from the buffer at the offset location

writeBEInt

public static int writeBEInt(byte[] b,
                             int off,
                             int val)
Writes the given integer to the given buffer at the given location in big endian format.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
val - the integer to write
Returns:
the number of bytes written

writeLEInt

public static int writeLEInt(byte[] b,
                             int off,
                             int val)
Writes the given integer to the given buffer at the given location in little endian format.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
val - the integer to write
Returns:
the number of bytes written

writeLELong

public static int writeLELong(byte[] b,
                              int off,
                              long val)
Writes the given long to the given buffer at the given location in little endian format.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
val - the long to write
Returns:
the number of bytes written

writeLEDouble

public static int writeLEDouble(byte[] b,
                                int off,
                                double val)
Writes the given double to the given buffer at the given location in little endian format.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
val - the double to write
Returns:
the number of bytes written

writePoint

public static int writePoint(byte[] b,
                             int off,
                             ESRIPoint point)
Writes the given point to the given buffer at the given location. The point is written as a double representing x followed by a double representing y.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
Returns:
the number of bytes written

writeBox

public static int writeBox(byte[] b,
                           int off,
                           ESRIBoundingBox box)
Writes the given bounding box to the given buffer at the given location. The bounding box is written as four doubles representing, in order, xmin, ymin, xmax, ymax.

Parameters:
b - the data buffer
off - the offset into the buffer where writing should occur
Returns:
the number of bytes written


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.