org.geotools.data.shapefile.indexed
Class IndexedShapefileDataStore

java.lang.Object
  extended byorg.geotools.data.AbstractDataStore
      extended byorg.geotools.data.AbstractFileDataStore
          extended byorg.geotools.data.shapefile.ShapefileDataStore
              extended byorg.geotools.data.shapefile.indexed.IndexedShapefileDataStore
All Implemented Interfaces:
DataStore

public class IndexedShapefileDataStore
extends ShapefileDataStore

A DataStore implementation which allows reading and writing from Shapefiles.

Author:
Ian Schneider, Tommaso Nolli
To Do:
fix file creation bug

Nested Class Summary
protected static class IndexedShapefileDataStore.Reader
          An AttributeReader implementation for shape.
protected  class IndexedShapefileDataStore.Writer
          A FeatureWriter for ShapefileDataStore.
 
Field Summary
 java.net.URL fixURL
           
static byte TREE_GRX
           
static byte TREE_NONE
           
static byte TREE_QIX
           
 
Fields inherited from class org.geotools.data.shapefile.ShapefileDataStore
dbfURL, namespace, prjURL, readWriteLock, schema, shpURL, shxURL, useMemoryMappedBuffer, xmlURL
 
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)
          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)
          Creates a new instance of ShapefileDataStore.
IndexedShapefileDataStore(java.net.URL url, java.net.URI namespace, boolean useMemoryMappedBuffer, boolean createIndex, byte treeType)
          Creates a new instance of ShapefileDataStore.
 
Method Summary
protected  FeatureReader createFeatureReader(java.lang.String typeName, IndexedShapefileDataStore.Reader r, FeatureType readerSchema)
          DOCUMENT ME!
protected  java.lang.String createFeatureTypeName()
          Create the type name of the single FeatureType this DataStore represents.
protected  FeatureWriter createFeatureWriter(java.lang.String typeName, Transaction transaction)
          Create a FeatureWriter for the given type name.
protected  void finalize()
           
protected  IndexedShapefileDataStore.Reader getAttributesReader(boolean readDbf, boolean readGeometry, Filter filter)
          Returns the attribute reader, allowing for a pure shape reader, or a combined dbf/shp reader.
protected  com.vividsolutions.jts.geom.Envelope 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  int getCount(Query query)
          Gets the number of the features that would be returned by this query for the specified feature type.
protected  java.lang.String getCurrentTypeName()
           
protected  FeatureReader 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.
 FeatureSource getFeatureSource(java.lang.String typeName)
          Default implementation based on getFeatureReader and getFeatureWriter.
 FeatureWriter getFeatureWriterAppend(java.lang.String typeName, Transaction transaction)
          Aquire a FeatureWriter for adding new content to a FeatureType.
 FeatureType getSchema()
          Singular version, returns the FeatureType for the url being read.
 FeatureType getSchema(java.lang.String typeName)
          Obtain the FeatureType of the given name.
 java.lang.String[] getTypeNames()
          Get an array of type names this DataStore holds.
