-
Notifications
You must be signed in to change notification settings - Fork 0
/
GEO6_map_production.py
313 lines (274 loc) · 11.4 KB
/
GEO6_map_production.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import arcpy
beginTime = time.clock()
#set to overwrite existing outputs
arcpy.env.overwriteOutput = True
#list workspaces for inputs and outputs
myWorkspace=r"C:\Data\GEO6\Final_Maps\Africa"
arcpy.env.workspace = myWorkspace
############################################################
#Create lists of layers in current data frame
mxd = arcpy.mapping.MapDocument('CURRENT')
for df in arcpy.mapping.ListDataFrames(mxd):
if (df.name=='Layers'):
layers=arcpy.mapping.ListLayers(mxd,"*", df)
#for layer in layers:
# if layer not in NonList:
# LayerList.append(layer)
layers=layers[1:17]
#State output path
outPath = "C:/Data/GEO6/Final_Maps/Africa"
#Eulayer=arcpy.mapping.ListLayers(mxd,"Europe", df)
#Retrieve the symbology from existing layer files:
#Create path to each layer file:
#Build loop to change the names of the raster layers
for layer in layers:
if layer.name == str("MODIS_VCF_2010_clean_scaled"):
newname = str("Tree cover (%)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Mines_all_prosp"):
newname = str("Count of early-stage development mines")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Mines_all_futur"):
newname = str("Count of late-stage development mines")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Mines_all_curre"):
newname = str("Count of current mines")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("GPWv4_0"):
newname = str("Human population density (persons per km sq)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Fields_all_over"):
newname = str("Area of overlap of future and current fields (oil&gas)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Fields_all_futu"):
newname = str("Area of future fields (oil&gas)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Fields_all_curr"):
newname = str("Area of current fields (oil&gas)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("all_oil_gas_pip"):
newname = str("Length of pipelines (oil&gas)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("AbovegroundBiomassCarbon_Lay1_halfd_sumi"):
newname = str("Total Above Ground Biomass Carbon (ha)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("Wat_yield_NC"):
newname = str("Freshwater resources (mm)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("sprich_mab"):
newname = str("Species richness: mammals, amphibians, birds (number of species)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("rrarity_mab_avg"):
newname = str("Mean range-size rarity: mammals, amphibians and birds")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("glues_cropsuit_recent_1981_2010_halfdeg"):
newname = str("Current agricultural suitability (1981-2010)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("glues_cropsuit_future_2011_2040_halfdeg"):
newname = str("Future agricultural suitability (2011-2040)")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
for layer in layers:
if layer.name == str("all_rast_future_dev_corr_infr_binary"):
newname = str("Future development corridors")
layer.name = newname
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
#update their symbology:
#Create new list of layers with their new names
for df in arcpy.mapping.ListDataFrames(mxd):
if (df.name=='Layers'):
layers=arcpy.mapping.ListLayers(mxd,"*", df)
#for layer in layers:
# if layer not in NonList:
# LayerList.append(layer)
layers=layers[1:17]
print layers
#Source layer files
lyrFile1 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Total Above Ground Biomass Carbon (ha).lyr")
lyrFile2 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Length of pipelines (oil&gas).lyr")
lyrFile3 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Area of current fields (oil&gas).lyr")
lyrFile4 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Area of overlap of future and current fields (oil&gas).lyr")
lyrFile5 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Count of late-stage development mines.lyr")
lyrFile6 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Count of future mines.lyr")
lyrFile7 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Count of early-stage development mines.lyr")
lyrFile8 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Human population density (persons per km sq).lyr")
lyrFile9 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Tree cover (%).lyr")
lyrFile10 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Area of future fields (oil&gas).lyr")
lyrFile11 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Mean range-size rarity for mammals, amphibians and birds.lyr")
lyrFile12 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Future agricultural suitability (2011-2040).lyr")
lyrFile13 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Current agricultural suitability (1981-2010).lyr")
lyrFile14 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Future development corridors.lyr")
lyrFile15 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Species richness of mammals, amphibians and birds (number of species).lyr")
lyrFile16 = arcpy.mapping.Layer(r"C:\Data\GEO6\Final_Maps\Template_design\Freshwater resources (mm).lyr")
# update the symbology of re-named rasters with the layer files
df = arcpy.mapping.ListDataFrames(mxd)[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "Total*", df)
sourceLayer = lyrFile1
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Length*", df)
sourceLayer = lyrFile2
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Area of current*", df)
sourceLayer = lyrFile3
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Area of overlap*", df)
sourceLayer = lyrFile4
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Count of current*", df)
sourceLayer = lyrFile5
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Count of future*", df)
sourceLayer = lyrFile6
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Count of prospective*", df)
sourceLayer = lyrFile7
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Human population*", df)
sourceLayer = lyrFile8
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Tree*", df)
sourceLayer = lyrFile9
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Area of future*", df)
sourceLayer = lyrFile10
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Mean range-size*", df)
sourceLayer = lyrFile11
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Future agricultural*", df)
sourceLayer = lyrFile12
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Current agricultural*", df)
sourceLayer = lyrFile13
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Future development*", df)
sourceLayer = lyrFile14
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Species richness*", df)
sourceLayer = lyrFile15
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
updateLayer = arcpy.mapping.ListLayers(mxd, "Freshwater resources*", df)
sourceLayer = lyrFile16
for lyr in updateLayer:
arcpy.mapping.UpdateLayer(df, lyr, sourceLayer)
print lyr, "symbology updated"
#========================================================================================================================================
#set to overwrite existing outputs
arcpy.env.overwriteOutput = True
import arcpy
import os
import time
#list workspaces for inputs and outputs
arcpy.env.overwriteOutput = True
#list workspaces for inputs and outputs
#myWorkspace="C:/Data/GEO6/Final_Maps/EU"
arcpy.env.workspace = "C:/Data/GEO6/Final_Maps/Africa"
#Define outpath
outPath = "C:/Data/GEO6/Final_Maps/Africa"
#Set the mxd:
mxd = arcpy.mapping.MapDocument("C:/Data/GEO6/Final_Maps/Africa/Africa.mxd")
#Create a fresh layer list
for df in arcpy.mapping.ListDataFrames(mxd):
if (df.name=='Layers'):
layers=arcpy.mapping.ListLayers(mxd,"*", df)
#Export the maps:
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print "Exporting maps for each layer"
for layer in layers:
if layer.name=='Africa' or layer.name=='Other countries':
layer.visible=True
else:
layer.visible=False
layer.visible=True
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
out_png=outPath + "/test"+ str(layer)+".png"
try:
print out_png
arcpy.mapping.ExportToPNG(mxd,out_png,resolution=600)
arcpy.mapping.ExportToPDF(mxd,out_png,resolution=600)
print "printing to file", layer
except:
print 'failed to write map'
pass
layer.visible=False
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
#del (mxd)
print "Finished processing"
print("Total elapsed time (minutes): " + str((time.clock() - beginTime)/60))