Class ArcInfoASCIIGridReader

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.Destroyable, adams.core.ErrorProvider, adams.core.GlobalInfoSupporter, adams.core.io.EncodingSupporter, adams.core.io.FileFormatHandler, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, adams.data.io.input.ChunkedSpreadSheetReader, adams.data.io.input.SpreadSheetReader, adams.data.spreadsheet.DataRowTypeHandler, adams.data.spreadsheet.SpreadSheetTypeHandler, Serializable

    public class ArcInfoASCIIGridReader
    extends adams.data.io.input.AbstractSpreadSheetReader
    implements adams.data.io.input.ChunkedSpreadSheetReader
    Reads ASCII files in ESRI Grid format.

    For more information see:
    https://en.wikipedia.org/wiki/Esri_grid

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -data-row-type <adams.data.spreadsheet.DataRow> (property: dataRowType)
        The type of row to use for the data.
        default: adams.data.spreadsheet.DenseDataRow
     
    -spreadsheet-type <adams.data.spreadsheet.SpreadSheet> (property: spreadSheetType)
        The type of spreadsheet to use for the data.
        default: adams.data.spreadsheet.DefaultSpreadSheet
     
    -output-grid <boolean> (property: outputGrid)
        If enabled, a spreadsheet is generated that represents the data in the file
        rather than one value per row with GPS coordinates.
        default: false
     
    -chunk-size <int> (property: chunkSize)
        The size of the chunks (= number of rows) of spreadsheets to output if not
        in grid mode.
        default: -1
        minimum: -1
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class adams.data.io.input.AbstractSpreadSheetReader

        adams.data.io.input.AbstractSpreadSheetReader.InputType
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String KEY_BOTTOM
      the bottom corner key.
      static String KEY_CELLSIZE
      the number of columns key.
      static String KEY_LEFT
      the left corner key.
      static String KEY_NODATAVALUE
      the no data value key.
      static String KEY_NUMCOLS
      the number of columns key.
      static String KEY_NUMROWS
      the number of rows key.
      protected int m_ChunkSize
      the chunk size.
      protected int m_Header
      the size of the header in rows.
      protected HashMap<String,​String> m_MetaData
      the meta data.
      protected int m_Offset
      the current offset.
      protected boolean m_OutputGrid
      whether to output the grid instead the values alongside their GPS coordinates.
      protected List<String> m_Raw
      the raw data.
      • Fields inherited from class adams.data.io.input.AbstractSpreadSheetReader

        m_DataRowType, m_Encoding, m_LastError, m_SpreadSheetType, m_Stopped, OPTION_INPUT, OPTION_OUTPUT
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String chunkSizeTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      protected adams.data.spreadsheet.SpreadSheet doRead​(File file)
      Performs the actual reading.
      int getChunkSize()
      Returns the current chunk size (non-grid mode).
      adams.data.io.output.SpreadSheetWriter getCorrespondingWriter()
      Returns, if available, the corresponding writer.
      String getFormatDescription()
      Returns a string describing the format (used in the file chooser).
      String[] getFormatExtensions()
      Returns the extension(s) of the format.
      protected adams.data.io.input.AbstractSpreadSheetReader.InputType getInputType()
      Returns how to read the data, from a file, stream or reader.
      boolean getOutputGrid()
      Returns whether to output a grid of values (as stored in the file) instead of the values associated with their GPS coordinates.
      String globalInfo()
      Returns a string describing the object.
      boolean hasMoreChunks()
      Checks whether there is more data to read.
      static void main​(String[] args)
      Runs the reader from the command-line.
      adams.data.spreadsheet.SpreadSheet nextChunk()
      Returns the next chunk.
      String outputGridTipText()
      Returns the tip text for this property.
      protected adams.data.spreadsheet.SpreadSheet readData()
      Generates spreadsheets from the raw ASCII data.
      protected void reset()
      Resets the scheme.
      void setChunkSize​(int value)
      Sets the maximum chunk size (non-grid mode).
      void setOutputGrid​(boolean value)
      Sets whether to output a grid of values (as stored in the file) instead of the values associated with their GPS coordinates.
      • Methods inherited from class adams.data.io.input.AbstractSpreadSheetReader

        canDecompress, check, dataRowTypeTipText, doRead, doRead, encodingTipText, getAdditionalInformation, getDataRowType, getDefaultDataRowType, getDefaultFormatExtension, getDefaultSpreadSheet, getEncoding, getLastError, getReaders, getSpreadSheetType, hasLastError, initialize, isStopped, read, read, read, read, runReader, setDataRowType, setEncoding, setLastError, setSpreadSheetType, spreadSheetTypeTipText, stopExecution, supportsCompressedInput
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.Destroyable

        destroy
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
      • Methods inherited from interface adams.core.option.OptionHandler

        cleanUpOptions, getOptionManager, toCommandLine
    • Field Detail

      • m_OutputGrid

        protected boolean m_OutputGrid
        whether to output the grid instead the values alongside their GPS coordinates.
      • m_ChunkSize

        protected int m_ChunkSize
        the chunk size.
      • m_Raw

        protected List<String> m_Raw
        the raw data.
      • m_Header

        protected int m_Header
        the size of the header in rows.
      • m_Offset

        protected int m_Offset
        the current offset.
    • Constructor Detail

      • ArcInfoASCIIGridReader

        public ArcInfoASCIIGridReader()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.data.io.input.AbstractSpreadSheetReader
      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class adams.core.option.AbstractOptionHandler
      • setOutputGrid

        public void setOutputGrid​(boolean value)
        Sets whether to output a grid of values (as stored in the file) instead of the values associated with their GPS coordinates.
        Parameters:
        value - true if to output grid
      • getOutputGrid

        public boolean getOutputGrid()
        Returns whether to output a grid of values (as stored in the file) instead of the values associated with their GPS coordinates.
        Returns:
        true if to output grid
      • outputGridTipText

        public String outputGridTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setChunkSize

        public void setChunkSize​(int value)
        Sets the maximum chunk size (non-grid mode).
        Specified by:
        setChunkSize in interface adams.data.io.input.ChunkedSpreadSheetReader
        Parameters:
        value - the size of the chunks, < 1 denotes infinity
      • getChunkSize

        public int getChunkSize()
        Returns the current chunk size (non-grid mode).
        Specified by:
        getChunkSize in interface adams.data.io.input.ChunkedSpreadSheetReader
        Returns:
        the size of the chunks, < 1 denotes infinity
      • chunkSizeTipText

        public String chunkSizeTipText()
        Returns the tip text for this property.
        Specified by:
        chunkSizeTipText in interface adams.data.io.input.ChunkedSpreadSheetReader
        Returns:
        tip text for this property suitable for displaying in the gui
      • getInputType

        protected adams.data.io.input.AbstractSpreadSheetReader.InputType getInputType()
        Returns how to read the data, from a file, stream or reader.
        Specified by:
        getInputType in class adams.data.io.input.AbstractSpreadSheetReader
        Returns:
        how to read the data
      • getFormatDescription

        public String getFormatDescription()
        Returns a string describing the format (used in the file chooser).
        Specified by:
        getFormatDescription in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatDescription in interface adams.data.io.input.SpreadSheetReader
        Specified by:
        getFormatDescription in class adams.data.io.input.AbstractSpreadSheetReader
        Returns:
        a description suitable for displaying in the file chooser
      • getFormatExtensions

        public String[] getFormatExtensions()
        Returns the extension(s) of the format.
        Specified by:
        getFormatExtensions in interface adams.core.io.FileFormatHandler
        Specified by:
        getFormatExtensions in interface adams.data.io.input.SpreadSheetReader
        Specified by:
        getFormatExtensions in class adams.data.io.input.AbstractSpreadSheetReader
        Returns:
        the extension (without the dot!)
      • getCorrespondingWriter

        public adams.data.io.output.SpreadSheetWriter getCorrespondingWriter()
        Returns, if available, the corresponding writer.
        Specified by:
        getCorrespondingWriter in interface adams.data.io.input.SpreadSheetReader
        Returns:
        the writer, null if none available
      • readData

        protected adams.data.spreadsheet.SpreadSheet readData()
        Generates spreadsheets from the raw ASCII data.
        Returns:
        the generated spreadsheet
      • doRead

        protected adams.data.spreadsheet.SpreadSheet doRead​(File file)
        Performs the actual reading. Must handle compression itself, if AbstractSpreadSheetReader.supportsCompressedInput() returns true.
        Overrides:
        doRead in class adams.data.io.input.AbstractSpreadSheetReader
        Parameters:
        file - the file to read from
        Returns:
        the spreadsheet or null in case of an error
        See Also:
        getInputType(), AbstractSpreadSheetReader.supportsCompressedInput()
      • hasMoreChunks

        public boolean hasMoreChunks()
        Checks whether there is more data to read.
        Specified by:
        hasMoreChunks in interface adams.data.io.input.ChunkedSpreadSheetReader
        Returns:
        true if there is more data available
      • nextChunk

        public adams.data.spreadsheet.SpreadSheet nextChunk()
        Returns the next chunk.
        Specified by:
        nextChunk in interface adams.data.io.input.ChunkedSpreadSheetReader
        Returns:
        the next chunk
      • main

        public static void main​(String[] args)
        Runs the reader from the command-line. Use the option AbstractSpreadSheetReader.OPTION_INPUT to specify the input file. If the option AbstractSpreadSheetReader.OPTION_OUTPUT is specified then the read sheet gets output as .csv files in that directory.
        Parameters:
        args - the command-line options to use