org.geotools.data.shapefile.indexed
Class IndexedShapefileDataStore

java.lang.Object
  extended by org.geotools.data.AbstractDataStore
      extended by org.geotools.data.AbstractFileDataStore
          extended by org.geotools.data.shapefile.ShapefileDataStore
              extended by org.geotools.data.shapefile.indexed.IndexedShapefileDataStore
All Implemented Interfaces:
DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.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

Field Summary
 
Fields inherited from class org.geotools.data.shapefile.ShapefileDataStore
dbfCharset, DEFAULT_STRING_CHARSET, namespace, schema, shpFiles, useMemoryMappedBuffer
 
Fields inherited from class org.geotools.data.AbstractDataStore
isWriteable, listenerManager, LOGGER
 
Constructor Summary
IndexedShapefileDataStore(java.net.URL url)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(java.net.URL url, boolean useMemoryMappedBuffer, boolean createIndex)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(java.net.URL url, java.net.URI namespace)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(java.net.URL url, java.net.URI namespace, boolean useMemoryMappedBuffer, boolean createIndex, IndexType treeType)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(java.net.URL url, java.net.URI namespace, boolean useMemoryMappedBuffer, boolean createIndex, IndexType treeType, java.nio.charset.Charset dbfCharset)
          Creates a new instance of ShapefileDataStore.
 
Method Summary
 void buildQuadTree()
          Builds the QuadTree index.
protected  FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> createFeatureReader(java.lang.String typeName, IndexedShapefileAttributeReader r, org.opengis.feature.simple.SimpleFeatureType readerSchema)
           
protected  FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> createFeatureWriter(java.lang.String typeName, Transaction transaction)
          Create a FeatureWriter for the given type name.
 void createSpatialIndex()
          Forces the spatial index to be created
 org.opengis.feature.simple.SimpleFeatureType createSubType(java.lang.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, org.opengis.feature.simple.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureReader(java.lang.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterAppend(java.lang.String typeName, Transaction transaction)
          Aquire a FeatureWriter for adding new content to a FeatureType.
protected  java.util.Set getSupportedHints()
          If you are using the automated FeatureSource/Store/Locking creation, this method allows for the specification of the supported hints.
protected  org.opengis.filter.Filter getUnsupportedFilter(java.lang.String typeName, org.opengis.filter.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.
 java.lang.String id()
          An id for the writer.
 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(com.vividsolutions.jts.geom.Envelope bbox)
          QuadTree Query
protected  TransactionStateDiff state(Transaction transaction)
          This method is identical to the super class WHY?
 
Methods inherited from class org.geotools.data.shapefile.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 org.geotools.data.AbstractFileDataStore
getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, updateSchema
 
Methods inherited from class org.geotools.data.AbstractDataStore
createLockingManager, getFeatureReader, getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriter, getLockingManager, getNames, getSchema, getView, updateSchema, updateSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.geotools.data.DataStore
getFeatureReader, getFeatureWriter, getFeatureWriter, getLockingManager, getView, updateSchema
 
Methods inherited from interface org.geotools.data.DataAccess
getFeatureSource, getNames, getSchema, updateSchema
 

Constructor Detail

IndexedShapefileDataStore

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

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

IndexedShapefileDataStore

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

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

IndexedShapefileDataStore

public IndexedShapefileDataStore(java.net.URL url,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex)
                          throws java.net.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:
java.net.MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(java.net.URL url,
                                 java.net.URI namespace,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex,
                                 IndexType treeType)
                          throws java.net.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:
java.net.MalformedURLException

IndexedShapefileDataStore

public IndexedShapefileDataStore(java.net.URL url,
                                 java.net.URI namespace,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex,
                                 IndexType treeType,
                                 java.nio.charset.Charset dbfCharset)
                          throws java.net.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:
java.lang.NullPointerException - DOCUMENT ME!
.
java.net.MalformedURLException
Method Detail

createSpatialIndex

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

Throws:
java.io.IOException

getUnsupportedFilter

protected org.opengis.filter.Filter getUnsupportedFilter(java.lang.String typeName,
                                                         org.opengis.filter.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterAppend(java.lang.String typeName,
                                                                                                                                   Transaction transaction)
                                                                                                                            throws java.io.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:
java.io.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureReader(java.lang.String typeName,
                                                                                                                                Query query)
                                                                                                                         throws java.io.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:
java.io.IOException
See Also:
AbstractDataStore.getFeatureReader(java.lang.String, org.geotools.data.Query)

createSubType

public org.opengis.feature.simple.SimpleFeatureType createSubType(java.lang.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> createFeatureReader(java.lang.String typeName,
                                                                                                                                   IndexedShapefileAttributeReader r,
                                                                                                                                   org.opengis.feature.simple.SimpleFeatureType readerSchema)
                                                                                                                            throws SchemaException,
                                                                                                                                   java.io.IOException
Throws:
SchemaException
java.io.IOException

generateFidIndex

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

Throws:
java.io.IOException

getAttributesReader

protected IndexedShapefileAttributeReader getAttributesReader(boolean readDbf,
                                                              boolean readGeometry,
                                                              Query query,
                                                              org.opengis.feature.simple.SimpleFeatureType targetSchema)
                                                       throws java.io.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:
java.io.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(com.vividsolutions.jts.geom.Envelope bbox)
                                           throws DataSourceException,
                                                  java.io.IOException,
                                                  TreeException
QuadTree Query

Parameters:
bbox -
Throws:
DataSourceException
java.io.IOException
TreeException - DOCUMENT ME!

openDbfReader

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

Overrides:
openDbfReader in class ShapefileDataStore
Returns:
A new DbaseFileReader
Throws:
java.io.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<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> createFeatureWriter(java.lang.String typeName,
                                                                                                                                   Transaction transaction)
                                                                                                                            throws java.io.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:
java.io.IOException - If the typeName is not available or some other error occurs.

getBounds

protected ReferencedEnvelope getBounds(Query query)
                                throws java.io.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
java.io.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 java.lang.String id()
Description copied from interface: FileWriter
An id for the writer. This is only used for debugging.

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

getSupportedHints

protected java.util.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-2010 Geotools. All Rights Reserved.