org.geotools.data.shapefile.indexed
Class IndexedShapefileDataStore

Object
  extended by AbstractDataStore
      extended by AbstractFileDataStore
          extended by ShapefileDataStore
              extended by IndexedShapefileDataStore
All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>, DataStore, FileDataStore, FileReader, FileWriter

public class IndexedShapefileDataStore
extends ShapefileDataStore
implements FileWriter

A DataStore implementation which allows reading and writing from Shapefiles.

Author:
Ian Schneider, Tommaso Nolli, jesse eichar
Module:

Field Summary
 
Fields inherited from class ShapefileDataStore
dbfCharset, DEFAULT_STRING_CHARSET, namespace, schema, shpFiles, useMemoryMappedBuffer
 
Fields inherited from class AbstractDataStore
isWriteable, listenerManager, LOGGER
 
Constructor Summary
IndexedShapefileDataStore(URL url)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(URL url, boolean useMemoryMappedBuffer, boolean createIndex)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(URL url, URI namespace)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(URL url, URI namespace, boolean useMemoryMappedBuffer, boolean createIndex, IndexType treeType)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(URL url, URI namespace, boolean useMemoryMappedBuffer, boolean createIndex, IndexType treeType, Charset dbfCharset)
          Creates a new instance of ShapefileDataStore.
 
Method Summary
 void buildQuadTree()
          Builds the QuadTree index.
protected  FeatureReader<SimpleFeatureType,SimpleFeature> createFeatureReader(String typeName, IndexedShapefileAttributeReader r, SimpleFeatureType readerSchema)
           
protected  FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName, Transaction transaction)
          Create a FeatureWriter for the given type name.
 void createSpatialIndex()
          Forces the spatial index to be created
 SimpleFeatureType createSubType(String[] properties)
          Much like DataUtilities.createSubType(SimpleFeatureType, String[]), but makes sure to preserve the original attribute order
 void generateFidIndex()
          Forces the FID index to be regenerated
protected  IndexedShapefileAttributeReader getAttributesReader(boolean readDbf, boolean readGeometry, Query query, SimpleFeatureType targetSchema)
          Returns the attribute reader, allowing for a pure shape reader, or a combined dbf/shp reader.
protected  ReferencedEnvelope getBounds(Query query)
          Computes the bounds of the features for the specified feature type that satisfy the query provided that there is a fast way to get that result.
protected  FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName, Query query)
          Use the spatial index if available and adds a small optimization: if no attributes are going to be read, don't uselessly open and read the dbf file.
 FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName, Transaction transaction)
          Aquire a FeatureWriter for adding new content to a FeatureType.
protected  Set getSupportedHints()
          If you are using the automated FeatureSource/Store/Locking creation, this method allows for the specification of the supported hints.
