diff --git a/README.md b/README.md index 34ed462..fbb9f8a 100644 --- a/README.md +++ b/README.md @@ -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。工程中放在竞对信号上面,默认勾选,蓝色空心边,避免挡住下面的竞对信号。 ### 竞对信号.tif diff --git a/marketgrid/sample_grid.py b/marketgrid/sample_grid.py index 04035c0..812d356 100644 --- a/marketgrid/sample_grid.py +++ b/marketgrid/sample_grid.py @@ -15,7 +15,7 @@ from .raster_math import to_float TABLE = "采样点图层" GEOM = "geom" SRS_ID = 4326 -FIELDS = ("mro_total_dl", "mro_total_gd", "mro_total_yd", "总采样点数") +FIELDS = ("电联采样点", "广电采样点", "移动采样点", "总采样点数") STYLES = Path(__file__).with_name("styles") WGS84 = ( 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,' @@ -214,10 +214,11 @@ def _write(output_path, records, fallback_extent): "VALUES ('','',?,?,?,?,?,1,'','',NULL,?)", (TABLE, GEOM, "Default", qml, "", now), ) + columns = ", ".join(f'"{name}"' for name in FIELDS) + placeholders = ", ".join(["?"] * (2 + len(FIELDS))) for index, record in enumerate(records, start=1): conn.execute( - f'INSERT INTO "{TABLE}" (fid, "{GEOM}", "mro_total_dl", "mro_total_gd", "mro_total_yd", "总采样点数") ' - "VALUES (?,?,?,?,?,?)", + f'INSERT INTO "{TABLE}" (fid, "{GEOM}", {columns}) VALUES ({placeholders})', (index, record["blob"], record["dl"], record["gd"], record["yd"], record["total"]), ) minx, miny, maxx, maxy = record["bounds"] diff --git a/tests/test_sample_grid.py b/tests/test_sample_grid.py index e4c942b..46c88fd 100644 --- a/tests/test_sample_grid.py +++ b/tests/test_sample_grid.py @@ -59,7 +59,7 @@ class SampleMergeTests(unittest.TestCase): self.assertEqual(result["feature_count"], 1) conn = sqlite3.connect(root / "采样点图层.gpkg") try: - row = conn.execute('select "mro_total_dl","mro_total_gd","mro_total_yd","总采样点数" from "采样点图层"').fetchone() + row = conn.execute('select "电联采样点","广电采样点","移动采样点","总采样点数" from "采样点图层"').fetchone() finally: conn.close() self.assertEqual(row, (14, 7, 108, 129)) diff --git a/tests/test_toolbox.py b/tests/test_toolbox.py index 65de10e..a6a7c7a 100644 --- a/tests/test_toolbox.py +++ b/tests/test_toolbox.py @@ -225,7 +225,7 @@ class TaskIntegrationTest(unittest.TestCase): sample_path.write_bytes(archive.read("采样点图层.gpkg")) sample_conn = sqlite3.connect(sample_path) try: - totals = {row[-1] for row in sample_conn.execute('select "mro_total_dl","mro_total_gd","mro_total_yd","总采样点数" from "采样点图层"')} + totals = {row[-1] for row in sample_conn.execute('select "电联采样点","广电采样点","移动采样点","总采样点数" from "采样点图层"')} finally: sample_conn.close() if name == "31-甲.zip":