| 1 |
# Examples with Jinja2 templating. |
| 2 |
# The input data is in input/cities.json. |
| 3 |
# The template files are under templates. |
| 4 |
# Several examples extending into more advanced: |
| 5 |
# - xml: templates/cities.jinja2 simple with just for loop |
| 6 |
# - gml: templates/gmlcities.jinja2 advanced with globals and macros |
| 7 |
# |
| 8 |
# All rendered output under output/ |
| 9 |
# |
| 10 |
[etl] |
| 11 |
chains = input_json|filter_template_xml|output_xml_file |
| 12 |
,input_json|filter_template_gml|output_gml_file |
| 13 |
,input_geojson|filter_template_geojson2gml|output_gml_file2 |
| 14 |
,input_geojson|filter_template_geojson2gml|output_std |
| 15 |
,input_addresses_csv|convert_record_array_to_struct|filter_template_addresses2inspire|output_inspire_addresses |
| 16 |
|
| 17 |
[input_json] |
| 18 |
class = stetl.inputs.fileinput.JsonFileInput |
| 19 |
file_path = input/cities.json |
| 20 |
|
| 21 |
# EXAMPLE 1 - simple Jinja2 templating: JSON to XML |
| 22 |
|
| 23 |
# Simple xml templating |
| 24 |
[filter_template_xml] |
| 25 |
class = stetl.filters.templatingfilter.Jinja2TemplatingFilter |
| 26 |
template_file = templates/cities-json2xml.jinja2 |
| 27 |
|
| 28 |
[output_xml_file] |
| 29 |
class = stetl.outputs.fileoutput.FileOutput |
| 30 |
file_path = output/cities.xml |
| 31 |
|
| 32 |
|
| 33 |
# EXAMPLE 2 - advanced Jinja2 templating : JSON to GML |
| 34 |
|
| 35 |
# Advanced gml templating with globals for more or less static content |
| 36 |
# like contact info etc |
| 37 |
[filter_template_gml] |
| 38 |
class = stetl.filters.templatingfilter.Jinja2TemplatingFilter |
| 39 |
template_file = templates/cities-json2gml.jinja2 |
| 40 |
template_globals_path = input/globals.json |
| 41 |
|
| 42 |
[output_gml_file] |
| 43 |
class = stetl.outputs.fileoutput.FileOutput |
| 44 |
file_path = output/cities.gml |
| 45 |
|
| 46 |
# EXAMPLE 3 - more advanced Jinja2 templating - GeoJSON to GML - and reading from URL |
| 47 |
|
| 48 |
[input_geojson] |
| 49 |
class = stetl.inputs.fileinput.JsonFileInput |
| 50 |
# file_path = input/cities-gjson.json |
| 51 |
file_path = https://raw.githubusercontent.com/justb4/stetl/master/examples/basics/10_jinja2_templating/input/cities-gjson.json |
| 52 |
output_format = geojson_collection |
| 53 |
|
| 54 |
# More advanced gml templating with globals for more or less static content |
| 55 |
# and GeoJSON to GML geometry conversion |
| 56 |
[filter_template_geojson2gml] |
| 57 |
class = stetl.filters.templatingfilter.Jinja2TemplatingFilter |
| 58 |
template_file = templates/cities-gjson2gml.jinja2 |
| 59 |
template_globals_path = input/globals.json,https://raw.githubusercontent.com/justb4/stetl/master/examples/basics/10_jinja2_templating/input/more-globals.json |
| 60 |
input_format = geojson_collection |
| 61 |
|
| 62 |
[output_gml_file2] |
| 63 |
class = stetl.outputs.fileoutput.FileOutput |
| 64 |
file_path = output/cities-gjson.gml |
| 65 |
|
| 66 |
# EXAMPLE 4 - very advanced Jinja2 templating - local addresd data (CSV) to INSPIRE Addresses (AD) GML |
| 67 |
|
| 68 |
[input_addresses_csv] |
| 69 |
class = stetl.inputs.fileinput.CsvFileInput |
| 70 |
file_path = input/addresses.csv |
| 71 |
|
| 72 |
# We need this, since the Jinja2 template expects a named struct |
| 73 |
# So basically we will convert to a JSON-like structure where the root |
| 74 |
# member is named "addresses" as an array of records (name/value pairs). |
| 75 |
[convert_record_array_to_struct] |
| 76 |
class = stetl.filters.formatconverter.FormatConverter |
| 77 |
input_format = record_array |
| 78 |
output_format = struct |
| 79 |
converter_args = {'top_name' : 'addresses'} |
| 80 |
|
| 81 |
# More advanced gml templating with globals for more or less static content |
| 82 |
# and GeoJSON to GML geometry conversion |
| 83 |
[filter_template_addresses2inspire] |
| 84 |
class = stetl.filters.templatingfilter.Jinja2TemplatingFilter |
| 85 |
template_file = templates/addresses2inspire-ad.jinja2 |
| 86 |
template_globals_path = input/addresses-globals.json |
| 87 |
|
| 88 |
[output_inspire_addresses] |
| 89 |
class = stetl.outputs.fileoutput.FileOutput |
| 90 |
file_path = output/inspire-addresses.gml |
| 91 |
|
| 92 |
# EXTRA |
| 93 |
# for testing/debugging only: replace file output with this to directly show results |
| 94 |
[output_std] |
| 95 |
class = stetl.outputs.standardoutput.StandardOutput |