Last active
July 31, 2022 00:23
-
-
Save typebrook/bc6960e7b25e83ced50980c99d99636c to your computer and use it in GitHub Desktop.
[contour-tippecannoe] Script to add extra info into contour geojson for tippecannoe #tile #mapbox #tippecanoe #contour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for size in 500 200 100 50 20 10 ; do | |
if [ $size -ne 10 ]; then | |
rm $size"m.geojson" | |
fi | |
awk -v size=$size 'BEGIN{ | |
ele[500]=9 | |
ele[200]=10 | |
ele[100]=11 | |
ele[50]=12 | |
ele[20]=13 | |
ele[10]=14 | |
output=size"m.geojson" | |
} | |
{ | |
if(NR>3 && NF>=9){ | |
if ($9%size==0 && $9>0 && $9<=4000){ | |
printf $1 FS $2 FS $3 FS > output | |
printf ("\"tippecanoe\": { \"minzoom\": "ele[size]", \"maxzoom\": "ele[size]", \"layer\": \"Taiwan_contour\" },") > output | |
printf FS $4 FS $5 FS $8 FS $9 ", " > output | |
if ($9/size%10==0) printf "\"index\": 10" > output | |
else if ($9/size%5==0) printf "\"index\": 5" > output | |
else if ($9/size%2==0) printf "\"index\": 2" > output | |
else printf "\"index\": 1" > output | |
for (k=10;k<=NF;k++) printf FS $k > output | |
printf "\n" > output | |
} | |
} | |
else print $0 > output | |
if (NR%1000==0) print NR/1000"/192", output | |
}' 10m_origin.geojson | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
lines=wc -l $1 | |
awk 'BEGIN{ | |
ele[500]=9 | |
ele[200]=10 | |
ele[100]=11 | |
ele[50]=12 | |
ele[20]=13 | |
ele[10]=14 | |
output=$1 | |
} | |
{ | |
if(NR>3 && NF>=9){ | |
if ($9>10 && $9<=4000){ | |
printf $1 FS $2 FS $3 FS > output | |
printf "\"tippecanoe\": { \"minzoom\": " > output | |
if ($9%500==0) printf (""ele[500]"") > output | |
else if ($9%200==0) printf (""ele[200]"") > output | |
else if ($9%100==0) printf (""ele[100]"") > output | |
else if ($9%50==0) printf (""ele[50]"") > output | |
else if ($9%20==0) printf (""ele[20]"") > output | |
else printf (""ele[10]"") > output | |
printf ", \"maxzoom\": 14, \"layer\": \"contour\" }," > output | |
printf FS $4 FS $5 FS $8 FS $9 > output | |
for (k=10;k<=NF;k++) printf FS $k > output | |
printf "\n" > output | |
} | |
} | |
else print $0 > output | |
if (NR%1000==0) print NR/1000"/192", output | |
}' 10m_origin.geojson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment