Class TLcdS57UnifiedModelDecoder

java.lang.Object
com.luciad.format.s57.TLcdS57UnifiedModelDecoder
All Implemented Interfaces:
ILcdMetadataDecoder, ILcdInputStreamFactoryCapable, ILcdDataSourceModelDecoder, ILcdModelDecoder

This model decoder decodes ECDIS S-57 data into ILcdModel objects.

This model decoder is capable of decoding catalogue files and single cell files. It can also handle both ENC files and AML files. Internally the model decoder delegates to a TLcdS57ModelDecoder and TLcdS57CatalogueModelDecoder. As a result, this model decoder returns models with the same structure as those model decoders. It also has the same set of features and limitations. Consult the javadoc of those model decoders for more information.

This model decoder is the recommended one for all users who just want to visualize S-57 data. Only if you need access to the more specialized methods/functionality of the individual model decoders you should use those classes directly.

The models created by this model decoder can directly be passed to the TLcdS52GXYLayerFactory and the TLspS52LayerBuilder.

Input files

File Required Entry point Description
CATALOG.031 x x An S-57 catalog
*.000 x x Individual S-57 cells
Notes:
  • The individual ENC cell files should be located relatively to the catalogue file, as specified in the FILE subfield of the CATD fields of the catalogue.
  • The decoder also supports the simultaneous decoding of multiple catalogues as a single, virtual catalogue. To decode multiple catalogues simultaneously, put the catalogue directories in a common parent directory, and place an empty file, called MULTICATALOG.031, in this parent directory. When decoding this file, the decoder will automatically scan for catalogues in the subdirectories and decode them as one catalogue.

Supported file transfer protocols

  • This model decoder supports all transfer protocols that are supported by the ILcdInputStreamFactory of this decoder.

Model structure

  • When decoding individual cells, this model decoder creates a single model for the file.
  • When decoding catalogs, this model decoder creates a hierarchy of models per ... file: Each catalogue model list on itself contains another list of model lists, one per level (=navigation purpose). Each of these level model lists contains a model per ENC cell in that level.
    
     TLcdModelList (catalogue) --> TLcdS57CatalogueModelDescriptor
       |
       +-- TLcdModelList (one for each level) --> TLcdS57LevelModelDescriptor
             |
             +-- ILcdModel (one for each ENC cell) --> TLcdS57ModelDescriptor
     
  • All models returned by this model decoder implement ILcd2DBoundsIndexedModel.

Model descriptor

Model reference

  • All models returned by this model decoder have a TLcdGeodeticReference, as described by the specification.

Model elements

  • See the documentation of TLcdS57ModelDecoder for more information on domain objects.

Useful settings

Sample code


 ILcdModelDecoder decoder = new TLcdS57UnifiedModelDecoder();
 ILcdModel model = decoder.decode("/path/to/CATALOG.031");
 // Or ILcdModel model = decoder.decode("/path/to/GB4D132.000");

 // To add to a Lightspeed view:
 lspView.addLayer(TLspS52LayerBuilder.newBuilder().model(model).build());
 // To add to a GXY view:
 gxyView.addLayer(new TLcdS52GXYLayerFactory().createGXYLayer(model));
 

Performance tips

  • When a catalogue is used, the presence of the M_COVR class can have a small impact on the rendering performance. See the performance tips of the TLcdS57ModelDecoder for more information on this topic.
  • The policy to be used to load individual ENC cells can be controlled via the setLoadingPolicy method: it allows to use lazy loading with weak or soft references, necessary when dealing with large catalogues that are too large to load fully into memory. If the decoded models are processed by the TLcdS52ModelListBuilder and all consecutive operations are performed on the S-52 ordered model list (not on the original model list), it is advised to use the LoadingPolicy.WEAK_REFERENCED policy for optimal performance and memory usage.

Thread safety

  • The decoding of models is thread-safe, as long as no properties are changed during the decoding.
  • The decoded models are thread-safe for read access.

Error handling

You can configure how errors are handled while decoding cells or catalogs through setIgnoreInvalidCells(boolean) and setInvalidCellExceptionHandler(com.luciad.format.s57.ILcdS57InvalidCellExceptionHandler).

By default, ignore invalid cells is set to false, and the exception handler logs and re-throws all exceptions, except for missing cell files: these are simply logged and ignored.

For missing cell files, you can expect an FileNotFoundException as error.

See also the class documentation of TLcdS63UnifiedModelDecoder for more information on error and warning handling of S-63 catalogs.

Since cells in a catalog are lazy-loaded, exceptions can occur not only during the decode(java.lang.String), but also when accessing the data later, for example listing elements, or by accessing some properties of TLcdS57ModelDescriptor.

