feat: 采样点按总量名次用红色深浅显示
This commit is contained in:
@@ -15,7 +15,9 @@ from .raster_math import to_float
|
||||
TABLE = "采样点图层"
|
||||
GEOM = "geom"
|
||||
SRS_ID = 4326
|
||||
FIELDS = ("电联采样点", "广电采样点", "移动采样点", "总采样点数")
|
||||
FIELDS = ("电联采样点", "广电采样点", "移动采样点", "总采样点数", "透明度")
|
||||
OPACITY_MIN = 5.0
|
||||
OPACITY_MAX = 65.0
|
||||
STYLES = Path(__file__).with_name("styles")
|
||||
WGS84 = (
|
||||
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,'
|
||||
@@ -30,6 +32,9 @@ def export_sample_grid(grid_5g_conn, grid_5g_layer, grid_5g_rtree, grid_4g_conn,
|
||||
four = _collect(grid_4g_conn, grid_4g_layer, grid_4g_rtree, market)
|
||||
lat0 = (market.geometry.bounds[1] + market.geometry.bounds[3]) / 2
|
||||
merged = merge_sample_records(five, four, lat0, config.SAMPLE_MATCH_METERS)
|
||||
opacity = opacity_by_total(record["total"] for record in merged)
|
||||
for record in merged:
|
||||
record["opacity"] = opacity[record["total"]]
|
||||
_write(output_path, merged, market.geometry.bounds)
|
||||
return {
|
||||
"market_code": market.code,
|
||||
@@ -46,6 +51,20 @@ def export_sample_grid(grid_5g_conn, grid_5g_layer, grid_5g_rtree, grid_4g_conn,
|
||||
}
|
||||
|
||||
|
||||
def opacity_by_total(totals):
|
||||
"""总采样点数的名次映射到 5–65。越多越高,最多为 65;相同数量同一档。"""
|
||||
levels = sorted(set(totals))
|
||||
if not levels:
|
||||
return {}
|
||||
if len(levels) == 1:
|
||||
return {levels[0]: OPACITY_MAX}
|
||||
span = len(levels) - 1
|
||||
return {
|
||||
value: OPACITY_MIN + index / span * (OPACITY_MAX - OPACITY_MIN)
|
||||
for index, value in enumerate(levels)
|
||||
}
|
||||
|
||||
|
||||
def merge_sample_records(five, four, latitude, meters):
|
||||
"""中心相距不超过 meters 的 4G、5G 栅格合成一条,图形保留 5G。"""
|
||||
scale_x = 111_320 * math.cos(math.radians(latitude))
|
||||
@@ -219,7 +238,10 @@ def _write(output_path, records, fallback_extent):
|
||||
for index, record in enumerate(records, start=1):
|
||||
conn.execute(
|
||||
f'INSERT INTO "{TABLE}" (fid, "{GEOM}", {columns}) VALUES ({placeholders})',
|
||||
(index, record["blob"], record["dl"], record["gd"], record["yd"], record["total"]),
|
||||
(
|
||||
index, record["blob"], record["dl"], record["gd"], record["yd"],
|
||||
record["total"], record["opacity"],
|
||||
),
|
||||
)
|
||||
minx, miny, maxx, maxy = record["bounds"]
|
||||
conn.execute(
|
||||
|
||||
Reference in New Issue
Block a user