{# This is a Jinja2 template for generating one of the most complex INSPIRE Schema's: Annex I Addresses specified in http://inspire.jrc.ec.europa.eu/documents/Data_Specifications/INSPIRE_DataSpecification_AD_v3.1.pdf The GML Application Schema is complex and verbose, but the actual required input is quite small. At a minimum just 4 variables for a complete address: street, house number, postal code, city plus a point (lat,lon) for each address. This makes Templating so powerful. The input in Stetl are both records (an array of records (dict's) called "addresses" originating from a CSV (here addresses.csv) or possibly some database records. The other input is a JSON file (addresses-globals.json) with global static variables, called "globs" below. The output is plain GML according to the XSD http://inspire.ec.europa.eu/schemas/ad/3.0/Addresses.xsd to which the output also validates. Note the verbosity: a one-line CSV address expands to 100 lines/elements of uncommented GML #} {# Macro's, a very powerful reuse mechanism, e.g. for common elements and structures like INSPIRE id and GeographicalName's. #} {% import 'templates/macros-inspire.jinja2' as macros_inspire %} 0 {{ globs.namespace }} {# Tracking for Address components that should appear only once, as they are xlinked as AD:component-s #} {% set cities = {} %} {% set streets = {} %} {% set postal_codes = {} %} {% for address in addresses %} {{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.Address.{{ address.address_id }} {{ macros_inspire.render_inspire_id(globs.namespace, address.address_id) }} {{ address.lat }} {{ address.lon }} entrance byOtherParty true {# In the Netherlands a house number is always required #} {{ address.house_number }} {{ globs.locator_designator.house_number }} {% if address.house_letter %} {{ address.house_letter }} {{ globs.locator_designator.house_letter }} {% endif %} {% if address.house_number_add %} {{ address.house_number_add }} {{ globs.locator_designator.house_number_add }} {% endif %} unitLevel {{ globs.valid_from }} {% if streets[address.street_id] is not defined %} {# Each street (BAG id) may appear only once within the Spatial Dataset. Track the unique street id in a map (dict) and check below to add only once. #} {% do streets.update({address.street_id:address.street_id}) %} {{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.ThoroughfareName.{{ address.street_id }} {{ macros_inspire.render_inspire_id(globs.namespace, address.street_id) }} {{ globs.valid_from }} {{ macros_inspire.render_geographical_name(address.street_name, globs.geographical_name) }} {% endif %} {% if cities[address.city_id] is not defined %} {# Each city may appear only once within the Spatial Dataset. Track the unique city id in a map (dict) and check below to add only once. #} {% do cities.update({address.city_id:address.city_id}) %} {{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.AddressAreaName.{{ address.city_id }} {{ macros_inspire.render_inspire_id(globs.namespace, address.city_id) }} {{ globs.valid_from }} {{ macros_inspire.render_geographical_name(address.city_name, globs.geographical_name) }} {% endif %} {% if postal_codes[address.postal_code] is not defined %} {# Each postal code (NL Postcode) may appear only once within the Spatial Dataset. Track the unique posatl codes id in a map (dict) and check below to add only once. #} {% do postal_codes.update({address.postal_code:address.postal_code}) %} {{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.PostalDescriptor.{{ address.postal_code }} {{ macros_inspire.render_inspire_id(globs.namespace, address.postal_code) }} {{ globs.valid_from }} {{ address.postal_code }} {% endif %} {% endfor %}