-
Notifications
You must be signed in to change notification settings - Fork 25
/
create_prior.py
1338 lines (980 loc) · 48.5 KB
/
create_prior.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import geokit as gk
import numpy as np
from os.path import join, isdir, isfile, basename, splitext
from os import mkdir
import sys
from multiprocessing import Pool
import time
from datetime import datetime as dt
from glob import glob
from collections import namedtuple, OrderedDict
from json import dumps
#################################################################
## DEFINE SOURCES
clcSource="/home/s.ryberg/data/zena_data/CLC/g100_clc12_V18_5_SRS_FIX.tif"
waterbodySource="/home/s.ryberg/data/COPERNICUS/20/l6_pwb_eur_20m_full01_100_fin06.tif"
urbanClustersSource="/home/s.ryberg/data/EUROSTAT/Urban_Clusters/URB_CLST_2011.tif"
airportsSource = "/home/s.ryberg/data/EUROSTAT/Airports/AIRP_PT_2013.shp"
osmRailwaysSource = "/home/s.ryberg/data/OSM/geofabrik/railways/","*gis.osm_railways*.shp"
osmRoadsSource = "/home/s.ryberg/data/OSM/geofabrik/roads/","*gis.osm_roads*.shp"
osmPowerlinesSource = "/home/s.ryberg/data/OSM/osm2shp/power_ln/power_ln_europe_clip.shp"
riverSegmentsSource = "/home/s.ryberg/data/EUROSTAT/rivers_and_catchments/data/","*Riversegments.shp"
hydroLakesSource = "/home/s.ryberg/data/WWF/HydroLAKES_polys_v10.shp"
wdpaSource = "/home/s.ryberg/data/protected/WDPA/WDPA_Apr2017-shapefile/clipped","*.shp"
demSource = "/home/s.ryberg/data/zena_data/DEM/eudem_dem_4258_europe.tif"
gwaSource = "/home/s.ryberg/data/global_wind_atlas/WS_%03dm_global_wgs84_mean_trimmed.tif"
dniSource = "/home/s.ryberg/data/global_solar_atlas/World_DNI_GISdata_LTAy_DailySum_GlobalSolarAtlas_GEOTIFF/DNI.tif"
ghiSource = "/home/s.ryberg/data/global_solar_atlas/World_GHI_GISdata_LTAy_DailySum_GlobalSolarAtlas_GEOTIFF/GHI.tif"
##################################################################
## DEFINE EDGES
EVALUATION_VALUES = {
"woodland_mixed_proximity":
# Indicates distances too close to mixed-tree forests (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"woodland_coniferous_proximity":
# Indicates distances too close to coniferous forests (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"woodland_deciduous_proximity":
# Indicates distances too close to deciduous forests(m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"waterbody_proximity":
# Indicates distances too close to lakes (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"lake_proximity":
# Indicates distances too close to lakes (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"river_proximity":
# Indicates distances too close to rivers (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"ocean_proximity":
# Indicates distances too close to oceans (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000, 10000, 15000, 20000],
"wetland_proximity":
# Indicates distances too close to wetlands (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"elevation_threshold":
# Indicates elevations above X (m)
np.linspace(-1000, 3000, 41),
"slope_threshold":
# Indicates slopes above X (degree)
np.linspace(0, 30, 61),
"slope_north_facing_threshold":
# Indicates north-facing slopes above X (degree)
np.linspace(-20, 20, 81),
"power_line_proximity":
# Indicates distances too close to power-lines (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000,
6000, 7000, 8000, 9000, 10000, 12000, 14000, 16000, 18000, 20000, 25000, 30000, 35000, 40000, 45000, 50000],
"roads_main_proximity":
# Indicates distances too close to main roads (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2250, 2500, 2750, 3000,
3500, 4000, 4500, 5000, 6000, 7000, 8000, 10000, 12000, 14000, 16000, 18000, 20000],
"roads_secondary_proximity":
# Indicates distances too close to secondary roads (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2250, 2500, 2750, 3000,
3500, 4000, 4500, 5000, 6000, 7000, 8000, 10000, 12000, 14000, 16000, 18000, 20000],
"roads_proximity":
# Indicates distances too close to all accissible roads (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2250, 2500, 2750, 3000,
3500, 4000, 4500, 5000, 6000, 7000, 8000, 10000, 12000, 14000, 16000, 18000, 20000],
"railway_proximity":
# Indicates distances too close to railways (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000,
6000, 7000, 8000, 9000, 10000, 12000, 14000, 16000, 18000, 20000],
"settlement_urban_proximity":
# Indicates distances too close to dense settlements (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000,
2200, 2400, 2600, 2800, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 15000, 20000],
"settlement_proximity":
# Indicates distances too close to light settlements (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000,
2200, 2400, 2600, 2800, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 15000, 20000],
"industrial_proximity":
# Indicates distances too close to industrial areas (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"mining_proximity":
# Indicates distances too close to mines (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"agriculture_proximity":
# Indicates distances too close to aggriculture areas (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"airport_proximity":
# Indicates distances too close to airports (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 3000, 3500, 4000,
4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 15000],
"airfield_proximity":
# Indicates distances too close to airfields (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 3000, 3500, 4000,
4500, 5000, 5500, 6000, 7000, 8000, 9000, 10000, 15000],
"protected_park_proximity":
# Indicates distances too close to protected parks (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_landscape_proximity":
# Indicates distances too close to protected landscapes (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_natural_monument_proximity":
# Indicates distances too close to protected natural-monuments (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_reserve_proximity":
# Indicates distances too close to protected reserves (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_wilderness_proximity":
# Indicates distances too close to protected wilderness (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_biosphere_proximity":
# Indicates distances too close to protected biospheres (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_habitat_proximity":
# Indicates distances too close to protected habitats (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"protected_bird_proximity":
# Indicates distances too close to protected bird areas (m)
[0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1400, 1600, 1800, 2000, 2500, 3000, 4000, 5000],
"windspeed_50m_threshold":
# Indicates areas with average wind speed below X (m/s)
np.linspace(0, 20, 81),
"windspeed_100m_threshold":
# Indicates areas with average wind speed below X (m/s)
np.linspace(0, 20, 81),
"ghi_threshold":
# Indicates areas with average total daily irradiance below X (kWh/m2/day)
np.linspace(0, 20, 81),
"dni_threshold":
# Indicates areas with average total daily irradiance below X (kWh/m2/day)
np.linspace(0, 20, 81),
#"connection_distance": # Indicates distances too far from power grid (m)
# [50000, 45000, 40000, 35000, 30000, 25000, 20000, 18000, 16000,
# 14000, 12000, 11000, 10000, 9000, 8000, 7000, 6000, 5000,
# 4000, 3500, 3000, 2500, 2000, 1500, 1250, 1000, 750,
# 500, 250, 0],
#"access_distance": # Indicates distances too far from roads (m)
# [20000, 19000, 18000, 17000, 16000, 15000, 14000, 13000, 12000,
# 11000, 10000, 9000, 8000, 7000, 6000, 5000, 4000, 3500,
# 3000, 2500, 2000, 1500, 1250, 1000, 750, 500, 250, 0],
}
#######################################################
## EVALUATION FUNCTIONS
def evaluate_OCEAN(regSource, ftrID, tail):
name = "ocean_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from an ocean"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=44, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WETLAND(regSource, ftrID, tail):
name = "wetland_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a wetland area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=(35,39), applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_INDUSTRIAL(regSource, ftrID, tail):
name = "industrial_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from an industrial area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=3, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_MINING(regSource, ftrID, tail):
name = "mining_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a mining area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=7, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AGRICULTURE(regSource, ftrID, tail):
name = "agriculture_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from an agriculture area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=(12,22), applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AG_ARABLE(regSource, ftrID, tail):
name = "agriculture_arable_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from an arable agriculture area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES["agriculture_proximity"]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=(12,14), applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AG_PERMANENT(regSource, ftrID, tail):
name = "agriculture_permanent_crop_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a permanent-crop agriculture area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES["agriculture_proximity"]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=(15,17), applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AG_PASTURE(regSource, ftrID, tail):
name = "agriculture_pasture_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a pastural agriculture area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES["agriculture_proximity"]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=18, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AG_HETEROGENEOUS(regSource, ftrID, tail):
name = "agriculture_heterogeneous_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a heterogeneous agriculture area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES["agriculture_proximity"]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=(19,22), applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WOODLANDS_MIXED(regSource, ftrID, tail):
name = "woodland_mixed_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a mixed-tree woodland area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=23, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WOODLANDS_CONIFEROUS(regSource, ftrID, tail):
name = "woodland_coniferous_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a predominantly coniferous (needle leaved) woodland area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=24, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WOODLANDS_DECIDUOUS(regSource, ftrID, tail):
name = "woodland_deciduous_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a predominantly deciduous (broad leaved) woodland area"
source = "CLC12"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(clcSource, value=25, applyMask=False) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_ROADS(regSource, ftrID, tail):
name = "roads_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from all accessible roadways"
source = "OSM"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm filesi
whereStmt = r"fclass LIKE '%motorway%' OR fclass LIKE '%trunk%' OR fclass LIKE '%primary%' OR fclass LIKE '%secondary%' OR fclass LIKE '%tertiary%' OR fclass = 'service' OR fclass = 'unclassified'"
geom = geomExtractor( reg.extent, osmRoadsSource, whereStmt)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_ROADS_MAIN(regSource, ftrID, tail):
name = "roads_main_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from major roadways"
source = "OSM"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, osmRoadsSource, r"fclass LIKE '%motorway%' OR fclass LIKE '%trunk%' OR fclass LIKE '%primary%'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_ROADS_SECONDARY(regSource, ftrID, tail):
name = "roads_secondary_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from secondary roadways"
source = "OSM"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, osmRoadsSource, r"fclass LIKE '%secondary%' OR fclass LIKE '%tertiary%'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_POWER_LINE(regSource, ftrID, tail):
name = "power_line_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a power line"
source = "OSM"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, osmPowerlinesSource, r"power='line'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_RAILWAY(regSource, ftrID, tail):
name = "railway_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a railway"
source = "OSM"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, osmRailwaysSource, r"fclass = 'rail'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WATERBODY(regSource, ftrID, tail):
name = "waterbody_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from permanent water bodies"
source = "COPERNICUS HRL"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Indicate values and create a geomoetry from the result
matrix = reg.indicateValues(waterbodySource, value=1, applyMask=False, resolutionDiv=5) > 0.5
geom = gk.geom.convertMask(matrix, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_RIVER(regSource, ftrID, tail):
name = "river_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from rivers and other running water bodies"
source = "WWF hydroBASINS"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, riverSegmentsSource)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_LAKE(regSource, ftrID, tail):
name = "lake_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from lakes and other stagnant water bodies"
source = "WWF HydroLAKES"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, hydroLakesSource)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_PARK(regSource, ftrID, tail):
name = "protected_park_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected park"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%park%' OR IUCN_CAT = 'II'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_LANDSCAPE(regSource, ftrID, tail):
name = "protected_landscape_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected landscape"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%landscape%' OR IUCN_CAT = 'V'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_MONUMENT(regSource, ftrID, tail):
name = "protected_natural_monument_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected natural monument"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%monument%' OR IUCN_CAT = 'III'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_RESERVE(regSource, ftrID, tail):
name = "protected_reserve_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected reserve"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%reserve%' OR IUCN_CAT = 'Ia'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_WILDERNESS(regSource, ftrID, tail):
name = "protected_wilderness_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected wilderness"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
#geoms = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%wilderness%' OR IUCN_CAT = 'Ib'", simplify=reg.pixelSize/5)
matrix = None
for f in reg.extent.filterSources( join(wdpaSource[0], wdpaSource[1])):
tmp = reg.indicateFeatures(f, where=r"DESIG_ENG LIKE '%wilderness%' OR IUCN_CAT = 'Ib'", resolutionDiv=5, applyMask=False ) > 0.5
if matrix is None: matrix = tmp
else: np.logical_or(tmp, matrix, matrix)
if matrix.any():
geom = gk.geom.convertMask(matrix, reg.extent.xyXY, reg.srs)
else:
geom = None
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_BIOSPHERE(regSource, ftrID, tail):
name = "protected_biosphere_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected biosphere"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%bio%'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_HABITAT(regSource, ftrID, tail):
name = "protected_habitat_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected habitat"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
#geoms = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%habitat%' OR IUCN_CAT = 'IV'", simplify=reg.pixelSize/5)
matrix = None
for f in reg.extent.filterSources( join(wdpaSource[0], wdpaSource[1])):
tmp = reg.indicateFeatures(f, where=r"DESIG_ENG LIKE '%habitat%' OR IUCN_CAT = 'IV'", resolutionDiv=5, applyMask=False ) > 0.5
if matrix is None: matrix = tmp
else: np.logical_or(tmp, matrix, matrix)
if matrix.any():
geom = gk.geom.convertMask(matrix, reg.extent.xyXY, reg.srs)
else:
geom = None
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_BIRDS(regSource, ftrID, tail):
name = "protected_bird_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from a protected bird area"
source = "WDPA"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
geom = geomExtractor( reg.extent, wdpaSource, where=r"DESIG_ENG LIKE '%bird%'")
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_URBAN(regSource, ftrID, tail):
name = "settlement_urban_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from dense-urban and city settlements"
source = "EUROSTAT"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
indicated = reg.indicateValues(urbanClustersSource, value=(5000, 2e7), applyMask=False) > 0.5
geom = gk.geom.convertMask(indicated, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_SETTLEMENT(regSource, ftrID, tail):
name = "settlement_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from any settlement area"
source = "CLC"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances))
# Create a geometry list from the osm files
#eurostatUrban = reg.indicateValues(urbanClustersSource, value=(5000, 2e7), applyMask=False) > 0.5
clcUrban = reg.indicateValues(clcSource, value=(1,2), applyMask=False) > 0.5
geom = gk.geom.convertMask( clcUrban, bounds=reg.extent.xyXY, srs=reg.srs)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
def evaluate_AIRPORT(regSource, ftrID, tail):
######################
## Evaluate airports
name = "airport_proximity"
unit = "meters"
description = "Indicates pixels which are less-than or equal-to X meters from an airport"
source = "EUROSTAT, CLC"
output_dir = join("outputs", name)
# Get distances
distances = EVALUATION_VALUES[name]
# Make Region Mask
reg = gk.RegionMask.load(regSource, select=ftrID, padExtent=max(distances)*1.25)
### Get airport regions
airportMask = reg.indicateValues(clcSource, value=6, applyMask=False) > 0.5
airportGeoms = gk.geom.convertMask(airportMask, bounds=reg.extent.xyXY, srs=reg.srs)
if airportGeoms is None: airportGeoms = []
### define an airport/airfield shape matcher
def airportShapes( points, minSize, defaultRadius, minDistance=2000 ):
locatedGeoms = []
# look for best geometry for each airport
for pt in points:
found = False
# First look for containing geometries greater than the minimal area
containingGeoms = filter(lambda x: x.Contains(pt), airportGeoms)
for geom in containingGeoms:
if geom.Area() > minSize:
locatedGeoms.append( geom.Clone() )
found = True
if found: continue
if found: continue
# Next look for nearby geometries greater than the minimal area
nearbyGeoms = filter(lambda x: pt.Distance(x) <= minDistance, airportGeoms)
for geom in nearbyGeoms:
if geom.Area() > minSize:
locatedGeoms.append( geom.Clone() )
found = True
if found: continue
if found: continue
# if all else fails, apply a default distance
locatedGeoms.append( pt.Buffer(defaultRadius) )
if len(locatedGeoms)==0: return None
else: return locatedGeoms
### Locate airports
airportWhere = "AIRP_USE!=4 AND (AIRP_PASS=1 OR AIRP_PASS=2) AND AIRP_LAND='A'"
airportCoords = [point.Clone() for point,i in gk.vector.extractFeatures(airportsSource, reg.extent.box, where=airportWhere)]
for pt in airportCoords: pt.TransformTo(reg.srs)
geom = airportShapes(airportCoords, minSize=1e6, defaultRadius=3000)
# Get edge matrix
result = edgesByProximity(reg, geom, distances)
# make result
writeEdgeFile( result, reg, ftrID, output_dir, name, tail, unit, description, source, distances)
#####################
## Evaluate airfields
name = "airfield_proximity"