Skip to content

Commit 7c5e04e

Browse files
committed
Added documentation on fetching GeoJSON using the API
1 parent de9a7a1 commit 7c5e04e

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

modules/os2forms_webform_maps/README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,55 @@ The module can be installed using the standard Drupal installation procedure.
1717

1818
## Fetching GeoJSON using the API
1919

20-
``` shell
21-
@todo
20+
Assume that we have a webform with ID `my_webform` and the webform has a Map element with ID `my_map`. We can then fetch
21+
the data for a submission with UUID `c34d01c5-7bd9-4b15-8b01-5787959453c0` on the webform with a HTTP `GET` request (cf.
22+
[OS2Forms REST API](https://github.com/itk-dev/os2forms_rest_api/blob/main/README.md)):
23+
24+
``` shell name=api-fetch-submission-data
25+
curl --silent --location --header 'api-key: my-api-key' http://127.0.0.1:8000/webform_rest/my_webform/submission/c34d01c5-7bd9-4b15-8b01-5787959453c0
26+
# {"entity":{"serial":[{"value":1}],"sid":[{"value":2}],"uuid":[{"value":"c34d01c5-7bd9-4b15-8b01-5787959453c0"}],…```
27+
```
28+
29+
The result, however, contains a lot of data and we need a little more work the extract just the GeoJSON data.
30+
31+
Using [`jq`](https://jqlang.org/) (or similar tools), we can drill down into the full submission data to extract just
32+
the GeoJSON data from the Map element (JSON decoding twice along the way):
33+
34+
``` shell name=api-extract-map-element-data
35+
curl --silent --location --header 'api-key: my-api-key' http://127.0.0.1:8000/webform_rest/my_webform/submission/c34d01c5-7bd9-4b15-8b01-5787959453c0 | jq '.data.my_map | fromjson | .geojson | fromjson'
36+
```
37+
38+
The final result will be something like
39+
40+
``` json
41+
{
42+
"type": "FeatureCollection",
43+
"features": [
44+
{
45+
"type": "Feature",
46+
"properties": {},
47+
"geometry": {
48+
"type": "LineString",
49+
"coordinates": [
50+
[
51+
10.193674,
52+
56.158929
53+
],
54+
[
55+
10.241758,
56+
56.155296
57+
],
58+
[
59+
10.242788,
60+
56.130048
61+
],
62+
[
63+
10.189209,
64+
56.129283
65+
]
66+
]
67+
}
68+
}
69+
]
70+
}
2271
```

0 commit comments

Comments
 (0)