protected  Filter getUnsupportedFilter(java.lang.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.
 boolean isLocal()
          Determine if the location of this shape is local or remote.
 boolean isMemoryMapped()
           
protected  DbaseFileReader openDbfReader()
          Convenience method for opening a DbaseFileReader.
protected  IndexFile openIndexFile()
          Convenience method for opening a ShapefileReader.
protected  QuadTree openQuadTree()
          Convenience method for opening a QuadTree index.
protected  RTree openRTree()
          Convenience method for opening an RTree index.
protected  AttributeType[] readAttributes()
          Create the AttributeTypes contained within this DataStore.
protected  void typeCheck(java.lang.String requested)
          A convenience method to check if a type name is correct.
 
Methods inherited from class org.geotools.data.shapefile.ShapefileDataStore
copyAndDelete, createDbaseHeader, createFeatureReader, createMetadata, createSchema, getAttributesReader, getFeatureReader, getFeatureReader, getReadChannel, getStorageFile, getStorageURL, getWriteChannel, openPrjReader, openShapeReader
 
Methods inherited from class org.geotools.data.AbstractFileDataStore
getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, updateSchema
 
Methods inherited from class org.geotools.data.AbstractDataStore
createLockingManager, getFeatureReader, getFeatureWriter, getFeatureWriter, getFeatureWriter, getLockingManager, getView, updateSchema
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TREE_NONE

public static final byte TREE_NONE
See Also:
Constant Field Values

TREE_GRX

public static final byte TREE_GRX
See Also:
Constant Field Values

TREE_QIX

public static final byte TREE_QIX
See Also:
Constant Field Values

fixURL

public java.net.URL fixURL
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.

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!

IndexedShapefileDataStore

public IndexedShapefileDataStore(java.net.URL url,
                                 java.net.URI namespace,
                                 boolean useMemoryMappedBuffer)
                          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

IndexedShapefileDataStore

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

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

IndexedShapefileDataStore

public IndexedShapefileDataStore(java.net.URL url,
                                 java.net.URI namespace,
                                 boolean useMemoryMappedBuffer,
                                 boolean createIndex,
                                 byte 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 - DOCUMENT ME!
Throws:
java.lang.NullPointerException - DOCUMENT ME!
.
java.net.MalformedURLException
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

isLocal

public boolean isLocal()
Determine if the location of this shape is local or remote.

Overrides:
isLocal in class ShapefileDataStore
Returns:
true if local, false if remote

getUnsupportedFilter

protected Filter getUnsupportedFilter(java.lang.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.NONE

Overrides:
getUnsupportedFilter in class AbstractDataStore

getFeatureWriterAppend

public FeatureWriter 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
Throws:
java.io.IOException

getFeatureReader

protected FeatureReader 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)

createFeatureReader

protected FeatureReader createFeatureReader(java.lang.String typeName,
                                            IndexedShapefileDataStore.Reader r,
                                            FeatureType readerSchema)
                                     throws SchemaException,
                                            java.io.IOException
DOCUMENT ME!

Parameters:
typeName -
r -
readerSchema -
Returns:
Throws:
SchemaException
java.io.IOException

getAttributesReader

protected IndexedShapefileDataStore.Reader getAttributesReader(boolean readDbf,
                                                               boolean readGeometry,
                                                               Filter filter)
                                                        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
Returns:
Throws:
java.io.IOException

openIndexFile

protected IndexFile openIndexFile()
                           throws java.io.IOException
Convenience method for opening a ShapefileReader.

Returns:
An IndexFile
Throws:
java.io.IOException

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.

openRTree

protected RTree openRTree()
                   throws java.io.IOException
Convenience method for opening an RTree index.

Returns:
A new RTree.
Throws:
java.io.IOException - If an error occurs during creation.
DataSourceException - DOCUMENT ME!

openQuadTree

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

Returns:
A new QuadTree
Throws:
StoreException

getTypeNames

public java.lang.String[] getTypeNames()
Get an array of type names this DataStore holds.
ShapefileDataStore will always return a single name.

Specified by:
getTypeNames in interface DataStore
Overrides:
getTypeNames in class ShapefileDataStore
Returns:
An array of length one containing the single type held.

createFeatureTypeName

protected java.lang.String createFeatureTypeName()
Create the type name of the single FeatureType this DataStore represents.
For example, if the urls path is file:///home/billy/mytheme.shp, the type name will be mytheme.

Overrides:
createFeatureTypeName in class ShapefileDataStore
Returns:
A name based upon the last path component of the url minus the extension.

getCurrentTypeName

protected java.lang.String getCurrentTypeName()
Overrides:
getCurrentTypeName in class ShapefileDataStore

typeCheck

protected void typeCheck(java.lang.String requested)
                  throws java.io.IOException
A convenience method to check if a type name is correct.

Overrides:
typeCheck in class ShapefileDataStore
Parameters:
requested - The type name requested.
Throws:
java.io.IOException - If the type name is not available

createFeatureWriter

protected FeatureWriter 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.

getSchema

public FeatureType getSchema(java.lang.String typeName)
                      throws java.io.IOException
Obtain the FeatureType of the given name. ShapefileDataStore contains only one FeatureType.

Specified by:
getSchema in interface DataStore
Overrides:
getSchema in class ShapefileDataStore
Parameters:
typeName - The name of the FeatureType.
Returns:
The FeatureType that this DataStore contains.
Throws:
java.io.IOException - If a type by the requested name is not present.

getSchema

public FeatureType getSchema()
                      throws java.io.IOException
Description copied from class: AbstractFileDataStore
Singular version, returns the FeatureType for the url being read.

Overrides:
getSchema in class ShapefileDataStore
Throws:
java.io.IOException

readAttributes

protected AttributeType[] readAttributes()
                                  throws java.io.IOException
Create the AttributeTypes contained within this DataStore.

Overrides:
readAttributes in class ShapefileDataStore
Returns:
An array of new AttributeTypes
Throws:
java.io.IOException - If AttributeType reading fails

getBounds

protected com.vividsolutions.jts.geom.Envelope 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
Throws:
java.io.IOException
See Also:
AbstractDataStore.getBounds(org.geotools.data.Query)

getFeatureSource

public FeatureSource getFeatureSource(java.lang.String typeName)
                               throws java.io.IOException
Description copied from class: AbstractDataStore
Default implementation based on getFeatureReader and getFeatureWriter.

We should be able to optimize this to only get the RowSet once

Specified by:
getFeatureSource in interface DataStore
Overrides:
getFeatureSource in class ShapefileDataStore
Throws:
java.io.IOException
See Also:
DataStore.getFeatureSource(java.lang.String)

getCount

protected int getCount(Query query)
                throws java.io.IOException
Description copied from class: AbstractDataStore
Gets the number of the features that would be returned by this query for the specified feature type.

If getBounds(Query) returns -1 due to expense consider using getFeatures(Query).getCount() as a an alternative.

Overrides:
getCount in class ShapefileDataStore
Throws:
java.io.IOException
See Also:
AbstractDataStore.getCount(org.geotools.data.Query)

isMemoryMapped

public boolean isMemoryMapped()


Copyright © GeoTools. All Rights Reserved.