@LcdService(service=ILcdModelEncoder.class, priority=20000) public class TLcdGeoJsonModelEncoder extends Object implements ILcdModelEncoder, ILcdOutputStreamFactoryCapable
FeatureCollection
FeatureCollection
.
Any instance of ILcdModel is encoded as a single FeatureCollection.
FeatureCollection
. The model
encoder will convert an ILcdModel
to a single FeatureCollection
.
Feature
.ILcdDataObject
. Properties of such an object are
converted to key-value pairs in the properties
member of the Feature
.
ILcdShape
to one of these types.
Following shapes can be encoded to a GeoJson geometry:
ILcdPoint
: encoded as a Point
ILcdPolyline
: encoded as a LineString
ILcdPolygon
: encoded as a Polygon
ILcdComplexPolygon
:
Polygon
MultiPolygon
Polygon
ILcdPolypoint
: encoded as a MultiPoint
ILcdSurface
: encoded as a Polygon
, providing the exterior ring and
interior rings are instances of ILcdPointList
ILcdCurve
: encoded as a LineString
, providing the object is also an instance of
ILcdPointList
, or is a ILcdCompositeCurve
with a single ILcdPointList
inside ILcdRing
: encoded as a Polygon
with only a single ring, providing the object is also an instance of ILcdPointList
ILcdShapeList
:
ILcdPoint
: encoded as a MultiPoint
ILcdPolyline
: encoded as a MultiLineString
GeometryCollection
, where each shape in the list is encoded
individuallyILcdExtrudedShape
: the baseShape
is encoded individually. ILcdDataObject
with a type that has a TLcdHasGeometryAnnotation
and the value of the
geometry property is one of the geometries listed above.
ILcdDataObject
, its properties are encoded as
well. The Json format only supports following types: String
, number
,
object
(a collection of key-value pairs), array
(a list of values),
true
, false
, and null
.TLcdCoreDataTypes.STRING_TYPE
: encoded to String
TLcdCoreDataTypes.NUMBER_TYPE
: encoded to Number
TLcdCoreDataTypes.BOOLEAN_TYPE
: encoded to true
/false
TLcdDataProperty.CollectionType.LIST/SET
: encoded to array
TLcdDataProperty.CollectionType.MAP
: encoded to Object
. The key of the map is converted to a string.
TLcdPrimaryKeyAnnotation
, the value of that property
will be used as id
value of the GeoJson Feature. It will then be omitted from the properties
list.
TLcdFeatureMetaDataProvider
, it is possible to customize how a domain object from the model
is encoded.
id
value of the GeoJson FeaturesetFeatureMetaDataProvider(TLcdFeatureMetaDataProvider)
to set the TLcdFeatureMetaDataProvider
for the encoder.Constructor and Description |
---|
TLcdGeoJsonModelEncoder()
Create a new model encoder with following default configuration: Json format is
"pretty": see
setPrettyJson for details Json format is "2D": see
set2DJson for details encoding is "strict": see
setPolygonEncodingStrict for details |
Modifier and Type | Method and Description |
---|---|
boolean |
canExport(ILcdModel aModel,
String aDestinationName)
Verifies whether this encoder can export the specified model to the specified destination.
|
boolean |
canSave(ILcdModel aModel)
Returns whether this model encoder can save the specified model to the location it originally came from.
|
void |
export(ILcdModel aModel,
String aDestinationName)
Exports a model to the specified destination.
|
void |
exportFeature(Object aObject,
OutputStream aOutputStream)
A convenience method to encode a domain object to a GeoJson Feature.
|
void |
exportGeometry(ILcdShape aShape,
OutputStream aOutputStream)
A convenience method to encode a shape to a GeoJson geometry.
|
String |
getDisplayName()
Returns a short, displayable name for the format this
ILcdModelEncoder encodes to. |
TLcdFeatureMetaDataProvider |
getFeatureMetaDataProvider()
Get the metadata provider that is used by this encoder.
|
ILcdModelReferenceFormatter |
getModelReferenceFormatter()
Get the reference formatter that is used by the encoder.
|
ILcdOutputStreamFactory |
getOutputStreamFactory()
Returns the output stream factory that is used.
|
String |
getTextEncodingCharset()
return the text encoding character set.
|
boolean |
is2DJson()
Is the coordinate output 2-dimensional or not?
|
boolean |
isPolygonEncodingStrict()
Is polygon encoding strict or not?
|
boolean |
isPrettyJson()
Is the Json output pretty or not?
|
boolean |
isSkipUnsupportedFeature()
Are unsupported features ignored? When
false , an error will be thrown when
exporting a model containing unsupported features. |
void |
save(ILcdModel aModel)
Saves the model to the location where it originally came from.
|
void |
set2DJson(boolean a2d)
true : output coordinates will have 2 dimensions (x,y or lon,lat). |
void |
setFeatureMetaDataProvider(TLcdFeatureMetaDataProvider aFeatureMetaDataProvider)
Sets the metadata provider to be used by the encoder.
|
void |
setModelReferenceFormatter(ILcdModelReferenceFormatter aFormatter)
Set the reference formatter the encoder will use to format a spatial reference.
|
void |
setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
Sets the output stream factory to be used.
|
void |
setPolygonEncodingStrict(boolean aPolygonEncodingStrict)
Set polygon encoding to strict.
|
void |
setPrettyJson(boolean aPretty)
Sets whether the output json needs to be human readable or not.
|
void |
setSkipUnsupportedFeature(boolean aSkip)
Set to
true if unsupported features in the model may be ommitted from the exported
GeoJson file. |
void |
setTextEncodingCharset(String aCharSet)
Set the text encoding character set: for example "UTF-8".
|
public TLcdGeoJsonModelEncoder()
setPrettyJson
for detailsset2DJson
for detailssetPolygonEncodingStrict
for detailspublic void setModelReferenceFormatter(ILcdModelReferenceFormatter aFormatter)
aFormatter
- the formatter for the encoder to usepublic ILcdModelReferenceFormatter getModelReferenceFormatter()
public void setTextEncodingCharset(String aCharSet)
aCharSet
- the identifier of the character set.public String getTextEncodingCharset()
public void setPrettyJson(boolean aPretty)
Use true
to make the json output "pretty". For example, this would be a point in pretty GeoJson.
{
"type":"Point",
"coordinates":[10.1,12.3]
}
Use false
to optimize the json output. For example, this would be a
point in optimized GeoJson.
{"type":"Point","coordinates":[10.1,12.3]}
The above format is more efficient for machin readable applications (for example, a webservice
supporting a rich internet application). aPretty
- is json pretty or not.public boolean isPrettyJson()
true
when pretty, false
when optimized.public void set2DJson(boolean a2d)
true
: output coordinates will have 2 dimensions (x,y or lon,lat). Use this
when the geometries to encode are 2-dimensional, or the 3rd dimension is irrelevant. For
instance, you might want to use this option to limit the size of the data when building web
applications.
false
: output coordinates have 3 dimensions.
a2d
- is the coordinate output 2-dimensional or not.public boolean is2DJson()
true
when 2d, false
when 3d.public void setPolygonEncodingStrict(boolean aPolygonEncodingStrict)
true
: validate and correct polygons.
Instances of ILcdComplexPolygon
will be strictly validated before encoding.
ILcdComplexPolygon
may be encoded as a GeoJson
MultiPolygon
, instead of a GeoJson Polygon
with multiple rings. This
is the case when the first polygon in the ComplexPolygon does not contain all other
Polygons.ILcdComplexPolygon
may be flipped. This happens when the orientation of the first
polygon in the ComplexPolygon is not opposite to the orientation of the points in the other
polygons. Note that this is not strictly enforced by the GeoJson specification. (v 1.0)true
is more performance intensive.
false
: do not validate polygons
false
may be used to improve performance when encoding models. aPolygonEncodingStrict
- is polygon encoding strict or notpublic boolean isPolygonEncodingStrict()
true
when strict validation of polygons, false
when not.public void setSkipUnsupportedFeature(boolean aSkip)
true
if unsupported features in the model may be ommitted from the exported
GeoJson file.
This is useful when objects in the model that do no implement a supported shape interface can safely be discarded.
See the constructor documentation for more information about which shapes are supported.
When set to false
, an IllegalArgumentException
will be thrown.
This is the default behavior.
aSkip
- should unsupported features be ignored? The default is false
.public boolean isSkipUnsupportedFeature()
false
, an error will be thrown when
exporting a model containing unsupported features. When true
, a warning will be
logged to the console when an unsupported feature is encountered.public void setFeatureMetaDataProvider(TLcdFeatureMetaDataProvider aFeatureMetaDataProvider)
aFeatureMetaDataProvider
- the feature metadata provider to usepublic TLcdFeatureMetaDataProvider getFeatureMetaDataProvider()
public String getDisplayName()
ILcdModelEncoder
ILcdModelEncoder
encodes to.getDisplayName
in interface ILcdModelEncoder
ILcdModelEncoder
.public boolean canSave(ILcdModel aModel)
ILcdModelEncoder
canSave
in interface ILcdModelEncoder
aModel
- the model to be verified.true
if this encoder can save the model in the location where it originally came from,
false
otherwise.ILcdModelEncoder.save(com.luciad.model.ILcdModel)
public void save(ILcdModel aModel) throws IllegalArgumentException, IOException
ILcdModelEncoder
save
in interface ILcdModelEncoder
aModel
- the model to be saved.IllegalArgumentException
- if the model cannot be saved by this encoder (!canSave(aModel)
).IOException
- if an I/O error occurs during encoding.public boolean canExport(ILcdModel aModel, String aDestinationName)
setSkipUnsupportedFeature
.canExport
in interface ILcdModelEncoder
aModel
- the model to be verified.aDestinationName
- the location where the model should be exported to.true
if this encoder can export the specified model to the
specified location, false
otherwise.ILcdModelEncoder.export(com.luciad.model.ILcdModel, java.lang.String)
public void exportFeature(Object aObject, OutputStream aOutputStream) throws IOException
TLcdGeoJsonModelDecoder.decodeFeature(java.io.InputStream,
com.luciad.model.ILcdModelReference, com.luciad.datamodel.TLcdDataType)
static method for the
reverse operation.aObject
- the domain object to encode. Usually, this object would implement both
ILcdDataObject
as well as implement one of the supported
shape interfaces (see the constructor
documentation for details on the supported shape types).aOutputStream
- the outputstream to which the Feature is written.IOException
- if an I/O error occurs during encoding.public void exportGeometry(ILcdShape aShape, OutputStream aOutputStream) throws IOException
aShape
- the shape to encode.aOutputStream
- the output stream to which the geometry is writtenIOException
- if an I/O error occurs during encoding.public void export(ILcdModel aModel, String aDestinationName) throws IllegalArgumentException, IOException
canExport
.export
in interface ILcdModelEncoder
aModel
- the model to be exported.aDestinationName
- the location where the model should be saved. Typically, this is a name
for the output file, but it can also point to a file containing the
required properties to create a set of data files.IllegalArgumentException
IOException
public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
ILcdOutputStreamFactoryCapable
setOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable
aOutputStreamFactory
- the output stream factory to be used.public ILcdOutputStreamFactory getOutputStreamFactory()
ILcdOutputStreamFactoryCapable
getOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable