管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-09-19 5eb4b1b063d4ff6df13758648dfef19e27ac105a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using ExportMap.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace ExportMap.cs
{
    public class TerrainUtils
    {
        private static int terrainMaxLevel = 0;
 
        /// <summary>
        /// 地形最大级别
        /// </summary>
        public static int TERRAIN_MAX_LEVEL
        {
            get
            {
                if (0 == terrainMaxLevel)
                {
                    string str = Tools.GetSetting("terrainMaxLevel");
                    if (!int.TryParse(str, out terrainMaxLevel))
                    {
                        terrainMaxLevel = 14;
                    }
                }
 
                return terrainMaxLevel;
            }
        }
 
        /// <summary>
        /// 重投影
        /// </summary>
        public static void Reproject(string sourceFile, string targetFile, string sourceSrs, string targetSrs)
        {
            string gdalPath = Tools.GetSetting("gdalPath");
            string cmd = string.Format("{0}\\gdalwarp.exe -s_srs {1} -t_srs {2} -r near -of GTiff {3} {4}", gdalPath, sourceSrs, targetSrs, sourceFile, targetFile);
 
            Tools.ExecCmd(new List<string> { cmd });
        }
 
        /// <summary>
        /// 指定投影
        /// </summary>
        public static void Project(string sourceFile, string targetSrs)
        {
            List<string> list = new List<string>();
            list.Add("cd \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\"");
            //list.Add("set GDAL_DATA=\"C:\\Program Files\\QGIS 3.16\\share\\gdal\"");
            //list.Add("set PROJ_LIB=\"C:\\Program Files\\QGIS 3.16\\share\\proj\"");
            list.Add("\"C:\\Program Files\\QGIS 3.16\\bin\\qgis_process-qgis-ltr.bat\"");
 
            string cmd = string.Format("python \"C:\\Program Files\\QGIS 3.16\\apps\\Python37\\Scripts\\gdal_edit.py\" -a_srs {0} {1}", targetSrs, sourceFile);
            list.Add(cmd);
 
            string rs = "";
            string err = Tools.ExecCmd(new List<string> { cmd }, ref rs);
        }
    }
}