Folium Lines Visualization System¶
viz_lines
¶
ResolvedLineFeature
dataclass
¶
Bases: ResolvedFeature
Resolved visual properties for line/connection map elements.
Container for all computed styling properties of line visualizations, including colors, widths, dash patterns, and animation effects. Used by LineGenerator to create folium PolyLine objects.
Source code in src/mesqual/visualizations/folium_viz_system/viz_lines.py
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 | |
LineFeatureResolver
¶
Bases: FeatureResolver[ResolvedLineFeature]
Resolves visual properties for line/connection map elements.
Specialized feature resolver for line visualizations that handles LineString geometries, styling options like colors and widths, and animated ant paths. Commonly used for visualizing transmission lines, interconnectors, or any linear connections between geographic points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line_color
|
PropertyMapper | str
|
Line stroke color (static value or PropertyMapper) |
'#000000'
|
line_width
|
PropertyMapper | float
|
Line width in pixels (static value or PropertyMapper) |
3.0
|
line_opacity
|
PropertyMapper | float
|
Line transparency 0-1 (static value or PropertyMapper) |
1.0
|
dash_pattern
|
PropertyMapper | List[int]
|
Dash pattern as list of integers (static value or PropertyMapper) |
None
|
line_ant_path
|
PropertyMapper | bool
|
Enable animated "marching ants" effect (static value or PropertyMapper) |
False
|
line_ant_path_delay
|
PropertyMapper | int
|
Animation delay in milliseconds (static value or PropertyMapper) |
1500
|
line_ant_path_pulse_color
|
PropertyMapper | str
|
Color of animation pulses (static value or PropertyMapper) |
'#DBDBDB'
|
reverse_path_direction
|
PropertyMapper | bool
|
Reverse line direction (static value or PropertyMapper) |
False
|
tooltip
|
PropertyMapper | str | bool
|
Tooltip content, see |
True
|
popup
|
PropertyMapper | Popup | bool
|
Popup content, see |
False
|
geometry
|
PropertyMapper | LineString
|
LineString geometry (defaults to 'geometry' attribute) |
None
|
**property_mappers
|
PropertyMapper | Any
|
Additional custom property mappings |
{}
|
Examples:
Static styling:
>>> resolver = LineFeatureResolver(line_color='#FF0000', line_width=3.0, line_opacity=0.8)
Color and width from the absolute flow, an ant path for large flows, and the
geometry from the geo_line_string column of the border model:
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> from mesqual.visualizations.value_mapping_system import (
... SegmentedContinuousColorscale,
... SegmentedContinuousLineWidthMapping,
... )
>>> resolver = LineFeatureResolver(
... line_color=PropertyMapper.from_kpi_value(
... SegmentedContinuousColorscale(segments={(0, 1000): 'Blues'}), use_abs_kpi_value=True
... ),
... line_width=PropertyMapper.from_kpi_value(
... SegmentedContinuousLineWidthMapping(segments={(0, 1000): [1.0, 6.0]}), use_abs_kpi_value=True
... ),
... line_ant_path=PropertyMapper.from_kpi_value(lambda v: abs(v) > 100),
... geometry=PropertyMapper.from_item_attr('geo_line_string'),
... )
Source code in src/mesqual/visualizations/folium_viz_system/viz_lines.py
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 | |
LineGenerator
¶
Bases: FoliumObjectGenerator[LineFeatureResolver]
Generates folium PolyLine objects for lines, with offsets for parallel lines.
Creates one line per data item with the styling of its
LineFeatureResolver, with tooltip and popup. Lines with the same
coordinates in the same order get an offset; ant paths get none. A line
can be an animated ant path, for example to show the flow direction.
Typical uses are transmission lines or borders with flows, capacities or
utilization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_resolver
|
LineFeatureResolver
|
|
None
|
per_feature_group_offset_registry
|
bool
|
Track the offsets per feature group. |
True
|
offset_increment
|
int
|
Offset in pixels between lines with the same coordinates. Default: 5. |
5
|
Examples:
>>> from mesqual.kpis import Aggregations, FlagAggKPIBuilder
>>> from mesqual.visualizations.folium_viz_system import PropertyMapper
>>> dataset.add_kpis_from_definitions(
... FlagAggKPIBuilder().for_flag('CountryBorder.Results.flow_sent_net').with_aggregation(Aggregations.Mean).build()
... )
>>> flows = dataset.kpi_collection.filter(flag='CountryBorder.Results.flow_sent_net')
>>> import folium
>>> from mesqual.visualizations.value_mapping_system import SegmentedContinuousLineWidthMapping
>>> widths = SegmentedContinuousLineWidthMapping(segments={(0, 1000): [1.0, 6.0]})
>>> generator = LineGenerator(
... LineFeatureResolver(
... line_width=PropertyMapper.from_kpi_value(widths, use_abs_kpi_value=True),
... reverse_path_direction=PropertyMapper.from_kpi_value(lambda v: v < 0),
... line_ant_path=True,
... geometry=PropertyMapper.from_item_attr('geo_line_string'),
... ),
... offset_increment=10,
... )
>>> fg = generator.generate_objects_for_kpi_collection(flows, folium.FeatureGroup('Flows'))
Source code in src/mesqual/visualizations/folium_viz_system/viz_lines.py
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 | |
generate
¶
generate(data_item: VisualizableDataItem, feature_group: FeatureGroup) -> None
Generate and add a folium PolyLine to the feature group with automatic offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_item
|
VisualizableDataItem
|
Data item containing LineString geometry and associated data |
required |
feature_group
|
FeatureGroup
|
Folium feature group to add the line to |
required |
Source code in src/mesqual/visualizations/folium_viz_system/viz_lines.py
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 | |