Class TLcdSHPModelEncoder
- All Implemented Interfaces:
ILcdOutputStreamFactoryCapable
,ILcdModelEncoder
,Serializable
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 PointMTLcdSHPPointZ
as PointZILcdPoint
as:- PointZ if the
export3D
property istrue
- Point if the
export3D
property isfalse
- PointZ if the
ILcdPolyline
as:- PolylineZ if the
export3D
property istrue
- PolylineM if the
export3D
property isfalse
but the shape implementsILcdSHPMeasureList
- Polyline otherwise
- PolylineZ if the
ILcdPolygon
as:- PolygonZ if the
export3D
property istrue
- PolygonM if the
export3D
property isfalse
but the shape implementsILcdSHPMeasureList
- Polygon otherwise
- PolygonZ if the
ILcdShapeList
as- PointZ when the first shape in the shape list extends
TLcdSHPPointZ
or theexport3D
property istrue
- 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 theexport3D
property istrue
- PolylineM when the first shape in the shape list implements
ILcdSHPMeasureList
andILcdPolyline
- Polyline when the first shape in the shape list implements
ILcdPolyline
- PolygonZ when the first shape in the shape list extends
TLcdSHPPointZ
or theexport3D
property istrue
- Polygon when the first shape in the shape list implements
ILcdPolygon
- PolylineM when the first shape in the shape list implements
ILcdSHPMeasureList
andILcdPolyline
- PolygonM when the first shape in the shape list implements
ILcdSHPMeasureList
andILcdPolygon
- PointZ when the first shape in the shape list extends
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.
TLcdWKTModelReferenceEncoder
for writing the model
reference as a ".prj" file.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether aILcdModel
can be exported to a SHP file.boolean
Returns whether this model encoder can save the specified model to the location it originally came from.void
Exports aILcdModel
to a destination file.Returns the display name for this encoder.Returns theILcdModelReferenceEncoder
used by thisTLcdSHPModelEncoder
.Returns theILcdOutputStreamFactory
used to create output.boolean
Indicates whether shapes will be exported as 3D shapes.boolean
Deprecated.This method has been deprecated.boolean
Indicates whether or not string values are trimmed when encoding DBF files.boolean
Returns true if a DBF file will also be written next to the .shp file.boolean
Returns whether an index file (.shx) should be written next to the .shp file.void
Saves the model to the location where it originally came from.void
setCharacterSet
(String aCharacterSet) Sets the character set to encode DBF files.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setExport3D
(boolean aExport3D) Sets whether the polylines and polygons should be exported as 3D shapes.void
setModelReferenceEncoder
(ILcdModelReferenceEncoder aModelReferenceEncoder) Sets theILcdModelReferenceEncoder
to be used by thisTLcdSHPModelEncoder
.void
setOutputStreamFactory
(ILcdOutputStreamFactory aOutputStreamFactory) SetsaOutputStreamFactory
asILcdOutputStreamFactory
on thisTLcdSHPModelDecoder
.void
setTraceOn
(boolean aTraceOn) Deprecated.This method has been deprecated.void
setTrimStringPropertyValues
(boolean aTrimStringPropertyValues) Specifies whether or not leading and trailing whitespace should be removed from string properties while encoding DBF files.void
setWithDBF
(boolean aBoolean) Sets whether to produce a DBF file next to the .shp file.void
setWithIndexFile
(boolean aWithIndexFile) Sets whether an index file (.shx) should be written next to the .shp file.protected void
write2DBounds
(ILcdBounds aBounds, TLcdDataOutputStream aDOS) Encodes aILcdBounds
to the output stream following the ESRI SHP file technical specification.protected void
write2DPoint
(ILcdPoint aPoint, TLcdDataOutputStream aDOS) Encodes aILcdPoint
as a Point to the output stream following the ESRI SHP file technical specification.protected void
write2DPointM
(TLcdSHPPointM aPointM, TLcdDataOutputStream aDOS) Encodes aTLcdSHPPointM
as a PointM to the output stream following the ESRI SHP file technical specification.protected void
write2DPointZ
(TLcdSHPPointZ aPointZ, TLcdDataOutputStream aDOS) Encodes aTLcdSHPPointM
as a PointZ to the output stream following the ESRI SHP file technical specification.protected void
write2DPolygon
(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeList
containingILcdPointList
as a set of Polygons to the output stream following the ESRI SHP file technical specification.protected void
write2DPolygonM
(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeList
containingILcdPolygon
as a set of PolygonM's to the output stream following the ESRI SHP file technical specification.protected void
write2DPolyline
(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeList
containingILcdPolyline
as a set of Polylines to the output stream following the ESRI SHP file technical specification.protected void
write2DPolylineM
(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeList
containingILcdPolyline
as a set of PolylineM's to the output stream following the ESRI SHP file technical specification.
-
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 istrue
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 eithertrue
orfalse
as argument automatically turns off tracing for all other class instances for whichsetTraceOn
has not been called. If the argument isfalse
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.Returnstrue
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
SetsaOutputStreamFactory
asILcdOutputStreamFactory
on thisTLcdSHPModelDecoder
.aOutputStreamFactory
is then used for retrievingOutputStream
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 tonull
.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 interfaceILcdOutputStreamFactoryCapable
- Parameters:
aOutputStreamFactory
- theILcdOutputStreamFactory
to use to create output.- See Also:
-
getOutputStreamFactory
Returns theILcdOutputStreamFactory
used to create output.- Specified by:
getOutputStreamFactory
in interfaceILcdOutputStreamFactoryCapable
- Returns:
- the current
ILcdOutputStreamFactory
set on thisTLcdSHPModelEncoder
- 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 istrue
.- 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
Returns theILcdModelReferenceEncoder
used by thisTLcdSHPModelEncoder
.- Returns:
- the
ILcdModelReferenceEncoder
used by thisTLcdSHPModelEncoder
. - See Also:
-
setModelReferenceEncoder
Sets theILcdModelReferenceEncoder
to be used by thisTLcdSHPModelEncoder
.- Parameters:
aModelReferenceEncoder
- theILcdModelReferenceEncoder
to be used by thisTLcdSHPModelEncoder
.- See Also:
-
setCharacterSet
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 atString(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
Returns the display name for this encoder.- Specified by:
getDisplayName
in interfaceILcdModelEncoder
- Returns:
- ESRI-ShapeFile
-
canExport
Checks whether aILcdModel
can be exported to a SHP file.- Specified by:
canExport
in interfaceILcdModelEncoder
- Parameters:
aModel
- the model to be exportedaDestination
- 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 aILcdPolygon
as a first shape - a
ILcdShapeList
containing aILcdPolyline
as a first shape
ILcdFeaturedDescriptor
or aILcdDataModelDescriptor
. - a
- See Also:
-
export
public void export(ILcdModel aModel, String aDestination) throws IllegalArgumentException, IOException Exports aILcdModel
to a destination file. Before calling this method, check if the model can be exported to the destination withcanExport(com.luciad.model.ILcdModel, String)
.- Specified by:
export
in interfaceILcdModelEncoder
- Parameters:
aModel
- theILcdModel
to export.aDestination
- the file to write to- Throws:
IllegalArgumentException
IOException
- when the destination file cannot be written to.
-
canSave
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 interfaceILcdModelEncoder
- Parameters:
aModel
- the model for which the check is to be performed- Returns:
- true if the
ILcdModelDescriptor
of theILcdModel
is an instance of the classTLcdSHPModelDescriptor
- See Also:
-
save
Description copied from interface:ILcdModelEncoder
Saves the model to the location where it originally came from.- Specified by:
save
in interfaceILcdModelEncoder
- 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 aILcdShapeList
containingILcdPointList
as a set of Polygons to the output stream following the ESRI SHP file technical specification.- Parameters:
aShapeList
- aILcdShapeList
containing 1 or moreILcdPointList
objectsaDOS
- a output stream- Throws:
IOException
- for any I/O errors
-
write2DPolygonM
protected void write2DPolygonM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeList
containingILcdPolygon
as a set of PolygonM's to the output stream following the ESRI SHP file technical specification. AllILcdPolygon
should also implementILcdSHPMeasureList
- Parameters:
aShapeList
- aILcdShapeList
containing 1 or moreILcdPolygon
,ILcdSHPMeasureList
objectsaDOS
- a output stream- Throws:
IOException
- for any I/O errors
-
write2DPolyline
protected void write2DPolyline(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeList
containingILcdPolyline
as a set of Polylines to the output stream following the ESRI SHP file technical specification.- Parameters:
aShapeList
- aILcdShapeList
containing 1 or moreILcdPolyline
objectsaDOS
- a output stream- Throws:
IOException
- for any I/O errors
-
write2DPolylineM
protected void write2DPolylineM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeList
containingILcdPolyline
as a set of PolylineM's to the output stream following the ESRI SHP file technical specification. AllILcdPolyline
should also implementILcdSHPMeasureList
- Parameters:
aShapeList
- aILcdShapeList
containing 1 or moreILcdPolyline
,ILcdSHPMeasureList
objectsaDOS
- a output stream- Throws:
IOException
- for any I/O errors
-
write2DPoint
Encodes aILcdPoint
as a Point to the output stream following the ESRI SHP file technical specification.- Parameters:
aPoint
- theILcdPoint
to be encodedaDOS
- the output stream to write to- Throws:
IOException
- for any I/O errors
-
write2DPointM
Encodes aTLcdSHPPointM
as a PointM to the output stream following the ESRI SHP file technical specification.- Parameters:
aPointM
- theILcdPoint
to be encodedaDOS
- the output stream to write to- Throws:
IOException
- for any I/O errors
-
write2DPointZ
Encodes aTLcdSHPPointM
as a PointZ to the output stream following the ESRI SHP file technical specification.- Parameters:
aPointZ
- theILcdPoint
to be encodedaDOS
- the output stream to write to- Throws:
IOException
- for any I/O errors
-
write2DBounds
Encodes aILcdBounds
to the output stream following the ESRI SHP file technical specification.- Parameters:
aBounds
- theILcdPoint
to be encodedaDOS
- the output stream to write to- Throws:
IOException
- for any I/O errors
-