import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))

import csv
from gml_templating_lib import render_gml_from_IMAERtemplate, IMAERgeometry

data = {}

old_gmlId = 'a bogus string which will be never ased as an id'
data['featureMembers'] = []

with open('example.csv', 'rt') as csvFile:
    reader = csv.DictReader(csvFile)
    for row in reader:
        if not old_gmlId == row['gmlId']:
            # add a complete new featureMember
            old_gmlId = row['gmlId']
            data['featureMembers'].append({
                'gmlId': row['gmlId'],
                'cp_label': row['cp_label'],
                'geometry': str(IMAERgeometry(row['WKT'],row['gmlId'], isCalculationPoint = True))
            })
        else:
            # should not happen
            pass

output = render_gml_from_IMAERtemplate(".", "feature_members_template.gml", **data).strip()
with open('result_modified.gml','wt') as gmlFile:
    gmlFile.write(output)
print output
示例#2
0
                'label':
                row['label'],
                'geometry':
                str(IMAERgeometry(row['WKT'], row['gmlId'])),
                'offRoadMobileSources': [{
                    'offRoadMobileSourceType':
                    row['offRoadMobileSourceType'],
                    'description':
                    row['description'],
                    'literFuelPerYear':
                    row['literFuelPerYear']
                }]
            })
        else:
            # add an inlandShipping to the last featureMember
            # this assumes that the data in the csv file is ordered bu gmlId
            data['featureMembers'][-1]['offRoadMobileSources'].append({
                'offRoadMobileSourceType':
                row['offRoadMobileSourceType'],
                'description':
                row['description'],
                'literFuelPerYear':
                row['literFuelPerYear']
            })

output = render_gml_from_IMAERtemplate(".", "feature_members_template.gml",
                                       **data).strip()
with open('result_modified.gml', 'wt') as gmlFile:
    gmlFile.write(output)
print output