-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB2d_XML2.py
222 lines (208 loc) · 16.8 KB
/
B2d_XML2.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 3 09:15:57 2016
@author: Standard
"""
def xml(A,title, abstract,data_type,North,East,South,West,Depth1,Depth2,T1,T2,Creation_date,subject_Study, project_Phase, location, variables, format1, quality,process, use_lim,access,citation, resource_contact, owner1, owner2, distributor, name):
from lxml import etree
from copy import deepcopy
import csv
with open('Contact.csv', 'r') as f:
reader = csv.reader(f, delimiter=';')
contact_list = list(reader)
#Changement de direction
from os import chdir
import matplotlib.pyplot as plt
# Les variables sont chargés via le formulaire développé dans test5_widget.py
# Le chargement
#Analyser le fichier xml pour remplacer les attributs voulus
doc=etree.parse('Metadata_template3.xml')
root=doc.getroot()
tree = etree.ElementTree(root)
for e in root.iter():
if tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString":
POC_Organisation_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint/gco:CharacterString":
POC_Adress_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city/gco:CharacterString":
POC_City_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode/gco:CharacterString":
POC_Postalcode_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress/gco:CharacterString":
POC_email_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:country/gco:CharacterString":
POC_Country_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:dateStamp/gco:DateTime":
Creation_date_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:referenceSystemInfo/gmd:MD_ReferenceSystem/gmd:referenceSystemIdentifier/gmd:RS_Identifier/gmd:code/gco:CharacterString":
reference_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString":
Title_xml=e
# elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:DateTime":
# creationdate??
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString":
Abstract_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:organisationName/gco:CharacterString":
OW1_Organisation_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint/gco:CharacterString":
OW1_Adress_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city/gco:CharacterString":
OW1_City_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode/gco:CharacterString":
OW1_Postalcode_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:country/gco:CharacterString":
OW1_Country_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[1]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress/gco:CharacterString":
OW1_email_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]":
OW1_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:organisationName/gco:CharacterString":
OW2_Organisation_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint/gco:CharacterString":
OW2_Adress_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city/gco:CharacterString":
OW2_City_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode/gco:CharacterString":
OW2_Postalcode_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:country/gco:CharacterString":
OW2_Country_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[1]/gmd:CI_ResponsibleParty[2]/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress/gco:CharacterString":
OW2_email_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString":
D_Organisation_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint/gco:CharacterString":
D_Adress_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city/gco:CharacterString":
D_City_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode/gco:CharacterString":
D_Postalcode_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:country/gco:CharacterString":
D_Country_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:pointOfContact[2]/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress/gco:CharacterString":
D_email_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[1]/gmd:MD_Keywords/gmd:keyword":
subject_study0_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[1]/gmd:MD_Keywords/gmd:keyword/gco:CharacterString":
subject_study_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[2]/gmd:MD_Keywords/gmd:keyword":
project_phase0_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[2]/gmd:MD_Keywords/gmd:keyword/gco:CharacterString":
project_phase_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[3]/gmd:MD_Keywords/gmd:keyword/gco:CharacterString":
location_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[3]/gmd:MD_Keywords/gmd:keyword":
location0_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[4]/gmd:MD_Keywords/gmd:keyword":
variable0_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords[4]/gmd:MD_Keywords/gmd:keyword/gco:CharacterString":
variable_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:useLimitation/gco:CharacterString":
Use_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[1]/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition":
Date1_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[1]/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition":
Date2_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[2]/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:minimumValue/gco:Real":
Depth1_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[2]/gmd:EX_Extent/gmd:verticalElement/gmd:EX_VerticalExtent/gmd:maximumValue/gco:Real":
Depth2_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[3]/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal":
West_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[3]/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal":
East_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[3]/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal":
South_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent[3]/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal":
North_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:distributionInfo/gmd:MD_Distribution/gmd:distributionFormat/gmd:MD_Format/gmd:name":
format0_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:distributionInfo/gmd:MD_Distribution/gmd:distributionFormat/gmd:MD_Format/gmd:name/gco:CharacterString":
format1_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:dataQualityInfo[1]/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:statement/gco:CharacterString":
Quality_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:dataQualityInfo[1]/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:processStep/gmd:LI_ProcessStep/gmd:description/gco:CharacterString":
Process_step_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:dataQualityInfo[1]/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:processStep/gmd:LI_ProcessStep/gmd:source/gmd:LI_Source/gmd:description/gco:CharacterString":
Citation_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:dataQualityInfo[1]/gmd:DQ_DataQuality/gmd:scope/gmd:DQ_Scope/gmd:level/gmd:MD_ScopeCode":
datatype_xml=e
elif tree.getpath(e)=="/gmd:MD_Metadata/gmd:identificationInfo/gmd:MD_DataIdentification/gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:accessConstraints/gmd:MD_RestrictionCode":
access_xml=e
print( POC_Organisation_xml.text, POC_City_xml.text,POC_Postalcode_xml.text,POC_email_xml.text,POC_Country_xml.text,Creation_date_xml.text,reference_xml.text,Title_xml.text,Abstract_xml.text,D_Organisation_xml.text,D_Adress_xml.text, D_City_xml.text,D_Postalcode_xml.text,D_Country_xml.text,D_email_xml.text,OW1_Organisation_xml.text,OW1_Adress_xml.text,OW1_City_xml.text,OW1_Postalcode_xml.text,OW1_Country_xml.text,OW1_email_xml.text,OW2_Organisation_xml.text,OW2_City_xml.text,OW2_Postalcode_xml.text,OW2_Country_xml.text,OW2_email_xml.text,subject_study_xml.text,project_phase_xml.text,location_xml.text,variable_xml.text,Use_xml.text,Date1_xml.text,Date2_xml.text,Depth1_xml.text,Depth2_xml.text,West_xml.text,East_xml.text,South_xml.text, North_xml.text,format1_xml.text,Quality_xml.text,Process_step_xml.text,Citation_xml.text,datatype_xml.attrib['codeListValue'],access_xml.attrib['codeListValue'])
#Remplisage du fichier xml pour chaque donnée
Title_xml.text=title
Abstract_xml.text=abstract
root[10][0][0][0][0][0].attrib['codeListValue']=data_type
North_xml.text=str(North)
East_xml.text=str(East)
South_xml.text=str(South)
West_xml.text=str(West)
Depth1_xml.text=str(Depth1)
Depth2_xml.text=str(Depth2)
Date1_xml.text=T1
Date2_xml.text=T2
Creation_date_xml.text=Creation_date
Len_su=len(subject_Study)
subject_study_xml.text=subject_Study[0]
if Len_su>1:
for i in range(0, Len_su-1):
subject_study0_xml.getparent()[i].addnext(deepcopy(subject_study0_xml))
subject_study0_xml.getparent()[i+1][0].text=subject_Study[i+1]
Len_pro=len(project_Phase)
project_phase_xml.text=project_Phase[0]
if Len_pro>1:
for i in range(0, Len_pro-1):
project_phase0_xml.getparent()[i].addnext(deepcopy(project_phase0_xml))
project_phase0_xml.getparent()[i+1][0].text=project_Phase[i+1]
Len_loc=len(location)
location_xml.text=location[0]
if Len_loc>1:
for i in range(0, Len_loc-1):
location0_xml.getparent()[i].addnext(deepcopy(location0_xml))
location0_xml.getparent()[i+1][0].text=location[i+1]
Len_var=len(variables)
variable_xml.text=variables[0]
if Len_var>1:
for i in range(0, Len_var-1):
variable0_xml.getparent()[i].addnext(deepcopy(variable0_xml))
variable0_xml.getparent()[i+1][0].text=variables[i+1]
Len_for=len(format1)
format1_xml
format1_xml.text=format1[0]
if Len_var>1:
for i in range(0, Len_for-1):
format0_xml.getparent()[i].addnext(deepcopy(format0_xml))
format0_xml.getparent()[i+1][0].text=format1[i+1]
else:
format1_xml.text=format1[0]
Quality_xml.text=quality
Process_step_xml.text=process
Use_xml.text=use_lim
access_xml.attrib['codeListValue']=access
Citation_xml.text=citation
condition_contact(resource_contact,POC_Organisation_xml,POC_Adress_xml, POC_City_xml,POC_Postalcode_xml , POC_Country_xml, POC_email_xml, contact_list)
condition_contact(distributor,D_Organisation_xml,D_Adress_xml, D_City_xml,D_Postalcode_xml , D_Country_xml, D_email_xml, contact_list)
condition_contact(owner1,OW1_Organisation_xml,OW1_Adress_xml, OW1_City_xml,OW2_Postalcode_xml , OW1_Country_xml, OW1_email_xml, contact_list)
condition_contact(owner2, OW2_Organisation_xml,OW2_Adress_xml, OW2_City_xml,OW2_Postalcode_xml , OW2_Country_xml, OW2_email_xml, contact_list)
if owner2==0:
OW1_xml.remove(OW1_xml[1])
if owner1==0:
OW1_xml.remove(OW1_xml[0])
doc.write('%s' %name, xml_declaration=True)
def condition_contact(type_contact, organisation, adress, city, post_code, country, mail, contact_list):
if type_contact=='EOST/ IPGS':
variable=1
elif type_contact=='BRGM':
variable=2
elif type_contact=='Es Géothermie':
variable=3
elif type_contact=='GEIE':
variable=4
else:
return
organisation.text=contact_list[variable][0]
adress.text=contact_list[variable][1]
city.text=contact_list[variable][3]
post_code.text=contact_list[variable][2]
country.text=contact_list[variable][4]
mail.text=contact_list[variable][5]