Skip to content

Commit

Permalink
add 2024花蓮地震新崩坍圖層製作 note
Browse files Browse the repository at this point in the history
 add new rudymap_download script
  • Loading branch information
happyman committed Aug 14, 2024
1 parent febaf36 commit e0425f5
Show file tree
Hide file tree
Showing 13 changed files with 8,400 additions and 22 deletions.
Binary file not shown.
Binary file not shown.
Binary file added docs/hl20240403/HL.map
Binary file not shown.
Binary file added docs/hl20240403/HL.osm.gz
Binary file not shown.
Binary file added docs/hl20240403/HL.pbf
Binary file not shown.
6,276 changes: 6,276 additions & 0 deletions docs/hl20240403/HL.xml

Large diffs are not rendered by default.

1,953 changes: 1,953 additions & 0 deletions docs/hl20240403/HL3.geojson

Large diffs are not rendered by default.

Binary file added docs/hl20240403/HL_ref.osm.gz
Binary file not shown.
37 changes: 37 additions & 0 deletions docs/hl20240403/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 花蓮地震圖層 hl20240403 製作 Note 20240813

1. 原始檔案 gpx 匯入 Qgis 3.16, 只取tracks

1. 將圖層匯出成 geojson, (Optional: Vector->Geometry Tools->Line to polygon )

1. 使用 exportpbf 的 geojsontoosm 轉換成 osm
```
geojsontoosm HL3.geojson > HL.osm
```
1. osm 裡面的 description 太長, strip 掉(CludeAI 幫忙寫的)
```
python rmdesc.py 產生 HL_ref.osm
```
1. 將 osm 轉成 pbf
```
osmium sort --overwrite HL_ref.osm -o HL.pbf
```
1. 將 pbf 轉成
```
pbf2map.php
```
1. 使用 mapsforgesrv 將 tile serve 出去
```
#!/bin/bash
export JAVA_FONTS=/usr/share/fonts/truetype/msttcorefonts/
mapsforgesrv_bin="java -Xmx512m -jar /home/happyman/mapsforge/mapsforgesrv-fatjar.jar"
cd /home/happyman/mapsforge
exec setuidgid happyman $mapsforgesrv_bin -m HL.map -t HL.xml -o elmt-track,elmt-waymarks,elmt-waypoint -p 8994
```
其中 HL.xml 是直接複製 MOI_OSM_twmap.xml 只改 gpx trk 的 <rule e="way" k="color" v="~"> 的顏色
1. tilestache 做 proxy, 記得 transparent=true, nginx 的 reverse proxy 設定
1. 感謝東華大學張光承提供 原始檔案
44 changes: 44 additions & 0 deletions docs/hl20240403/pbf2map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
$dd="./eq";
exec("mkdir -p $dd");

$finalmap="$dd/HL.map";
$finalpbf="./HL.pbf";
$cmt="Rock Slides after 202404 earthquake";
$log="$dd/HL.log";

