CSV File Formats
This topic contains details of the format for comma separated variable (CSV) files used in importing and exporting Network data.
The following sections are included:
- General File Formatting Information
- Formatting Details for Specific Field Types
- Using Data Exported from InfoAsset Manager
General file formatting
The way in which data is distributed between files is quite flexible:
- Data can be contained in one file, or spread over several files.
- Each file can contain data about one or more network object types.
- More than one file can contain data about objects of the same type (duplication will cause errors).
- Files can reside in different directories.
Each file consists of a combination of:
- One or more data type delimiter records, dividing the file into one or more sections.
- Each section contains:
- A compulsory header record, listing the field names.
- One data record per network object.
Each file is treated as an individual entity. The data type delimiter and header record information is not carried forward from one file to another.
The data type delimiter takes the form of four stars followed by the name of the database table containing details of this type of network object.
Details of database table names can be found in the Network Data Fields topic.
Click on the image below to display an example.
Example:
xxx_node.csv
tells InfoAsset Manager that the file begins with Node data.
Using the filename is a more visible way to organise your data if you have one network object type per file. This approach is used when you export from InfoAsset Manager using the Export each table to a different file option.
A filename can be used to define the data type at the start of a file and data type delimiters used to define different types further down the file, however this approach is unlikely to be of much benefit.
The delimiter ****deletes can be used to define a list of objects to be deleted when updating a network. The delimiter is followed by a record for each object to be deleted containing table name and Asset ID of the object.
Click on the image below to show an example.
Alternatively, append deletes to the filename to delete all objects in a file.
Note:
- Objects will be deleted regardless of the Type of update (Update and Add, Mixed, Deletes) selected on the Import / Update CSV Data dialog.
- Asset IDs are always used regardless of whether the Update uses "Asset ID" field on the Import / Update CSV Data Dialog is checked.
The header record contains a list of the field names contained in the database table for the network object.
- The field names can be in any order.
- The list of field names does not have to be complete. The only essential fields are the primary key field(s). This field (or fields) uniquely identify the individual record within the database table (see below for list of primary key fields).
- The list may contain blanks or names not recognised by InfoAsset Manager. These fields will be ignored.
For InfoAsset Manager the primary key fields are:
Nodes tables |
The primary key for nodes is the node_id field. This field contains a string up to 30 characters long. The ID must be unique within the network |
Pipes tables |
Pipes require three fields: upstream_node_id, downstream_nde_idand link_suffix. The combination of the three fields must be unique within the network. |
The header record is followed by zero or more data records.
- The data records must follow the same structure as the header record, with all the fields in the same order.
- Zero data records is allowed so that any external software you may use to generate CSV data for use in InfoAsset Manager does not have to check whether records exist.
In certain circumstances it is necessary to use escape characters to maintain the structure of the exported data.
- For Memo type fields (see Data Type Key) the text is surrounded by quotation marks only if it contains certain special characters , " \ CR(carriage return) or LF (line feed). In the exported text, " is changed to "", CR is changed to \r, LF is changed to \n and \ is changed to \\.
- For all other text fields the text is surrounded by quotation marks only if it contains " or , . In the exported text, " is changed to "".
Formatting details for specific field types
Text fields
Text fields must be contained in double quotation marks if they contain commas or other double quotation marks. Otherwise quotation marks are optional.
Arrays of values of a single type
Arrays of values of a single type, such as coordinates, can be defined as packed (as a single field) or as unpacked (each value is defined in a separate field).
Arrays of values containing more than one field
These arrays contain lists of values that describe more complex parts of particular objects, for example:
- Pipes in and out of manhole surveys.
- CCTV survey defect details.
The arrays can be defined as packed (as a single field) or separately (in a separate block or separate file).
Each array is defined in a single field:
- The field starts and ends with opening and closing curly brackets. The field has one or more sub-fields containing the data for one of the items in the list above.
- Sub-fields start and finish with opening and closing curly brackets. Sub-fields are separated by commas.
- Within each sub-field a number of fields are separated by commas. These fields must appear in a fixed order.
Click on the image below to show an example with CCTV Survey details.
Each array is defined in a separate block or separate file. Each value in the array is defined in a separate field.
The Data Type Delimiter takes the form of four starts followed by the Database Data Structure name.
Details of Database Data Structure names can be found in the Network Data Fields section.
Click on the image below to show an example with CCTV Survey details.
Using data exported from InfoAsset Manager
When CSV files are exported from InfoAsset Manager, you have the option to export descriptive field names and units information. These are exported as additional records placed before the data records. If you export files including these additional records, and then try to import them, InfoAsset Manager will try to interpret the additional data as normal data records. You will almost certainly get error messages telling you that values in the file have the wrong size or type.
The additional export options are there for your convenience when viewing InfoAsset Manager data in other packages. You should make sure that data you intend to import back into InfoAsset Manager is exported without these additional records. The Select CSV Export Options Dialog divides the options needed for re-import from the additional options and you should have no trouble exporting in the correct format. The additional records could also be removed by editing the file in another package prior to re-import.