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);
|
}
|
}
|
}
|