fix(map): DXCC 资产重建——俄罗斯拆欧/亚、提取子实体、英国四实体、德巴改现行码

- dxcc.json(176→189区): 沿乌拉尔山/河(OSM relation 21368163 + NE 乌拉尔河)
  把整只俄罗斯切成 European Russia(54)/Asiatic Russia(15)——修复亚洲俄罗斯
  永不填绿; 从父国环提取 Alaska/Hawaii/East Malaysia/French Guiana/Corsica/
  Crete/Sardinia/Kaliningrad/Franz Josef 9 子实体; 英国拆 England(223)/
  Scotland(279)/Wales(294)/N.Ireland(265) 四实体; Germany 81→230、
  Palestine 196→510 改为 ADIF 现行码(81/196 已删除, LoTW 导出现行码永不匹配)
- 新增 DxccAssetTest 5 例: 必备码齐全/ADIF名/环完整性/26城侧归属/禁用
  ADIF 3.1.7 全部62个已删除码; build.gradle 补 testImplementation org.json
- THIRD_PARTY_NOTICES: 补 OSM(ODbL) 与 Natural Earth(公共领域) 数据出处
This commit is contained in:
atsunatsu committed 2026-10-05 17:13:50 +08:00
1 parent f35d78186c
commit 881ca442ff
4 files changed
+207 -1

No files matched your search

