管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2022-12-31 c0d3cbe8940500a7c6db123036d8a42376855275
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
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace JavaCode.cs
{
    public class QGisHelper
    {
        public static void Create()
        {
            String path = @"E:\terrait\TianJin\ExportMap\ExportMap\Sources\";
 
            String appendStr =
                "  <property key=\"layers\" value=\"项目,站场,管道中心线,战略通道,影像注记,影像图\"/>" +
                "\r\n  <property key=\"imgPath\" value=\"" + path + "Test.png\"/>" +
                "\r\n </customproperties>";
 
            string testPath = Path.Combine(path, "Test.qpt");
            string testXml = File.ReadAllText(testPath);
 
            String newTestXml = testXml.Replace("\"./", "\"" + path)
                .Replace(" </customproperties>", appendStr);
            File.WriteAllText(testPath, newTestXml);
 
            appendStr =
                "  <property key=\"layers\" value=\"{layers}\"/>" +
                "\r\n  <property key=\"imgPath\" value=\"{imgPath}\"/>" +
                "\r\n </customproperties>";
            String tempXml = testXml
                .Replace("printResolution=\"300\"", "printResolution=\"{dpi}\"")
                .Replace("labelText=\"管道基础大数据平台(DW1-1)\"", "labelText=\"{title}\"")
                .Replace("中国石油天然气管道工程有限公司", "中国 x x x x x 工程有限公司")
                .Replace("\"./Lengend.png\"", "\"{sourcesPath}\\Lengend.png\"")
                .Replace("\"./logo.png\"", "\"{sourcesPath}\\logo.png\"")
                .Replace("mapRotation=\"0\"", "mapRotation=\"{rotation}\"")
 
                .Replace(getStrByKey(testXml, "xmin"), "xmin=\"{xmin}")
                .Replace(getStrByKey(testXml, "ymin"), "ymin=\"{ymin}")
                .Replace(getStrByKey(testXml, "ymax"), "ymax=\"{ymax}")
                .Replace(getStrByKey(testXml, "xmax"), "xmax=\"{xmax}")
 
                .Replace("\"河北省\"", "\"{province}\"")
                .Replace("\"1:25万\"", "\"{scale}\"")
                .Replace("\"20米\"", "\"{resolution}\"")
                .Replace("\"2022.11.06\"", "\"{date}\"")
                .Replace(" </customproperties>", appendStr); ;
 
            string tempPath = Path.Combine(path, "Template.qpt");
            File.WriteAllText(tempPath, tempXml);
 
            MessageBox.Show("生成完毕!");
        }
 
        private static String getStrByKey(string xml, string key)
        {
            int start = xml.IndexOf(key);
            int end = xml.IndexOf("\"", start + key.Length + 3);
 
            //string ss = "<Extent ymax=\"64.11233836183852475\" ymin=\"9.57730491702214692\" xmin=\"59.05829972526095162\" xmax=\"146.81582480887351494\"/>";
 
            return xml.Substring(start, end - start);
        }
    }
}