Class 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 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 behavior

        This 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 columns
        geometryType - The name of the geometry type, will be null if there is no need for a geometry type suffix