Package org.geotools.data.shapefile
Class ShapefileDumper
- Object
-
- ShapefileDumper
-
public class ShapefileDumper extends Object
Class specializing in dumping a feature collection onto one or more shapefiles into a target directory.The collection will be distributed among different shapefiles if needed To respect certain limitations:
- Only a single geometry type per shapefile, in case the source feature collection contains more than one parallel shapefiles will be generated, by default appending the type of geometry at the end of the file name
- Maximum file size, by default, 2GB for the shp file, 4GB for the dbf file. In case the maximum size is exceeded the code will create a new shapefile appending a counter at the end of the file name
- Author:
- Andrea Aime - GeoSolutions
-
-
Constructor Summary
Constructors Constructor Description ShapefileDumper(File targetDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleandump(String fileName, SimpleFeatureCollection fc)Dumps the collection into one or more shapefiles.booleandump(SimpleFeatureCollection fc)Dumps the collection into one or more shapefiles.CharsetgetCharset()The charset used in the DBF files.longgetMaxDbfSize()Maximums size of the DBF files being generatedlonggetMaxShpSize()Maximum size of the shapefiles being generatedprotected StringgetShapeName(SimpleFeatureType schema, String geometryType)Deprecated.protected StringgetShapeName(SimpleFeatureType schema, String geometryName, String geometryType)Returns the shapefile name from the given schema and geometry type.booleanisEmptyShapefileAllowed()Returns true if empty shpaefile dumping is allowed (true by default)voidsetCharset(Charset charset)Sets the charset used to dump the DBF files.voidsetEmptyShapefileAllowed(boolean emptyShapefileAllowed)Settings this flag to false will avoid empty shapefiles to be createdvoidsetMaxDbfSize(long maxDbfSize)Sets the maximum size of the DBF files the dumper will generate.voidsetMaxShpSize(long maxShapeSize)Sets the maximum size of the shp files the dumper will generate.protected voidshapefileDumped(String fileName, SimpleFeatureType remappedSchema)Allows subsclasses to perform extra actions against a shapefile that was completely written.
-
-
-
Constructor Detail
-
ShapefileDumper
public ShapefileDumper(File targetDirectory)
-
-
Method Detail
-
getMaxShpSize
public long getMaxShpSize()
Maximum size of the shapefiles being generated
-
setMaxShpSize
public void setMaxShpSize(long maxShapeSize)
Sets the maximum size of the shp files the dumper will generate. The default is 2GB. When the threshold is reached a new shapefile with a progressive number at the end will be written to continue dumping features.
-
getMaxDbfSize
public long getMaxDbfSize()
Maximums size of the DBF files being generated
-
setMaxDbfSize
public void setMaxDbfSize(long maxDbfSize)
Sets the maximum size of the DBF files the dumper will generate. The default is 4GB, but some systems might be able to only read DBF files up to 2GB. When the threshold is reached a new shapefile with a progressive number at the end will be written to continue dumping features.
-
getCharset
public Charset getCharset()
The charset used in the DBF files. It's ISO-8859-1 by default (per DBF spec)
-
setCharset
public void setCharset(Charset charset)
Sets the charset used to dump the DBF files.
-
isEmptyShapefileAllowed
public boolean isEmptyShapefileAllowed()
Returns true if empty shpaefile dumping is allowed (true by default)
-
setEmptyShapefileAllowed
public void setEmptyShapefileAllowed(boolean emptyShapefileAllowed)
Settings this flag to false will avoid empty shapefiles to be created
-
dump
public boolean dump(SimpleFeatureCollection fc) throws IOException
Dumps the collection into one or more shapefiles. Multiple files will be geneated when the input collection contains multiple geometry types, or as the size limit for output files get reached- Parameters:
fc- The input feature collection- Returns:
- True if at least one feature got written, false otherwise
- Throws:
IOException
-
dump
public boolean dump(String fileName, SimpleFeatureCollection fc) throws IOException
Dumps the collection into one or more shapefiles. Multiple files will be generated when the input collection contains multiple geometry types, or as the size limit for output files get reached- Parameters:
fc- The input feature collection- Returns:
- True if at least one feature got written, false otherwise
- Throws:
IOException
-
shapefileDumped
protected void shapefileDumped(String fileName, SimpleFeatureType remappedSchema) throws IOException
Allows subsclasses to perform extra actions against a shapefile that was completely written.- Throws:
IOException
-
getShapeName
protected String getShapeName(SimpleFeatureType schema, String geometryName, String geometryType)
Returns the shapefile name from the given schema and geometry type. By default it's simple typeName and geometryType concatenated, subclasses can override this behaviorThis method will only be called if a custom name was not provided.
- Parameters:
geometryName- The name of the geometry column, in case the original data source had multiple geometry columnsgeometryType- The name of the geometry type, will be null if there is no need for a geometry type suffix
-
getShapeName
@Deprecated protected String getShapeName(SimpleFeatureType schema, String geometryType)
Deprecated.Please usegetShapeName(SimpleFeatureType, String, String)instead
-
-