Pre-release. Until the official launch, content may change, including published files.
Skip to content

Source: https://datamodels.jp/en/guide/csv · Text CC BY 4.0

Using a spreadsheet ​

The page of every entity model has a CSV template and its Table Schema in the Download row (value types such as Geometry have none). With them, people who work in a spreadsheet can make data in the shape of a model without writing JSON. This page fills in the template of designated emergency evacuation site (EvacuationSite), checks it, and turns it into NGSI-LD entities.

CSV templateDownload row of the model page① fill in, in a spreadsheetsites.csvone row per site② frictionless validateChecked sites.csvevery cell checked with the Table Schema③ datamodels convertNGSI-LD entitiesalso checked with the JSON Schema

You need Node.js 24 or later, and Python for frictionless.

1. Get the files ​

Both files are in the Download row of the model page. On the command line:

bash
BASE=https://datamodels.jp/adapters
curl -sSfO "$BASE/csv/disaster/EvacuationSite.csv"
curl -sSfO "$BASE/table-schema/disaster/EvacuationSite.tableschema.json"

2. Fill in the template ​

Open EvacuationSite.csv in a spreadsheet. Its first row has one column per attribute; the attribute table on the model page says what each one means. Add one row per site, leave the cells you do not know empty, and save the file as sites.csv in UTF-8 (in Excel: "CSV UTF-8"). This row has two mistakes on purpose, for the next steps to find:

ColumnValue
idurn:ngsi-ld:EvacuationSite:0012
name都立一橋高校
externalSiteId13101-0012
localGovernmentCode13101
address.addressText東京都千代田区東神田1-12-13
longitude, latitude139.7810002, 35.6945488
hazardTypesearthquake;fire
alsoDesignatedSheltertrue

A list such as hazardTypes is split at ;, and longitude and latitude make the location. Keep every column of the template, also the empty ones: the Table Schema expects all of them, in this order.

3. Check it with frictionless ​

frictionless checks every cell against the Table Schema: the type, the pattern, the allowed values, and whether a required cell is filled in.

bash
pip install frictionless   # or: pipx install frictionless
frictionless validate sites.csv --schema EvacuationSite.tableschema.json

The result, shortened:

text
│ sites │ table │ sites.csv │ INVALID │
┃ Row ┃ Field ┃ Type             ┃ Message                                     ┃
│ 2   │ 7     │ constraint-error │ The cell "13101" in row at position "2" and │
│     │       │                  │ field "localGovernmentCode" at position "7" │
│     │       │                  │ does not conform to a constraint:           │
│     │       │                  │ constraint "pattern" is "\d{6}"             │

The local government code has 6 digits, with the check digit at the end. Change the cell to 131016, save, and run the same command again:

text
│ sites │ table │ sites.csv │ VALID  │

4. Convert it into NGSI-LD entities ​

datamodels convert from datamodels-toolkit turns each row into an entity and checks it against the model's JSON Schema:

bash
npx github:geolonia/datamodels-toolkit#v0.3.5 convert \
  disaster/EvacuationSite csv-template sites.csv --out entities.json
text
sites.csv: utf-8, 1 row(s), 0 valid EvacuationSite, 1 invalid
  line 2: data/hazardTypes/1 must be equal to one of the allowed values

The JSON Schema checks what the Table Schema cannot: the values inside a list, and rules on several columns, such as "externalSiteId or nationalShelterId". fire is not a hazard type of this model; the attribute table lists them. Change it to inlandFlood and run convert again:

text
sites.csv: utf-8, 1 row(s), 1 valid EvacuationSite, 0 invalid

entities.json now has the entity, with the empty cells left out:

json
[
  {
    "id": "urn:ngsi-ld:EvacuationSite:0012",
    "type": "EvacuationSite",
    "name": "都立一橋高校",
    "externalSiteId": "13101-0012",
    "localGovernmentCode": "131016",
    "address": { "addressText": "東京都千代田区東神田1-12-13" },
    "location": { "type": "Point", "coordinates": [139.7810002, 35.6945488] },
    "hazardTypes": ["earthquake", "inlandFlood"],
    "alsoDesignatedShelter": true
  }
]

This is the key-values form. Add --normalized to get the form an NGSI-LD broker takes, with the @context (Sending to an NGSI-LD broker). More about the columns of the template: Converting your data.

Your own models ​

For the models of a site of your own, make the same two files with datamodels export (Exporting to other tools).