feat: 采样点透明度范围可在图层行设置
This commit is contained in:
@@ -201,7 +201,7 @@ AOI 在包内 `GIS.qgz` 中使用相对路径引用,默认不勾选。`output/
|
||||
|
||||
### 采样点图层.gpkg
|
||||
|
||||
来源:`source/Grid_5G.gpkg` 与 `source/Grid_4G.gpkg`。按当前市场范围筛出栅格后,比较栅格图形中心;相距 8 米以内视为同一个栅格,保留 5G 的图形(没有 5G 时保留 4G)。两边都有的 `mro_total_dl`、`mro_total_gd`、`mro_total_yd` 分别相加,写入 `电联采样点`、`广电采样点`、`移动采样点`,`总采样点数` 是这三个和。不计入 `mro_total_dx`、`mro_total_lt`。属性缺失按 0。`rank` 按本图层里 `总采样点数` 的名次从 10 到 70:相同数量同一档,最少为 10,最多为 70。样式为红色均匀填充和红色边界,符号不透明度等于该百分比,所以采样点越多颜色越深。工程中放在竞对信号上面,默认勾选。
|
||||
来源:`source/Grid_5G.gpkg` 与 `source/Grid_4G.gpkg`。按当前市场范围筛出栅格后,比较栅格图形中心;相距 8 米以内视为同一个栅格,保留 5G 的图形(没有 5G 时保留 4G)。两边都有的 `mro_total_dl`、`mro_total_gd`、`mro_total_yd` 分别相加,写入 `电联采样点`、`广电采样点`、`移动采样点`,`总采样点数` 是这三个和。不计入 `mro_total_dx`、`mro_total_lt`。属性缺失按 0。`rank` 按本图层里 `总采样点数` 的名次映射到图层选择里填写的透明度范围,默认 10 到 70:相同数量同一档,最少用下限,最多用上限。样式为红色均匀填充和红色边界,符号不透明度等于该百分比,所以采样点越多颜色越深。工程中放在竞对信号上面,默认勾选。
|
||||
|
||||
### 竞对信号.tif
|
||||
|
||||
|
||||
+15
@@ -78,6 +78,15 @@ def require_int(params, key, low, high, label):
|
||||
return value
|
||||
|
||||
|
||||
def opacity_percent(value, label):
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
||||
raise ValueError(f"{label}必须为数字。")
|
||||
number = float(value)
|
||||
if not 0 <= number <= 100:
|
||||
raise ValueError(f"{label}需在 0 到 100 之间。")
|
||||
return number
|
||||
|
||||
|
||||
def require_float(params, key, low, high, label):
|
||||
value = params.get(key)
|
||||
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
||||
@@ -211,6 +220,12 @@ def prepare_market(raw):
|
||||
params = dict(raw or {})
|
||||
plan = normalize(params.get("OUTPUT_LAYERS"))
|
||||
params["OUTPUT_LAYERS"] = plan
|
||||
low = opacity_percent(params.get("SAMPLE_OPACITY_MIN", 10), "透明度下限")
|
||||
high = opacity_percent(params.get("SAMPLE_OPACITY_MAX", 70), "透明度上限")
|
||||
if low > high:
|
||||
raise ValueError("透明度下限不能大于上限。")
|
||||
params["SAMPLE_OPACITY_MIN"] = low
|
||||
params["SAMPLE_OPACITY_MAX"] = high
|
||||
needed = needed_sources(plan)
|
||||
for key in SOURCES:
|
||||
if key not in needed:
|
||||
|
||||
@@ -10,6 +10,8 @@ SAMPLE_LAYER_NAME = "采样点图层"
|
||||
SAMPLE_LAYER_FILENAME = "采样点图层.gpkg"
|
||||
SAMPLE_MATCH_METERS = 8.0 # 栅格中心相距不超过该距离时视为同一个栅格。
|
||||
SAMPLE_VALUE_FIELDS = ("mro_total_dl", "mro_total_gd", "mro_total_yd")
|
||||
SAMPLE_OPACITY_MIN = 10.0 # 采样点最少一档的符号不透明度百分比。
|
||||
SAMPLE_OPACITY_MAX = 70.0 # 采样点最多一档的符号不透明度百分比。
|
||||
# 用户量图层停用;以下原代码以注释保留,便于按需恢复。
|
||||
BUILDING_INFO_GPKG = DEFAULT_SOURCE_DIR / "BuildingInfo.gpkg" # 建筑信息 GeoPackage 文件路径,用于结果包 BuildingInfo 分割和楼宇指标 CSV 名称匹配。
|
||||
NR_BUILDINGS_DATA_GPKG = DEFAULT_SOURCE_DIR / "NRBuildingsData.gpkg" # 清洗后的楼宇边界数据。
|
||||
|
||||
@@ -16,8 +16,6 @@ TABLE = "采样点图层"
|
||||
GEOM = "geom"
|
||||
SRS_ID = 4326
|
||||
FIELDS = ("电联采样点", "广电采样点", "移动采样点", "总采样点数", "rank")
|
||||
OPACITY_MIN = 10.0
|
||||
OPACITY_MAX = 70.0
|
||||
STYLES = Path(__file__).with_name("styles")
|
||||
WGS84 = (
|
||||
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,'
|
||||
@@ -51,16 +49,18 @@ def export_sample_grid(grid_5g_conn, grid_5g_layer, grid_5g_rtree, grid_4g_conn,
|
||||
}
|
||||
|
||||
|
||||
def opacity_by_total(totals):
|
||||
"""总采样点数的名次映射到 10–70。越多越高,最多为 70;相同数量同一档。"""
|
||||
def opacity_by_total(totals, low=None, high=None):
|
||||
"""总采样点数的名次映射到 low–high。越多越高,最多为 high;相同数量同一档。"""
|
||||
low = config.SAMPLE_OPACITY_MIN if low is None else float(low)
|
||||
high = config.SAMPLE_OPACITY_MAX if high is None else float(high)
|
||||
levels = sorted(set(totals))
|
||||
if not levels:
|
||||
return {}
|
||||
if len(levels) == 1:
|
||||
return {levels[0]: OPACITY_MAX}
|
||||
if len(levels) == 1 or low == high:
|
||||
return {value: high for value in levels}
|
||||
span = len(levels) - 1
|
||||
return {
|
||||
value: OPACITY_MIN + index / span * (OPACITY_MAX - OPACITY_MIN)
|
||||
value: low + index / span * (high - low)
|
||||
for index, value in enumerate(levels)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,12 @@ class SampleOpacityTests(unittest.TestCase):
|
||||
def test_single_total_is_the_darkest(self):
|
||||
self.assertEqual(opacity_by_total([4, 4]), {4: 70})
|
||||
|
||||
def test_custom_range_keeps_the_ends(self):
|
||||
mapping = opacity_by_total([1, 3, 9], 20, 80)
|
||||
self.assertEqual(mapping[1], 20)
|
||||
self.assertEqual(mapping[9], 80)
|
||||
self.assertEqual(mapping[3], 50)
|
||||
|
||||
def test_style_is_solid_red_using_opacity_percent(self):
|
||||
qml = (Path(__file__).resolve().parents[1] / "marketgrid" / "styles" / "sample_points.qml").read_text(encoding="utf-8")
|
||||
self.assertIn('value="solid"', qml)
|
||||
|
||||
@@ -27,6 +27,8 @@ const draft = reactive({
|
||||
summaryRaster: 100,
|
||||
clipMode: 'intersects',
|
||||
padding: 0.05,
|
||||
opacityMin: 10,
|
||||
opacityMax: 70,
|
||||
lastTaskId: '',
|
||||
})
|
||||
const sources = ref([])
|
||||
@@ -106,6 +108,8 @@ function persistForm() {
|
||||
summaryRaster: draft.summaryRaster,
|
||||
clipMode: draft.clipMode,
|
||||
padding: draft.padding,
|
||||
opacityMin: draft.opacityMin,
|
||||
opacityMax: draft.opacityMax,
|
||||
lastTaskId: draft.lastTaskId,
|
||||
layerPlan: JSON.parse(JSON.stringify(layerPlan)),
|
||||
step: step.value,
|
||||
@@ -124,7 +128,7 @@ function restoreForm() {
|
||||
if (saved.paths && typeof saved.paths === 'object') Object.assign(draft.paths, saved.paths)
|
||||
if (typeof saved.allMarkets === 'boolean') draft.allMarkets = saved.allMarkets
|
||||
if (Array.isArray(saved.chosen)) draft.chosen = saved.chosen
|
||||
for (const key of ['maxWorkers', 'scale', 'maxRaster', 'summaryRaster', 'padding']) {
|
||||
for (const key of ['maxWorkers', 'scale', 'maxRaster', 'summaryRaster', 'padding', 'opacityMin', 'opacityMax']) {
|
||||
if (typeof saved[key] === 'number') draft[key] = saved[key]
|
||||
}
|
||||
if (typeof saved.summary === 'boolean') draft.summary = saved.summary
|
||||
@@ -261,7 +265,7 @@ async function restoreTask() {
|
||||
}
|
||||
|
||||
function numbersReady() {
|
||||
return [draft.maxWorkers, draft.scale, draft.maxRaster, draft.summaryRaster, draft.padding]
|
||||
return [draft.maxWorkers, draft.scale, draft.maxRaster, draft.summaryRaster, draft.padding, draft.opacityMin, draft.opacityMax]
|
||||
.every((value) => typeof value === 'number')
|
||||
}
|
||||
|
||||
@@ -276,6 +280,11 @@ async function submit() {
|
||||
error.value = '请填写完整参数。'
|
||||
return
|
||||
}
|
||||
if (draft.opacityMin < 0 || draft.opacityMax > 100 || draft.opacityMin > draft.opacityMax) {
|
||||
error.value = '采样点透明度需在 0 到 100 之间,且下限不能大于上限。'
|
||||
step.value = 1
|
||||
return
|
||||
}
|
||||
const ids = [...draft.chosen]
|
||||
if (!ids.length) {
|
||||
error.value = '请至少选择一个网格。'
|
||||
@@ -301,6 +310,8 @@ async function submit() {
|
||||
SUMMARY_MAX_RASTER_PIXELS: Math.round(draft.summaryRaster * 1_000_000),
|
||||
CLIP_MODE: draft.clipMode,
|
||||
PROJECT_EXTENT_PADDING_RATIO: draft.padding,
|
||||
SAMPLE_OPACITY_MIN: draft.opacityMin,
|
||||
SAMPLE_OPACITY_MAX: draft.opacityMax,
|
||||
OUTPUT_LAYERS: JSON.parse(JSON.stringify(layerPlan)),
|
||||
},
|
||||
})
|
||||
@@ -374,9 +385,33 @@ onUnmounted(() => {
|
||||
<div v-for="item in outputLayers" :key="item.key" class="layer-row">
|
||||
<n-checkbox :checked="layerPlan[item.key]?.enabled" @update:checked="setLayerEnabled(item.key, $event)" />
|
||||
<n-checkbox v-model:checked="layerPlan[item.key].visible" :disabled="!layerPlan[item.key]?.enabled" />
|
||||
<span>
|
||||
{{ item.name }}
|
||||
<span v-if="item.key === 'boundary'" class="muted">成果中的名称是网格名称加“边界”</span>
|
||||
<span class="layer-name">
|
||||
<span>
|
||||
{{ item.name }}
|
||||
<span v-if="item.key === 'boundary'" class="muted">成果中的名称是网格名称加“边界”</span>
|
||||
</span>
|
||||
<span v-if="item.key === 'sample'" class="opacity-range">
|
||||
<span class="muted">透明度</span>
|
||||
<n-input-number
|
||||
v-model:value="draft.opacityMin"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="0"
|
||||
size="small"
|
||||
:disabled="!layerPlan.sample?.enabled"
|
||||
placeholder="最小"
|
||||
/>
|
||||
<span class="muted">-</span>
|
||||
<n-input-number
|
||||
v-model:value="draft.opacityMax"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="0"
|
||||
size="small"
|
||||
:disabled="!layerPlan.sample?.enabled"
|
||||
placeholder="最大"
|
||||
/>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -488,6 +523,9 @@ onUnmounted(() => {
|
||||
}
|
||||
.layer-head { color: #66788a; font-size: 12px; border-bottom: 1px solid #f0f3f6; }
|
||||
.layer-row + .layer-row { border-top: 1px solid #f0f3f6; }
|
||||
.layer-name { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
|
||||
.opacity-range { display: flex; align-items: center; gap: 6px; flex: none; }
|
||||
.opacity-range :deep(.n-input-number) { width: 84px; }
|
||||
.wizard-nav { display: flex; justify-content: space-between; gap: 8px; }
|
||||
.wizard-nav:not(:has(button + button)) { justify-content: flex-end; }
|
||||
.step-hit { cursor: pointer; }
|
||||
|
||||
Reference in New Issue
Block a user