+2
View File
@@ -8,4 +8,6 @@ android {
dependencies {
implementation(libs.other.osmdroid)
// Real org.json for unit tests (android.jar stub throws "not mocked")
testImplementation(libs.test.json)
}
+1 -1
View File
@@ -1 +1 @@
{"type":"dxcc","regions":[{"id":0,"code":176,"name":"Fiji","label_lon":177.9759,"label_lat":-17.9376,"rings":[[[180.0,-16.0671],[180.0,-16.5552],[179.3641,-16.8014],[178.7251,-17.012],[178.5968,-16.6392],[179.0966,-16.434],[179.4135,-16.3791],[180.0,-16.0671]],[[178.1256,-17.5048],[178.3736,-17.3399],[178.7181,-17.6285],[178.5527,-18.1506],[177.9327,-18.288],[177.3815,-18.1643],[177.285,-17.7247],[177.6709,-17.3811]],[[-179.7933,-16.0209],[-179.9174,-16.5018],[-180.0,-16.5552],[-180.0,-16.0671]]]},{"id":1,"code":470,"name":"Tanzania","label_lon":34.1421,"label_lat":-6.2078,"rings":[[[33.9037,-0.95],[34.0726,-1.0598],[37.6987,-3.097],[37.7669,-3.6771],[39.2022,-4.6768],[38.7405,-5.9089],[38.7998,-6.4757],[39.44,-6.84],[39.47,-7.1],[39.1947,-7.7039],[39.252,-8.0078],[39.1865,-8.4855],[39.5357,-9.1124],[39.9496,-10.0984],[40.3166,-10.3171],[40.3166,-10.3171],[39.521,-10.8969],[38.4276,-11.2852],[37.8276,-11.2688],[37.4713,-11.5688],[36.7752,-11.5945],[36.5141,-11.7209],[35.3124,-11.4391],[34.56,-11.52],[34.28,-10.16],[33.9408,-9.6937],[33.7397,-9.4171],[32.7594,-9.2306],[32.1919,-8.9304],[31.5563,-8.762],[31.1578,-8.5946],[30.74,-8.34],[30.74,-8.34],[30.2,-7.08],[29.62,-6.52],[29.42,-5.94],[29.52,-5.42],[29.34,-4.5],[29.7535,-4.4524],[30.1163,-4.0901],[30.5055,-3.5686],[30.7522,-3.3593],[30.743,-3.0343],[30.5277,-2.8076],[30.4697,-2.4139],[30.4697,-2.4138],[30.7583,-2.2872],[30.8161,-1.6989],[30.4191,-1.1347],[30.7699,-1.0146],[31.8662,-1.0274]]]},{"id":2,"code":302,"name":"W. Sahara","label_lon":-12.572,"label_lat":24.2306,"rings":[[[-8.6656,27.6564],[-8.6651,27.5895],[-8.6844,27.3957],[-8.6873,25.8811],[-11.9694,25.9334],[-11.9372,23.3746],[-12.8742,23.2848],[-13.1188,22.7712],[-12.9291,21.3271],[-16.8452,21.3333],[-17.0634,20.9998],[-17.0204,21.4223],[-17.003,21.4207],[-14.751,21.5006],[-14.6308,21.8609],[-14.2212,22.3102],[-13.8911,23.691],[-12.501,24.7701],[-12.0308,26.0309],[-11.7182,26.1041],[-11.3926,26.8834],[-10.5513,26.9908],[-10.1894,26.8609],[-9.7353,26.8609],[-9.413,27.0885],[-8.7949,27.1207],[-8.8178,27.6564]]]},{"id":3,"code":1,"name":"Canada","label_lon":-110.2438,"label_lat":56.7019,"rings":[[[-122.84,49.0],[-122.9742,49.0025],[-124.9102,49.9846],[-125.6246,50.4166],[-127.4356,50.8306],[-127.9928,51.7158],[-127.8503,52.3296],[-129.1298,52.7554],[-129.3052,53.5616],[-130.515,54.2876],[-130.5361,54.8028],[-130.5361,54.8028],[-129.98,55.285],[-130.0078,55.9158],[-131.7078,56.5521],[-132.7304,57.6929],[-133.3556,58.4103],[-134.2711,58.8611],[-134.945,59.2706],[-135.4758,59.7878],[-136.4797,59.4639],[-137.4525,58.905],[-138.3409,59.5621],[-139.039,60.0],[-140.013,60.2768],[-140.9978,60.3064],[-140.9925,66.0],[-140.986,69.712],[-140.986,69.712],[-139.1205,69.471],[-137.5464,68.99],[-136.5036,68.898],[-135.6258,69.3151],[-134.4146,69.6274],[-132.9292,69.5053],[-131.4314,69.9445],[-129.7947,70.1937],[-129.1077,69.7793],[-128.3616,70.0129],[-128.1382,70.4838],[-127.4471,70.3772],[-125.7563,69.4806],[-124.4248,70.1584],[-124.2897,69.3997],[-123.0611,69.5637],[-122.6835,69.8555],[-121.4723,69.7978],[-119.9429,69.3779],[-117.6027,69.0113],[-116.2264,68.8415],[-115.2469,68.9059],[-113.8979,68.3989],[-115.3049,67.9026],[-113.4973,67.6881],[-110.798,67.8061],[-109.9462,67.981],[-108.8802,67.3814],[-107.7924,67.8874],[-108.813,68.3116],[-108.1672,68.6539],[-106.95,68.7],[-106.15,68.8],[-105.3428,68.5612],[-104.3379,68.018],[-103.2211,68.0978],[-101.4543,67.6469],[-99.9019,67.8057],[-98.4432,67.7816],[-98.5586,68.4039],[-97.6695,68.5786],[-96.1199,68.2394],[-96.1259,67.2934],[-95.4894,68.0907],[-94.685,68.0638],[-94.2328,69.069],[-95.3041,69.6857],[-96.4713,70.0898],[-96.3911,71.1948],[-95.2088,71.9205],[-93.89,71.7601],[-92.8782,71.3187],[-91.5196,70.1913],[-92.4069,69.7],[-90.5471,69.4977],[-90.5515,68.475],[-89.2151,69.2587],[-88.0197,68.6151],[-88.3175,67.8734],[-87.3502,67.1987],[-86.3061,67.9215],[-85.5766,68.7846],[-85.522,69.8821],[-84.1008,69.8054],[-82.6226,69.6583],[-81.2804,69.162],[-81.2202,68.6657],[-81.9644,68.1325],[-81.2593,67.5972],[-81.3865,67.1108],[-83.3446,66.4115],[-84.7354,66.2573],[-85.7694,66.5583],[-86.0676,66.0563],[-87.0314,65.213],[-87.3232,64.7756],[-88.483,64.099],[-89.9144,64.0327],[-90.704,63.6102],[-90.77,62.9602],[-91.9334,62.8351],[-93.157,62.0247],[-94.2415,60.8987],[-94.6293,60.1102],[-94.6846,58.9488],[-93.215,58.7821],[-92.7646,57.8457],[-92.297,57.0871],[-90.8977,57.2847],[-89.0395,56.8517],[-88.0398,56.4716],[-87.3242,55.9991],[-86.0712,55.7238],[-85.0118,55.3026],[-83.3606,55.2449],[-82.2729,55.1483],[-82.4362,54.2823],[-82.125,53.277],[-81.4008,52.1579],[-79.9129,51.2084],[-79.143,51.5339],[-78.6019,52.5621],[-79.1242,54.1414],[-79.8296,54.6677],[-78.2287,55.1365],[-77.0956,55.8374],[-76.5414,56.5342],[-76.6232,57.2026],[-77.3023,58.0521],[-78.5169,58.8046],[-77.3368,59.8526],[-77.7727,60.7579],[-78.1069,62.3196],[-77.4107,62.5505],[-75.6962,62.2784],[-74.6682,62.1811],[-73.8399,62.4438],[-72.9085,62.1051],[-71.6771,61.5254],[-71.3737,61.1372],[-69.5904,61.0614],[Line truncated
{"type":"dxcc","regions":[{"id":0,"code":176,"name":"Fiji","label_lon":177.9759,"label_lat":-17.9376,"rings":[[[180.0,-16.0671],[180.0,-16.5552],[179.3641,-16.8014],[178.7251,-17.012],[178.5968,-16.6392],[179.0966,-16.434],[179.4135,-16.3791],[180.0,-16.0671]],[[178.1256,-17.5048],[178.3736,-17.3399],[178.7181,-17.6285],[178.5527,-18.1506],[177.9327,-18.288],[177.3815,-18.1643],[177.285,-17.7247],[177.6709,-17.3811]],[[-179.7933,-16.0209],[-179.9174,-16.5018],[-180.0,-16.5552],[-180.0,-16.0671]]]},{"id":1,"code":470,"name":"Tanzania","label_lon":34.1421,"label_lat":-6.2078,"rings":[[[33.9037,-0.95],[34.0726,-1.0598],[37.6987,-3.097],[37.7669,-3.6771],[39.2022,-4.6768],[38.7405,-5.9089],[38.7998,-6.4757],[39.44,-6.84],[39.47,-7.1],[39.1947,-7.7039],[39.252,-8.0078],[39.1865,-8.4855],[39.5357,-9.1124],[39.9496,-10.0984],[40.3166,-10.3171],[40.3166,-10.3171],[39.521,-10.8969],[38.4276,-11.2852],[37.8276,-11.2688],[37.4713,-11.5688],[36.7752,-11.5945],[36.5141,-11.7209],[35.3124,-11.4391],[34.56,-11.52],[34.28,-10.16],[33.9408,-9.6937],[33.7397,-9.4171],[32.7594,-9.2306],[32.1919,-8.9304],[31.5563,-8.762],[31.1578,-8.5946],[30.74,-8.34],[30.74,-8.34],[30.2,-7.08],[29.62,-6.52],[29.42,-5.94],[29.52,-5.42],[29.34,-4.5],[29.7535,-4.4524],[30.1163,-4.0901],[30.5055,-3.5686],[30.7522,-3.3593],[30.743,-3.0343],[30.5277,-2.8076],[30.4697,-2.4139],[30.4697,-2.4138],[30.7583,-2.2872],[30.8161,-1.6989],[30.4191,-1.1347],[30.7699,-1.0146],[31.8662,-1.0274]]]},{"id":2,"code":302,"name":"W. Sahara","label_lon":-12.572,"label_lat":24.2306,"rings":[[[-8.6656,27.6564],[-8.6651,27.5895],[-8.6844,27.3957],[-8.6873,25.8811],[-11.9694,25.9334],[-11.9372,23.3746],[-12.8742,23.2848],[-13.1188,22.7712],[-12.9291,21.3271],[-16.8452,21.3333],[-17.0634,20.9998],[-17.0204,21.4223],[-17.003,21.4207],[-14.751,21.5006],[-14.6308,21.8609],[-14.2212,22.3102],[-13.8911,23.691],[-12.501,24.7701],[-12.0308,26.0309],[-11.7182,26.1041],[-11.3926,26.8834],[-10.5513,26.9908],[-10.1894,26.8609],[-9.7353,26.8609],[-9.413,27.0885],[-8.7949,27.1207],[-8.8178,27.6564]]]},{"id":3,"code":1,"name":"Canada","label_lon":-110.2438,"label_lat":56.7019,"rings":[[[-122.84,49.0],[-122.9742,49.0025],[-124.9102,49.9846],[-125.6246,50.4166],[-127.4356,50.8306],[-127.9928,51.7158],[-127.8503,52.3296],[-129.1298,52.7554],[-129.3052,53.5616],[-130.515,54.2876],[-130.5361,54.8028],[-130.5361,54.8028],[-129.98,55.285],[-130.0078,55.9158],[-131.7078,56.5521],[-132.7304,57.6929],[-133.3556,58.4103],[-134.2711,58.8611],[-134.945,59.2706],[-135.4758,59.7878],[-136.4797,59.4639],[-137.4525,58.905],[-138.3409,59.5621],[-139.039,60.0],[-140.013,60.2768],[-140.9978,60.3064],[-140.9925,66.0],[-140.986,69.712],[-140.986,69.712],[-139.1205,69.471],[-137.5464,68.99],[-136.5036,68.898],[-135.6258,69.3151],[-134.4146,69.6274],[-132.9292,69.5053],[-131.4314,69.9445],[-129.7947,70.1937],[-129.1077,69.7793],[-128.3616,70.0129],[-128.1382,70.4838],[-127.4471,70.3772],[-125.7563,69.4806],[-124.4248,70.1584],[-124.2897,69.3997],[-123.0611,69.5637],[-122.6835,69.8555],[-121.4723,69.7978],[-119.9429,69.3779],[-117.6027,69.0113],[-116.2264,68.8415],[-115.2469,68.9059],[-113.8979,68.3989],[-115.3049,67.9026],[-113.4973,67.6881],[-110.798,67.8061],[-109.9462,67.981],[-108.8802,67.3814],[-107.7924,67.8874],[-108.813,68.3116],[-108.1672,68.6539],[-106.95,68.7],[-106.15,68.8],[-105.3428,68.5612],[-104.3379,68.018],[-103.2211,68.0978],[-101.4543,67.6469],[-99.9019,67.8057],[-98.4432,67.7816],[-98.5586,68.4039],[-97.6695,68.5786],[-96.1199,68.2394],[-96.1259,67.2934],[-95.4894,68.0907],[-94.685,68.0638],[-94.2328,69.069],[-95.3041,69.6857],[-96.4713,70.0898],[-96.3911,71.1948],[-95.2088,71.9205],[-93.89,71.7601],[-92.8782,71.3187],[-91.5196,70.1913],[-92.4069,69.7],[-90.5471,69.4977],[-90.5515,68.475],[-89.2151,69.2587],[-88.0197,68.6151],[-88.3175,67.8734],[-87.3502,67.1987],[-86.3061,67.9215],[-85.5766,68.7846],[-85.522,69.8821],[-84.1008,69.8054],[-82.6226,69.6583],[-81.2804,69.162],[-81.2202,68.6657],[-81.9644,68.1325],[-81.2593,67.5972],[-81.3865,67.1108],[-83.3446,66.4115],[-84.7354,66.2573],[-85.7694,66.5583],[-86.0676,66.0563],[-87.0314,65.213],[-87.3232,64.7756],[-88.483,64.099],[-89.9144,64.0327],[-90.704,63.6102],[-90.77,62.9602],[-91.9334,62.8351],[-93.157,62.0247],[-94.2415,60.8987],[-94.6293,60.1102],[-94.6846,58.9488],[-93.215,58.7821],[-92.7646,57.8457],[-92.297,57.0871],[-90.8977,57.2847],[-89.0395,56.8517],[-88.0398,56.4716],[-87.3242,55.9991],[-86.0712,55.7238],[-85.0118,55.3026],[-83.3606,55.2449],[-82.2729,55.1483],[-82.4362,54.2823],[-82.125,53.277],[-81.4008,52.1579],[-79.9129,51.2084],[-79.143,51.5339],[-78.6019,52.5621],[-79.1242,54.1414],[-79.8296,54.6677],[-78.2287,55.1365],[-77.0956,55.8374],[-76.5414,56.5342],[-76.6232,57.2026],[-77.3023,58.0521],[-78.5169,58.8046],[-77.3368,59.8526],[-77.7727,60.7579],[-78.1069,62.3196],[-77.4107,62.5505],[-75.6962,62.2784],[-74.6682,62.1811],[-73.8399,62.4438],[-72.9085,62.1051],[-71.6771,61.5254],[-71.3737,61.1372],[-69.5904,61.0614],[Line truncated
@@ -0,0 +1,183 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2026 Arty Bishop and contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.feature.map
import java.io.File
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* Guards `assets/awards/dxcc.json`, the DXCC boundary asset behind the grid-mode
* award overlay (`AwardBoundaryOverlay` matches worked codes against
* `region.code`). The 2026-10 rebuild split Russia into European (54) /
* Asiatic (15), extracted sub-entities (Alaska, Hawaii, East Malaysia,
* French Guiana, Corsica, Crete, Sardinia, Kaliningrad, Franz Josef Land)
* and partitioned the UK into England/Scotland/Wales/Northern Ireland —
* and re-keyed Germany (81 -> 230) / Palestine (196 -> 510) to current ADIF
* codes — these tests pin the invariants that regeneration must keep.
*/
class DxccAssetTest {
private val assetRelPath = "src/main/assets/awards/dxcc.json"
private data class CityCheck(
val name: String, val lon: Double, val lat: Double,
val inside: Int, val outside: Int
)
private fun loadRegions(): List<JSONObject> {
// Unit-test working dir varies (module dir vs repo root) — walk upwards.
val file = generateSequence(File("").absoluteFile) { it.parentFile }
.mapNotNull { base ->
listOf(File(base, assetRelPath), File(base, "feature/map/$assetRelPath"))
.firstOrNull { it.isFile }
}
.firstOrNull()
?: error("dxcc.json not found starting from ${File("").absolutePath}")
val root = JSONObject(file.readText())
val arr = root.getJSONArray("regions")
return (0 until arr.length()).map { arr.getJSONObject(it) }
}
private fun List<JSONObject>.byCode(code: Int): JSONObject =
first { it.getInt("code") == code }
/** Even-odd ray casting across all rings of a region (rings are disjoint parts). */
private fun regionContains(region: JSONObject, lon: Double, lat: Double): Boolean {
val rings = region.getJSONArray("rings")
var inside = false
for (r in 0 until rings.length()) {
val ring = rings.getJSONArray(r)
val n = ring.length()
for (j in 0 until n) {
val a = ring.getJSONArray(j)
val b = ring.getJSONArray((j + 1) % n)
val y1 = a.getDouble(1)
val y2 = b.getDouble(1)
if ((y1 > lat) != (y2 > lat)) {
val x = a.getDouble(0) + (lat - y1) / (y2 - y1) * (b.getDouble(0) - a.getDouble(0))
if (x > lon) inside = !inside
}
}
}
return inside
}
@Test
fun `required ADIF entity codes are present exactly once`() {
val regions = loadRegions()
val codes = regions.map { it.getInt("code") }
assertEquals("duplicate codes", codes.size, codes.toSet().size)
val required = listOf(
15, 54, // Asiatic / European Russia
6, 110, 291, // Alaska / Hawaii / rest of USA
46, 299, // East / West Malaysia
63, 214, 227, // French Guiana / Corsica / rest of France
40, 236, // Crete / rest of Greece
225, 248, // Sardinia / rest of Italy
126, 61, // Kaliningrad / Franz Josef Land
223, 279, 294, 265, // England / Scotland / Wales / N. Ireland
230, 510 // Germany / Palestine (current ADIF codes)
)
required.forEach { code -> assertTrue("missing code $code", code in codes) }
}
@Test
fun `no region uses an ADIF-deleted entity code`() {
// ADIF 3.1.7 deleted DXCC codes. A polygon keyed to a deleted code
// never matches LoTW exports (they carry the active code, e.g.
// Germany 81 -> 230, Palestine 196 -> 510), so the award never fills.
val deleted = setOf(
2, 8, 19, 23, 25, 26, 28, 30, 39, 42, 44, 55, 57, 58, 59, 67, 68,
81, 85, 93, 101, 102, 113, 115, 119, 127, 128, 134, 139, 151, 154, 155,
164, 178, 183, 184, 186, 193, 194, 196, 198, 200, 208, 210, 218, 220,
226, 228, 229, 231, 243, 244, 255, 258, 261, 264, 267, 268, 271, 307,
488, 493
)
loadRegions().forEach { region ->
val code = region.getInt("code")
assertTrue("${region.getString("name")} uses deleted code $code", code !in deleted)
}
}
@Test
fun `entities carry their ADIF names`() {
val regions = loadRegions()
assertEquals("England", regions.byCode(223).getString("name"))
assertEquals("European Russia", regions.byCode(54).getString("name"))
assertEquals("Asiatic Russia", regions.byCode(15).getString("name"))
assertEquals("Scotland", regions.byCode(279).getString("name"))
assertEquals("Alaska", regions.byCode(6).getString("name"))
}
@Test
fun `every region has drawable rings within coordinate bounds`() {
loadRegions().forEach { region ->
val name = region.getString("name")
val rings = region.getJSONArray("rings")
assertTrue("$name: no rings", rings.length() >= 1)
for (r in 0 until rings.length()) {
val ring = rings.getJSONArray(r)
assertTrue("$name: ring $r has ${ring.length()} pts", ring.length() >= 3)
for (p in 0 until ring.length()) {
val pt = ring.getJSONArray(p)
val lon = pt.getDouble(0)
val lat = pt.getDouble(1)
assertTrue("$name: lon out of range $lon", lon in -180.0..180.0)
assertTrue("$name: lat out of range $lat", lat in -90.0..90.0)
}
}
}
}
@Test
fun `cities fall on the correct side of the rebuilt boundaries`() {
val regions = loadRegions()
val checks = listOf(
// European/Asiatic Russia split along the Urals (OSM ridge + Ural river)
CityCheck("Moscow", 37.61, 55.75, inside = 54, outside = 15),
CityCheck("Perm", 56.24, 58.01, inside = 54, outside = 15),
CityCheck("Yekaterinburg", 60.61, 56.84, inside = 15, outside = 54),
CityCheck("Novosibirsk", 82.93, 55.03, inside = 15, outside = 54),
CityCheck("Kaliningrad", 20.51, 54.71, inside = 126, outside = 54),
// UK four-entity partition
CityCheck("London", -0.13, 51.51, inside = 223, outside = 279),
CityCheck("Edinburgh", -3.19, 55.95, inside = 279, outside = 223),
CityCheck("Cardiff", -3.18, 51.48, inside = 294, outside = 223),
CityCheck("Belfast", -5.93, 54.60, inside = 265, outside = 223),
// Extracted sub-entities
CityCheck("Anchorage", -149.90, 61.22, inside = 6, outside = 291),
CityCheck("Central Oahu", -157.90, 21.45, inside = 110, outside = 291),
CityCheck("Los Angeles", -118.24, 34.05, inside = 291, outside = 6),
CityCheck("Kuching", 110.34, 1.55, inside = 46, outside = 299),
CityCheck("Kuala Lumpur", 101.69, 3.14, inside = 299, outside = 46),
CityCheck("Cayenne", -52.32, 4.94, inside = 63, outside = 227),
CityCheck("Ajaccio", 8.74, 41.93, inside = 214, outside = 227),
CityCheck("Heraklion", 25.14, 35.34, inside = 40, outside = 236),
CityCheck("Cagliari", 9.12, 39.22, inside = 225, outside = 248)
)
for (c in checks) {
assertTrue("${c.name} should be in ${c.inside}",
regionContains(regions.byCode(c.inside), c.lon, c.lat))
assertTrue("${c.name} should NOT be in ${c.outside}",
!regionContains(regions.byCode(c.outside), c.lon, c.lat))
}
}
}