天天看點

利用ironPython.NET接口,在C#WPF裡自動釋出geoserver。

geoserver的圖層釋出是基于Python寫的,C#沒有寫出來(要是有大神寫出來可以發我一份)。這個問題困擾了我很多天,終于在大神的幫助下解決了。

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WpfApp1
{
    class CurlLoad
    {
        public static void Get()
        {
            var rr = Guid.NewGuid().ToString();
            string tmpFile = Path.GetTempPath() + "/curl_temp_" + rr + ".txt";

            Process p = new Process();
            p.StartInfo = new ProcessStartInfo();
            p.StartInfo.FileName = "curl.exe";
            string workspace = "tiff";
            string fpname = "D:\\sixindexdata\\result\\tif\\NO2\\20191121\\NO2_2019112114.tif";
            string layername = "NO2_2019112114";
            string url = "-u admin:geoserver -XPUT -H \"Content-type:image/tiff\" --data-binary @{0} http://localhost:8080/geoserver/rest/workspaces/{1}/coveragestores/{2}/file.geotiff";
            Console.WriteLine(url);
            //p.StartInfo.Arguments = string.Format("-v -u admin:geoserver -XPOST -H \"Content - type: text / xml\" -d \" < workspace >< name > {0} </ name ></ workspace > \" http://localhost:8080/geoserver/rest/workspaces", workspace);
            p.StartInfo.Arguments = string.Format(url,fpname, workspace,layername);
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();

        }

    }
}
           

這裡的curl.exe是大神給我的一個Python內建的自動釋出的程式,隻要調用就可以了。

string workspace = "tiff";這是geoserver的工作空間。

fpname是本機的栅格資料的路徑。

layername是釋出圖層的名稱。

url是本機的geoserver的服務。

就是這麼多。。。小白自己放在這記錄和供他人學習,有什麼更簡單的可以告訴我。