$mapping_xml = "/home/happyman/projects/taiwan-topo/osm_scripts/gpx-mapping.xml";
$osmosis_bin = "/home/happyman/projects/taiwan-topo/tools/osmosis-0.48.3/bin/osmosis";
echo "finally...\n";
if (!file_exists($finalmap)){
$cmd = sprintf("export JAVACMD_OPTIONS=\"-Xmx30G\";
unbuffer $osmosis_bin \
--read-pbf \"%s\" \
--buffer --mapfile-writer \
type=ram \
threads=8 \
bbox=21.55682,118.12141,26.44212,122.31377 \
preferred-languages=\"zh,en\" \
tag-conf-file=\"%s\" \
polygon-clipping=true way-clipping=true label-position=false \
zoom-interval-conf=6,0,6,10,7,11,14,12,21 \
map-start-zoom=10 \
comment=\"%s / (c) Map: Happyman\" \
file=\"%s\" > %s 2>&1 &",
$finalpbf, $mapping_xml, $cmt, $finalmap , $log);

// not yet
echo $cmd;
$pid = exec($cmd);
echo "process in background...\n";
while(1) {
//system("tail -1 $log");
exec(sprintf("fgrep \"finished...\" %s",$log),$out,$ret);
if ($ret == 0 ) {
exec("ps ax |grep osmosis |grep java |awk '{print $1}' |xargs kill");
echo "done...\n";
break;
}
sleep(10);
}
}
27 changes: 27 additions & 0 deletions docs/hl20240403/rmdesc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import xml.etree.ElementTree as ET
import os
if not os.path.exists('descriptions'):
os.makedirs('descriptions')
inf='HL.osm'
outf='HL_ref.osm'
# Parse the OSM file
tree = ET.parse(inf)
root = tree.getroot()
# Counter for generating unique file names
counter = 1
# Find all tag elements with k="description"
for tag in root.findall(".//tag[@k='description']"):
# Get the original description
original_description = tag.get('v')
# Generate a unique filename
filename = f"desc_{counter}.html"
# Save the original description to an HTML file
with open(os.path.join('descriptions', filename), 'w', encoding='utf-8') as f:
f.write(original_description)
# Replace the original description with a reference
tag.set('v', f"See {filename}")
# Increment the counter
counter += 1
# Write the modified XML back to a file
tree.write(outf, encoding='utf-8', xml_declaration=True)
print(f"Processed {counter-1} description tags. to {outf}")
84 changes: 62 additions & 22 deletions docs/rudymap/rudymap_download.php
Original file line number Diff line number Diff line change
@@ -1,75 +1,107 @@
#!/usr/bin/php
<?php

/// check version and donwload the weekly release
$admin_email ="happyman";
$fpath = "/home/mountain/mapsforge";
$cpath = "/home/nas/twmapcache/tmp/stache";
$fpath = "/home/happyman/mapsforge";
$cpath = "/home/happyman/stache";
$cur_ver_fpath = $fpath . "/VERSION";
$want = array("MOI_OSM_Taiwan_TOPO_Rudy.map.zip","MOI_OSM_Taiwan_TOPO_Rudy.poi.zip");
$want = array("MOI_OSM_Taiwan_TOPO_Rudy.map.zip","MOI_OSM_Taiwan_TOPO_Rudy.poi.zip","MOI_OSM_Taiwan_TOPO_Rudy_style.zip");
$base = "http://rudy.basecamp.tw/";
//$base = "https://rudy.outdoors.tw/";
// prevent cache
$ver_data = file_get_contents($base . "/index.json". '?'.mt_rand());
$dirty = 0;
$v = json_decode($ver_data, true);

$opt = getopt("v");
if (isset($opt['v']))
$version_only = 1;
else
$version_only = 0;

if (file_exists($cur_ver_fpath)) {
$cur_ver = trim(file_get_contents($cur_ver_fpath));
} else {
}
if (empty($cur_ver))
{
$cur_ver = "v0.0";
}

