<?xml version='1.0' encoding='utf-8'?>
<cities:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xmlns:cities="http://cities.maptools.org/"
                       xmlns:gml="http://www.opengis.net/gml"
                       xsi:schemaLocation="http://cities.maptools.org/ ../gmlcities.xsd  http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd">

    <!--
    Generated with a Jinja2 template. The 'globs' variables come from the file globals.json containing global
    variables/structures. The actual/dynamic data (cities) comes from the input CSV file cities.json.
    Also a file with macros templates/macros.tpl.xml is imported, allowing reuse for common structures like INSPIRE id's.
    -->


    {#  Show the use of globals, more or less static content. #}
    <gml:description>
       {{ globs.description }}
    </gml:description>

    {#  Show the use of macro's, a very powerful reuse mechanism, e.g. for common elements and structures like INSPIRE id. #}
    {% import 'templates/macros.jinja2' as macros %}

    {# {{ macros.render_element('gml:description', globs.description) }} #}

    {{ macros.render_name(globs.name) }}


    <!-- bbox present in geojson input -->
    <gml:boundedBy>
        <gml:Box>
            <gml:coord>
                <gml:X>{{ bbox[0] }}</gml:X>
                <gml:Y>{{ bbox[1] }}</gml:Y>
            </gml:coord>
            <gml:coord>
                <gml:X>{{ bbox[2] }}</gml:X>
                <gml:Y>{{ bbox[3] }}</gml:Y>
            </gml:coord>
        </gml:Box>
    </gml:boundedBy>

    {% for feature in features %}
        <gml:featureMember>
            <cities:City>
                <cities:name>{{ feature.properties.CITY_NAME }}</cities:name>
                {#  get population from reference data in globals struct #}
                <cities:population>{{ refdata.city_population[feature.properties.CITY_NAME] }}</cities:population>
                <cities:geometry>
                    {# Generate gml id #}
                    {% set gml_id = 'point-%d' % loop.index %}
                    {# Generate a Point (or any other) GML geometry from a GeoJSON geometry using the geojson2gml
                       Jinja2 custom Filter.
                        By specifying a target_crs we can even reproject from the source CRS.
                       The gml_format=GML2|GML3 determines the general GML form: e.g. pos/posList or coordinates. gml_longsrs=YES|NO
                       determines the srsName format like EPSG:4326 or urn:ogc:def:crs:EPSG::4326 (long).
                    #}
                    {{ feature.geometry | geojson2gml(source_crs=crs, target_crs=4258, gml_id=gml_id, gml_format='GML3', gml_longsrs='YES') }}
                </cities:geometry>
            </cities:City>
        </gml:featureMember>
    {% endfor %}

</cities:FeatureCollection>