protected  Filter getUnsupportedFilter(String typeName, Filter filter)
          GR: if a subclass supports filtering, it should override this method to return the unsupported part of the passed filter, so a FilteringFeatureReader will be constructed upon it.
 String id()
          An id for the reader.
 boolean indexUseable(ShpFileType indexType)
          Returns true if the index for the given type exists and is useable.
 boolean isIndexed()
          Returns true if the indices already exist and do not need to be regenerated or cannot be generated (IE isn't local).
 boolean isMemoryMapped()
           
protected  DbaseFileReader openDbfReader()
          Convenience method for opening a DbaseFileReader.
protected  QuadTree openQuadTree()
          Convenience method for opening a QuadTree index.
protected  CloseableCollection<Data> queryQuadTree(Envelope bbox)
          QuadTree Query
protected  TransactionStateDiff state(Transaction transaction)
          This method is identical to the super class WHY?
 
Methods inherited from class ShapefileDataStore
createDbaseHeader, createFeatureReader, createFeatureTypeName, createMetadata, createSchema, dispose, forceSchemaCRS, getAttributesReader, getBounds, getCount, getCurrentTypeName, getFeatureReader, getFeatureReader, getFeatureSource, getGeometryFactory, getInfo, getSchema, getSchema, getStringCharset, getTypeNames, isLocal, openIndexFile, openPrjReader, openShapeReader, readAttributes, setStringCharset, toString, typeCheck
 
Methods inherited from class AbstractFileDataStore
getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, updateSchema
 
Methods inherited from class AbstractDataStore
createLockingManager, getFeatureReader, getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriter, getLockingManager, getNames, getSchema, getView, updateSchema, updateSchema
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface DataStore
getFeatureReader, getFeatureWriter, getFeatureWriter, getLockingManager, getView, updateSchema
 
Methods inherited from interface DataAccess
getFeatureSource, getNames, getSchema, updateSchema
 

Constructor Detail

IndexedShapefileDataStore

public IndexedShapefileDataStore(URL url)
                          throws MalformedURLException
Creates a new instance of ShapefileDataStore.

Parameters:
url - The URL of the shp file to use for this DataSource.
Throws:
MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(URL url,
                                 URI namespace)
                          throws MalformedURLException
Creates a new instance of ShapefileDataStore.

Parameters:
url - The URL of the shp file to use for this DataSource.
namespace - DOCUMENT ME!
Throws:
MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(URL url,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex)
                          throws MalformedURLException
Creates a new instance of ShapefileDataStore.

Parameters:
url - The URL of the shp file to use for this DataSource.
useMemoryMappedBuffer - enable/disable memory mapping of files
createIndex - enable/disable automatic index creation if needed
Throws:
MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(URL url,
                                 URI namespace,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex,
                                 IndexType treeType)
                          throws MalformedURLException
Creates a new instance of ShapefileDataStore.

Parameters:
url - The URL of the shp file to use for this DataSource.
namespace - DOCUMENT ME!
useMemoryMappedBuffer - enable/disable memory mapping of files
createIndex - enable/disable automatic index creation if needed
treeType - The type of index to use
Throws:
MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(URL url,
                                 URI namespace,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex,
                                 IndexType treeType,
                                 Charset dbfCharset)
                          throws MalformedURLException
Creates a new instance of ShapefileDataStore.

Parameters:
url - The URL of the shp file to use for this DataSource.
namespace - DOCUMENT ME!
useMemoryMappedBuffer - enable/disable memory mapping of files
createIndex - enable/disable automatic index creation if needed
treeType - The type of index used
dbfCharset - Charset used to decode strings from the DBF
Throws:
NullPointerException - DOCUMENT ME!
.
MalformedURLException
Method Detail

createSpatialIndex

public void createSpatialIndex()
                        throws IOException
Forces the spatial index to be created

Throws:
IOException

getUnsupportedFilter

protected Filter getUnsupportedFilter(String typeName,
                                      Filter filter)
Description copied from class: AbstractDataStore
GR: if a subclass supports filtering, it should override this method to return the unsupported part of the passed filter, so a FilteringFeatureReader will be constructed upon it. Otherwise it will just return the same filter.

If the complete filter is supported, the subclass must return Filter.INCLUDE

Overrides:
getUnsupportedFilter in class AbstractDataStore

getFeatureWriterAppend

public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(String typeName,
                                                                             Transaction transaction)
                                                                      throws IOException
Description copied from interface: DataStore
Aquire a FeatureWriter for adding new content to a FeatureType.

This FeatureWriter will return false for hasNext(), however next() may be used to aquire new Features that may be writen out to add new content.

Specified by:
getFeatureWriterAppend in interface DataStore
Overrides:
getFeatureWriterAppend in class AbstractDataStore
Parameters:
typeName - Indicates featureType to be modified
transaction - Transaction to operates against
Returns:
FeatureWriter that may only be used to append new content
Throws:
IOException

state

protected TransactionStateDiff state(Transaction transaction)
This method is identical to the super class WHY?

Overrides:
state in class AbstractDataStore
Returns:
TransactionStateDiff or null if subclass is handling differences

getFeatureReader

protected FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader(String typeName,
                                                                          Query query)
                                                                   throws IOException
Use the spatial index if available and adds a small optimization: if no attributes are going to be read, don't uselessly open and read the dbf file.

Overrides:
getFeatureReader in class ShapefileDataStore
Throws:
IOException
See Also:
AbstractDataStore.getFeatureReader(java.lang.String, org.geotools.data.Query)

createSubType

public SimpleFeatureType createSubType(String[] properties)
                                throws SchemaException
Much like DataUtilities.createSubType(SimpleFeatureType, String[]), but makes sure to preserve the original attribute order

Parameters:
properties -
Returns:
Throws:
SchemaException

createFeatureReader

protected FeatureReader<SimpleFeatureType,SimpleFeature> createFeatureReader(String typeName,
                                                                             IndexedShapefileAttributeReader r,
                                                                             SimpleFeatureType readerSchema)
                                                                      throws SchemaException,
                                                                             IOException
Throws:
SchemaException
IOException

generateFidIndex

public void generateFidIndex()
                      throws IOException
Forces the FID index to be regenerated

Throws:
IOException

getAttributesReader

protected IndexedShapefileAttributeReader getAttributesReader(boolean readDbf,
                                                              boolean readGeometry,
                                                              Query query,
                                                              SimpleFeatureType targetSchema)
                                                       throws IOException
Returns the attribute reader, allowing for a pure shape reader, or a combined dbf/shp reader.

Parameters:
readDbf - - if true, the dbf fill will be opened and read
readGeometry - DOCUMENT ME!
filter - - a Filter to use
Throws:
IOException

indexUseable

public boolean indexUseable(ShpFileType indexType)
Returns true if the index for the given type exists and is useable.

Parameters:
indexType - the type of index to check
Returns:
true if the index for the given type exists and is useable.

isIndexed

public boolean isIndexed()
Returns true if the indices already exist and do not need to be regenerated or cannot be generated (IE isn't local).

Returns:
true if the indices already exist and do not need to be regenerated.

queryQuadTree

protected CloseableCollection<Data> queryQuadTree(Envelope bbox)
                                           throws DataSourceException,
                                                  IOException,
                                                  TreeException
QuadTree Query

Parameters:
bbox -
Throws:
DataSourceException
IOException
TreeException - DOCUMENT ME!

openDbfReader

protected DbaseFileReader openDbfReader()
                                 throws IOException
Convenience method for opening a DbaseFileReader.

Overrides:
openDbfReader in class ShapefileDataStore
Returns:
A new DbaseFileReader
Throws:
IOException - If an error occurs during creation.

openQuadTree

protected QuadTree openQuadTree()
                         throws StoreException
Convenience method for opening a QuadTree index.

Returns:
A new QuadTree
Throws:
StoreException

createFeatureWriter

protected FeatureWriter<SimpleFeatureType,SimpleFeature> createFeatureWriter(String typeName,
                                                                             Transaction transaction)
                                                                      throws IOException
Create a FeatureWriter for the given type name.

Overrides:
createFeatureWriter in class ShapefileDataStore
Parameters:
typeName - The typeName of the FeatureType to write
transaction - DOCUMENT ME!
Returns:
A new FeatureWriter.
Throws:
IOException - If the typeName is not available or some other error occurs.

getBounds

protected ReferencedEnvelope getBounds(Query query)
                                throws IOException
Description copied from class: AbstractDataStore
Computes the bounds of the features for the specified feature type that satisfy the query provided that there is a fast way to get that result.

Will return null if there is not fast way to compute the bounds. Since it's based on some kind of header/cached information, it's not guaranteed to be real bound of the features

Overrides:
getBounds in class ShapefileDataStore
Returns:
the bounds, or null if too expensive
Throws:
SchemaNotFoundException
IOException
See Also:
AbstractDataStore.getBounds(org.geotools.data.Query)

buildQuadTree

public void buildQuadTree()
                   throws TreeException
Builds the QuadTree index. Usually not necessary since reading features will index when required

Throws:
TreeException

isMemoryMapped

public boolean isMemoryMapped()

id

public String id()
Description copied from interface: FileReader
An id for the reader. This is only used for debugging.

Specified by:
id in interface FileReader
Specified by:
id in interface FileWriter
Returns:
id for the reader.

getSupportedHints

protected Set getSupportedHints()
Description copied from class: AbstractDataStore
If you are using the automated FeatureSource/Store/Locking creation, this method allows for the specification of the supported hints.

Overrides:
getSupportedHints in class ShapefileDataStore
Returns:


Copyright © 1996-2009 Geotools. All Rights Reserved.