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。工程中放在竞对信号上面,默认勾选,蓝色空心边,避免挡住下面的竞对信号。
|
||||
来源:`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。`透明度` 按本图层里 `总采样点数` 的名次从 5 到 65:相同数量同一档,最少为 5,最多为 65。样式为红色均匀填充和红色边界,符号不透明度等于该百分比,所以采样点越多颜色越深。工程中放在竞对信号上面,默认勾选。
|
||||
|
||||
### 竞对信号.tif
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -3,19 +3,32 @@
|
||||
<renderer-v2 type="singleSymbol" symbollevels="0" forceraster="0" enableorderby="0">
|
||||
<symbols>
|
||||
<symbol type="fill" name="0" alpha="1" clip_to_extent="1" force_rhr="0">
|
||||
<data_defined_properties>
|
||||
<Option type="Map">
|
||||
<Option name="name" type="QString" value=""/>
|
||||
<Option name="properties" type="Map">
|
||||
<Option name="alpha" type="Map">
|
||||
<Option name="active" type="bool" value="true"/>
|
||||
<Option name="expression" type="QString" value=""透明度""/>
|
||||
<Option name="type" type="int" value="3"/>
|
||||
</Option>
|
||||
</Option>
|
||||
<Option name="type" type="QString" value="collection"/>
|
||||
</Option>
|
||||
</data_defined_properties>
|
||||
<layer class="SimpleFill" enabled="1" pass="0" locked="0">
|
||||
<Option type="Map">
|
||||
<Option name="border_width_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
|
||||
<Option name="color" type="QString" value="0,0,0,0"/>
|
||||
<Option name="color" type="QString" value="255,0,0,255"/>
|
||||
<Option name="joinstyle" type="QString" value="bevel"/>
|
||||
<Option name="offset" type="QString" value="0,0"/>
|
||||
<Option name="offset_map_unit_scale" type="QString" value="3x:0,0,0,0,0,0"/>
|
||||
<Option name="offset_unit" type="QString" value="MM"/>
|
||||
<Option name="outline_color" type="QString" value="0,114,178,255"/>
|
||||
<Option name="outline_color" type="QString" value="255,0,0,255"/>
|
||||
<Option name="outline_style" type="QString" value="solid"/>
|
||||
<Option name="outline_width" type="QString" value="0.26"/>
|
||||
<Option name="outline_width_unit" type="QString" value="MM"/>
|
||||
<Option name="style" type="QString" value="no"/>
|
||||
<Option name="style" type="QString" value="solid"/>
|
||||
</Option>
|
||||
</layer>
|
||||
</symbol>
|
||||
|
||||
@@ -12,7 +12,7 @@ from shapely.geometry import box
|
||||
from marketgrid import config, qgis
|
||||
from marketgrid.models import MarketFeature
|
||||
from marketgrid.output_layers import needed_sources, normalize
|
||||
from marketgrid.sample_grid import merge_sample_records
|
||||
from marketgrid.sample_grid import merge_sample_records, opacity_by_total
|
||||
from tests.test_toolbox import create_gpkg
|
||||
from marketgrid.gpkg import open_read_connection, resolve_feature_layer, rtree_name
|
||||
from marketgrid.jobs import process_market
|
||||
@@ -23,6 +23,23 @@ def _record(lon, lat, dl, gd, yd):
|
||||
return {"lon": lon, "lat": lat, "dl": dl, "gd": gd, "yd": yd, "blob": b"", "bounds": (lon, lat, lon, lat)}
|
||||
|
||||
|
||||
class SampleOpacityTests(unittest.TestCase):
|
||||
def test_rank_runs_from_five_to_sixty_five(self):
|
||||
mapping = opacity_by_total([1, 1, 5, 9])
|
||||
self.assertEqual(mapping[1], 5)
|
||||
self.assertEqual(mapping[5], 35)
|
||||
self.assertEqual(mapping[9], 65)
|
||||
|
||||
def test_single_total_is_the_darkest(self):
|
||||
self.assertEqual(opacity_by_total([4, 4]), {4: 65})
|
||||
|
||||
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)
|
||||
self.assertIn('value="255,0,0,255"', qml)
|
||||
self.assertIn('value=""透明度""', qml)
|
||||
|
||||
|
||||
class SampleMergeTests(unittest.TestCase):
|
||||
def test_cells_within_eight_meters_sum_and_keep_five_g_geometry(self):
|
||||
five = [_record(113.0, 22.0, 10, 1, 100)]
|
||||
@@ -60,9 +77,11 @@ class SampleMergeTests(unittest.TestCase):
|
||||
conn = sqlite3.connect(root / "采样点图层.gpkg")
|
||||
try:
|
||||
row = conn.execute('select "电联采样点","广电采样点","移动采样点","总采样点数" from "采样点图层"').fetchone()
|
||||
opacity = conn.execute('select "透明度" from "采样点图层"').fetchone()[0]
|
||||
finally:
|
||||
conn.close()
|
||||
self.assertEqual(row, (14, 7, 108, 129))
|
||||
self.assertEqual(opacity, 65)
|
||||
|
||||
def test_project_places_checked_sample_layer_above_competitor_signal(self):
|
||||
market = MarketFeature(1, "1-甲", "甲", box(0, 0, 1, 1))
|
||||
|
||||
Reference in New Issue
Block a user