org.geotools.data.shapefile
Class ShapefileFeatureWriter

Object
  extended by ShapefileFeatureWriter
All Implemented Interfaces:
FeatureWriter<SimpleFeatureType,SimpleFeature>

public class ShapefileFeatureWriter
extends Object
implements FeatureWriter<SimpleFeatureType,SimpleFeature>

A FeatureWriter for ShapefileDataStore. Uses a write and annotate technique to avoid buffering attributes and geometries. Because the shapefile and dbf require header information which can only be obtained by reading the entire series of Features, the headers are updated after the initial write completes.

Author:
Jesse Eichar

Field Summary
protected  ShapefileAttributeReader attReader
           
protected  Envelope bounds
           
protected  SimpleFeature currentFeature
           
protected  DbaseFileWriter dbfWriter
           
protected  Object[] emptyAtts
           
protected  FeatureReader<SimpleFeatureType,SimpleFeature> featureReader
           
protected  SimpleFeatureType featureType
           
protected  ShapeHandler handler
           
protected  int records
           
protected  int shapefileLength
           
protected  ShapeType shapeType
           
protected  ShpFiles shpFiles
           
protected  ShapefileWriter shpWriter
           
protected  Map<ShpFileType,StorageFile> storageFiles
           
protected  Object[] transferCache
           
protected  byte[] writeFlags
           
 
Constructor Summary
ShapefileFeatureWriter(String typeName, ShpFiles shpFiles, ShapefileAttributeReader attsReader, FeatureReader<SimpleFeatureType,SimpleFeature> featureReader, Charset charset)
           
 
Method Summary
protected  void clean()
          Clean up our temporary write if there was one
 void close()
          Release resources and flush the header information.
protected  void doClose()
           
protected  void finalize()
          In case someone doesn't close me.
protected  void flush()
          Go back and update the headers with the required info.
 SimpleFeatureType getFeatureType()
          FeatureType this reader has been configured to create.
 boolean hasNext()
          Query whether this FeatureWriter has another Feature.
 SimpleFeature next()
          Reads a Feature from the underlying AttributeReader.
protected  String nextFeatureId()
          Called when a new feature is being created and a new fid is required
 void remove()
          Removes current Feature, must be called before hasNext.
 void write()
          Wrties the current Feature, must be called before hasNext.
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

featureReader

protected FeatureReader<SimpleFeatureType,SimpleFeature> featureReader

attReader

protected ShapefileAttributeReader attReader

currentFeature

protected SimpleFeature currentFeature

featureType

protected SimpleFeatureType featureType

emptyAtts

protected Object[] emptyAtts

transferCache

protected Object[] transferCache

shapeType

protected ShapeType shapeType

handler

protected ShapeHandler handler

shapefileLength

protected int shapefileLength

records

protected int records

writeFlags

protected byte[] writeFlags

shpWriter

protected ShapefileWriter shpWriter

dbfWriter

protected DbaseFileWriter dbfWriter

storageFiles

protected Map<ShpFileType,StorageFile> storageFiles

bounds

protected Envelope bounds

shpFiles

protected ShpFiles shpFiles
Constructor Detail

ShapefileFeatureWriter

public ShapefileFeatureWriter(String typeName,
                              ShpFiles shpFiles,
                              ShapefileAttributeReader attsReader,
                              FeatureReader<SimpleFeatureType,SimpleFeature> featureReader,
                              Charset charset)
                       throws IOException
Throws:
IOException
Method Detail

flush

protected void flush()
              throws IOException
Go back and update the headers with the required info.

Throws:
IOException - DOCUMENT ME!

finalize

protected void finalize()
                 throws Throwable
In case someone doesn't close me.

Overrides:
finalize in class Object
Throws:
Throwable - DOCUMENT ME!

clean

protected void clean()
              throws IOException
Clean up our temporary write if there was one

Throws:
IOException - DOCUMENT ME!

close

public void close()
           throws IOException
Release resources and flush the header information.

Specified by:
close in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Throws:
IOException - DOCUMENT ME!

doClose

protected void doClose()
                throws IOException
Throws:
IOException

getFeatureType

public SimpleFeatureType getFeatureType()
Description copied from interface: FeatureWriter
FeatureType this reader has been configured to create.

Specified by:
getFeatureType in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Returns:
FeatureType this writer has been configured to create.

hasNext

public boolean hasNext()
                throws IOException
Description copied from interface: FeatureWriter
Query whether this FeatureWriter has another Feature.

Please note: it is more efficient to construct your FeatureWriter with a Filer (to skip entries you do not want), than to force the creation of entire Features only to skip over them.

FeatureWriters that support append opperations will allow calls to next, even when haveNext() returns false.

Specified by:
hasNext in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Returns:
true if an additional Feature is available.
Throws:
IOException - DOCUMENT ME!

next

public SimpleFeature next()
                   throws IOException
Description copied from interface: FeatureWriter
Reads a Feature from the underlying AttributeReader.

This method may return a Feature even though hasNext() returns false, this allows FeatureWriters to provide an ability to append content.

Specified by:
next in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Returns:
Feature from Query, or newly appended Feature
Throws:
IOException - DOCUMENT ME!

nextFeatureId

protected String nextFeatureId()
Called when a new feature is being created and a new fid is required

Returns:
a fid for the new feature

remove

public void remove()
            throws IOException
Description copied from interface: FeatureWriter
Removes current Feature, must be called before hasNext.

FeatureWriters will need to allow all FeatureSources of the same typeName to issue a FeatureEvent event of type FeatureEvent.FEATURES_REMOVED when this method is called.

If this FeatureWriter is opperating against a Transaction FEATURES_REMOVED events should only be sent to FeatureSources operating on the same Transaction. When Transaction commit() is called other FeatureSources will be informed of the modifications.

When the current Feature has been provided as new content, this method "cancels" the add opperation (and notification needed).

Specified by:
remove in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Throws:
IOException - DOCUMENT ME!

write

public void write()
           throws IOException
Description copied from interface: FeatureWriter
Wrties the current Feature, must be called before hasNext.

FeautreWriters will need to allow FeatureSources of the same typeName to issue a FeatureEvent:

If this FeatureWriter is opperating against a Transaction the FEATURES_MODIFIED or FEATURES_ADDED events should only be sent to FeatureSources opperating on the same Transaction. When Transaction commit() is called other FeatureSources will be informed of the modifications.

If you have not called write() when you call hasNext() or next(), no modification will occur().

Specified by:
write in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Throws:
IOException


Copyright © 1996-2009 Geotools. All Rights Reserved.