แผนที่จาก GPKG + บทความ 6 ชิ้น + ลดความหนา footer
== แผนที่ / GIS ==
- qgis-to-web.py: อ่าน GPKG ได้ (--from gpkg) + เพิ่ม dream-Watcharapol
- เพิ่ม dream-*.geojson 6 ไฟล์ (เส้นทางที่เสนอ: บ้านภาชี · ชานเมืองอยุธยา · HSR · เมืองทองธานี · ปากเกร็ด · วัชรพล)
- map.js: ATMap.proposal() วาดเส้นจริงจาก geojson (ไม่ใช่เส้นตรง) · smoothFactor 0.5
· coordOf() รับ coords=[lat,lng] · fitAll รับได้ทั้งจุดเดี่ยวและเส้น · setStyle บน featureGroup
== บทความ (blog) ==
- text3: ถ้าผมได้ออกแบบสายเดินรถเอง (จาก mydream.html) TH+EN
- text4: วิธีเดินทางไปสถานีรถไฟ และสนามบิน (จาก train-airplane.html) TH+EN
- text5/text6: โครงเปล่ารอเติมเนื้อหา (แสวงหา-โพธิ์ทอง · อำเภอเข้าเมือง)
- แผนที่ความฝัน: map.groups 3 กลุ่ม · คลิกเส้น/หมุด/แถวได้ · ป้ายที่มา
- ย่อหน้า: ระยะห่าง 20px + ย่อหน้าหน้าบรรทัด 1.5em
== ตารางเดินรถ ==
- เปลี่ยนชื่อคีย์ dir_* -> direction_* ทุกไฟล์ (backward-compat ในโค้ด)
- 1011: จุดย่อย 2 ทิศ + offsets [0,25,55]
- 954/2194: จุดย่อย station 8 + offsets
- refreshHighlights: วนข้ามวันเมื่อเลยเที่ยวสุดท้าย + ไฮเทลต์ชิปทุกจุด
- 8 other_stop.md: อัปเดตตรงข้อมูลจริง 8 รายการ
== i18n ==
- แยกไฟล์ต่อภาษา ui/locales/{th,en}.json + i18n.js = loader (ลด 28KB -> 6.5KB)
- resource/tools/check-i18n.py ตรวจคีย์ขาด/ซ้ำ
- ข้อความผู้สนับสนุนหน้าแรก + คำแปล EN
== UI ==
- ฝังฟอนต์ K2D (ui/vendor/fonts/) ออฟไลน์ 100%
- cache busting ?v=<SW VERSION> ทุกรูป (ui/imageurl.js)
- footer: ลดความหนา 468 -> 349px + line-height 1.5 กันสระ/วรรณยุกต์ซ้อน
- QR modal + ปุ่มคัดลอกลิงก์ · หน้าอัปเดตล่าสุดใน #/check
- credits: ขอขอบคุณภาพรถ 3 สาย
== เครื่องมือ ==
- bump-version.py · stamp-schedules.py · derive-times.py (จุดอ้างอิง ± นาที)
This commit is contained in:
1 parent
1cfaeb1526
commit
656f65b41c
109 files changed
+3335
-1225
No files matched your search
@@ -8,6 +8,7 @@
|
||||
แหล่งข้อมูล 2 ทาง (ค่าเริ่มต้น = shapefile เพราะวิธีทำงานจริงคือแก้ใน QGIS แล้วกด Save):
|
||||
python resource/tools/qgis-to-web.py # อ่าน <รหัสสาย>.shp ตามตาราง SHP_MAP (แนะนำ)
|
||||
python resource/tools/qgis-to-web.py --from geojson # อ่าน GeoJSON-2/*.geojson (เส้นทางเดิม)
|
||||
python resource/tools/qgis-to-web.py --from gpkg # อ่าน angthongtoanytrain/*.gpkg (เส้นทางที่เสนอ/ความฝัน)
|
||||
|
||||
ธงอื่น:
|
||||
--check ตรวจเทียบกับไฟล์ปัจจุบัน ไม่เขียนไฟล์
|
||||
@@ -29,7 +30,20 @@ from pathlib import Path
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
QDIR = ROOT / "resource" / "data" / "QGIS Project"
|
||||
SRC_GEOJSON = QDIR / "GeoJSON-2"
|
||||
SRC_GPKG = QDIR / "angthongtoanytrain" # เส้นทางที่เสนอ (ยังไม่มีจริง) — 1 ไฟล์ = 1 เส้นทาง
|
||||
DST = ROOT / "resource" / "data" / "geojson-web"
|
||||
|
||||
# ── ตารางจับคู่ "ชื่อไฟล์ .gpkg → route_id" (เส้นทางที่เสนอ) ──────────────────
|
||||
# route_id ต้องไม่ชนกับสายจริง (902/15/951/952/954/8/101/464/641/2194/324/1011/2231/999)
|
||||
# ชื่อไฟล์ .gpkg เป็นภาษาไทยได้ — คีย์คือชื่อ stem (ไม่รวม .gpkg)
|
||||
GPKG_MAP = {
|
||||
"อ่างทอง-บ้านภาชี(สายสีแดงเข้ม)": "dream-banchang",
|
||||
"อ่างทอง-รถไฟฟ้าชานเมืองอยุธยา(สายสีแดงเข้ม)": "dream-ayutthaya-redline",
|
||||
"อ่างทอง-สถานีรถไฟความเร็วสูงอยุธยา": "dream-ayutthaya-hsr",
|
||||
"อ่างทอง-เมืองทองธานี": "dream-muangthong",
|
||||
"อ่างทอง-แยกปากเกร็ด": "dream-pakkret",
|
||||
"อ่างทอง-วัชรพล": "dream-Watcharapol",
|
||||
}
|
||||
BBOX = (97.0, 103.0, 12.0, 17.5) # lng_min, lng_max, lat_min, lat_max
|
||||
|
||||
# ── ตารางจับคู่ "รหัสสาย → ไฟล์ .shp ในโปรเจกต์ QGIS" ─────────────────────────
|
||||
@@ -112,6 +126,85 @@ def looks_like_utm(lines):
|
||||
return max(abs(min(xs)), abs(max(xs))) > 1000
|
||||
|
||||
|
||||
# ── อ่าน GeoPackage (.gpkg = SQLite) — ไม่ต้องพึ่ง GDAL/geopandas ──
|
||||
def read_gpkg(path):
|
||||
"""คืน (lines, srs_id, ชื่อชั้น) — รองรับ LineString/MultiLineString · พิกัด (lng, lat)
|
||||
GPKG geometry blob = 'GP' + ver(1) + flags(1) + srs_id(4) + envelope(ตาม flags) + WKB"""
|
||||
import sqlite3
|
||||
con = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
|
||||
try:
|
||||
cur = con.cursor()
|
||||
row = cur.execute(
|
||||
"SELECT table_name FROM gpkg_contents WHERE data_type='features' LIMIT 1").fetchone()
|
||||
if not row:
|
||||
return None, None, None
|
||||
table = row[0]
|
||||
srs = cur.execute("SELECT srs_id FROM gpkg_geometry_columns WHERE table_name=?",
|
||||
(table,)).fetchone()
|
||||
blob = cur.execute(f'SELECT geometry FROM "{table}" LIMIT 1').fetchone()[0]
|
||||
finally:
|
||||
con.close()
|
||||
return _parse_gpkg_blob(blob), (srs[0] if srs else None), table
|
||||
|
||||
|
||||
def _parse_gpkg_blob(blob):
|
||||
"""ถอด WKB จาก GPKG blob → list ของเส้น; แต่ละเส้น = list ของ [lng, lat]"""
|
||||
if not blob or blob[:2] != b"GP":
|
||||
return []
|
||||
flags = blob[3]
|
||||
env = {0: 0, 1: 4, 2: 6, 3: 6, 4: 8}.get((flags >> 1) & 0x07, 0)
|
||||
o = 8 + env * 8
|
||||
order = blob[o]
|
||||
E = "<" if order == 1 else ">"
|
||||
gtype = struct.unpack(E + "I", blob[o + 1:o + 5])[0]
|
||||
o += 5
|
||||
lines = []
|
||||
if gtype == 2: # LineString
|
||||
n = struct.unpack(E + "I", blob[o:o + 4])[0]
|
||||
o += 4
|
||||
lines.append([list(struct.unpack(E + "dd", blob[o + 16 * i:o + 16 * i + 16]))
|
||||
for i in range(n)])
|
||||
elif gtype == 5: # MultiLineString
|
||||
n = struct.unpack(E + "I", blob[o:o + 4])[0]
|
||||
o += 4
|
||||
for _ in range(n):
|
||||
E2 = "<" if blob[o] == 1 else ">"
|
||||
m = struct.unpack(E2 + "I", blob[o + 5:o + 9])[0]
|
||||
o += 9
|
||||
lines.append([list(struct.unpack(E2 + "dd", blob[o + 16 * i:o + 16 * i + 16]))
|
||||
for i in range(m)])
|
||||
o += 16 * m
|
||||
return [l for l in lines if len(l) >= 2]
|
||||
|
||||
|
||||
def from_gpkg(route_id):
|
||||
"""คืน (features, รายงาน) จาก angthongtoanytrain/<ชื่อ>.gpkg ตาม GPKG_MAP"""
|
||||
stem = next((k for k, v in GPKG_MAP.items() if v == route_id), None)
|
||||
if stem is None:
|
||||
return None, ["ไม่มีในตาราง GPKG_MAP — ข้าม"]
|
||||
path = SRC_GPKG / f"{stem}.gpkg"
|
||||
if not path.exists():
|
||||
return None, [f"ไม่พบไฟล์ {path.name} (ชื่อเปลี่ยน? แก้ GPKG_MAP)"]
|
||||
lines, srs, table = read_gpkg(path)
|
||||
if not lines:
|
||||
return None, ["ไม่มีเส้นในไฟล์ (หรือชนิด geometry ไม่รองรับ)"]
|
||||
if srs not in (None, 4326):
|
||||
return None, [f"SRS = {srs} (ไม่ใช่ EPSG:4326) — บันทึกใหม่ใน QGIS"]
|
||||
if looks_like_utm(lines):
|
||||
return None, ["พิกัดเป็น UTM (ไม่ใช่ WGS84) — บันทึกใหม่โดยตั้ง CRS = EPSG:4326"]
|
||||
|
||||
kept, dropped = clean_lines(lines)
|
||||
if not kept:
|
||||
return None, ["หลังกรองแล้วไม่มีเส้นเหลือ — ข้าม"]
|
||||
geom = ("MultiLineString" if len(kept) > 1 else "LineString")
|
||||
feat = {"type": "Feature", "properties": {"route_id": route_id},
|
||||
"geometry": {"type": geom, "coordinates": (kept if len(kept) > 1 else kept[0])}}
|
||||
notes = [f"ชั้น '{table}' · srs={srs}"]
|
||||
if dropped:
|
||||
notes.append(f"ตัด {dropped} ช่วงที่สั้น/หลุดกรอบ")
|
||||
return [feat], notes
|
||||
|
||||
|
||||
def from_shp(route_id):
|
||||
"""คืน (features, รายงาน) จาก shapefile ตาม SHP_MAP"""
|
||||
stem = SHP_MAP.get(route_id)
|
||||
@@ -193,12 +286,14 @@ def targets(mode):
|
||||
"""รายการ route_id ที่จะสร้าง (จากตาราง SHP_MAP หรือไฟล์ GeoJSON-2)"""
|
||||
if mode == "shp":
|
||||
return sorted(SHP_MAP)
|
||||
if mode == "gpkg":
|
||||
return sorted(GPKG_MAP.values())
|
||||
return sorted(p.stem for p in SRC_GEOJSON.glob("*.geojson"))
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description="QGIS (shapefile/GeoJSON) → resource/data/geojson-web/")
|
||||
ap.add_argument("--from", dest="src", choices=["shp", "geojson"], default="shp",
|
||||
ap.add_argument("--from", dest="src", choices=["shp", "geojson", "gpkg"], default="shp",
|
||||
help="แหล่งข้อมูล (ค่าเริ่มต้น shp)")
|
||||
ap.add_argument("--check", action="store_true", help="ตรวจอย่างเดียว ไม่เขียนไฟล์")
|
||||
ap.add_argument("--list", action="store_true", help="แสดงตารางจับคู่ + สถานะไฟล์")
|
||||
@@ -216,7 +311,9 @@ def main():
|
||||
return
|
||||
|
||||
from_shp_source = args.src == "shp"
|
||||
label = "shapefile (QGIS Project/*.shp)" if from_shp_source else "GeoJSON-2/*.geojson"
|
||||
label = {"shp": "shapefile (QGIS Project/*.shp)",
|
||||
"geojson": "GeoJSON-2/*.geojson",
|
||||
"gpkg": "angthongtoanytrain/*.gpkg (เส้นทางที่เสนอ)"}[args.src]
|
||||
print(f"ต้นทาง : {label} ({len(ids)} สาย)")
|
||||
print(f"ปลายทาง: {DST.relative_to(ROOT)}" + (" [--check: ไม่เขียนไฟล์]\n" if args.check else "\n"))
|
||||
DST.mkdir(parents=True, exist_ok=True)
|
||||
@@ -224,8 +321,14 @@ def main():
|
||||
print(f"{'สาย':<8}{'จุด':<7}{'ไฟล์เดิม':<10}สถานะ")
|
||||
written = skipped = unchanged = 0
|
||||
for rid in ids:
|
||||
rid = re.sub(r"[^0-9A-Za-z]", "", rid) or rid
|
||||
feats, notes = (from_shp(rid) if from_shp_source else from_geojson(rid))
|
||||
if args.src != "gpkg": # dream-* มี "-" ต้องคงไว้
|
||||
rid = re.sub(r"[^0-9A-Za-z]", "", rid) or rid
|
||||
if args.src == "shp":
|
||||
feats, notes = from_shp(rid)
|
||||
elif args.src == "gpkg":
|
||||
feats, notes = from_gpkg(rid)
|
||||
else:
|
||||
feats, notes = from_geojson(rid)
|
||||
if feats is None:
|
||||
print(f"{rid:<8}{'-':<7}{'-':<10}ข้าม — {'; '.join(notes)}")
|
||||
skipped += 1
|
||||
|
||||
Reference in new issue
Block a user