-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathrun_DEM_EUDEMv11.py
244 lines (166 loc) · 7.39 KB
/
run_DEM_EUDEMv11.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
'''Python for Processing Digital Elevation Models (DEMs).
Author: He Zhang @ University of Exeter
Date: 16th March 2019 (Update: 20th April 2019)
Contact: [email protected] [email protected]
Copyright (c) 2019 He Zhang
'''
'''
DEM Data:
EUDEMv11 - EU-DEMv1.1
Download Link: https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1
Terms and Abbreviations:
EPSG - European Petroleum Survey Group
GCS - Geographic Coordinate System (Identified by an unique EPSG code)
PCS - Projected Coordinate System (Identified by an unique EPSG code)
WGS-84 [EPSG 4326] - 1984 World Geodetic System [GCS]
Merc [EPSG 3857] - Mercator -> Web Mercator -> Pseudo Mercator [PCS of WGS-84]
OSGB-36 [EPSG 4277] - 1936 Ordnance Survey Great Britain [GCS]
BNG [EPSG 27700] - British National Grid [PCS of OSGB-36]
ETRS-89 [EPSG 4258] - 1989 European Terrestrial Reference System [GCS]
LAEA [EPSG 3035] - Lambert Azimuthal Equal-Area [PCS of ETRS-89]
lat - Latitude
lng - Longitude
Transform - GCS to GCS
Project - GCS to PCS, PCS to PCS
Convert - PCS to PCS
Functions:
Convert DEM from LAEA PCS to ETRS-89 GCS.
Transform DEM from ETRS-89 GCS to WGS-84 GCS.
Transform DEM from ETRS-89 GCS to OSGB-36 GCS.
Get the elevation from DEM in WGS-84 GCS.
Get the elevation from DEM in OSGB-36 GCS.
Get the elevation from DEM in ETRS-89 GCS.
******************** Important Information of Code Usage ********************
- Use 'GDAL.GetProjection()' to check the GCS/PCS information of DEM (in TIF format).
- Use 'GDAL.GetGeoTransform()' to check the resolution of DEMs.
- Use 'GDAL.GetGeoTransform()' to check (lat, lng) of top-left corner of DEM (in GCS).
- The (lat, lng) of other locations in DEM can therefore be calculated.
- Each GCS has one related PCS (GCS/PCS is identified by an unique EPSG code).
- You can transform DEM between different GCSs (e.g., WGS-84 <-> OSGB-36 <-> ETRS-89).
- You can project DEM in GCS to the related PCS and then display its 2D image.
- You can not display DEM in GCS as 2D image (e.g., WGS-84 -> 2D image is wrong).
- You can not project DEM in GCS to the unrelated PCS (e.g., WGS-84 -> BNG is wrong).
- You can not project DEM between different PCSs (e.g., Pseudo Mercator <-> BNG is wrong).
* Use 'gdalwarp' command to transform/project DEM to different GCSs/PCSs might be correct.
'''
# Python 3.7
# import os
# import re
# import shutil
# import subprocess
# import matplotlib.pyplot as plt
import numpy as np
from osgeo import gdal
from pandas import read_csv
from pyDEM_function import get_dem_info
from pyDEM_function import get_elevation
# from pyDEM_function import get_file_names
# from pyDEM_function import show_2d_dem
from pyDEM_function import transprojcnvt_dem
# from pyDEM_function import write_dem
# Specify user settings.
# Set the EPSG code.
EPSG_WGS84 = 4326
EPSG_OSGB36 = 4277
EPSG_ETRS89 = 4258
EPSG_LAEA = 3035
# Set the format of DEMs.
DEM_FORMAT = '.tif'
# Set the path of DEMs.
PATH_EUDEM = 'DATA/DATA_EUDEMv11/'
# PATH_EUDEM_SOURCE = 'DATA/DATA_EUDEMv11/EPSG3035_s/' # The folder of source DEMs must exist.
# Set the name of DEMs in GCSs.
EUDEM_GCS_WD = 'EUDEMv11_EPSG4326.tif'
EUDEM_GCS_UK = 'EUDEMv11_EPSG4277.tif'
EUDEM_GCS_EU = 'EUDEMv11_EPSG4258.tif'
# Set the name of DEMs in PCSs.
EUDEM_PCS_WD = 'EUDEMv11_EPSG3857.tif'
EUDEM_PCS_UK = 'EUDEMv11_EPSG27700.tif'
EUDEM_PCS_EU = 'EUDEMv11_EPSG3035.tif'
# Set the path of location data file.
PATH_LD_STATION_DATA = 'DATA/DATA_LD_AirQuality/London_AirQuality_Stations.csv'
# <EUDEMv11> Convert DEM from LAEA PCS to ETRS-89 GCS.
print('\n>>> <EUDEMv11> Convert DEM from LAEA PCS to ETRS-89 GCS.')
path = PATH_EUDEM
dem_in = path + EUDEM_PCS_EU
dem_out = path + EUDEM_GCS_EU
epsg_in = EPSG_LAEA
epsg_out = EPSG_ETRS89
transprojcnvt_dem(dem_in, epsg_in, dem_out, epsg_out)
data = gdal.Open(dem_in)
get_dem_info(data, if_print=True)
data = gdal.Open(dem_out)
get_dem_info(data, if_print=True)
print('\n>>> Complete!\n')
# <EUDEMv11> Transform DEM from ETRS-89 GCS to WGS-84 GCS.
print('\n>>> <EUDEMv11> Transform DEM from ETRS-89 GCS to WGS-84 GCS.')
path = PATH_EUDEM
dem_in = path + EUDEM_GCS_EU
dem_out = path + EUDEM_GCS_WD
epsg_in = EPSG_ETRS89
epsg_out = EPSG_WGS84
transprojcnvt_dem(dem_in, epsg_in, dem_out, epsg_out)
data = gdal.Open(dem_in)
get_dem_info(data, if_print=True)
data = gdal.Open(dem_out)
get_dem_info(data, if_print=True)
print('\n>>> Complete!\n')
# <EUDEMv11> Transform DEM from ETRS-89 GCS to OSGB-36 GCS.
print('\n>>> <EUDEMv11> Transform DEM from ETRS-89 GCS to OSGB-36 GCS.')
path = PATH_EUDEM
dem_in = path + EUDEM_GCS_EU
dem_out = path + EUDEM_GCS_UK
epsg_in = EPSG_ETRS89
epsg_out = EPSG_OSGB36
transprojcnvt_dem(dem_in, epsg_in, dem_out, epsg_out)
data = gdal.Open(dem_in)
get_dem_info(data, if_print=True)
data = gdal.Open(dem_out)
get_dem_info(data, if_print=True)
print('\n>>> Complete!\n')
# Read London air quality monitoring station data file.
print('\n>>> Read London air quality monitoring station data file.')
site_data = read_csv(PATH_LD_STATION_DATA)
print(site_data.head(3))
site_num = site_data['SiteName'].count()
print('\n*==> The number of stations is: %d' % site_num)
# Get the latitude and longitude of stations.
site_latlng = np.zeros((site_num, 2))
site_latlng[:, 0] = site_data['Latitude'] # The 0-th column - Latitude.
site_latlng[:, 1] = site_data['Longitude'] # The 1-th column - Longitude.
np.set_printoptions(suppress=True) # Print numbers without scientific notation.
print('\n*==> The location (lat, lng) of stations are:\n', site_latlng)
print('\n>>> Complete!\n')
# <EUDEMv11> Get the elevation from DEM in WGS-84 GCS.
print('\n>>> <EUDEMv11> Get the elevation from DEM in WGS-84 GCS.')
dem_gcs = gdal.Open(PATH_EUDEM + EUDEM_GCS_WD)
get_dem_info(dem_gcs, if_print=True)
site_ele_eudem_wgs = get_elevation(dem_gcs, site_latlng)
np.set_printoptions(suppress=True)
print('\n*==> The elevation information of stations is:\n', site_ele_eudem_wgs)
print('\n*==> The elevation value of stations is:\n', site_ele_eudem_wgs[:, 5].astype(int))
print('\n>>> Complete!\n')
# <EUDEMv11> Get the elevation from DEM in OSGB-36 GCS.
print('\n>>> <EUDEMv11> Get the elevation from DEM in OSGB-36 GCS.')
dem_gcs = gdal.Open(PATH_EUDEM + EUDEM_GCS_UK)
get_dem_info(dem_gcs, if_print=True)
site_ele_eudem_osgb = get_elevation(dem_gcs, site_latlng)
np.set_printoptions(suppress=True)
print('\n*==> The elevation information of stations is:\n', site_ele_eudem_osgb)
print('\n*==> The elevation value of stations is:\n', site_ele_eudem_osgb[:, 5].astype(int))
print('\n>>> Complete!\n')
# <EUDEMv11> Get the elevation from DEM in ETRS-89 GCS.
print('\n>>> <EUDEMv11> Get the elevation from DEM in ETRS-89 GCS.')
dem_gcs = gdal.Open(PATH_EUDEM + EUDEM_GCS_EU)
get_dem_info(dem_gcs, if_print=True)
site_ele_eudem_etrs = get_elevation(dem_gcs, site_latlng)
np.set_printoptions(suppress=True)
print('\n*==> The elevation information of stations is:\n', site_ele_eudem_etrs)
print('\n*==> The elevation value of stations is:\n', site_ele_eudem_etrs[:, 5].astype(int))
print('\n>>> Complete!\n')
# Compare the elevation obtained from different DEMs.
print('\n>>> Compare the elevation obtained from different DEMs.')
print('\nEUDEMv11_WD', site_ele_eudem_wgs[:, 5].astype(int))
print('\nEUDEMv11_UK', site_ele_eudem_osgb[:, 5].astype(int))
print('\nEUDEMv11_EU', site_ele_eudem_etrs[:, 5].astype(int))
print('\n>>> Complete!\n')