| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
{# |
| 3 |
This is a Jinja2 template for generating one of the most complex INSPIRE Schema's: Annex I Addresses specified in |
| 4 |
http://inspire.jrc.ec.europa.eu/documents/Data_Specifications/INSPIRE_DataSpecification_AD_v3.1.pdf |
| 5 |
The GML Application Schema is complex and verbose, but the actual required input is quite small. |
| 6 |
At a minimum just 4 variables for a complete address: street, house number, postal code, city plus a point (lat,lon) |
| 7 |
for each address. This makes Templating so powerful. The input in Stetl are both records (an array of records (dict's) |
| 8 |
called "addresses" originating from a CSV (here addresses.csv) or possibly some database records. The other input is a |
| 9 |
JSON file (addresses-globals.json) with global static variables, called "globs" below. The output is plain GML according to |
| 10 |
the XSD http://inspire.ec.europa.eu/schemas/ad/3.0/Addresses.xsd to which the output also validates. Note the verbosity: |
| 11 |
a one-line CSV address expands to 100 lines/elements of uncommented GML |
| 12 |
#} |
| 13 |
|
| 14 |
{# Macro's, a very powerful reuse mechanism, e.g. for common elements and structures like INSPIRE id and GeographicalName's. #} |
| 15 |
{% import 'templates/macros-inspire.jinja2' as macros_inspire %} |
| 16 |
|
| 17 |
<base:SpatialDataSet xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2" |
| 18 |
xmlns:AD="urn:x-inspire:specification:gmlas:Addresses:3.0" |
| 19 |
xmlns:GN="urn:x-inspire:specification:gmlas:GeographicalNames:3.0" |
| 20 |
xmlns:gmd="http://www.isotc211.org/2005/gmd" |
| 21 |
xmlns:xlink="http://www.w3.org/1999/xlink" |
| 22 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 23 |
xmlns:gml="http://www.opengis.net/gml/3.2" |
| 24 |
xsi:schemaLocation="urn:x-inspire:specification:gmlas:BaseTypes:3.2 http://inspire.ec.europa.eu/schemas/base/3.2/BaseTypes.xsd |
| 25 |
urn:x-inspire:specification:gmlas:Addresses:3.0 http://inspire.ec.europa.eu/schemas/ad/3.0/Addresses.xsd |
| 26 |
urn:x-inspire:specification:gmlas:GeographicalNames:3.0 http://inspire.ec.europa.eu/schemas/gn/3.0/GeographicalNames.xsd" |
| 27 |
gml:id="{{ globs.namespace }}"> |
| 28 |
<base:identifier> |
| 29 |
<base:Identifier> |
| 30 |
<base:localId>0</base:localId> |
| 31 |
<base:namespace>{{ globs.namespace }}</base:namespace> |
| 32 |
</base:Identifier> |
| 33 |
</base:identifier> |
| 34 |
<base:metadata xsi:nil="true"/> |
| 35 |
{# Tracking for Address components that should appear only once, as they are xlinked as AD:component-s #} |
| 36 |
{% set cities = {} %} |
| 37 |
{% set streets = {} %} |
| 38 |
{% set postal_codes = {} %} |
| 39 |
|
| 40 |
{% for address in addresses %} |
| 41 |
<base:member> |
| 42 |
<AD:Address gml:id="{{ globs.namespace }}.Address.{{ address.address_id }}"> |
| 43 |
<gml:identifier |
| 44 |
codeSpace="{{ globs.inspire_codespace_uri }}">{{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.Address.{{ address.address_id }}</gml:identifier> |
| 45 |
<AD:inspireId> |
| 46 |
{{ macros_inspire.render_inspire_id(globs.namespace, address.address_id) }} |
| 47 |
</AD:inspireId> |
| 48 |
<AD:position> |
| 49 |
<AD:GeographicPosition> |
| 50 |
<AD:geometry> |
| 51 |
<gml:Point gml:id="{{ globs.namespace }}.Address.{{ address.address_id }}_P" |
| 52 |
srsName="{{ globs.srs_name }}"> |
| 53 |
<gml:pos>{{ address.lat }} {{ address.lon }}</gml:pos> |
| 54 |
</gml:Point> |
| 55 |
</AD:geometry> |
| 56 |
<AD:specification>entrance</AD:specification> |
| 57 |
<AD:method>byOtherParty</AD:method> |
| 58 |
<AD:default>true</AD:default> |
| 59 |
</AD:GeographicPosition> |
| 60 |
</AD:position> |
| 61 |
<AD:locator> |
| 62 |
<AD:AddressLocator> |
| 63 |
{# In the Netherlands a house number is always required #} |
| 64 |
<AD:designator> |
| 65 |
<AD:LocatorDesignator> |
| 66 |
<AD:designator>{{ address.house_number }}</AD:designator> |
| 67 |
<AD:type>{{ globs.locator_designator.house_number }}</AD:type> |
| 68 |
</AD:LocatorDesignator> |
| 69 |
</AD:designator> |
| 70 |
{% if address.house_letter %} |
| 71 |
<!-- Optional House Letter Addition, e.g. "Huisletter" in The Netherlands --> |
| 72 |
<AD:designator> |
| 73 |
<AD:LocatorDesignator> |
| 74 |
<AD:designator>{{ address.house_letter }}</AD:designator> |
| 75 |
<AD:type>{{ globs.locator_designator.house_letter }}</AD:type> |
| 76 |
</AD:LocatorDesignator> |
| 77 |
</AD:designator> |
| 78 |
{% endif %} |
| 79 |
{% if address.house_number_add %} |
| 80 |
<!-- Optional House Number Addition, e.g. Floornumber "Huisnummertoevoeging" in The Netherlands --> |
| 81 |
<AD:designator> |
| 82 |
<AD:LocatorDesignator> |
| 83 |
<AD:designator>{{ address.house_number_add }}</AD:designator> |
| 84 |
<AD:type>{{ globs.locator_designator.house_number_add }}</AD:type> |
| 85 |
</AD:LocatorDesignator> |
| 86 |
</AD:designator> |
| 87 |
{% endif %} |
| 88 |
<AD:level>unitLevel</AD:level> |
| 89 |
</AD:AddressLocator> |
| 90 |
</AD:locator> |
| 91 |
<AD:validFrom>{{ globs.valid_from }}</AD:validFrom> |
| 92 |
<AD:validTo xsi:nil="true" nilReason="other:unpopulated"/> |
| 93 |
|
| 94 |
<AD:beginLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 95 |
<AD:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 96 |
<!-- Inline reference to address components: street (ThoroughfareName_, city (AddressAreaName) |
| 97 |
and postal code (PostalDescriptor) --> |
| 98 |
<AD:component xmlns:xlink="http://www.w3.org/1999/xlink" |
| 99 |
xlink:href="#{{ globs.namespace }}.ThoroughfareName.{{ address.street_id }}"/> |
| 100 |
<AD:component xmlns:xlink="http://www.w3.org/1999/xlink" |
| 101 |
xlink:href="#{{ globs.namespace }}.AddressAreaName.{{ address.city_id }}"/> |
| 102 |
<AD:component xmlns:xlink="http://www.w3.org/1999/xlink" |
| 103 |
xlink:href="#{{ globs.namespace }}.PostalDescriptor.{{ address.postal_code }}"/> |
| 104 |
</AD:Address> |
| 105 |
</base:member> |
| 106 |
{% if streets[address.street_id] is not defined %} |
| 107 |
{# Each street (BAG id) may appear only once within the Spatial Dataset. |
| 108 |
Track the unique street id in a map (dict) and check below to add only once. #} |
| 109 |
{% do streets.update({address.street_id:address.street_id}) %} |
| 110 |
|
| 111 |
<base:member> |
| 112 |
<AD:ThoroughfareName gml:id="{{ globs.namespace }}.ThoroughfareName.{{ address.street_id }}"> |
| 113 |
<gml:identifier codeSpace="{{ globs.inspire_codespace_uri }}"> |
| 114 |
{{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.ThoroughfareName.{{ address.street_id }} |
| 115 |
</gml:identifier> |
| 116 |
<AD:inspireId> |
| 117 |
{{ macros_inspire.render_inspire_id(globs.namespace, address.street_id) }} |
| 118 |
</AD:inspireId> |
| 119 |
<AD:beginLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 120 |
<AD:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 121 |
<AD:validFrom>{{ globs.valid_from }}</AD:validFrom> |
| 122 |
<AD:validTo xsi:nil="true" nilReason="other:unpopulated"/> |
| 123 |
<AD:name> |
| 124 |
<AD:ThoroughfareNameValue> |
| 125 |
<AD:name> |
| 126 |
{{ macros_inspire.render_geographical_name(address.street_name, globs.geographical_name) }} |
| 127 |
</AD:name> |
| 128 |
</AD:ThoroughfareNameValue> |
| 129 |
</AD:name> |
| 130 |
</AD:ThoroughfareName> |
| 131 |
</base:member> |
| 132 |
{% endif %} |
| 133 |
{% if cities[address.city_id] is not defined %} |
| 134 |
{# Each city may appear only once within the Spatial Dataset. |
| 135 |
Track the unique city id in a map (dict) and check below to add only once. #} |
| 136 |
{% do cities.update({address.city_id:address.city_id}) %} |
| 137 |
<base:member> |
| 138 |
<AD:AddressAreaName gml:id="{{ globs.namespace }}.AddressAreaName.{{ address.city_id }}"> |
| 139 |
<gml:identifier codeSpace="{{ globs.inspire_codespace_uri }}"> |
| 140 |
{{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.AddressAreaName.{{ address.city_id }} |
| 141 |
</gml:identifier> |
| 142 |
<AD:inspireId> |
| 143 |
{{ macros_inspire.render_inspire_id(globs.namespace, address.city_id) }} |
| 144 |
</AD:inspireId> |
| 145 |
<AD:beginLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 146 |
<AD:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 147 |
<AD:validFrom>{{ globs.valid_from }}</AD:validFrom> |
| 148 |
<AD:validTo xsi:nil="true" nilReason="other:unpopulated"/> |
| 149 |
<AD:name> |
| 150 |
{{ macros_inspire.render_geographical_name(address.city_name, globs.geographical_name) }} |
| 151 |
</AD:name> |
| 152 |
<AD:namedPlace xsi:nil="true" nilReason="other:unpopulated"/> |
| 153 |
</AD:AddressAreaName> |
| 154 |
</base:member> |
| 155 |
{% endif %} |
| 156 |
|
| 157 |
{% if postal_codes[address.postal_code] is not defined %} |
| 158 |
{# Each postal code (NL Postcode) may appear only once within the Spatial Dataset. |
| 159 |
Track the unique posatl codes id in a map (dict) and check below to add only once. #} |
| 160 |
{% do postal_codes.update({address.postal_code:address.postal_code}) %} |
| 161 |
<base:member> |
| 162 |
<AD:PostalDescriptor gml:id="{{ globs.namespace }}.PostalDescriptor.{{ address.postal_code }}"> |
| 163 |
<gml:identifier codeSpace="{{ globs.inspire_codespace_uri }}"> |
| 164 |
{{ globs.inspire_urn_prefix_id }}:{{ globs.namespace }}.PostalDescriptor.{{ address.postal_code }} |
| 165 |
</gml:identifier> |
| 166 |
<AD:inspireId> |
| 167 |
{{ macros_inspire.render_inspire_id(globs.namespace, address.postal_code) }} |
| 168 |
</AD:inspireId> |
| 169 |
<AD:beginLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 170 |
<AD:endLifespanVersion xsi:nil="true" nilReason="other:unpopulated"/> |
| 171 |
<AD:validFrom>{{ globs.valid_from }}</AD:validFrom> |
| 172 |
<AD:validTo xsi:nil="true" nilReason="other:unpopulated"/> |
| 173 |
<AD:postCode>{{ address.postal_code }}</AD:postCode> |
| 174 |
</AD:PostalDescriptor> |
| 175 |
</base:member> |
| 176 |
{% endif %} |
| 177 |
{% endfor %} |
| 178 |
|
| 179 |
</base:SpatialDataSet> |