File: cities-gjson2gml.jinja2

package info (click to toggle)
python-stetl 1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 89,988 kB
  • sloc: python: 5,007; xml: 707; sql: 430; makefile: 155; sh: 50
file content (62 lines) | stat: -rw-r--r-- 2,901 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?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>