geohierarchy.maps.folium.resolution¶
Zoom-resolution assignment for hierarchy levels.
Each level of a :class:~geohierarchy.core.GeoHierarchy is shown at exactly
one, level-specific range of Leaflet zoom levels (0-25 inclusive), so that at
any given zoom exactly one level's vector tiles are visible. This module
computes that assignment automatically from feature size (area/length), and
validates manually-specified ranges for gaps/overlaps.
assign_resolutions(hierarchy, levels=None, method='area')
¶
Automatically assign a contiguous, non-overlapping zoom range to each level.
Levels are sorted by median geoweight (area or length, whichever the
level already stores) descending -- coarsest (biggest features) first.
Bin edges are placed at the midpoints between consecutive levels'
log10(median size) values, then the full edge range is linearly
rescaled onto integer zooms [0, 25]: the coarsest level's range
always starts at 0 and the finest level's range always ends at 25, so
the returned ranges partition [0, 25] with no gaps or overlaps
regardless of how many levels are involved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
A :class: |
required | |
levels
|
Optional[Iterable[str]]
|
Level names to assign. Defaults to every level in
|
None
|
method
|
str
|
Unused placeholder for future weighting methods; kept for
API stability (geoweight column is always whatever
|
'area'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Tuple[int, int]]
|
Mapping of level name to an inclusive |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
fill_around_manual(hierarchy, all_levels, manual)
¶
Auto-assign zoom ranges for the levels not in manual, fit around it.
manual entries are kept exactly as given. The remaining levels are
grouped into the maximal runs of consecutive positions (in coarsest-first
size order over all levels) that fall between two manual pins (or the
ends of [0, 25]), and each run is independently log-size-binned via
:func:_bin_by_size onto its own leftover zoom sub-range -- so the
overall result still partitions [0, 25] with no gaps/overlaps as
long as manual itself doesn't already overlap/gap (validated by the
caller with :func:validate_resolutions).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
A :class: |
required | |
all_levels
|
List[str]
|
Every level name that needs a zoom range (manual + auto). |
required |
manual
|
Dict[str, Tuple[int, int]]
|
Manually pinned |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Tuple[int, int]]
|
Mapping covering every name in |
Dict[str, Tuple[int, int]]
|
unchanged, others auto-filled). |
validate_resolutions(resolutions)
¶
Validate a full set of manually-specified zoom ranges.
Checks that the given ranges, taken together, partition
[MIN_ZOOM, MAX_ZOOM] with no overlaps and no gaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolutions
|
Dict[str, Tuple[int, int]]
|
Mapping of level name to |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any range is invalid, ranges overlap, or ranges
leave a gap anywhere inside |