Class TLcdSHPModelEncoder

java.lang.Object
com.luciad.format.shp.TLcdSHPModelEncoder
All Implemented Interfaces:
ILcdOutputStreamFactoryCapable, ILcdModelEncoder, Serializable

@LcdService(service=ILcdModelEncoder.class, priority=20000) public class TLcdSHPModelEncoder extends Object implements ILcdModelEncoder, ILcdOutputStreamFactoryCapable
This ILcdModelEncoder creates SHP (ESRI Shapefile) files from an ILcdModel following the ESRI Shapefile Technical Description. Only ILcdModel containing one shape type will be fully encoded, as the technical specification prescribes that all shapes in a SHP file are required to be of the same shape type. The TLcdSHPModelEncoder supports the following shape types:
  • TLcdSHPPointM as PointM
  • TLcdSHPPointZ as PointZ
  • ILcdPoint as:
    • PointZ if the export3D property is true
    • Point if the export3D property is false
  • ILcdPolyline as:
    • PolylineZ if the export3D property is true
    • PolylineM if the export3D property is false but the shape implements ILcdSHPMeasureList
    • Polyline otherwise
  • ILcdPolygon as:
    • PolygonZ if the export3D property is true
    • PolygonM if the export3D property is false but the shape implements ILcdSHPMeasureList
    • Polygon otherwise
  • ILcdShapeList as
    • PointZ when the first shape in the shape list extends TLcdSHPPointZ or the export3D property is true
    • PointM when the first shape in the shape list extends TLcdSHPPointM
    • Point when the first shape in the shape list implements ILcdPoint
    • PolylineZ when the first shape in the shape list extends TLcdSHPPointZ or the export3D property is true
    • PolylineM when the first shape in the shape list implements ILcdSHPMeasureList and ILcdPolyline
    • Polyline when the first shape in the shape list implements ILcdPolyline
    • PolygonZ when the first shape in the shape list extends TLcdSHPPointZ or the export3D property is true
    • Polygon when the first shape in the shape list implements ILcdPolygon
    • PolylineM when the first shape in the shape list implements ILcdSHPMeasureList and ILcdPolyline
    • PolygonM when the first shape in the shape list implements ILcdSHPMeasureList and ILcdPolygon

Since all ILcdShape implementations are essentially three dimensional, the property export3D defines whether shapes should be exported as two dimensional or as three dimensional data. The default value of the property is false, two dimensional export, for backwards compatibility.

When a ILcdShapeList is encoded, all shapes in the shape list are assumed to be of the same type, the type of the first shape in the shape list.

By default the accompanying shx file is written and the accompanying dbf file is written for a ILcdModel with a ILcdFeaturedDescriptor or a ILcdDataModelDescriptor containing a single model element type that only has simple properties. Both can be turned off by setting the properties WithIndexFile and WithDBF. If the DBF file could not be encoded completely, a warning message is put on the log. No exception will be thrown.

Features are encoded according to their type:

  • Byte, Short, Integer, Long, BigDecimal, BigInteger, Float, and Double as numerical. The field width and the number of decimals is computed automatically from the data.
  • String as string
  • All other types as string, by calling the feature's toString method.
