윤영준 윤영준 2023-06-14
moved opensource code into other folder. do not mix it.
@a862d38624b9224e279711da84210b00a1ea7e2d
choropleth.py
--- choropleth.py
+++ choropleth.py
@@ -26,52 +26,8 @@
     coords = list(geom.exterior.coords)
     return (coords)
 
-
 # def vor_ver(furthest_pnt, i):
 #     return furthest_pnt[i].vertices
-
-def get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples(longitudes=None, latitudes=None):
-    """Function documentation:\n
-    Basic framework adopted from Krichardson under the following thread:
-    https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/7
-
-    # NOTE:
-    # THIS IS A TEMPORARY SOLUTION UNTIL THE DASH TEAM IMPLEMENTS DYNAMIC ZOOM
-    # in their plotly-functions associated with mapbox, such as go.Densitymapbox() etc.
-
-    Returns the appropriate zoom-level for these plotly-mapbox-graphics along with
-    the center coordinate tuple of all provided coordinate tuples.
-    """
-
-    # Check whether both latitudes and longitudes have been passed,
-    # or if the list lenghts don't match
-    if ((latitudes is None or longitudes is None)
-            or (len(latitudes) != len(longitudes))):
-        # Otherwise, return the default values of 0 zoom and the coordinate origin as center point
-        return 0, (0, 0)
-
-    # Get the boundary-box
-    b_box = {}
-    b_box['height'] = latitudes.max() - latitudes.min()
-    b_box['width'] = longitudes.max() - longitudes.min()
-    b_box['center'] = (np.mean(longitudes), np.mean(latitudes))
-
-    # get the area of the bounding box in order to calculate a zoom-level
-    area = b_box['height'] * b_box['width']
-
-    # * 1D-linear interpolation with numpy:
-    # - Pass the area as the only x-value and not as a list, in order to return a scalar as well
-    # - The x-points "xp" should be in parts in comparable order of magnitude of the given area
-    # - The zoom-levels are adapted to the areas, i.e. start with the smallest area possible of 0
-    # which leads to the highest possible zoom value 20, and so forth decreasing with increasing areas
-    # as these variables are antiproportional
-    zoom = np.interp(x=area,
-                     xp=[0, 5 ** -10, 4 ** -10, 3 ** -10, 2 ** -10, 1 ** -10, 1 ** -5],
-                     fp=[20, 15, 14, 13, 12, 7, 5])
-
-    # Finally, return the zoom level and the associated boundary-box center coordinates
-    return zoom, b_box['center']
-
 
 def plotly_fig2array(fig, scale):
     # convert Plotly fig to  an array
 
opensourcecode/get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples.py (added)
+++ opensourcecode/get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples.py
@@ -0,0 +1,43 @@
+import numpy as np
+
+def get_plotting_zoom_level_and_center_coordinates_from_lonlat_tuples(longitudes=None, latitudes=None):
+    """Function documentation:\n
+    Basic framework adopted from Krichardson under the following thread:
+    https://community.plotly.com/t/dynamic-zoom-for-mapbox/32658/7
+
+    # NOTE:
+    # THIS IS A TEMPORARY SOLUTION UNTIL THE DASH TEAM IMPLEMENTS DYNAMIC ZOOM
+    # in their plotly-functions associated with mapbox, such as go.Densitymapbox() etc.
+
+    Returns the appropriate zoom-level for these plotly-mapbox-graphics along with
+    the center coordinate tuple of all provided coordinate tuples.
+    """
+
+    # Check whether both latitudes and longitudes have been passed,
+    # or if the list lenghts don't match
+    if ((latitudes is None or longitudes is None)
+            or (len(latitudes) != len(longitudes))):
+        # Otherwise, return the default values of 0 zoom and the coordinate origin as center point
+        return 0, (0, 0)
+
+    # Get the boundary-box
+    b_box = {}
+    b_box['height'] = latitudes.max() - latitudes.min()
+    b_box['width'] = longitudes.max() - longitudes.min()
+    b_box['center'] = (np.mean(longitudes), np.mean(latitudes))
+
+    # get the area of the bounding box in order to calculate a zoom-level
+    area = b_box['height'] * b_box['width']
+
+    # * 1D-linear interpolation with numpy:
+    # - Pass the area as the only x-value and not as a list, in order to return a scalar as well
+    # - The x-points "xp" should be in parts in comparable order of magnitude of the given area
+    # - The zoom-levels are adapted to the areas, i.e. start with the smallest area possible of 0
+    # which leads to the highest possible zoom value 20, and so forth decreasing with increasing areas
+    # as these variables are antiproportional
+    zoom = np.interp(x=area,
+                     xp=[0, 5 ** -10, 4 ** -10, 3 ** -10, 2 ** -10, 1 ** -10, 1 ** -5],
+                     fp=[20, 15, 14, 13, 12, 7, 5])
+
+    # Finally, return the zoom level and the associated boundary-box center coordinates
+    return zoom, b_box['center'](No newline at end of file)
Add a comment
List