/** * Write a single Geometry to this shapefile. The Geometry must be compatable with the ShapeType * assigned during the writing of the headers. */ public void writeGeometry(final Geometry g) throws IOException { if (shapeBuffer == null) throw new IOException("Must write headers first"); lp = shapeBuffer.position(); // see doc for handling null geometries // http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf int length; if (g == null) { length = writeNullGeometry(); } else { length = writeNonNullGeometry(g); } assert (length * 2 == (shapeBuffer.position() - lp) - 8); lp = shapeBuffer.position(); // write to the shx shx.writeRecord(offset, length); offset += length + 4; drain(); assert (shapeBuffer.position() == 0); }