01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
05: * (C) 2002, Centre for Computational Geography
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.data.shapefile.shp;
18:
19: import java.nio.ByteBuffer;
20:
21: /** A ShapeHandler defines what is needed to construct and persist geometries
22: * based upon the shapefile specification.
23: * @author aaime
24: * @author Ian Schneider
25: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/shp/ShapeHandler.java $
26: *
27: */
28: public interface ShapeHandler {
29: /** Get the ShapeType of this handler.
30: * @return The ShapeType.
31: */
32: public ShapeType getShapeType();
33:
34: /** Read a geometry from the ByteBuffer. The buffer's position, byteOrder, and limit
35: * are set to that which is needed. The record has been read as well as the shape
36: * type integer. The handler need not worry about reading unused information as
37: * the ShapefileReader will correctly adjust the buffer position after this call.
38: * @param buffer The ByteBuffer to read from.
39: * @return A geometry object.
40: */
41: public Object read(ByteBuffer buffer, ShapeType type);
42:
43: /** Write the geometry into the ByteBuffer. The position, byteOrder, and limit are
44: * all set. The handler is not responsible for writing the record or
45: * shape type integer.
46: * @param buffer The ByteBuffer to write to.
47: * @param geometry The geometry to write.
48: */
49: public void write(ByteBuffer buffer, Object geometry);
50:
51: /** Get the length of the given geometry Object in <b>bytes</b> not 16-bit words.
52: * This is easier to keep track of, since the ByteBuffer deals with bytes. <b>Do
53: * not include the 8 bytes of record.</b>
54: * @param geometry The geometry to analyze.
55: * @return The number of <b>bytes</b> the shape will take up.
56: */
57: public int getLength(Object geometry);
58: }
|