Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Python API Alter Tabular Data

Johannes Kolbe edited this page Jul 31, 2014 · 6 revisions

There are mainly two ways to alter tables on the Python side of ILWIS, you can either add a new column or alter the value of an existing cell.

Add Column

If you want to add new completely new data to a table you will first have to create a new column to put it in. This is done by the .addColumn() method. There are two ways to use this method. The first one needs two arguments, which are both strings: a name and a value domain. The value domain will specify what kind of values and ranges are accepted inside this column. You can find a list of supported domains in the Python API Tutorial.

table = Table("newTable")
table.addColumn("sealevel", "value")
table.addColumn("rise", "percentage")
table.addColumn("date", "time")

The secon way to use .addColumn() is with a ColumnDefinition. You can find more about what ColumnDefinitions are in this part of the Tutorial. You just have to create a new definition and then pass it to the .addColumn() function.

table = Table("newTable")
# create a new Text Domain, this means there will be only string values allowed in this column
txtDom = TextDomain()
# create a new ColumnDefinition with the domain
coldef = ColumnDefinition("Cities", txtDom, 0)
# add a new column
table.addColumnd(coldef)

Alter a Cell

If you want to alter the data of existing cell you can use the setCell() function. The arguments you need to provided are in the following order: column(name or index), row(index), value Like in most cases you choose wether you want to use the column name or it's index to define the target cell. As input values there are only integers, doubles, string, dates and times supported so far.

table = Table("rainfall.shp")
table.setCell("FEBRUARY", 3, 57)
table.setCell(0, 1, "Rio_Glara")

Clone this wiki locally