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:
TLcdSHPPointMas PointMTLcdSHPPointZas PointZILcdPointas:- PointZ if the
export3Dproperty istrue - Point if the
export3Dproperty isfalse
- PointZ if the
ILcdPolylineas:- PolylineZ if the
export3Dproperty istrue - PolylineM if the
export3Dproperty isfalsebut the shape implementsILcdSHPMeasureList - Polyline otherwise
- PolylineZ if the
ILcdPolygonas:- PolygonZ if the
export3Dproperty istrue - PolygonM if the
export3Dproperty isfalsebut the shape implementsILcdSHPMeasureList - Polygon otherwise
- PolygonZ if the
ILcdShapeListas- PointZ when the first shape in the shape list extends
TLcdSHPPointZor theexport3Dproperty 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
TLcdSHPPointZor theexport3Dproperty istrue - PolylineM when the first shape in the shape list implements
ILcdSHPMeasureListandILcdPolyline - Polyline when the first shape in the shape list implements
ILcdPolyline - PolygonZ when the first shape in the shape list extends
TLcdSHPPointZor theexport3Dproperty istrue - Polygon when the first shape in the shape list implements
ILcdPolygon - PolylineM when the first shape in the shape list implements
ILcdSHPMeasureListandILcdPolyline - PolygonM when the first shape in the shape list implements
ILcdSHPMeasureListandILcdPolygon
- 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
toStringmethod.
TLcdWKTModelReferenceEncoder for writing the model
reference as a ".prj" file.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks whether aILcdModelcan be exported to a SHP file.booleanReturns whether this model encoder can save the specified model to the location it originally came from.voidExports aILcdModelto a destination file.Returns the display name for this encoder.Returns theILcdModelReferenceEncoderused by thisTLcdSHPModelEncoder.Returns theILcdOutputStreamFactoryused to create output.booleanIndicates whether shapes will be exported as 3D shapes.booleanDeprecated.This method has been deprecated.booleanIndicates whether or not string values are trimmed when encoding DBF files.booleanReturns true if a DBF file will also be written next to the .shp file.booleanReturns whether an index file (.shx) should be written next to the .shp file.voidSaves the model to the location where it originally came from.voidsetCharacterSet(String aCharacterSet) Sets the character set to encode DBF files.static voidsetClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated.voidsetExport3D(boolean aExport3D) Sets whether the polylines and polygons should be exported as 3D shapes.voidsetModelReferenceEncoder(ILcdModelReferenceEncoder aModelReferenceEncoder) Sets theILcdModelReferenceEncoderto be used by thisTLcdSHPModelEncoder.voidsetOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory) SetsaOutputStreamFactoryasILcdOutputStreamFactoryon thisTLcdSHPModelDecoder.voidsetTraceOn(boolean aTraceOn) Deprecated.This method has been deprecated.voidsetTrimStringPropertyValues(boolean aTrimStringPropertyValues) Specifies whether or not leading and trailing whitespace should be removed from string properties while encoding DBF files.voidsetWithDBF(boolean aBoolean) Sets whether to produce a DBF file next to the .shp file.voidsetWithIndexFile(boolean aWithIndexFile) Sets whether an index file (.shx) should be written next to the .shp file.protected voidwrite2DBounds(ILcdBounds aBounds, TLcdDataOutputStream aDOS) Encodes aILcdBoundsto the output stream following the ESRI SHP file technical specification.protected voidwrite2DPoint(ILcdPoint aPoint, TLcdDataOutputStream aDOS) Encodes aILcdPointas a Point to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPointM(TLcdSHPPointM aPointM, TLcdDataOutputStream aDOS) Encodes aTLcdSHPPointMas a PointM to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPointZ(TLcdSHPPointZ aPointZ, TLcdDataOutputStream aDOS) Encodes aTLcdSHPPointMas a PointZ to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPolygon(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeListcontainingILcdPointListas a set of Polygons to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPolygonM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeListcontainingILcdPolygonas a set of PolygonM's to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPolyline(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeListcontainingILcdPolylineas a set of Polylines to the output stream following the ESRI SHP file technical specification.protected voidwrite2DPolylineM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) Encodes aILcdShapeListcontainingILcdPolylineas 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 istruethen 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 eithertrueorfalseas argument automatically turns off tracing for all other class instances for whichsetTraceOnhas not been called. If the argument isfalsethen 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.Returnstrueif 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
SetsaOutputStreamFactoryasILcdOutputStreamFactoryon thisTLcdSHPModelDecoder.aOutputStreamFactoryis then used for retrievingOutputStreamobjects 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
OutputStreamleave this property unset or set it tonull.This can be used to define a specific way of transferring data from this
TLcdSHPModelEncoderto the destination, e.g., in an encrypted way.- Specified by:
setOutputStreamFactoryin interfaceILcdOutputStreamFactoryCapable- Parameters:
aOutputStreamFactory- theILcdOutputStreamFactoryto use to create output.- See Also:
-
getOutputStreamFactory
Returns theILcdOutputStreamFactoryused to create output.- Specified by:
getOutputStreamFactoryin interfaceILcdOutputStreamFactoryCapable- Returns:
- the current
ILcdOutputStreamFactoryset 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 theILcdModelReferenceEncoderused by thisTLcdSHPModelEncoder.- Returns:
- the
ILcdModelReferenceEncoderused by thisTLcdSHPModelEncoder. - See Also:
-
setModelReferenceEncoder
Sets theILcdModelReferenceEncoderto be used by thisTLcdSHPModelEncoder.- Parameters:
aModelReferenceEncoder- theILcdModelReferenceEncoderto 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:
getDisplayNamein interfaceILcdModelEncoder- Returns:
- ESRI-ShapeFile
-
canExport
Checks whether aILcdModelcan be exported to a SHP file.- Specified by:
canExportin 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
ILcdShapeListcontaining aILcdPolygonas a first shape - a
ILcdShapeListcontaining aILcdPolylineas a first shape
ILcdFeaturedDescriptoror aILcdDataModelDescriptor. - a
- See Also:
-
export
public void export(ILcdModel aModel, String aDestination) throws IllegalArgumentException, IOException Exports aILcdModelto 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:
exportin interfaceILcdModelEncoder- Parameters:
aModel- theILcdModelto export.aDestination- the file to write to- Throws:
IllegalArgumentExceptionIOException- when the destination file cannot be written to.
-
canSave
Description copied from interface:ILcdModelEncoderReturns 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:
canSavein interfaceILcdModelEncoder- Parameters:
aModel- the model for which the check is to be performed- Returns:
- true if the
ILcdModelDescriptorof theILcdModelis an instance of the classTLcdSHPModelDescriptor - See Also:
-
save
Description copied from interface:ILcdModelEncoderSaves the model to the location where it originally came from.- Specified by:
savein interfaceILcdModelEncoder- Parameters:
aModel- the model to be saved- Throws:
IllegalArgumentExceptionIOException- when the destination file cannot be written to.
-
write2DPolygon
protected void write2DPolygon(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeListcontainingILcdPointListas a set of Polygons to the output stream following the ESRI SHP file technical specification.- Parameters:
aShapeList- aILcdShapeListcontaining 1 or moreILcdPointListobjectsaDOS- a output stream- Throws:
IOException- for any I/O errors
-
write2DPolygonM
protected void write2DPolygonM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeListcontainingILcdPolygonas a set of PolygonM's to the output stream following the ESRI SHP file technical specification. AllILcdPolygonshould also implementILcdSHPMeasureList- Parameters:
aShapeList- aILcdShapeListcontaining 1 or moreILcdPolygon,ILcdSHPMeasureListobjectsaDOS- a output stream- Throws:
IOException- for any I/O errors
-
write2DPolyline
protected void write2DPolyline(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeListcontainingILcdPolylineas a set of Polylines to the output stream following the ESRI SHP file technical specification.- Parameters:
aShapeList- aILcdShapeListcontaining 1 or moreILcdPolylineobjectsaDOS- a output stream- Throws:
IOException- for any I/O errors
-
write2DPolylineM
protected void write2DPolylineM(ILcdShapeList aShapeList, TLcdDataOutputStream aDOS) throws IOException Encodes aILcdShapeListcontainingILcdPolylineas a set of PolylineM's to the output stream following the ESRI SHP file technical specification. AllILcdPolylineshould also implementILcdSHPMeasureList- Parameters:
aShapeList- aILcdShapeListcontaining 1 or moreILcdPolyline,ILcdSHPMeasureListobjectsaDOS- a output stream- Throws:
IOException- for any I/O errors
-
write2DPoint
Encodes aILcdPointas a Point to the output stream following the ESRI SHP file technical specification.- Parameters:
aPoint- theILcdPointto be encodedaDOS- the output stream to write to- Throws:
IOException- for any I/O errors
-
write2DPointM
Encodes aTLcdSHPPointMas a PointM to the output stream following the ESRI SHP file technical specification.- Parameters:
aPointM- theILcdPointto be encodedaDOS- the output stream to write to- Throws:
IOException- for any I/O errors
-
write2DPointZ
Encodes aTLcdSHPPointMas a PointZ to the output stream following the ESRI SHP file technical specification.- Parameters:
aPointZ- theILcdPointto be encodedaDOS- the output stream to write to- Throws:
IOException- for any I/O errors
-
write2DBounds
Encodes aILcdBoundsto the output stream following the ESRI SHP file technical specification.- Parameters:
aBounds- theILcdPointto be encodedaDOS- the output stream to write to- Throws:
IOException- for any I/O errors
-