
moved opensource code into other folder. do not mix it.
@a862d38624b9224e279711da84210b00a1ea7e2d
--- choropleth.py
+++ choropleth.py
... | ... | @@ -26,52 +26,8 @@ |
26 | 26 |
coords = list(geom.exterior.coords) |
27 | 27 |
return (coords) |
28 | 28 |
|
29 |
- |
|
30 | 29 |
# def vor_ver(furthest_pnt, i): |
31 | 30 |
# return furthest_pnt[i].vertices |
32 |
- |
|
33 |
-def get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples(longitudes=None, latitudes=None): |
|
34 |
- """Function documentation:\n |
|
35 |
- Basic framework adopted from Krichardson under the following thread: |
|
36 |
- https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/7 |
|
37 |
- |
|
38 |
- # NOTE: |
|
39 |
- # THIS IS A TEMPORARY SOLUTION UNTIL THE DASH TEAM IMPLEMENTS DYNAMIC ZOOM |
|
40 |
- # in their plotly-functions associated with mapbox, such as go.Densitymapbox() etc. |
|
41 |
- |
|
42 |
- Returns the appropriate zoom-level for these plotly-mapbox-graphics along with |
|
43 |
- the center coordinate tuple of all provided coordinate tuples. |
|
44 |
- """ |
|
45 |
- |
|
46 |
- # Check whether both latitudes and longitudes have been passed, |
|
47 |
- # or if the list lenghts don't match |
|
48 |
- if ((latitudes is None or longitudes is None) |
|
49 |
- or (len(latitudes) != len(longitudes))): |
|
50 |
- # Otherwise, return the default values of 0 zoom and the coordinate origin as center point |
|
51 |
- return 0, (0, 0) |
|
52 |
- |
|
53 |
- # Get the boundary-box |
|
54 |
- b_box = {} |
|
55 |
- b_box['height'] = latitudes.max() - latitudes.min() |
|
56 |
- b_box['width'] = longitudes.max() - longitudes.min() |
|
57 |
- b_box['center'] = (np.mean(longitudes), np.mean(latitudes)) |
|
58 |
- |
|
59 |
- # get the area of the bounding box in order to calculate a zoom-level |
|
60 |
- area = b_box['height'] * b_box['width'] |
|
61 |
- |
|
62 |
- # * 1D-linear interpolation with numpy: |
|
63 |
- # - Pass the area as the only x-value and not as a list, in order to return a scalar as well |
|
64 |
- # - The x-points "xp" should be in parts in comparable order of magnitude of the given area |
|
65 |
- # - The zoom-levels are adapted to the areas, i.e. start with the smallest area possible of 0 |
|
66 |
- # which leads to the highest possible zoom value 20, and so forth decreasing with increasing areas |
|
67 |
- # as these variables are antiproportional |
|
68 |
- zoom = np.interp(x=area, |
|
69 |
- xp=[0, 5 ** -10, 4 ** -10, 3 ** -10, 2 ** -10, 1 ** -10, 1 ** -5], |
|
70 |
- fp=[20, 15, 14, 13, 12, 7, 5]) |
|
71 |
- |
|
72 |
- # Finally, return the zoom level and the associated boundary-box center coordinates |
|
73 |
- return zoom, b_box['center'] |
|
74 |
- |
|
75 | 31 |
|
76 | 32 |
def plotly_fig2array(fig, scale): |
77 | 33 |
# convert Plotly fig to an array |
+++ opensourcecode/get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples.py
... | ... | @@ -0,0 +1,43 @@ |
1 | +import numpy as np | |
2 | + | |
3 | +def get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples(longitudes=None, latitudes=None): | |
4 | + """Function documentation:\n | |
5 | + Basic framework adopted from Krichardson under the following thread: | |
6 | + https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/7 | |
7 | + | |
8 | + # NOTE: | |
9 | + # THIS IS A TEMPORARY SOLUTION UNTIL THE DASH TEAM IMPLEMENTS DYNAMIC ZOOM | |
10 | + # in their plotly-functions associated with mapbox, such as go.Densitymapbox() etc. | |
11 | + | |
12 | + Returns the appropriate zoom-level for these plotly-mapbox-graphics along with | |
13 | + the center coordinate tuple of all provided coordinate tuples. | |
14 | + """ | |
15 | + | |
16 | + # Check whether both latitudes and longitudes have been passed, | |
17 | + # or if the list lenghts don't match | |
18 | + if ((latitudes is None or longitudes is None) | |
19 | + or (len(latitudes) != len(longitudes))): | |
20 | + # Otherwise, return the default values of 0 zoom and the coordinate origin as center point | |
21 | + return 0, (0, 0) | |
22 | + | |
23 | + # Get the boundary-box | |
24 | + b_box = {} | |
25 | + b_box['height'] = latitudes.max() - latitudes.min() | |
26 | + b_box['width'] = longitudes.max() - longitudes.min() | |
27 | + b_box['center'] = (np.mean(longitudes), np.mean(latitudes)) | |
28 | + | |
29 | + # get the area of the bounding box in order to calculate a zoom-level | |
30 | + area = b_box['height'] * b_box['width'] | |
31 | + | |
32 | + # * 1D-linear interpolation with numpy: | |
33 | + # - Pass the area as the only x-value and not as a list, in order to return a scalar as well | |
34 | + # - The x-points "xp" should be in parts in comparable order of magnitude of the given area | |
35 | + # - The zoom-levels are adapted to the areas, i.e. start with the smallest area possible of 0 | |
36 | + # which leads to the highest possible zoom value 20, and so forth decreasing with increasing areas | |
37 | + # as these variables are antiproportional | |
38 | + zoom = np.interp(x=area, | |
39 | + xp=[0, 5 ** -10, 4 ** -10, 3 ** -10, 2 ** -10, 1 ** -10, 1 ** -5], | |
40 | + fp=[20, 15, 14, 13, 12, 7, 5]) | |
41 | + | |
42 | + # Finally, return the zoom level and the associated boundary-box center coordinates | |
43 | + return zoom, b_box['center'](No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?