@LcdService(service=ILcdModelDecoder.class, priority=50000) public class TLcdSHPModelDecoder extends Object implements ILcdModelDecoder, ILcdCharsetSettable, ILcdInputStreamFactoryCapable
TLcdSHPModelDecoder2
instead: it does lazy loading depending on the client request.
For example, it will only load data within a requested area
based on a spatial index.
File | Required | Entry point | Description |
---|---|---|---|
*.shp | x | x | Shape file containing the vector data |
*.dbf | dBASE table file containing the feature attributes of the shapes | ||
*.shx | Index file containing the offset of each record from the beginning of the main file |
The model reference is obtained from an ILcdModelReferenceDecoder
. The default reference decoder set on this
model decoder is based on all model reference decoders annotated with the LcdService
annotation, and can handle
<filename>.epsg
): see TLcdEPSGModelReferenceDecoder
for more info.<filename>.prj
): see TLcdWKTModelReferenceDecoder
for more info.<filename>.ref
): see TLcdModelReferenceDecoder
for more info.input stream factory
of this decoder.
ILcd2DBoundsIndexedModel
.TLcdSHPModelDescriptor
.SHP
.SHP Type | Decoded Type |
---|---|
POINT | TLcd2DEditableFeaturedPoint |
POLYLINE | TLcdFeaturedShapeList with shape array of ILcd2DEditablePolyline objects |
POLYGON | TLcdFeaturedShapeList with shape array of a single TLcdComplexPolygon containing a set of ILcd2DEditablePolygon objects |
MULTI_POINT | TLcdFeaturedShapeList with shape array of ILcd2DEditablePolypoint objects |
POINT_Z | TLcd2DEditableFeaturedPoint with a TLcdSHPPointZ |
POLYLINE_Z | TLcdFeaturedShapeList with shape array of TLcdSHPPolylineZ objects |
POLYGON_Z | TLcdFeaturedShapeList with shape array of a single TLcdComplexPolygon containing a set of TLcdSHPPolygonZ objects |
MULTI_POINT_Z | TLcdFeaturedShapeList with shape array of TLcdSHPMultiPointZ objects |
POINT_M | TLcd2DEditableFeaturedPoint with a TLcdSHPPointM |
POLYLINE_M | TLcdFeaturedShapeList with shape array of TLcdSHPPolylineZ objects |
POLYGON_M | TLcdFeaturedShapeList with shape array of a single TLcdComplexPolygon containing a set of TLcdSHPPolygonZ objects |
MULTI_POINT_Z | TLcdFeaturedShapeList with shape array of TLcdSHPMultiPointZ objects |
true
.true
.
ILcdModelDecoder decoder = new TLcdSHPModelDecoder();
ILcdModel model = decoder.decode( "vector.shp" );
Constructor and Description |
---|
TLcdSHPModelDecoder()
Constructs a new SHP model decoder.
|
TLcdSHPModelDecoder(String aDataModelName)
Constructs a new SHP model decoder with a fixed
TLcdDataModel . |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeSource(String aSourceName)
Checks whether this model decoder can decode the specified data source.
|
ILcdModel |
decode(String aFullPathFileName)
Creates a new model from the given data source.
|
static String |
formatShapeType(int aShapeType)
Returns a shape type by in human-readable form.
|
String |
getCharacterSet()
Returns the name of the current Charset.
|
ILcdBounds |
getDecodingBounds()
Returns the decodingBounds of this decoder.
|
String |
getDefaultExtension()
Returns the default extension for files that can be read with this decoder.
|
ILcdModelReference |
getDefaultModelReference()
Returns the model reference to be used for models when the model reference decoder is set to null.
|
String |
getDisplayName()
Returns the display name to use for this decoder.
|
int |
getFeatureIndexForDisplayName()
Returns the index of the feature to be used as a default display name.
|
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the factory that creates input streams from which models are
decoded.
|
ILcdModelFactory |
getModelFactory()
Returns the factory object used for creating the output model.
|
ILcdModelReferenceDecoder |
getModelReferenceDecoder()
Returns the decoder used to produce model references.
|
boolean |
getUseXYFloatPoint()
Returns whether the decoder returns shapes containing TLcdXYFloatPoints
instead of the normal TLcdXYPoints.
|
boolean |
isLazyFeaturingOffForHTTP()
Returns whether the lazy feature mechanism should be switched of in case files
are retrieved via a
http connection. |
boolean |
isParseFloatAsDouble()
Indicates whether or not floating point values are parsed as a Float or a Double.
|
boolean |
isTraceOn()
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
boolean |
isTrimStringPropertyValues()
Indicates whether or not string values are trimmed when decoding DBF files.
|
boolean |
isUseXYFloatPoint()
Returns whether the decoder returns shapes containing TLcdXYFloatPoints
instead of the normal TLcdXYPoints.
|
protected boolean |
isValidField(String aField)
Returns whether the field with name
aField
is a valid field in the ILcdModel produced by this
TLcdSHPModelDecoder . |
static boolean |
isValidShape(int aShapeType)
Checks whether a shape type is valid for this decoder.
|
boolean |
isWithLazyFeaturing()
Returns whether the decoder will read the object's features with the lazy mechanism or not.
|
protected ILcdModel |
makeIndexedModel()
Creates a
TLcdVectorModel by calling makeVectorModel()
and then converts it to ILcd2DBoundsIndexedModel . |
protected ILcdModel |
makeVectorModel()
Creates a
TLcdVectorModel , sets a model reference,
adds all the SHP Objects in the TLcdVectorModel and closes the
inputStream. |
protected ILcdBounds |
readBounds(int aCoordType)
Reads a bounds from the input.
|
protected int |
readData(ILcdModel aModel,
int aCoordType)
Reads data from the input stream into a model.
|
protected ILcdFeatured |
readFeaturedObject()
Reads the features to an object.
|
protected ILcdShape[] |
readMultiPoint(int aCoordType,
int aRecordByteSize)
Reads a set of points as a multi point.
|
protected ILcdShape[] |
readMultiPointM(int aCoordType,
int aRecordByteSize)
Reads a set of measured points as a multi point.
|
protected ILcdShape[] |
readMultiPointZ(int aCoordType,
int aRecordByteSize)
Reads a set of three dimensional measured points as a multi point.
|
protected ILcdShape[] |
readOtherShapes(int aCoordType,
int aRecordByteSize)
Can be redefined to order to define how to read an ESRI shape not supported
by this
ILcdModelDecoder
Skips the unsupported shape. |
protected ILcd2DEditablePoint |
readPoint(int aCoordType)
Creates and reads a 2D point from the SHP file.
|
protected ILcd2DEditablePoint |
readPoint(int aCoordType,
int aDimension)
Creates a point with the specified dimension (2D,3D).
|
protected ILcd2DEditablePoint |
readPointM(int aCoordType)
Reads a 2 dimensional point and a value from the input.
|
protected ILcd3DEditablePoint |
readPointZ(int aCoordType)
Reads a 2 dimensional point and a value from the input.
|
protected ILcdShape[] |
readPolygon(int aCoordType,
int aRecordByteSize)
Reads a polygon from the input.
|
protected ILcdShape[] |
readPolygonM(int aCoordType,
int aRecordByteSize)
Reads a polygon consisting of measured points from the input.
|
protected ILcdShape[] |
readPolygonZ(int aCoordType,
int aRecordByteSize)
Reads a polygon consisting of three dimensional measured points from the input.
|
protected ILcdShape[] |
readPolyline(int aCoordType,
int aRecordByteSize)
Returns null when the decodingBounds is not null and the bounds of the polyline do not
interact with the decodingBounds.
|
protected ILcdShape[] |
readPolylineM(int aCoordType,
int aRecordByteSize)
Reads a polyline consisting of points accompanied with a value.
|
protected ILcdShape[] |
readPolylineZ(int aCoordType,
int aRecordByteSize)
Reads a polyline consisting of three dimensional points accompanied with a value.
|
protected int |
readShapeType()
Reads one integer as a shape type.
|
void |
setCharacterSet(String aCharacterSet)
Sets the character set to use to decode DBF files.
|
static void |
setClassTraceOn(boolean aClassTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setDecodingBounds(ILcdBounds aDecodingBounds)
Sets the decodingBounds of the decoder to aDecodingBounds.
|
void |
setDefaultModelReference(ILcdModelReference aDefaultModelReference)
Sets the model reference to be used for models when the model reference decoder is set to null.
|
void |
setFeatureIndexForDisplayName(int aFeatureIndexForDisplayName)
Set the index of the feature to be used as default display name (e.g.
the feature value to be used by the Object.toString() method).
|
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the factory that will create input streams from which models can be
decoded.
|
void |
setLazyFeaturingOffForHTTP(boolean aLazyFeaturingOffForHTTP)
Sets whether the lazy feature mechanism should be switched of in case files
are retrieved via a
http connection. |
void |
setModelFactory(ILcdModelFactory aModelFactory)
Sets the factory object used for creating the output model.
|
void |
setModelReferenceDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder)
Sets the decoder to use to produce model references for models created with this decoder.
|
void |
setParseFloatAsDouble(boolean aFloatAsDouble)
Specifies whether or not floating point values are parsed as a Float or a Double.
|
void |
setTraceOn(boolean aTraceOn)
Deprecated.
This method has been deprecated. It is recommended to use the
standard Java logging framework directly.
|
void |
setTrimStringPropertyValues(boolean aTrimStringPropertyValues)
Specifies whether or not leading and trailing whitespace should be removed
from string properties while decoding DBF files.
|
void |
setUseXYFloatPoint(boolean aUseXYFloatPoint)
Sets whether the decoder should return shapes containing TLcdXYFloatPoints
instead of the normal TLcdXYPoints.
|
void |
setWithFeatures(boolean aReadWithFeatures)
Sets whether the features of the objects should be read or not.
|
void |
setWithLazyFeaturing(boolean aLazyFeaturing)
Sets whether the features of the objects should be read with the lazy mechanism or not.
|
protected void |
skipBytes(int aNumberOfBytesToSkip)
Skips a number of bytes from the input stream.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
public TLcdSHPModelDecoder()
public TLcdSHPModelDecoder(String aDataModelName)
TLcdDataModel
.
All files that are decoded with this decoder will use exactly the same data model.
This data model will have the given name.
It is the responsibility of the caller of this method to ensure that all files that are decoded
have exactly the same structure; this means that the shape type is the same and that
all files contain the same feature structure. The result of decoding files with
different structures with a fixed data model is unspecified.public static void setClassTraceOn(boolean aClassTraceOn)
true
then all log messages are recorded, otherwise only
the informative, warning and error messages are recorded.aClassTraceOn
- if true then all log messages are recorded,
otherwise only the informative, warning and error messages are recorded.public void setTraceOn(boolean aTraceOn)
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.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.public boolean isTraceOn()
true
if tracing is enabled for this class.public void setCharacterSet(String aCharacterSet)
setCharacterSet
in interface ILcdCharsetSettable
aCharacterSet
- the character set to use to decode DBF files.
The supported character sets depend on the JVM implementation
and can be found at String.String(byte[], String)
.public String getCharacterSet()
ILcdCharsetSettable
getCharacterSet
in interface ILcdCharsetSettable
public void setParseFloatAsDouble(boolean aFloatAsDouble)
false
, parsing as Float.aFloatAsDouble
- whether or not floating point values are parsed as Float or Double.public boolean isParseFloatAsDouble()
false
for Float,
true
for Double.false
for Float, true
for Doublepublic final void setWithFeatures(boolean aReadWithFeatures)
setWithLazyFeaturing(boolean)
public void setWithLazyFeaturing(boolean aLazyFeaturing)
aLazyFeaturing
- true if the features of the objects should be read with the lazy mechanism.isWithLazyFeaturing()
,
setWithFeatures(boolean)
public boolean isWithLazyFeaturing()
setWithLazyFeaturing(boolean)
public void setLazyFeaturingOffForHTTP(boolean aLazyFeaturingOffForHTTP)
http
connection.aLazyFeaturingOffForHTTP
- true if the lazy feature mechanism should be switched of in case files
are retrieved via a http
connection.isLazyFeaturingOffForHTTP()
public boolean isLazyFeaturingOffForHTTP()
http
connection.http
connection.setLazyFeaturingOffForHTTP(boolean)
public void setUseXYFloatPoint(boolean aUseXYFloatPoint)
aUseXYFloatPoint
- true if the decoder should return shapes containing TLcdXYFloatPoints
instead of the normal TLcdXYPoints.isUseXYFloatPoint()
,
getUseXYFloatPoint()
public boolean isUseXYFloatPoint()
setUseXYFloatPoint(boolean)
public boolean getUseXYFloatPoint()
setUseXYFloatPoint(boolean)
public ILcdBounds getDecodingBounds()
setDecodingBounds(ILcdBounds)
public void setDecodingBounds(ILcdBounds aDecodingBounds)
aDecodingBounds
- The new decodingBounds to be set.getDecodingBounds()
public String getDisplayName()
getDisplayName
in interface ILcdModelDecoder
public String getDefaultExtension()
public void setFeatureIndexForDisplayName(int aFeatureIndexForDisplayName)
aFeatureIndexForDisplayName
- the index of the feature to be used as default display name.getFeatureIndexForDisplayName()
public int getFeatureIndexForDisplayName()
setFeatureIndexForDisplayName(int)
public boolean canDecodeSource(String aSourceName)
ILcdModelDecoder
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.
canDecodeSource
in interface ILcdModelDecoder
aSourceName
- the data source to be verified; typically a file name or a URL.true
if the file extension is <defaultExtension> or
<defaultExtension>.gz, false
otherwise (<defaultExtension> is the String
returned by getDefaultExtension.ILcdModelDecoder.decode(String)
,
ILcdModelDecoder.decodeModelMetadata(String)
public void setDefaultModelReference(ILcdModelReference aDefaultModelReference)
aDefaultModelReference
- the model reference to be used for models when the model reference
decoder is set to null.getDefaultModelReference()
public ILcdModelReference getDefaultModelReference()
setDefaultModelReference(com.luciad.model.ILcdModelReference)
public ILcdModelReferenceDecoder getModelReferenceDecoder()
setModelReferenceDecoder(com.luciad.model.ILcdModelReferenceDecoder)
,
setDefaultModelReference(com.luciad.model.ILcdModelReference)
public void setModelReferenceDecoder(ILcdModelReferenceDecoder aModelReferenceDecoder)
aModelReferenceDecoder
- the decoder to use to produce model references for models created with this decoder.getModelReferenceDecoder()
,
setDefaultModelReference(com.luciad.model.ILcdModelReference)
public void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
aInputStreamFactory
- the input stream factory to be used.public ILcdInputStreamFactory getInputStreamFactory()
getInputStreamFactory
in interface ILcdInputStreamFactoryCapable
public ILcdModelFactory getModelFactory()
public void setModelFactory(ILcdModelFactory aModelFactory)
aModelFactory
- the model factory.public ILcdModel decode(String aFullPathFileName) throws IOException
ILcdModelDecoder
decode
in interface ILcdModelDecoder
aFullPathFileName
- the data source to be decoded; typically a file name or a URL.null
is allowed, implementors are advised to throw an error instead.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);
}
}
InterruptedIOException
- When the thread on which this method is called is interrupted: it is recommended to stop the decoding
and throw an InterruptedIOException
.
This same exception can also be used if the decoder shows UI to the user, and the user cancels the decoding
through the UI.ILcdModelDecoder.canDecodeSource(String)
public void setTrimStringPropertyValues(boolean aTrimStringPropertyValues)
true
.aTrimStringPropertyValues
- whether or not string values in DBF files should be trimmedpublic boolean isTrimStringPropertyValues()
setTrimStringPropertyValues(boolean)
protected ILcdModel makeVectorModel() throws IOException
TLcdVectorModel
, sets a model reference,
adds all the SHP Objects in the TLcdVectorModel
and closes the
inputStream.TLcdVectorModel
containing all objects retrieved from the input stream.IOException
- when an I/O error occurs while reading the model from the input.protected ILcdModel makeIndexedModel() throws IOException
TLcdVectorModel
by calling makeVectorModel()
and then converts it to ILcd2DBoundsIndexedModel
.IOException
- when an I/O error occurs while reading the model from the input.makeVectorModel()
protected int readData(ILcdModel aModel, int aCoordType) throws IOException
aModel
- the model the objects created from the data are put in.aCoordType
- the type of data read ( Cartesian or Geodetic ).IOException
- when reading the data fails due to I/O.ILcdGeoReference
public static boolean isValidShape(int aShapeType)
aShapeType
- the shape type to check.TLcdSHPModelDescriptor.POINT
TLcdSHPModelDescriptor.POINT_M
TLcdSHPModelDescriptor.POINT_Z
TLcdSHPModelDescriptor.MULTI_POINT
TLcdSHPModelDescriptor.MULTI_POINT_M
TLcdSHPModelDescriptor.MULTI_POINT_Z
TLcdSHPModelDescriptor.POLYLINE
TLcdSHPModelDescriptor.POLYLINE_M
TLcdSHPModelDescriptor.POLYLINE_Z
TLcdSHPModelDescriptor.POLYGON_M
TLcdSHPModelDescriptor.POLYGON_Z
TLcdSHPModelDescriptor.POLYGON
protected int readShapeType() throws IOException
IOException
- when reading fails due to I/O.protected ILcdFeatured readFeaturedObject() throws IOException
IOException
- when reading fails due to I/O.protected ILcd2DEditablePoint readPoint(int aCoordType) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).IOException
- when an I/O error occurs while reading from the input.protected ILcd2DEditablePoint readPoint(int aCoordType, int aDimension) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aDimension
- the dimension of the point to be read.IOException
- when an I/O error occurs while reading from the input.protected ILcd2DEditablePoint readPointM(int aCoordType) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).TLcdSHPPointM
IOException
- when an I/O error occurs.protected ILcd3DEditablePoint readPointZ(int aCoordType) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).TLcdSHPPointZ
.IOException
- when an I/O error occurs.protected ILcdShape[] readOtherShapes(int aCoordType, int aRecordByteSize) throws IOException
ILcdModelDecoder
aCoordType
- the ESRI shape type (see ESRI documentation).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).null
.IOException
- when an I/O error occurs while reading from the input.protected final void skipBytes(int aNumberOfBytesToSkip) throws IOException
aNumberOfBytesToSkip
- the number of bytes to skip.IOException
- when an I/O error occurs.protected ILcdShape[] readPolyline(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdSHPPolylineZ
objects.IOException
- when an I/O error occurs.protected ILcdShape[] readPolylineM(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdSHPPolylineZ
IOException
- when an I/O error occurs.protected ILcdShape[] readPolylineZ(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdSHPPolylineZ
IOException
- when an I/O error occurs.protected ILcdShape[] readPolygon(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdComplexPolygon
.IOException
- when reading the data fails due to I/O.protected ILcdShape[] readPolygonM(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdComplexPolygon
.IOException
- when an I/O error occurs.protected ILcdShape[] readPolygonZ(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdComplexPolygon
.IOException
- when an I/O error occurs.protected ILcdShape[] readMultiPoint(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).ILcd2DEditablePolypoint
.IOException
- when an I/O error occurs.protected ILcdShape[] readMultiPointM(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdSHPMultiPointZ
.IOException
- when an I/O error occurs.protected ILcdShape[] readMultiPointZ(int aCoordType, int aRecordByteSize) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).aRecordByteSize
- the size of the record in bytes ( read from the input stream ).TLcdSHPMultiPointZ
.IOException
- when an I/O error occurs.protected ILcdBounds readBounds(int aCoordType) throws IOException
aCoordType
- the type of coordinates, cartesian or geodetic (ILcdGeoReference
).ILcdBounds
IOException
- when an I/O error occurs.public static String formatShapeType(int aShapeType)
aShapeType
- the shape type to format.protected boolean isValidField(String aField)
aField
is a valid field in the ILcdModel
produced by this
TLcdSHPModelDecoder
.aField
- the field to check.true
if and only if the field with name aField
is a valid field in the ILcdModel
produced by this
TLcdSHPModelDecoder
.