public interface ILcdModelEncoder extends Serializable
ILcdModel
objects (implemented interfaces, structure, contents, ...) are
defined by the actual implementations of this interface.
Each model encoder has a displayable name that identifies the data format, encoded by this encoder.
Two ways are provided for storing a model: saving and exporting. Saving a model is always done to its original location, and should normally not involve a conversion of the model's contents. Exporting a model however can be done to a different place and can involve a conversion from the model's contents if it is exported to another format than the one it originated from (for example, a model decoded from a SHP file will need to be converted when exported by a GML encoder). Since some formats store more or other information that others, exporting data may sometimes result in partial loss of data.
TLcdCompositeModelDecoder decoder = new TLcdCompositeModelDecoder(
TLcdServiceLoader.getInstance(ILcdModelDecoder.class)
);
ILcdModel model = decoder.decode(pathToGeoJsonFile);
// Make some changes to the model
// For example add, remove or update elements
// Save those changes back to disk
ILcdModelEncoder modelEncoder = model.getModelEncoder();
if (modelEncoder != null && modelEncoder.canSave(model)) {
//This will override the file located at 'pathToGeoJsonFile'
modelEncoder.save(model);
} else {
// this kind of model can't be saved back
}
//Decode a .shp file
TLcdCompositeModelDecoder decoder = new TLcdCompositeModelDecoder(
TLcdServiceLoader.getInstance(ILcdModelDecoder.class)
);
ILcdModel model = decoder.decode(pathToSHPFile);
TLcdGeoJsonModelEncoder geoJsonModelEncoder = new TLcdGeoJsonModelEncoder();
if (geoJsonModelEncoder.canExport(model, geoJsonOutputPath)) {
//This will create a .geojson file at 'geoJsonOutputPath'
geoJsonModelEncoder.export(model, geoJsonOutputPath);
} else {
// can happen, but probably not in this case
}
Modifier and Type | Method and Description |
---|---|
boolean |
canExport(ILcdModel aModel,
String aDestinationName)
Returns 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 the specified model to the specified destination.
|
String |
getDisplayName()
Returns a short, displayable name for the format this
ILcdModelEncoder encodes to. |
void |
save(ILcdModel aModel)
Saves the model to the location where it originally came from.
|
String getDisplayName()
ILcdModelEncoder
encodes to.ILcdModelEncoder
.boolean canSave(ILcdModel aModel)
aModel
- the model to be verified.true
if this encoder can save the model in the location where it originally came from,
false
otherwise.save(com.luciad.model.ILcdModel)
void save(ILcdModel aModel) throws IllegalArgumentException, IOException
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.boolean canExport(ILcdModel aModel, String aDestinationName)
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.export(com.luciad.model.ILcdModel, java.lang.String)
void export(ILcdModel aModel, String aDestinationName) throws IllegalArgumentException, IOException
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.NullPointerException
- if the specified model is null
, or if null
is not accepted as value
for aDestinationName
by this model encoder.IllegalArgumentException
- if the model cannot be saved by this encoder (!canExport(aModel, aDestinationName)
).IOException
- if an I/O error occurs during encoding.