Class ShapefileDataStore
- Object
-
- ContentDataStore
-
- ShapefileDataStore
-
- All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>
,DataStore
,FileDataStore
public class ShapefileDataStore extends ContentDataStore implements FileDataStore
-
-
Field Summary
Fields Modifier and Type Field Description static Charset
DEFAULT_STRING_CHARSET
static TimeZone
DEFAULT_TIMEZONE
static String
ORIGINAL_FIELD_DUPLICITY_COUNT
static String
ORIGINAL_FIELD_NAME
protected static Boolean
TRACE_ENABLED
When true, the stack trace that got a lock that wasn't released is recorded and then printed out when warning the user about this.-
Fields inherited from class ContentDataStore
dataStoreFactory, entries, featureFactory, filterFactory, geometryFactory, JOINED_FEATURE_TYPE, lockingManager, LOGGER, namespaceURI, typeFactory, WRITER_ADD, WRITER_COMMIT, WRITER_UPDATE
-
-
Constructor Summary
Constructors Constructor Description ShapefileDataStore(URL url)
ShapefileDataStore(URL url, boolean skipScan)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static DbaseFileHeader
createDbaseHeader(SimpleFeatureType featureType, Charset charset)
Attempt to create a DbaseFileHeader for the FeatureType.protected ContentFeatureSource
createFeatureSource(ContentEntry entry)
Instantiates new feature source for the entry.void
createSchema(SimpleFeatureType featureType)
Set the FeatureType of this DataStore.protected List<Name>
createTypeNames()
Creates a set of qualified names corresponding to the types that the datastore provides.void
dispose()
Disposes of this data store and releases any resource that it is using.protected void
finalize()
void
forceSchemaCRS(CoordinateReferenceSystem crs)
This method is used to force the creation of a .prj file.Charset
getCharset()
long
getCount(Query query)
FeatureReader<SimpleFeatureType,SimpleFeature>
getFeatureReader()
ContentFeatureSource
getFeatureSource()
FeatureWriter<SimpleFeatureType,SimpleFeature>
getFeatureWriter(Transaction transaction)
FeatureWriter<SimpleFeatureType,SimpleFeature>
getFeatureWriter(Filter filter, Transaction transaction)
FeatureWriter<SimpleFeatureType,SimpleFeature>
getFeatureWriterAppend(Transaction transaction)
SimpleFeatureType
getSchema()
FeatureType for the file being read.TimeZone
getTimeZone()
boolean
isBufferCachingEnabled()
boolean
isFidIndexed()
Returns true if the store uses the .fix index file for feature ids.boolean
isIndexCreationEnabled()
boolean
isIndexed()
boolean
isMemoryMapped()
boolean
isTryCPGFile()
Returns true, if the store tries to guess DBF file charset from CPG filevoid
removeSchema(String typeName)
Used to permanently remove a schema from the underlying storagevoid
removeSchema(Name typeName)
Used to permanently remove a schema from the underlying storagevoid
setBufferCachingEnabled(boolean bufferCachingEnabled)
void
setCharset(Charset charset)
void
setFidIndexed(boolean fidIndexed)
Enables/disables the feature id index.void
setIndexCreationEnabled(boolean indexCreationEnabled)
If true (default) the index file will be created on demand if missingvoid
setIndexed(boolean indexed)
When set to true, will use the spatial index if available (but will not create it if missing, unless also indexCreationEnabled is true)void
setMemoryMapped(boolean memoryMapped)
void
setTimeZone(TimeZone timeZone)
void
setTryCPGFile(boolean tryCPGFile)
Makes the store try to figure out DBF file charset from CPG file.String
toString()
void
updateSchema(SimpleFeatureType featureType)
-
Methods inherited from class ContentDataStore
createContentState, ensureEntry, ensureFeatureStore, entry, getDataStoreFactory, getEntry, getFeatureFactory, getFeatureReader, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureTypeFactory, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getFilterFactory, getGeometryFactory, getInfo, getLockingManager, getLogger, getNames, getNamespaceURI, getSchema, getSchema, getTypeNames, name, removeEntry, setDataStoreFactory, setFeatureFactory, setFeatureTypeFactory, setFilterFactory, setGeometryFactory, setNamespaceURI, updateSchema, updateSchema
-
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface DataAccess
getInfo, getNames, getSchema, updateSchema
-
Methods inherited from interface DataStore
getFeatureReader, getFeatureSource, getFeatureSource, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getLockingManager, getSchema, getTypeNames, updateSchema
-
-
-
-
Field Detail
-
ORIGINAL_FIELD_NAME
public static final String ORIGINAL_FIELD_NAME
- See Also:
- Constant Field Values
-
ORIGINAL_FIELD_DUPLICITY_COUNT
public static final String ORIGINAL_FIELD_DUPLICITY_COUNT
- See Also:
- Constant Field Values
-
DEFAULT_STRING_CHARSET
public static final Charset DEFAULT_STRING_CHARSET
-
DEFAULT_TIMEZONE
public static final TimeZone DEFAULT_TIMEZONE
-
TRACE_ENABLED
protected static final Boolean TRACE_ENABLED
When true, the stack trace that got a lock that wasn't released is recorded and then printed out when warning the user about this.
-
-
Method Detail
-
createTypeNames
protected List<Name> createTypeNames() throws IOException
Description copied from class:ContentDataStore
Creates a set of qualified names corresponding to the types that the datastore provides.Namespaces may be left
null
for data stores which do not support namespace qualified type names.- Specified by:
createTypeNames
in classContentDataStore
- Returns:
- A list of
Name
. - Throws:
IOException
- Any errors occuring connecting to data.
-
createFeatureSource
protected ContentFeatureSource createFeatureSource(ContentEntry entry) throws IOException
Description copied from class:ContentDataStore
Instantiates new feature source for the entry.Subclasses should override this method to return a specific subclass of
ContentFeatureSource
.- Specified by:
createFeatureSource
in classContentDataStore
- Parameters:
entry
- The entry.- Returns:
- An new instance of
ContentFeatureSource
for the entry. - Throws:
IOException
-
getFeatureSource
public ContentFeatureSource getFeatureSource() throws IOException
- Specified by:
getFeatureSource
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.getFeatureSource(java.lang.String)
-
getCharset
public Charset getCharset()
-
setCharset
public void setCharset(Charset charset)
-
getTimeZone
public TimeZone getTimeZone()
-
setTimeZone
public void setTimeZone(TimeZone timeZone)
-
isMemoryMapped
public boolean isMemoryMapped()
-
setMemoryMapped
public void setMemoryMapped(boolean memoryMapped)
-
isBufferCachingEnabled
public boolean isBufferCachingEnabled()
-
setBufferCachingEnabled
public void setBufferCachingEnabled(boolean bufferCachingEnabled)
-
isIndexed
public boolean isIndexed()
-
setIndexed
public void setIndexed(boolean indexed)
When set to true, will use the spatial index if available (but will not create it if missing, unless also indexCreationEnabled is true)
-
isTryCPGFile
public boolean isTryCPGFile()
Returns true, if the store tries to guess DBF file charset from CPG file
-
setTryCPGFile
public void setTryCPGFile(boolean tryCPGFile)
Makes the store try to figure out DBF file charset from CPG file. If succeeds, thecharset
property will be rewritten by guessed value.
-
getSchema
public SimpleFeatureType getSchema() throws IOException
Description copied from interface:FileDataStore
FeatureType for the file being read.This is the same as getSchema( getTypeName[0] )
- Specified by:
getSchema
in interfaceFileDataStore
- Returns:
- FeatureType of the file being read
- Throws:
IOException
- See Also:
DataStore.getSchema(java.lang.String)
-
getFeatureReader
public FeatureReader<SimpleFeatureType,SimpleFeature> getFeatureReader() throws IOException
- Specified by:
getFeatureReader
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.getFeatureReader(Query,Transaction)
-
getCount
public long getCount(Query query) throws IOException
- Throws:
IOException
-
createSchema
public void createSchema(SimpleFeatureType featureType) throws IOException
Set the FeatureType of this DataStore. This method will delete any existing local resources or throw an IOException if the DataStore is remote.- Specified by:
createSchema
in interfaceDataAccess<SimpleFeatureType,SimpleFeature>
- Overrides:
createSchema
in classContentDataStore
- Parameters:
featureType
- The desired FeatureType.- Throws:
IOException
- If the DataStore is remote.- See Also:
DataAccess.createSchema(FeatureType)
-
createDbaseHeader
protected static DbaseFileHeader createDbaseHeader(SimpleFeatureType featureType, Charset charset) throws IOException, DbaseFileException
Attempt to create a DbaseFileHeader for the FeatureType. Note, we cannot set the number of records until the write has completed.- Throws:
IOException
DbaseFileException
-
forceSchemaCRS
public void forceSchemaCRS(CoordinateReferenceSystem crs) throws IOException
This method is used to force the creation of a .prj file.The internally cached FeatureType will be removed, so the next call to getSchema() will read in the created file. This method is not thread safe and will have dire consequences for any other thread making use of the shapefile.
- Throws:
IOException
-
dispose
public void dispose()
Description copied from interface:DataAccess
Disposes of this data store and releases any resource that it is using.A
DataStore
cannot be used afterdispose
has been called, neither can any data access object it helped create, such asFeatureReader
,FeatureSource
orFeatureCollection
.This operation can be called more than once without side effects.
There is no thread safety assurance associated with this method. For example, client code will have to make sure this method is not called while retrieving/saving data from/to the storage, or be prepared for the consequences.
- Specified by:
dispose
in interfaceDataAccess<SimpleFeatureType,SimpleFeature>
- Overrides:
dispose
in classContentDataStore
-
finalize
protected void finalize() throws Throwable
-
isFidIndexed
public boolean isFidIndexed()
Returns true if the store uses the .fix index file for feature ids. The .fix file speeds up filters by feature id and allows for stable ids in face of feature removals, without it the feature id is simply the position of the feature in the shapefile, something which changes when data is removed
-
setFidIndexed
public void setFidIndexed(boolean fidIndexed)
Enables/disables the feature id index. The index is enabled by default
-
updateSchema
public void updateSchema(SimpleFeatureType featureType) throws IOException
- Specified by:
updateSchema
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.updateSchema(java.lang.String,SimpleFeatureType)
-
getFeatureWriter
public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(Filter filter, Transaction transaction) throws IOException
- Specified by:
getFeatureWriter
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.getFeatureWriter(String,Filter,Transaction)
-
getFeatureWriter
public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(Transaction transaction) throws IOException
- Specified by:
getFeatureWriter
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.getFeatureWriter(java.lang.String, Transaction)
-
getFeatureWriterAppend
public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(Transaction transaction) throws IOException
- Specified by:
getFeatureWriterAppend
in interfaceFileDataStore
- Throws:
IOException
- See Also:
DataStore.getFeatureWriterAppend(java.lang.String, Transaction)
-
isIndexCreationEnabled
public boolean isIndexCreationEnabled()
-
setIndexCreationEnabled
public void setIndexCreationEnabled(boolean indexCreationEnabled)
If true (default) the index file will be created on demand if missing
-
removeSchema
public void removeSchema(String typeName) throws IOException
Description copied from interface:DataStore
Used to permanently remove a schema from the underlying storageThis functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
- Specified by:
removeSchema
in interfaceDataStore
- Overrides:
removeSchema
in classContentDataStore
- Throws:
IOException
- if the operation failed- See Also:
DataStore.removeSchema(String)
-
removeSchema
public void removeSchema(Name typeName) throws IOException
Description copied from interface:DataAccess
Used to permanently remove a schema from the underlying storageThis functionality is similar to an "drop table" statement in SQL. Implementation is optional; it may not be supported by all servers or files.
- Specified by:
removeSchema
in interfaceDataAccess<SimpleFeatureType,SimpleFeature>
- Overrides:
removeSchema
in classContentDataStore
- Throws:
IOException
- if the operation failed- See Also:
DataAccess.removeSchema(Name)
-
-