Class ShapefileWriter

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class ShapefileWriter
    extends Object
    implements Closeable
    ShapefileWriter allows for the storage of geometries in esris shp format. During writing, an index will also be created. To create a ShapefileWriter, do something like
    GeometryCollection geoms; File shp = new File("myshape.shp"); File shx = new File("myshape.shx"); ShapefileWriter writer = new ShapefileWriter( shp.getChannel(),shx.getChannel() ); writer.write(geoms,ShapeType.ARC); This example assumes that each shape in the collection is a LineString.
    Author:
    jamesm, aaime, Ian Schneider
    See Also:
    ShapefileDataStore
    • Constructor Summary

      Constructors 
      Constructor Description
      ShapefileWriter​(FileChannel shpChannel, FileChannel shxChannel)
      Creates a new instance of ShapeFileWriter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the underlying Channels.
      void skipHeaders()
      Allocate internal buffers and position the channels to the beginning or the record section of the shapefile.
      void write​(GeometryCollection geometries, ShapeType type)
      Bulk write method for writing a collection of (hopefully) like geometries of the given ShapeType.
      void writeGeometry​(Geometry g)
      Write a single Geometry to this shapefile.
      void writeHeaders​(Envelope bounds, ShapeType type, int numberOfGeometries, int fileLength)
      Write the headers for this shapefile including the bounds, shape type, the number of geometries and the total fileLength (in actual bytes, NOT 16 bit words).
      protected int writeNullGeometry()  
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShapefileWriter

        public ShapefileWriter​(FileChannel shpChannel,
                               FileChannel shxChannel)
                        throws IOException
        Creates a new instance of ShapeFileWriter
        Throws:
        IOException
    • Method Detail

      • writeHeaders

        public void writeHeaders​(Envelope bounds,
                                 ShapeType type,
                                 int numberOfGeometries,
                                 int fileLength)
                          throws IOException
        Write the headers for this shapefile including the bounds, shape type, the number of geometries and the total fileLength (in actual bytes, NOT 16 bit words).
        Throws:
        IOException
      • skipHeaders

        public void skipHeaders()
                         throws IOException
        Allocate internal buffers and position the channels to the beginning or the record section of the shapefile. The headers MUST be rewritten after this operation, or the file may be corrupt...
        Throws:
        IOException
      • writeGeometry

        public void writeGeometry​(Geometry g)
                           throws IOException
        Write a single Geometry to this shapefile. The Geometry must be compatable with the ShapeType assigned during the writing of the headers.
        Throws:
        IOException
      • writeNullGeometry

        protected int writeNullGeometry()
                                 throws IOException
        Throws:
        IOException
      • close

        public void close()
                   throws IOException
        Close the underlying Channels.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        IOException
      • write

        public void write​(GeometryCollection geometries,
                          ShapeType type)
                   throws IOException,
                          ShapefileException
        Bulk write method for writing a collection of (hopefully) like geometries of the given ShapeType.
        Throws:
        IOException
        ShapefileException