echo "cur_ver = $cur_ver ";
// print_r($v);
foreach($v as $vv) {
if (in_array($vv['name'], $want)) {
if ($vv['version'] != $cur_ver ) {
$new_ver = $vv['version'];
$dirty = 1;

if ($vv['name'] == "MOI_OSM_Taiwan_TOPO_Rudy.map.zip" &&
$vv['version'] != $cur_ver ) {
$dirty = 1;
$ver = $vv['version'];
}
}


}
if ($dirty == 1 ) {
echo ";online_ver = $new_ver\n";
$ver = $new_ver;
do_update($base);
echo ";online_ver = $ver\n";
if ($version_only == 1 )
exit(0);
do_update($base,$ver,$cur_ver);
} else {
echo "no update required..\n";
mail($admin_email,"rudy map checked", "version is now $cur_ver");
}
//print_r($v);
function do_update($base) {
function do_update($base,$ver,$old_ver) {
// 1. download and unzip
global $fpath,$ver,$cpath,$admin_email;
global $fpath,$cpath,$admin_email;

@mkdir($fpath . "/$ver", 0755, true);
chdir($fpath . "/$ver");
$zips = array("MOI_OSM_Taiwan_TOPO_Rudy.map.zip","MOI_OSM_Taiwan_TOPO_Rudy.poi.zip","MOI_OSM_twmap_style.zip");
$zips = array("MOI_OSM_Taiwan_TOPO_Rudy.map.zip","MOI_OSM_Taiwan_TOPO_Rudy.poi.zip","MOI_OSM_twmap_style.zip", "MOI_OSM_bn_style.zip","MOI_OSM_dn_style.zip", "MOI_OSM_Taiwan_TOPO_Rudy_style.zip","MOI_OSM_tn_style.zip");
foreach($zips as $zip) {
my_system(sprintf("wget -O %s %s",$zip , $base . $zip));
//my_system(sprintf("wget -O %s %s",$zip , $base . $zip));
my_system(sprintf("rsync -avP homevm:rudy/static/%s ./%s",$zip,$zip));
my_system("unzip -o $zip");
}
// check version
// strings MOI_OSM_Taiwan_TOPO_Rudy.map
$cmd=sprintf("strings MOI_OSM_Taiwan_TOPO_Rudy.map |grep -e \"RuMAP %s\"",$ver);
my_system($cmd);
chdir($fpath);
// 3. clean tile cache
echo "tilestache clean...\n";
$layers = array("moi_osm","moi_osm_gpx");
$layers = array("moi_osm","moi_osm_gpx","rudy_default","moi_happyman_nowp_nocache","twmap_happyman_nowp_nocache");
foreach($layers as $layer) {
// slow method: my_system(sprintf("tilestache-clean -q -c /var/www/etc/tilestache.cfg -l %s -b 25.31 119.31 21.88 124.56 15 16 17 18 19",$layer));
echo "cleaning $layer...\n";
exec("rm -r $cpath/$layer/16");

$old=$layer.".old";
chdir($cpath);
if (file_exists($old)) {
exec("rm -r $old");
echo "$old removed\n";
}
exec("mv $layer $old && mkdir $layer");
echo "$layer created\n";
}
// 4. serve it
chdir($fpath);
exec("rm cur; ln -s $ver cur");
exec("rm -f cur; ln -s $ver cur");
// 5. update VERSION
echo "update VERSION file\n";
file_put_contents($fpath . "/VERSION", $ver);
// 6. restart java
echo "restart java tile server...\n";
system("killall java");
// 7. email me
system("killall -9 java");
// 7. update prop file
// exec("cp MOI_OSM.xml.prop cur");
// 8. purgecache from cloudflare
//exec("bash /home/happyman/bin/purgecache");
purge_cache();
// 9. delete unzipped files from old directory
echo "clean old directory...\n";
exec("cd $fpath; bash rudymap_clean.sh $old_ver");
// 10. email me
mail($admin_email,"rudy map updated!", "version is now $ver");


}
function my_system($cmd) {
Expand All @@ -81,3 +113,11 @@ function my_system($cmd) {
exit(1);
}
}
function purge_cache(){
$auth_email="";
$auth_key="";
if (empty($auth_email)) return;
$cmd=sprintf('curl -X POST "https://api.cloudflare.com/client/v4/zones/47e7b5f66904a67bbd6a7e58eda91331/purge_cache" -H "X-Auth-Email: %s" -H "X-Auth-Key: %s" -H "Content-Type: application/json" --data \'{"purge_everything":true}\'',$auth_email,$auth_key);
echo $cmd;
exec($cmd);
}
1 change: 1 addition & 0 deletions twmap_gen/config.inc.php.sample
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $gdal_dsn = sprintf("postgresql://%s:%s@%s:%s/%s",$db_user,$db_pass,$db_host,$db

require_once(__ROOT__."lib/twmapdb.inc.php");

use Smarty\Smarty;
if (php_sapi_name() != "cli") {
/* template */
$smarty = new Smarty();
Expand Down

0 comments on commit e0425f5

Please sign in to comment.