voxcity 0.7.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- voxcity/__init__.py +14 -14
- voxcity/exporter/__init__.py +12 -12
- voxcity/exporter/cityles.py +633 -633
- voxcity/exporter/envimet.py +733 -728
- voxcity/exporter/magicavoxel.py +333 -333
- voxcity/exporter/netcdf.py +238 -238
- voxcity/exporter/obj.py +1480 -1480
- voxcity/generator/__init__.py +47 -44
- voxcity/generator/api.py +721 -675
- voxcity/generator/grids.py +381 -379
- voxcity/generator/io.py +94 -94
- voxcity/generator/pipeline.py +282 -282
- voxcity/generator/update.py +429 -0
- voxcity/generator/voxelizer.py +18 -6
- voxcity/geoprocessor/__init__.py +75 -75
- voxcity/geoprocessor/draw.py +1488 -1219
- voxcity/geoprocessor/merge_utils.py +91 -91
- voxcity/geoprocessor/mesh.py +806 -806
- voxcity/geoprocessor/network.py +708 -708
- voxcity/geoprocessor/raster/buildings.py +435 -428
- voxcity/geoprocessor/raster/export.py +93 -93
- voxcity/geoprocessor/raster/landcover.py +5 -2
- voxcity/geoprocessor/utils.py +824 -824
- voxcity/models.py +113 -113
- voxcity/simulator/solar/__init__.py +66 -43
- voxcity/simulator/solar/integration.py +336 -336
- voxcity/simulator/solar/sky.py +668 -0
- voxcity/simulator/solar/temporal.py +792 -434
- voxcity/utils/__init__.py +11 -0
- voxcity/utils/classes.py +194 -0
- voxcity/utils/lc.py +80 -39
- voxcity/utils/shape.py +230 -0
- voxcity/visualizer/__init__.py +24 -24
- voxcity/visualizer/builder.py +43 -43
- voxcity/visualizer/grids.py +141 -141
- voxcity/visualizer/maps.py +187 -187
- voxcity/visualizer/renderer.py +1145 -928
- {voxcity-0.7.0.dist-info → voxcity-1.0.2.dist-info}/METADATA +90 -49
- {voxcity-0.7.0.dist-info → voxcity-1.0.2.dist-info}/RECORD +42 -38
- {voxcity-0.7.0.dist-info → voxcity-1.0.2.dist-info}/WHEEL +0 -0
- {voxcity-0.7.0.dist-info → voxcity-1.0.2.dist-info}/licenses/AUTHORS.rst +0 -0
- {voxcity-0.7.0.dist-info → voxcity-1.0.2.dist-info}/licenses/LICENSE +0 -0
voxcity/visualizer/maps.py
CHANGED
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
import matplotlib.pyplot as plt
|
|
5
|
-
import matplotlib.colors as mcolors
|
|
6
|
-
import seaborn as sns
|
|
7
|
-
import contextily as ctx
|
|
8
|
-
from shapely.geometry import Polygon
|
|
9
|
-
from pyproj import CRS
|
|
10
|
-
|
|
11
|
-
from ..geoprocessor.raster import (
|
|
12
|
-
calculate_grid_size,
|
|
13
|
-
create_coordinate_mesh,
|
|
14
|
-
)
|
|
15
|
-
from ..geoprocessor.utils import (
|
|
16
|
-
initialize_geod,
|
|
17
|
-
calculate_distance,
|
|
18
|
-
normalize_to_one_meter,
|
|
19
|
-
setup_transformer,
|
|
20
|
-
transform_coords,
|
|
21
|
-
)
|
|
22
|
-
from ..utils.lc import get_land_cover_classes
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def plot_grid(grid, origin, adjusted_meshsize, u_vec, v_vec, transformer, vertices, data_type, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light', **kwargs):
|
|
26
|
-
fig, ax = plt.subplots(figsize=(12, 12))
|
|
27
|
-
|
|
28
|
-
if data_type == 'land_cover':
|
|
29
|
-
land_cover_classes = kwargs.get('land_cover_classes')
|
|
30
|
-
colors = [mcolors.to_rgb(f'#{r:02x}{g:02x}{b:02x}') for r, g, b in land_cover_classes.keys()]
|
|
31
|
-
cmap = mcolors.ListedColormap(colors)
|
|
32
|
-
norm = mcolors.BoundaryNorm(range(len(land_cover_classes)+1), cmap.N)
|
|
33
|
-
elif data_type == 'building_height':
|
|
34
|
-
masked_grid = np.ma.masked_array(grid, mask=(np.isnan(grid) | (grid == 0)))
|
|
35
|
-
cmap = plt.cm.viridis
|
|
36
|
-
if vmin is None:
|
|
37
|
-
vmin = np.nanmin(masked_grid[masked_grid > 0])
|
|
38
|
-
if vmax is None:
|
|
39
|
-
vmax = np.nanmax(masked_grid)
|
|
40
|
-
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
41
|
-
elif data_type == 'dem':
|
|
42
|
-
cmap = plt.cm.terrain
|
|
43
|
-
if vmin is None:
|
|
44
|
-
vmin = np.nanmin(grid)
|
|
45
|
-
if vmax is None:
|
|
46
|
-
vmax = np.nanmax(grid)
|
|
47
|
-
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
48
|
-
elif data_type == 'canopy_height':
|
|
49
|
-
cmap = plt.cm.Greens
|
|
50
|
-
if vmin is None:
|
|
51
|
-
vmin = np.nanmin(grid)
|
|
52
|
-
if vmax is None:
|
|
53
|
-
vmax = np.nanmax(grid)
|
|
54
|
-
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
55
|
-
elif data_type in ('green_view_index', 'sky_view_index'):
|
|
56
|
-
cmap = plt.cm.get_cmap('BuPu_r').copy() if data_type == 'sky_view_index' else plt.cm.Greens
|
|
57
|
-
if vmin is None:
|
|
58
|
-
vmin = np.nanmin(grid)
|
|
59
|
-
if vmax is None:
|
|
60
|
-
vmax = np.nanmax(grid)
|
|
61
|
-
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
62
|
-
else:
|
|
63
|
-
cmap = plt.cm.viridis
|
|
64
|
-
if vmin is None:
|
|
65
|
-
vmin = np.nanmin(grid)
|
|
66
|
-
if vmax is None:
|
|
67
|
-
vmax = np.nanmax(grid)
|
|
68
|
-
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
69
|
-
|
|
70
|
-
if color_map:
|
|
71
|
-
cmap = sns.color_palette(color_map, as_cmap=True).copy()
|
|
72
|
-
|
|
73
|
-
grid = grid.T
|
|
74
|
-
|
|
75
|
-
for i in range(grid.shape[0]):
|
|
76
|
-
for j in range(grid.shape[1]):
|
|
77
|
-
cell = create_cell_polygon(origin, j, i, adjusted_meshsize, u_vec, v_vec) # type: ignore[name-defined]
|
|
78
|
-
x, y = cell.exterior.xy
|
|
79
|
-
x, y = zip(*[transformer.transform(lon, lat) for lat, lon in zip(x, y)])
|
|
80
|
-
value = grid[i, j]
|
|
81
|
-
if data_type == 'building_height':
|
|
82
|
-
if np.isnan(value):
|
|
83
|
-
ax.fill(x, y, alpha=alpha, fc='gray', ec='black' if edge else None, linewidth=0.1)
|
|
84
|
-
elif value == 0:
|
|
85
|
-
if edge:
|
|
86
|
-
ax.plot(x, y, color='black', linewidth=0.1)
|
|
87
|
-
elif value > 0:
|
|
88
|
-
ax.fill(x, y, alpha=alpha, fc=cmap(norm(value)), ec='black' if edge else None, linewidth=0.1)
|
|
89
|
-
elif data_type == 'canopy_height':
|
|
90
|
-
color = cmap(norm(value))
|
|
91
|
-
if value == 0:
|
|
92
|
-
if edge:
|
|
93
|
-
ax.plot(x, y, color='black', linewidth=0.1)
|
|
94
|
-
else:
|
|
95
|
-
ax.fill(x, y, alpha=alpha, fc=color, ec='black' if edge else None, linewidth=0.1)
|
|
96
|
-
elif 'view' in data_type:
|
|
97
|
-
if np.isnan(value):
|
|
98
|
-
if edge:
|
|
99
|
-
ax.plot(x, y, color='black', linewidth=0.1)
|
|
100
|
-
elif value >= 0:
|
|
101
|
-
ax.fill(x, y, alpha=alpha, fc=cmap(norm(value)), ec='black' if edge else None, linewidth=0.1)
|
|
102
|
-
else:
|
|
103
|
-
color = cmap(norm(value))
|
|
104
|
-
ax.fill(x, y, alpha=alpha, fc=color, ec='black' if edge else None, linewidth=0.1)
|
|
105
|
-
|
|
106
|
-
crs_epsg_3857 = CRS.from_epsg(3857)
|
|
107
|
-
basemaps = {
|
|
108
|
-
'CartoDB dark': ctx.providers.CartoDB.DarkMatter,
|
|
109
|
-
'CartoDB light': ctx.providers.CartoDB.Positron,
|
|
110
|
-
'CartoDB voyager': ctx.providers.CartoDB.Voyager,
|
|
111
|
-
'CartoDB light no labels': ctx.providers.CartoDB.PositronNoLabels,
|
|
112
|
-
'CartoDB dark no labels': ctx.providers.CartoDB.DarkMatterNoLabels,
|
|
113
|
-
}
|
|
114
|
-
ctx.add_basemap(ax, crs=crs_epsg_3857, source=basemaps[basemap])
|
|
115
|
-
|
|
116
|
-
all_coords = np.array(vertices)
|
|
117
|
-
x, y = zip(*[transformer.transform(lon, lat) for lat, lon in all_coords])
|
|
118
|
-
x_min, x_max = min(x), max(x)
|
|
119
|
-
y_min, y_max = min(y), max(y)
|
|
120
|
-
if x_min != x_max and y_min != y_max and buf != 0:
|
|
121
|
-
dist_x = x_max - x_min
|
|
122
|
-
dist_y = y_max - y_min
|
|
123
|
-
ax.set_xlim(x_min - buf * dist_x, x_max + buf * dist_x)
|
|
124
|
-
ax.set_ylim(y_min - buf * dist_y, y_max + buf * dist_y)
|
|
125
|
-
else:
|
|
126
|
-
ax.set_xlim(x_min, x_max)
|
|
127
|
-
ax.set_ylim(y_min, y_max)
|
|
128
|
-
|
|
129
|
-
plt.axis('off')
|
|
130
|
-
plt.tight_layout()
|
|
131
|
-
plt.show()
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def visualize_land_cover_grid_on_map(grid, rectangle_vertices, meshsize, source='Urbanwatch', vmin=None, vmax=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
135
|
-
geod = initialize_geod()
|
|
136
|
-
land_cover_classes = get_land_cover_classes(source)
|
|
137
|
-
vertex_0 = rectangle_vertices[0]; vertex_1 = rectangle_vertices[1]; vertex_3 = rectangle_vertices[3]
|
|
138
|
-
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
139
|
-
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
140
|
-
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
141
|
-
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
142
|
-
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
143
|
-
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
144
|
-
origin = np.array(rectangle_vertices[0])
|
|
145
|
-
grid_size, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
146
|
-
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
147
|
-
plot_grid(grid, origin, adjusted_meshsize, u_vec, v_vec, transformer, rectangle_vertices, 'land_cover', alpha=alpha, buf=buf, edge=edge, basemap=basemap, land_cover_classes=land_cover_classes)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
def visualize_building_height_grid_on_map(building_height_grid, filtered_buildings, rectangle_vertices, meshsize, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
151
|
-
geod = initialize_geod()
|
|
152
|
-
vertex_0, vertex_1, vertex_3 = rectangle_vertices[0], rectangle_vertices[1], rectangle_vertices[3]
|
|
153
|
-
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
154
|
-
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
155
|
-
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
156
|
-
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
157
|
-
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
158
|
-
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
159
|
-
origin = np.array(rectangle_vertices[0])
|
|
160
|
-
_, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
161
|
-
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
162
|
-
plot_grid(building_height_grid, origin, adjusted_meshsize, u_vec, v_vec, transformer,
|
|
163
|
-
rectangle_vertices, 'building_height', vmin=vmin, vmax=vmax, color_map=color_map, alpha=alpha, buf=buf, edge=edge, basemap=basemap, buildings=filtered_buildings)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
def visualize_numerical_grid_on_map(canopy_height_grid, rectangle_vertices, meshsize, type, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
167
|
-
geod = initialize_geod()
|
|
168
|
-
vertex_0, vertex_1, vertex_3 = rectangle_vertices[0], rectangle_vertices[1], rectangle_vertices[3]
|
|
169
|
-
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
170
|
-
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
171
|
-
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
172
|
-
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
173
|
-
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
174
|
-
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
175
|
-
origin = np.array(rectangle_vertices[0])
|
|
176
|
-
_, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
177
|
-
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
178
|
-
plot_grid(canopy_height_grid, origin, adjusted_meshsize, u_vec, v_vec, transformer,
|
|
179
|
-
rectangle_vertices, type, vmin=vmin, vmax=vmax, color_map=color_map, alpha=alpha, buf=buf, edge=edge, basemap=basemap)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
import matplotlib.colors as mcolors
|
|
6
|
+
import seaborn as sns
|
|
7
|
+
import contextily as ctx
|
|
8
|
+
from shapely.geometry import Polygon
|
|
9
|
+
from pyproj import CRS
|
|
10
|
+
|
|
11
|
+
from ..geoprocessor.raster import (
|
|
12
|
+
calculate_grid_size,
|
|
13
|
+
create_coordinate_mesh,
|
|
14
|
+
)
|
|
15
|
+
from ..geoprocessor.utils import (
|
|
16
|
+
initialize_geod,
|
|
17
|
+
calculate_distance,
|
|
18
|
+
normalize_to_one_meter,
|
|
19
|
+
setup_transformer,
|
|
20
|
+
transform_coords,
|
|
21
|
+
)
|
|
22
|
+
from ..utils.lc import get_land_cover_classes
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def plot_grid(grid, origin, adjusted_meshsize, u_vec, v_vec, transformer, vertices, data_type, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light', **kwargs):
|
|
26
|
+
fig, ax = plt.subplots(figsize=(12, 12))
|
|
27
|
+
|
|
28
|
+
if data_type == 'land_cover':
|
|
29
|
+
land_cover_classes = kwargs.get('land_cover_classes')
|
|
30
|
+
colors = [mcolors.to_rgb(f'#{r:02x}{g:02x}{b:02x}') for r, g, b in land_cover_classes.keys()]
|
|
31
|
+
cmap = mcolors.ListedColormap(colors)
|
|
32
|
+
norm = mcolors.BoundaryNorm(range(len(land_cover_classes)+1), cmap.N)
|
|
33
|
+
elif data_type == 'building_height':
|
|
34
|
+
masked_grid = np.ma.masked_array(grid, mask=(np.isnan(grid) | (grid == 0)))
|
|
35
|
+
cmap = plt.cm.viridis
|
|
36
|
+
if vmin is None:
|
|
37
|
+
vmin = np.nanmin(masked_grid[masked_grid > 0])
|
|
38
|
+
if vmax is None:
|
|
39
|
+
vmax = np.nanmax(masked_grid)
|
|
40
|
+
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
41
|
+
elif data_type == 'dem':
|
|
42
|
+
cmap = plt.cm.terrain
|
|
43
|
+
if vmin is None:
|
|
44
|
+
vmin = np.nanmin(grid)
|
|
45
|
+
if vmax is None:
|
|
46
|
+
vmax = np.nanmax(grid)
|
|
47
|
+
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
48
|
+
elif data_type == 'canopy_height':
|
|
49
|
+
cmap = plt.cm.Greens
|
|
50
|
+
if vmin is None:
|
|
51
|
+
vmin = np.nanmin(grid)
|
|
52
|
+
if vmax is None:
|
|
53
|
+
vmax = np.nanmax(grid)
|
|
54
|
+
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
55
|
+
elif data_type in ('green_view_index', 'sky_view_index'):
|
|
56
|
+
cmap = plt.cm.get_cmap('BuPu_r').copy() if data_type == 'sky_view_index' else plt.cm.Greens
|
|
57
|
+
if vmin is None:
|
|
58
|
+
vmin = np.nanmin(grid)
|
|
59
|
+
if vmax is None:
|
|
60
|
+
vmax = np.nanmax(grid)
|
|
61
|
+
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
62
|
+
else:
|
|
63
|
+
cmap = plt.cm.viridis
|
|
64
|
+
if vmin is None:
|
|
65
|
+
vmin = np.nanmin(grid)
|
|
66
|
+
if vmax is None:
|
|
67
|
+
vmax = np.nanmax(grid)
|
|
68
|
+
norm = mcolors.Normalize(vmin=vmin, vmax=vmax)
|
|
69
|
+
|
|
70
|
+
if color_map:
|
|
71
|
+
cmap = sns.color_palette(color_map, as_cmap=True).copy()
|
|
72
|
+
|
|
73
|
+
grid = grid.T
|
|
74
|
+
|
|
75
|
+
for i in range(grid.shape[0]):
|
|
76
|
+
for j in range(grid.shape[1]):
|
|
77
|
+
cell = create_cell_polygon(origin, j, i, adjusted_meshsize, u_vec, v_vec) # type: ignore[name-defined]
|
|
78
|
+
x, y = cell.exterior.xy
|
|
79
|
+
x, y = zip(*[transformer.transform(lon, lat) for lat, lon in zip(x, y)])
|
|
80
|
+
value = grid[i, j]
|
|
81
|
+
if data_type == 'building_height':
|
|
82
|
+
if np.isnan(value):
|
|
83
|
+
ax.fill(x, y, alpha=alpha, fc='gray', ec='black' if edge else None, linewidth=0.1)
|
|
84
|
+
elif value == 0:
|
|
85
|
+
if edge:
|
|
86
|
+
ax.plot(x, y, color='black', linewidth=0.1)
|
|
87
|
+
elif value > 0:
|
|
88
|
+
ax.fill(x, y, alpha=alpha, fc=cmap(norm(value)), ec='black' if edge else None, linewidth=0.1)
|
|
89
|
+
elif data_type == 'canopy_height':
|
|
90
|
+
color = cmap(norm(value))
|
|
91
|
+
if value == 0:
|
|
92
|
+
if edge:
|
|
93
|
+
ax.plot(x, y, color='black', linewidth=0.1)
|
|
94
|
+
else:
|
|
95
|
+
ax.fill(x, y, alpha=alpha, fc=color, ec='black' if edge else None, linewidth=0.1)
|
|
96
|
+
elif 'view' in data_type:
|
|
97
|
+
if np.isnan(value):
|
|
98
|
+
if edge:
|
|
99
|
+
ax.plot(x, y, color='black', linewidth=0.1)
|
|
100
|
+
elif value >= 0:
|
|
101
|
+
ax.fill(x, y, alpha=alpha, fc=cmap(norm(value)), ec='black' if edge else None, linewidth=0.1)
|
|
102
|
+
else:
|
|
103
|
+
color = cmap(norm(value))
|
|
104
|
+
ax.fill(x, y, alpha=alpha, fc=color, ec='black' if edge else None, linewidth=0.1)
|
|
105
|
+
|
|
106
|
+
crs_epsg_3857 = CRS.from_epsg(3857)
|
|
107
|
+
basemaps = {
|
|
108
|
+
'CartoDB dark': ctx.providers.CartoDB.DarkMatter,
|
|
109
|
+
'CartoDB light': ctx.providers.CartoDB.Positron,
|
|
110
|
+
'CartoDB voyager': ctx.providers.CartoDB.Voyager,
|
|
111
|
+
'CartoDB light no labels': ctx.providers.CartoDB.PositronNoLabels,
|
|
112
|
+
'CartoDB dark no labels': ctx.providers.CartoDB.DarkMatterNoLabels,
|
|
113
|
+
}
|
|
114
|
+
ctx.add_basemap(ax, crs=crs_epsg_3857, source=basemaps[basemap])
|
|
115
|
+
|
|
116
|
+
all_coords = np.array(vertices)
|
|
117
|
+
x, y = zip(*[transformer.transform(lon, lat) for lat, lon in all_coords])
|
|
118
|
+
x_min, x_max = min(x), max(x)
|
|
119
|
+
y_min, y_max = min(y), max(y)
|
|
120
|
+
if x_min != x_max and y_min != y_max and buf != 0:
|
|
121
|
+
dist_x = x_max - x_min
|
|
122
|
+
dist_y = y_max - y_min
|
|
123
|
+
ax.set_xlim(x_min - buf * dist_x, x_max + buf * dist_x)
|
|
124
|
+
ax.set_ylim(y_min - buf * dist_y, y_max + buf * dist_y)
|
|
125
|
+
else:
|
|
126
|
+
ax.set_xlim(x_min, x_max)
|
|
127
|
+
ax.set_ylim(y_min, y_max)
|
|
128
|
+
|
|
129
|
+
plt.axis('off')
|
|
130
|
+
plt.tight_layout()
|
|
131
|
+
plt.show()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def visualize_land_cover_grid_on_map(grid, rectangle_vertices, meshsize, source='Urbanwatch', vmin=None, vmax=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
135
|
+
geod = initialize_geod()
|
|
136
|
+
land_cover_classes = get_land_cover_classes(source)
|
|
137
|
+
vertex_0 = rectangle_vertices[0]; vertex_1 = rectangle_vertices[1]; vertex_3 = rectangle_vertices[3]
|
|
138
|
+
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
139
|
+
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
140
|
+
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
141
|
+
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
142
|
+
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
143
|
+
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
144
|
+
origin = np.array(rectangle_vertices[0])
|
|
145
|
+
grid_size, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
146
|
+
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
147
|
+
plot_grid(grid, origin, adjusted_meshsize, u_vec, v_vec, transformer, rectangle_vertices, 'land_cover', alpha=alpha, buf=buf, edge=edge, basemap=basemap, land_cover_classes=land_cover_classes)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def visualize_building_height_grid_on_map(building_height_grid, filtered_buildings, rectangle_vertices, meshsize, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
151
|
+
geod = initialize_geod()
|
|
152
|
+
vertex_0, vertex_1, vertex_3 = rectangle_vertices[0], rectangle_vertices[1], rectangle_vertices[3]
|
|
153
|
+
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
154
|
+
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
155
|
+
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
156
|
+
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
157
|
+
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
158
|
+
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
159
|
+
origin = np.array(rectangle_vertices[0])
|
|
160
|
+
_, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
161
|
+
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
162
|
+
plot_grid(building_height_grid, origin, adjusted_meshsize, u_vec, v_vec, transformer,
|
|
163
|
+
rectangle_vertices, 'building_height', vmin=vmin, vmax=vmax, color_map=color_map, alpha=alpha, buf=buf, edge=edge, basemap=basemap, buildings=filtered_buildings)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def visualize_numerical_grid_on_map(canopy_height_grid, rectangle_vertices, meshsize, type, vmin=None, vmax=None, color_map=None, alpha=0.5, buf=0.2, edge=True, basemap='CartoDB light'):
|
|
167
|
+
geod = initialize_geod()
|
|
168
|
+
vertex_0, vertex_1, vertex_3 = rectangle_vertices[0], rectangle_vertices[1], rectangle_vertices[3]
|
|
169
|
+
dist_side_1 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_1[1], vertex_1[0])
|
|
170
|
+
dist_side_2 = calculate_distance(geod, vertex_0[1], vertex_0[0], vertex_3[1], vertex_3[0])
|
|
171
|
+
side_1 = np.array(vertex_1) - np.array(vertex_0)
|
|
172
|
+
side_2 = np.array(vertex_3) - np.array(vertex_0)
|
|
173
|
+
u_vec = normalize_to_one_meter(side_1, dist_side_1)
|
|
174
|
+
v_vec = normalize_to_one_meter(side_2, dist_side_2)
|
|
175
|
+
origin = np.array(rectangle_vertices[0])
|
|
176
|
+
_, adjusted_meshsize = calculate_grid_size(side_1, side_2, u_vec, v_vec, meshsize)
|
|
177
|
+
transformer = setup_transformer(CRS.from_epsg(4326), CRS.from_epsg(3857))
|
|
178
|
+
plot_grid(canopy_height_grid, origin, adjusted_meshsize, u_vec, v_vec, transformer,
|
|
179
|
+
rectangle_vertices, type, vmin=vmin, vmax=vmax, color_map=color_map, alpha=alpha, buf=buf, edge=edge, basemap=basemap)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|