The majority of formats require the same two steps for visualization on a Lightspeed view. To visualize CSV data:

  1. Decode the data into an ILcdModel using an ILcdModelDecoder.

  2. Create an ILspLayer for the ILcdModel and add it to the ILspView.

//First create the model
ILcdModelDecoder decoder =
    new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
ILcdModel model = decoder.decode(sourceName);

//Create a layer for the model with default styling
ILspLayer layer = TLspShapeLayerBuilder.newBuilder()
                                       .model(model)
                                       .build();

//Add the layer to the Lightspeed view (an ILspView)
view.addLayer(layer);

This results in a CSV layer with default styling. See Visualizing Vector Data for more information about visualizing and styling vector data.

This code snippet uses the TLcdCompositeModelDecoder, initialized with all model decoders available in the service registry.

The model decoder class that is actually responsible for decoding CSV data is the TLcdCSVModelDecoder.

Handling non-standard CSV files

The above code relies on the model decoder to be able to correctly parse the CSV file. Sometimes the decoder does not have enough information to automatically determine the structure of the file.

In that case, you can pass extra information to the decoder in the form of a TLcdCSVDataSource. The following example uses the TLcdCSVDataSource to specify both the source CSV file and the separator used in that file.

//Create the TLcdCSVDataSource
//This is a container object with all the information needed
//by the model decoder to parse the CSV file
TLcdCSVDataSource dataSource =
    TLcdCSVDataSource.newBuilder()
                     .source(aCSVSourceFile) //specify the path
                     .separator(",") //specify extra information for the decoder
                     .build();

ILcdModelDecoder decoder =
    new TLcdCompositeModelDecoder(TLcdServiceLoader.getInstance(ILcdModelDecoder.class));
//Pass the TLcdCSVDataSource to the model decoder
ILcdModel model = decoder.decodeSource(dataSource);

There are a number of other settings that can be configured on the TLcdCSVDataSource allowing to deal with non-standard CSV files. Check the javadoc of that class for more information on the available settings.