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 CharsetDEFAULT_STRING_CHARSETstatic TimeZoneDEFAULT_TIMEZONEstatic StringORIGINAL_FIELD_DUPLICITY_COUNTstatic StringORIGINAL_FIELD_NAMEprotected static BooleanTRACE_ENABLEDWhen 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 DbaseFileHeadercreateDbaseHeader(SimpleFeatureType featureType, Charset charset)Attempt to create a DbaseFileHeader for the FeatureType.protected ContentFeatureSourcecreateFeatureSource(ContentEntry entry)Instantiates new feature source for the entry.voidcreateSchema(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.voiddispose()Disposes of this data store and releases any resource that it is using.protected voidfinalize()voidforceSchemaCRS(CoordinateReferenceSystem crs)This method is used to force the creation of a .prj file.CharsetgetCharset()longgetCount(Query query)FeatureReader<SimpleFeatureType,SimpleFeature>getFeatureReader()ContentFeatureSourcegetFeatureSource()FeatureWriter<SimpleFeatureType,SimpleFeature>getFeatureWriter(Transaction transaction)FeatureWriter<SimpleFeatureType,SimpleFeature>getFeatureWriter(Filter filter, Transaction transaction)FeatureWriter<SimpleFeatureType,SimpleFeature>getFeatureWriterAppend(Transaction transaction)SimpleFeatureTypegetSchema()FeatureType for the file being read.TimeZonegetTimeZone()booleanisBufferCachingEnabled()booleanisFidIndexed()Returns true if the store uses the .fix index file for feature ids.booleanisIndexCreationEnabled()booleanisIndexed()booleanisMemoryMapped()booleanisTryCPGFile()Returns true, if the store tries to guess DBF file charset from CPG filevoidremoveSchema(String typeName)Used to permanently remove a schema from the underlying storagevoidremoveSchema(Name typeName)Used to permanently remove a schema from the underlying storagevoidsetBufferCachingEnabled(boolean bufferCachingEnabled)voidsetCharset(Charset charset)voidsetFidIndexed(boolean fidIndexed)Enables/disables the feature id index.voidsetIndexCreationEnabled(boolean indexCreationEnabled)If true (default) the index file will be created on demand if missingvoidsetIndexed(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)voidsetMemoryMapped(boolean memoryMapped)voidsetTimeZone(TimeZone timeZone)voidsetTryCPGFile(boolean tryCPGFile)Makes the store try to figure out DBF file charset from CPG file.StringtoString()voidupdateSchema(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:ContentDataStoreCreates a set of qualified names corresponding to the types that the datastore provides.Namespaces may be left
nullfor data stores which do not support namespace qualified type names.- Specified by:
createTypeNamesin 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:ContentDataStoreInstantiates new feature source for the entry.Subclasses should override this method to return a specific subclass of
ContentFeatureSource.- Specified by:
createFeatureSourcein classContentDataStore- Parameters:
entry- The entry.- Returns:
- An new instance of
ContentFeatureSourcefor the entry. - Throws:
IOException
-
getFeatureSource
public ContentFeatureSource getFeatureSource() throws IOException
- Specified by:
getFeatureSourcein 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, thecharsetproperty will be rewritten by guessed value.
-
getSchema
public SimpleFeatureType getSchema() throws IOException
Description copied from interface:FileDataStoreFeatureType for the file being read.This is the same as getSchema( getTypeName[0] )
- Specified by:
getSchemain 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:
getFeatureReaderin 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:
createSchemain interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
createSchemain 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:
IOExceptionDbaseFileException
-
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:DataAccessDisposes of this data store and releases any resource that it is using.A
DataStorecannot be used afterdisposehas been called, neither can any data access object it helped create, such asFeatureReader,FeatureSourceorFeatureCollection.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:
disposein interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
disposein 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:
updateSchemain 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:
getFeatureWriterin interfaceFileDataStore- Throws:
IOException- See Also:
DataStore.getFeatureWriter(String,Filter,Transaction)
-
getFeatureWriter
public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriter(Transaction transaction) throws IOException
- Specified by:
getFeatureWriterin interfaceFileDataStore- Throws:
IOException- See Also:
DataStore.getFeatureWriter(java.lang.String, Transaction)
-
getFeatureWriterAppend
public FeatureWriter<SimpleFeatureType,SimpleFeature> getFeatureWriterAppend(Transaction transaction) throws IOException
- Specified by:
getFeatureWriterAppendin 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:DataStoreUsed 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:
removeSchemain interfaceDataStore- Overrides:
removeSchemain classContentDataStore- Throws:
IOException- if the operation failed- See Also:
DataStore.removeSchema(String)
-
removeSchema
public void removeSchema(Name typeName) throws IOException
Description copied from interface:DataAccessUsed 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:
removeSchemain interfaceDataAccess<SimpleFeatureType,SimpleFeature>- Overrides:
removeSchemain classContentDataStore- Throws:
IOException- if the operation failed- See Also:
DataAccess.removeSchema(Name)
-
-