By default the encoder uses a TLcdWKTModelReferenceEncoder for writing the model reference as a ".prj" file.
See Also:
  • Constructor Details

    • TLcdSHPModelEncoder

      public TLcdSHPModelEncoder()
  • Method Details

    • setClassTraceOn

      public static void setClassTraceOn(boolean aClassTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for all instances of this class. If the argument is true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
      Parameters:
      aClassTraceOn - if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
    • setTraceOn

      public void setTraceOn(boolean aTraceOn)
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Enables tracing for this class instance. Calling this method with either true or false as argument automatically turns off tracing for all other class instances for which setTraceOn has not been called. If the argument is false then only the informative, warning and error log messages are recorded.
      Parameters:
      aTraceOn - if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.
    • isTraceOn

      public boolean isTraceOn()
      Deprecated.
      This method has been deprecated. It is recommended to use the standard Java logging framework directly.
      Returns true if tracing is enabled for this class.
      Returns:
      true if tracing is enabled for this class, false otherwise.
    • setWithDBF

      public void setWithDBF(boolean aBoolean)
      Sets whether to produce a DBF file next to the .shp file.
      Parameters:
      aBoolean - indicating whether a dbf file should be written next to the .shp file.
      See Also:
    • isWithDBF

      public boolean isWithDBF()
      Returns true if a DBF file will also be written next to the .shp file.
      Returns:
      true if a DBF file will also be written next to the .shp file.
    • setWithIndexFile

      public void setWithIndexFile(boolean aWithIndexFile)
      Sets whether an index file (.shx) should be written next to the .shp file.
      Parameters:
      aWithIndexFile - indicating whether an index file (.shx) should be written next to the .shp file.
      See Also:
    • isWithIndexFile

      public boolean isWithIndexFile()
      Returns whether an index file (.shx) should be written next to the .shp file.
      Returns:
      whether an index file (.shx) should be written next to the .shp file.
      See Also:
    • setOutputStreamFactory

      public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
      Sets aOutputStreamFactory as ILcdOutputStreamFactory on this TLcdSHPModelDecoder. aOutputStreamFactory is then used for retrieving OutputStream objects when encoding a shp file.

      In future versions, it could also be used to save its accompanying ref file.

      To use the default way of creating an OutputStream leave this property unset or set it to null.

      This can be used to define a specific way of transferring data from this TLcdSHPModelEncoder to the destination, e.g., in an encrypted way.

      Specified by:
      setOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Parameters:
      aOutputStreamFactory - the ILcdOutputStreamFactory to use to create output.
      See Also:
    • getOutputStreamFactory

      public ILcdOutputStreamFactory getOutputStreamFactory()
      Returns the ILcdOutputStreamFactory used to create output.
      Specified by:
      getOutputStreamFactory in interface ILcdOutputStreamFactoryCapable
      Returns:
      the current ILcdOutputStreamFactory set on this TLcdSHPModelEncoder
      See Also:
    • setTrimStringPropertyValues

      public void setTrimStringPropertyValues(boolean aTrimStringPropertyValues)
      Specifies whether or not leading and trailing whitespace should be removed from string properties while encoding DBF files. The default setting is true.
      Parameters:
      aTrimStringPropertyValues - whether or not string values in DBF files should be trimmed
    • isTrimStringPropertyValues

      public boolean isTrimStringPropertyValues()
      Indicates whether or not string values are trimmed when encoding DBF files.
      Returns:
      whether or not string values are trimmed when encoding DBF files
      See Also:
    • getModelReferenceEncoder

      public ILcdModelReferenceEncoder getModelReferenceEncoder()
      Returns the ILcdModelReferenceEncoder used by this TLcdSHPModelEncoder.
      Returns:
      the ILcdModelReferenceEncoder used by this TLcdSHPModelEncoder.
      See Also:
    • setModelReferenceEncoder

      public void setModelReferenceEncoder(ILcdModelReferenceEncoder aModelReferenceEncoder)
      Sets the ILcdModelReferenceEncoder to be used by this TLcdSHPModelEncoder.
      Parameters:
      aModelReferenceEncoder - the ILcdModelReferenceEncoder to be used by this TLcdSHPModelEncoder.
      See Also:
    • setCharacterSet

      public void setCharacterSet(String aCharacterSet)
      Sets the character set to encode DBF files. Default value is "UTF-8".
      Parameters:
      aCharacterSet - the character set to encode DBF files. The supported character sets depend on the JVM implementation and can be found at String(byte[], String).
    • isExport3D

      public boolean isExport3D()
      Indicates whether shapes will be exported as 3D shapes. Default value is false.
      Returns:
      true when shapes will be exported as 3D shapes.
    • setExport3D

      public void setExport3D(boolean aExport3D)
      Sets whether the polylines and polygons should be exported as 3D shapes. Default value is false. If true, the following shapes will be exported as 3D shapes:
      Shape Type
      ILcdPolyline PolylineZ
      ILcdPolygon PolygonZ
      Parameters:
      aExport3D - true to have shapes exported as 3D shapes.
    • getDisplayName

      public String getDisplayName()
      Returns the display name for this encoder.
      Specified by:
      getDisplayName in interface ILcdModelEncoder
      Returns:
      ESRI-ShapeFile
    • canExport

      public boolean canExport(ILcdModel aModel, String aDestination)
      Checks whether a ILcdModel can be exported to a SHP file.
      Specified by:
      canExport in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be exported
      aDestination - the destination file to which the model is to be exported. No check is performed whether the destination file can be written to.
      Returns:
      true when the model contains at least one of the following:
      • a ILcdPoint
      • a ILcdShapeList containing a ILcdPolygon as a first shape
      • a ILcdShapeList containing a ILcdPolyline as a first shape
      If the withDBF is set to true, the model's model descriptor has to be a ILcdFeaturedDescriptor or a ILcdDataModelDescriptor.
      See Also:
    • export

      public void export(ILcdModel aModel, String aDestination) throws IllegalArgumentException, IOException
      Exports a ILcdModel to a destination file. Before calling this method, check if the model can be exported to the destination with canExport(com.luciad.model.ILcdModel, String).
      Specified by:
      export in interface ILcdModelEncoder
      Parameters:
      aModel - the ILcdModel to export.
      aDestination - the file to write to
      Throws:
      IllegalArgumentException
      IOException - when the destination file cannot be written to.
    • canSave

      public boolean canSave(ILcdModel aModel)
      Description copied from interface: ILcdModelEncoder
      Returns whether this model encoder can save the specified model to the location it originally came from. Often this will only be a simple test, for example checking the type of the model's model descriptor.
      Specified by:
      canSave in interface ILcdModelEncoder
      Parameters:
      aModel - the model for which the check is to be performed
      Returns:
      true if the ILcdModelDescriptor of the ILcdModel is an instance of the class TLcdSHPModelDescriptor
      See Also:
    • save

      public void save(ILcdModel aModel) throws IllegalArgumentException, IOException
      Description copied from interface: ILcdModelEncoder
      Saves the model to the location where it originally came from.
      Specified by:
      save in interface ILcdModelEncoder
      Parameters:
      aModel - the model to be saved
      Throws:
      IllegalArgumentException
      IOException - when the destination file cannot be written to.
    • write2DPolygon

      protected void write2DPolygon(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdShapeList containing ILcdPointList as a set of Polygons to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aShapeList - a ILcdShapeList containing 1 or more ILcdPointList objects
      aDOS - a output stream
      Throws:
      IOException - for any I/O errors
    • write2DPolygonM

      protected void write2DPolygonM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdShapeList containing ILcdPolygon as a set of PolygonM's to the output stream following the ESRI SHP file technical specification. All ILcdPolygon should also implement ILcdSHPMeasureList
      Parameters:
      aShapeList - a ILcdShapeList containing 1 or more ILcdPolygon, ILcdSHPMeasureList objects
      aDOS - a output stream
      Throws:
      IOException - for any I/O errors
    • write2DPolyline

      protected void write2DPolyline(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdShapeList containing ILcdPolyline as a set of Polylines to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aShapeList - a ILcdShapeList containing 1 or more ILcdPolyline objects
      aDOS - a output stream
      Throws:
      IOException - for any I/O errors
    • write2DPolylineM

      protected void write2DPolylineM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdShapeList containing ILcdPolyline as a set of PolylineM's to the output stream following the ESRI SHP file technical specification. All ILcdPolyline should also implement ILcdSHPMeasureList
      Parameters:
      aShapeList - a ILcdShapeList containing 1 or more ILcdPolyline, ILcdSHPMeasureList objects
      aDOS - a output stream
      Throws:
      IOException - for any I/O errors
    • write2DPoint

      protected void write2DPoint(ILcdPoint aPoint, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdPoint as a Point to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aPoint - the ILcdPoint to be encoded
      aDOS - the output stream to write to
      Throws:
      IOException - for any I/O errors
    • write2DPointM

      protected void write2DPointM(TLcdSHPPointM aPointM, TLcdDataOutputStream aDOS) throws IOException
      Encodes a TLcdSHPPointM as a PointM to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aPointM - the ILcdPoint to be encoded
      aDOS - the output stream to write to
      Throws:
      IOException - for any I/O errors
    • write2DPointZ

      protected void write2DPointZ(TLcdSHPPointZ aPointZ, TLcdDataOutputStream aDOS) throws IOException
      Encodes a TLcdSHPPointM as a PointZ to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aPointZ - the ILcdPoint to be encoded
      aDOS - the output stream to write to
      Throws:
      IOException - for any I/O errors
    • write2DBounds

      protected void write2DBounds(ILcdBounds aBounds, TLcdDataOutputStream aDOS) throws IOException
      Encodes a ILcdBounds to the output stream following the ESRI SHP file technical specification.
      Parameters:
      aBounds - the ILcdPoint to be encoded
      aDOS - the output stream to write to
      Throws:
      IOException - for any I/O errors