瀏覽分類:

NCL

定義 sld 樣式 使用 NCL color table

接續之前的 sld 燙手山芋,需要定義多組 raster 的樣式,所幸 NCL 官方有提供非常多組色表可以下載。載回來後是一個 .rgb 的纇 csv 檔案,我用 csharp 的 console 寫了一個轉換程式好讓其變成 16 進位的表,詳細過程早就忘光光等腦子清楚再寫。

static void Main(string[] args)
        {
            //讀取color文字檔
            //name , r , g , b
            //轉換 rgb 為 hex
            var files = Directory.EnumerateFiles(@"D:\rgb\", "*.rgb");
            
            foreach (var file in files)
            {
                
                var fileName = Path.GetFileNameWithoutExtension(file);
                

                var lines = File.ReadAllLines(@"D:\rgb\" + fileName + ".rgb");
                List<string> colorList = new List<string>();



                //寫入檔案
                var flag = false;
                var skipColorCount = 0;
                List<string> hexs = new List<string>();

                int skip = 2;
                int counter = 1;
                foreach (var line in lines)
                {
                    if (counter <= skip)
                    {
                        counter++;
                        continue;
                    }

                    flag = !flag;
                    if (flag == false)
                    {
                        continue;
                    }


                    //skipColorCount++;
                    //if (skipColorCount % 16 != 0)
                    //{
                    //    continue;
                    //}


                    var lineResult = line.Split(' ');
                    //string name = lineResult[0];
                    int r = Convert.ToInt32(Convert.ToDouble(lineResult[0]) * 255.0);
                    int g = Convert.ToInt32(Convert.ToDouble(lineResult[1]) * 255.0);
                    int b = Convert.ToInt32(Convert.ToDouble(lineResult[2]) * 255.0);
                    Color color = Color.FromArgb(r, g, b);

                    string hex = color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");


                    hexs.Add(hex);

                    //writer.WriteLine("#{0}", hex);

                    //writer.WriteLine(string.Format("<option value='{0}' style='background: #{1};'>{0}</option>", name, hex));


                    

                }


                using (StreamWriter writer = new StreamWriter(@"D:\rgb\" + fileName + ".txt"))
                {
                    foreach (var hex in hexs)
                    {
                        writer.WriteLine("#{0}", hex);
                    }
                }

                hexs.Reverse();
                using (StreamWriter writer = new StreamWriter(@"D:\rgb\" + fileName + "-inv.txt"))
                {
                    foreach (var hex in hexs)
                    {
                        writer.WriteLine("#{0}", hex);
                    }
                }
            }


        }

以下提供一些現成的 64 色 colormap ,可以直接套在 ncWMS 或 GeoServer 使用

Rainbow

#7E03FF
#7510FF
#6E1CFF
#6529FE
#5E35FE
#5541FD
#4E4DFC
#4559FB
#3D65FA
#376DF9
#2D7BF7
#2884F6
#1D91F3
#1898F2
#0DA5EF
#08ACEE
#03B7EB
#0AC0E8
#12C8E6
#1BCFE3
#22D6E0
#2BDDDD
#32E3DA
#3BE8D6
#42EDD3
#4BF2CF
#52F5CB
#5BF8C8
#63FBC4
#6AFDC0
#73FEBB
#7AFFB7
#83FFB3
#8AFEAE
#93FDA9
#9AFBA5
#A3F9A0
#AAF69B
#B2F396
#BBEE91
#C2EA8C
#CBE486
#D2DE81
#DBD87B
#E2D176
#EBCA70
#F2C26B
#FBB965
#FFB05F
#FFA759
#FF9D53
#FF934D
#FF8947
#FF7E41
#FF733B
#FF6835
#FF5C2F
#FF5029
#FF4422
#FF381C
#FF2C16
#FF1F10
#FF1309
#FF0603

Jet

#000084
#000096
#0000A8
#0000BB
#0000CD
#0000DF
#0000F1
#0000FF
#0004FF
#0011FF
#0024FF
#0030FF
#0044FF
#0050FF
#0065FF
#0070FF
#0085FF
#0095FF
#00A4FF
#00B4FF
#00C4FF
#00D4FF
#00E4F8
#0CF5EB
#19FFDE
#26FFD1
#33FFC4
#40FFB7
#4DFFAA
#5AFF9D
#66FF90
#73FF83
#80FF77
#8DFF6A
#9AFF5D
#A7FF50
#B4FF43
#C1FF36
#CEFF29
#DBFF1C
#E7FF0F
#F4F802
#FFEA00
#FFDB00
#FFCC00
#FFBD00
#FFAE00
#FF9F00
#FF9100
#FF8200
#FF7300
#FF6400
#FF5500
#FF4700
#FF3800
#FF2900
#FF1A00
#F60B00
#E40000
#D10000
#BF0000
#AD0000
#9B0000
#890000

Ocean

#007E01
#007805
#007209
#006C0D
#006611
#006015
#005A19
#00541D
#004E21
#004924
#004229
#003D2C
#003631
#003234
#002A39
#00263C
#001E41
#001845
#001249
#000C4D
#000651
#000055
#000659
#000C5D
#001261
#001865
#001E69
#00246D
#002A71
#003075
#003679
#003C7D
#004281
#004885
#004E89
#00548D
#005A91
#006095
#006699
#006C9D
#0072A1
#0078A5
#007EA9
#0984AD
#158AB1
#2190B5
#2D96B9
#399CBD
#45A2C1
#51A8C5
#5DAEC9
#69B4CD
#75BAD1
#81C0D5
#8DC6D9
#99CCDD
#A5D2E1
#B1D8E5
#BDDEE9
#C9E4ED
#D5EAF1
#E1F0F5
#EDF6F9
#F9FCFD

 

CoolWarm

#3C4EC2
#4055C8
#455CCE
#4A63D3
#4F69D9
#5470DE
#5977E3
#5E7DE7
#6384EB
#6788EE
#6E90F2
#7295F4
#799CF8
#7DA0F9
#84A7FC
#88ABFD
#8FB1FE
#94B6FF
#9ABBFF
#9FBFFF
#A5C3FE
#AAC7FD
#AFCAFC
#B5CDFA
#BAD0F8
#BFD3F6
#C4D5F3
#C9D7F0
#CDD9EC
#D2DBE8
#D6DCE4
#DADCE0
#DEDCDB
#E2DAD5
#E6D7CF
#EAD5C9
#EDD2C3
#EFCEBD
#F2CBB7
#F3C7B1
#F5C2AA
#F6BEA4
#F7B99E
#F7B497
#F7AF91
#F7A98B
#F6A385
#F59D7E
#F39778
#F29072
#F08A6C
#ED8366
#EA7B60
#E7745B
#E36C55
#E0654F
#DC5D4A
#D75445
#D24B40
#CD423B
#C83836
#C32E31
#BD1F2D
#B70D28

 

 

NCL 安裝

方法1(推薦)

先至 ncl 官網下載
http://www.ncl.ucar.edu/Download/list_of_binaries.shtml

接著設定環境變數NCARG_ROOT

gedit ~/.bash_profile
export NCARG_ROOT=/home/yourname/ncl
export PATH=$NCARG_ROOT/bin:$PATH

最後別忘了讓設定啟用

source ~/.bash_profile

方法2

直接使用command安裝

sudo apt-get install ncl-ncarg

不過用這方法引用$NCARG_ROOT載入script時會出現錯誤

所以可以參考下面這篇的解法

http://mailman.ucar.edu/pipermail/ncl-install/2018-February/002567.html

加碼推薦 vscode NCL extension

由於 NCL 沒有比較好用的 editor ,某天寫網頁時無聊搜尋了一下,看看有無 NCL 的 extension 想不到還真的有,寫起來果真飛快。