After creating an empty table, as explained in Create an empty Informix Spatial table, you can start adding spatial data to the table.

You can load data from and external file — a JSON file in this example — and add the elements to the table. Start by decoding the GeoJSON data into an ILcdModel using an ILcdModelDecoder.

Program: Decode the geojson data.
static ILcdModel loadJsonModel() throws IOException {
  TLcdGeoJsonModelDecoder decoder = new TLcdGeoJsonModelDecoder();
  return decoder.decode("Data/geojson/world.geojson");
}

You must also decode the content of the table you want to add the GeoJSON data to.

Program: Decode the Informix Spatial table.
static TLcdDatabaseModel loadDatabaseModel() throws IOException {
  TLcdInformixSpatialModelDecoder decoder = new TLcdInformixSpatialModelDecoder();
  return (TLcdDatabaseModel) decoder.decode(getProperties());
}

To decode the Informix Spatial table, you can use the same properties as the ones used in the Create an empty Informix Spatial table article.

After decoding both ILcdModels, take these steps for all elements in the GeoJSON model:

  1. Create a TLcdFeaturedSingleShapeList with the features and data type of the TLcdDatabaseModelDescriptor of the TLcdDatabaseModel and the ILcdShape of the element of the GeoJSON model.

  2. Copy the values of the properties of the element of the JSON model to the newly created TLcdFeaturedSingleShapeList.

  3. Add the element to the TLcdDatabaseModel.

Finally, commit the changes.

Program: Add elements to the database table.
ILcdModel jsonModel = loadJsonModel();
TLcdDatabaseModel databaseModel = loadDatabaseModel();
TLcdDatabaseModelDescriptor databaseModelModelDescriptor = (TLcdDatabaseModelDescriptor) databaseModel.getModelDescriptor();

// Retrieve features and datatype of database model.
Object[] features = IntStream.range(0, databaseModelModelDescriptor.getFeatureCount()).mapToObj(databaseModelModelDescriptor::getFeatureName).toArray();
TLcdDataType dataType = databaseModelModelDescriptor.getModelElementType();

for (Object elementOfJsonModel : jsonModel.query(ILcdModel.all()).toList()) {
  // Retrieve the shape of the element of the json model and use it to construct an element for the database model.
  ILcdShape shape = ALcdShape.fromDomainObject(elementOfJsonModel);
  TLcdDataObjectShapeList element = new TLcdDataObjectShapeList(dataType, shape);

  // Copy the values of the properties of the element of the json model to the newly constructed element of the database model.
  // The featureNames (and there type) of the database model need to match those of the json model for this to work.
  for (TLcdDataProperty property : dataType.getProperties()) {
    element.setValue(property, ((ILcdDataObject) elementOfJsonModel).getValue(property.getName()));
  }
  databaseModel.addElement(element, ILcdModel.NO_EVENT);
}
databaseModel.fireCollectedModelChanges();

// Save the changes to the database model.
databaseModel.commit();

The TLcdDataType of the elements stored in the source model, GeoJSON in this example, and the TLcdDatabaseModel must have the same properties. Otherwise, you must map your input data object to a new data object with the database model’s data type.