If a cell is ignored, a empty stub model is inserted in place of the actual model.

Supported versions and specifications

  • This model decoder supports all ECDIS catalogues, encoded according to the IHO (International Hydrographic Organization) publication S-57 standard ("IHO Transfer Standard for Digital Hydrographic Data, Special Publication No. 57"). This includes S-63, Inland ECDIS (2.0 to 2.4) and AML data.

Known limitations

  • All limitations for the TLcdS57ModelDecoder apply.

Requirements

  • The current implementation requires JRE 1.2 or higher.
  • The current implementation requires native libraries.
Since:
2013.1
See Also:
  • Constructor Details

    • TLcdS57UnifiedModelDecoder

      public TLcdS57UnifiedModelDecoder()
      Create a new unified model decoder instance
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Description copied from interface: ILcdModelDecoder
      Returns a short, displayable name for the format that is decoded by this ILcdModelDecoder.
      Specified by:
      getDisplayName in interface ILcdModelDecoder
      Returns:
      the displayable name of this ILcdModelDecoder.
    • canDecodeSource

      public boolean canDecodeSource(String aSourceName)
      Description copied from interface: ILcdModelDecoder
      Checks whether this model decoder can decode the specified data source. It is acceptable for this method to return true for a source name while decode throws an exception for that same source name.

      For performance reasons, we strongly recommend that this will only be a simple test. For example: check the file extension of a file, but not that the file exists or contains expected content.

      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source to be verified; typically a file name or a URL.
      Returns:
      true if this decoder can likely decode the data specified by the source name, false otherwise.
      See Also:
    • decode

      public ILcdModel decode(String aSourceName) throws IOException
      Description copied from interface: ILcdModelDecoder
      Creates a new model from the given data source.
      Specified by:
      decode in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source to be decoded; typically a file name or a URL.
      Returns:
      A model containing the decoded data. While null is allowed, implementors are advised to throw an error instead.
      Throws:
      IOException - for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.
      
         public ILcdModel decode( String aSourceName ) throws IOException {
            try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) {
               // Perform decoding ...
            } catch (RuntimeException e) {
               throw new IOException(e);
            }
         }
       
      See Also:
    • canDecodeSource

      public boolean canDecodeSource(ILcdDataSource aDataSource)
      Checks whether this model decoder can decode the data source.

      Return true if:

      • The source is a TLcdS57CatalogueDataSource.
      • It contains at least one base (non-update) cell, either directly or in a catalogue.
      • The cell can be decoded and is an ENC, ENC or AML cell.
      Specified by:
      canDecodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the data source
      Returns:
      true if the data source can be decoded, false otherwise
      See Also:
    • decodeSource

      public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException
      Description copied from interface: ILcdModelDecoder

      Creates a new model from the given data source.

      By default, this method:

      Specified by:
      decodeSource in interface ILcdModelDecoder
      Parameters:
      aDataSource - the ILcdDataSource to be decoded.
      Returns:
      a model containing the decoded data. While null is allowed, implementors are advised to throw an error instead.
      Throws:
      IOException - for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.
      
       public ILcdModel decodeSource(ILcdDataSource aDataSource) throws IOException {
         try {
           // Perform decoding ...
         } catch (RuntimeException e) {
           throw new IOException(e);
         }
       }
       
      See Also:
    • canDecodeMetadata

      public boolean canDecodeMetadata(String aSourceName)
      Description copied from interface: ILcdMetadataDecoder
      Tells whether this metadata decoder can likely decode metadata for a given source name.
      Specified by:
      canDecodeMetadata in interface ILcdMetadataDecoder
      Parameters:
      aSourceName - the source name to decode metadata for
      Returns:
      true if this metadata decoder can decode metadata for the given source name, false otherwise
    • decodeMetadata

      public TLcdISO19115Metadata decodeMetadata(String aSourceName) throws IOException
      Description copied from interface: ILcdMetadataDecoder
      Decodes the metadata from a given source name as an ISO-19115 metadata object.

      Note that even if ILcdMetadataDecoder.canDecodeMetadata(String) returns true, this method may yet not be able to decode the given source name. While returning null is allowed when this decoder couldn't decode the given source name, implementors are advised to throw an error instead.

      Specified by:
      decodeMetadata in interface ILcdMetadataDecoder
      Parameters:
      aSourceName - the source name to decode metadata from
      Returns:
      a metadata object
      Throws:
      IOException - if the metadata cannot be decoded for some reason
    • decodeModelMetadata

      public TLcdModelMetadata decodeModelMetadata(String aSourceName) throws IOException
      Decodes metadata for the specified data source.
      Specified by:
      decodeModelMetadata in interface ILcdModelDecoder
      Parameters:
      aSourceName - the data source for which the model metadata will be decoded.
      Returns:
      the model metadata for the data source, never null.
      Throws:
      IOException - if the metadata cannot be decoded for some reason.
      See Also:
    • setInputStreamFactory

      public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
      Description copied from interface: ILcdInputStreamFactoryCapable
      Sets the input stream factory to be used.
      Specified by:
      setInputStreamFactory in interface ILcdInputStreamFactoryCapable
      Parameters:
      aInputStreamFactory - the input stream factory to be used.
    • getInputStreamFactory

      public ILcdInputStreamFactory getInputStreamFactory()
      Description copied from interface: ILcdInputStreamFactoryCapable
      Returns the input stream factory that is used.
      Specified by:
      getInputStreamFactory in interface ILcdInputStreamFactoryCapable
      Returns:
      the input stream factory that is used.
    • setInvalidCellExceptionHandler

      public void setInvalidCellExceptionHandler(ILcdS57InvalidCellExceptionHandler aHandler)
      Sets the cell exception handler to be used when decoding individual cells in a catalog. This exception handler will be called whenever a cell could not be decoded correctly.

      See class javadoc section "Error handling" for details.

      This handler is not invoked when decoding an individual faulty cell directly (not through a catalog). Instead, an exception will be thrown from the decode(java.lang.String) method.

      Parameters:
      aHandler - the exception handler to be used when decoding individual cells.
      See Also:
    • getInvalidCellExceptionHandler

      public ILcdS57InvalidCellExceptionHandler getInvalidCellExceptionHandler()
      Return the cell exception handler to be used when decoding individual cells.
      Returns:
      the cell exception handler to be used when decoding individual cells.
      See Also:
    • setIgnoreInvalidCells

      public void setIgnoreInvalidCells(boolean aIgnoreInvalidCells)
      Specifies whether to ignore invalid cells in a catalog or not.

      See class javadoc section "Error handling" for details.

      This setting has no effect when decoding an individual faulty cell directly (not through a catalog). Instead, an exception will be thrown from the decode(java.lang.String) method.

      Parameters:
      aIgnoreInvalidCells - true when invalid cells should be ignored
      See Also:
    • isIgnoreInvalidCells

      public boolean isIgnoreInvalidCells()
      Returns whether to ignore invalid cells or not.
      Returns:
      true if invalid cells have to be ignored, false otherwise.
      See Also:
    • setVerifyChecksum

      public void setVerifyChecksum(boolean aVerifyChecksum)
      Sets whether to compute the checksum of the ENC cells and verify it with the corresponding checksum in the catalogue. This feature is disabled by default, and is not supported for S-63 encrypted files.
      Parameters:
      aVerifyChecksum - boolean indicating whether to verify the ENC cell checksums.
    • isVerifyChecksum

      public boolean isVerifyChecksum()
      Returns whether to compute the checksum of the ENC cells and verify it with the corresponding checksum in the catalogue.
      Returns:
      whether to verify the ENC cell checksums.
    • setUseSENCCache

      public void setUseSENCCache(boolean aUseSENCCache)
      Enables or disables the use of SENC (System ENC) caches. If enabled, each S-57 cell will be converted into SENC format and cached in the SENC cache dir when it is decoded. The next time the S-57 cell is read, the cached SENC copy will be used instead.

      See the class javadoc for more information on SENC and its limitations.

      If SENC caching is enabled, a suitable caching dir should be set as well, see setSENCCacheDir(File).

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Parameters:
      aUseSENCCache - flag indicating whether to use the SENC cache or not.
      See Also:
    • isUseSENCCache

      public boolean isUseSENCCache()
      Returns true if the SENC cache is being used, false otherwise.

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Returns:
      true if the SENC cache is being used, false otherwise.
      See Also:
    • setSENCCacheDir

      public void setSENCCacheDir(File aSENCCacheDir)
      Sets the SENC cache dir where the converted SENC copies of S-57 cells should be stored. The default location is the .senccache directory in the user's home folder. If the specified directory does not exist yet, it will be automatically created by the decoder.

      SENC caches are not thread-safe: they should not be used simultaneously by multiple decoder instances; if multiple decoder instances run simultaneously they should all have their own SENC cache dir.

      Parameters:
      aSENCCacheDir - the SENC cache dir where the converted SENC copies of S-57 cells should be stored.
      See Also:
    • getSENCCacheDir

      public File getSENCCacheDir()
      Returns the SENC cache dir where the converted SENC copies of S-57 cells should be stored.

      This setting has no effect when decoding individual cells directly (not from a catalog).

      Returns:
      the SENC cache dir where the converted SENC copies of S-57 cells should be stored.
      See Also: