From 7e063d4b2812aeaabc247c2c3f0fc5b12b5478e8 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 12 十月 2023 16:26:13 +0800
Subject: [PATCH] 出图底图允许添加多个

---
 MoonExp/Models/ModelHandler.cs |   85 +++++++++++++++++++++
 MoonExp/Models/SysRes.cs       |   18 ++++
 .gitignore                     |    1 
 ExportMap/cs/PyLasUtils.cs     |    2 
 ExportMap/Sources/MoonExp.py   |   17 ++--
 MoonExp/MoonExp.csproj         |    2 
 MoonExp/cs/ExportUtil.cs       |   68 ++++++++++++++++
 ExportMap/Sources/Moon.qpt     |    2 
 MoonExp/export.html            |    3 
 MoonExp/Models/ExportArgs.cs   |    6 +
 MoonExp/Tools.cs               |    9 ++
 11 files changed, 200 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4061482..27b6cc1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@
 /MySqlCtrl
 /CutTiles
 /MoonExp/Sources/Test.png
+/MoonExp/Sources/log.txt
diff --git a/ExportMap/Sources/Moon.qpt b/ExportMap/Sources/Moon.qpt
index d9c4790..9634dea 100644
--- a/ExportMap/Sources/Moon.qpt
+++ b/ExportMap/Sources/Moon.qpt
@@ -469,7 +469,7 @@
   <property value="true" key="singleFile"/>
   <property key="layers" value="geo_albedo_feature_point,geo_alkaline_rock_suite,geo_cliff_annotation,geo_construction_unit_boundary,copernican_craters_180,geo_age_not_determined,moon"/>
   <property key="imgPath" value="E:\terrait\TianJin\ExportMap\MoonExp\Sources\Test.png"/>
-  <property key="wmsUrl" value="http://219.153.49.10:7511/sj_raster/v6/wmts/service/system/10000201/1?ak=mf72ff9295c740ec0f37e61433e8a3ad8d"/>
+  <property key="wmsUrl" value="http://172.16.2.10:50005/sj_raster/v6/wmts/service/system/10000201/5?ak=mf72ff9295c740ec0f37e61433e8a3ad8d,http://219.153.49.10:7511/sj_raster/v6/wmts/service/system/10000201/1?ak=mf72ff9295c740ec0f37e61433e8a3ad8d"/>
  </customproperties>
  <Atlas filenamePattern="'output_'||@atlas_featurenumber" filterFeatures="0" enabled="0" coverageLayer="" sortFeatures="0" hideCoverage="0" pageNameExpression=""/>
 </Layout>
diff --git a/ExportMap/Sources/MoonExp.py b/ExportMap/Sources/MoonExp.py
index f898115..181fddf 100644
--- a/ExportMap/Sources/MoonExp.py
+++ b/ExportMap/Sources/MoonExp.py
@@ -58,16 +58,15 @@
 
 # 娣诲姞搴曞浘锛歭ayer.isValid()锛宭ayer.metadataUri()锛宭ayer.providerType()
 def add_map_layer(prj, layout, args):
-    wms_url = layout.customProperty("wmsUrl")
-    if wms_url is None:
-        print("WmsUrl is None.")
-        return
+    uris = layout.customProperty("wmsUrl").split(',')
+    for uri in uris:
+        if uri is None:
+            continue
+        url = "crs=ESRI:104903&dpiMode=7&format=image/png&layers=Default&styles=default&tileMatrixSet=GoogleCRS84Quad01&url=" + uri
+        print("WMS鍦板潃锛�" + url)
 
-    url = "crs=ESRI:104903&dpiMode=7&format=image/png&layers=Default&styles=default&tileMatrixSet=GoogleCRS84Quad01&url=" + wms_url
-    print("WMS鍦板潃锛�" + url)
-
-    layer = QgsRasterLayer(url, "WmsLayer", "wms")
-    prj.addMapLayer(layer)
+        layer = QgsRasterLayer(url, "WmsLayer", "wms")
+        prj.addMapLayer(layer)
 
 
 # 鍒濆鍖�
diff --git a/ExportMap/cs/PyLasUtils.cs b/ExportMap/cs/PyLasUtils.cs
index 398a9c2..df920da 100644
--- a/ExportMap/cs/PyLasUtils.cs
+++ b/ExportMap/cs/PyLasUtils.cs
@@ -147,7 +147,7 @@
                 string[] scales = scaleStr.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                 double minX = double.Parse(minXYZ[0]), minY = double.Parse(minXYZ[1]), minZ = double.Parse(minXYZ[2]);
                 double maxX = double.Parse(maxXYZ[0]), maxY = double.Parse(maxXYZ[1]), maxZ = double.Parse(maxXYZ[2]);
-                double x = (minX + maxX) / 2, y = (minY + maxY) / 2, z = maxZ, scale = Math.Round(1 / double.Parse(scales[0]), 2);
+                double x = (minX + maxX) / 2, y = (minY + maxY) / 2, z = maxZ, scale = Math.Round(1 / double.Parse(scales[0]), 2) / 10;
 
                 string url = ExportUtil.LFServer + "/publish/selectCsTransform?token=" + Tools.Token + "&x=" + x + "&y=" + y + "&epsg=" + epsg;
                 rs = ExportUtil.GetData(url);
diff --git a/MoonExp/Models/ExportArgs.cs b/MoonExp/Models/ExportArgs.cs
index bff0b8f..7fcc25a 100644
--- a/MoonExp/Models/ExportArgs.cs
+++ b/MoonExp/Models/ExportArgs.cs
@@ -95,6 +95,11 @@
         public String wmtsUrl { set; get; }
 
         /// <summary>
+        /// 鍥惧眰ID闆嗗悎
+        /// </summary>
+        public List<int> layerIds { set; get; }
+
+        /// <summary>
         /// 璁剧疆榛樿鍊�
         /// </summary>
         public void SetDefault()
@@ -104,6 +109,7 @@
             if (string.IsNullOrWhiteSpace(scale)) scale = string.Empty;
             if (string.IsNullOrWhiteSpace(resolution)) resolution = string.Empty;
             if (string.IsNullOrWhiteSpace(date)) date = DateTime.Now.ToString("yyyy.MM.dd");
+            if (null == layerIds) layerIds = new List<int>();
 
             this.dpi = GetDpi(this.pageSize);
         }
diff --git a/MoonExp/Models/ModelHandler.cs b/MoonExp/Models/ModelHandler.cs
new file mode 100644
index 0000000..8337f75
--- /dev/null
+++ b/MoonExp/Models/ModelHandler.cs
@@ -0,0 +1,85 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Reflection;
+using System.Web;
+
+namespace MoonExp.cs
+{
+    /// <summary>
+    /// DataTable涓庡疄浣撶被鐩镐簰杞崲
+    /// </summary>
+    public class ModelHandler
+    {
+        /// <summary>
+        /// 濉厖瀵硅薄鍒楄〃
+        /// </summary>
+        public static List<T> FillModel<T>(DataTable dt) where T : new()
+        {
+            if (dt == null || dt.Rows.Count == 0)
+            {
+                return null;
+            }
+
+            List<T> list = new List<T>();
+            BindingFlags flag = BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance;
+            PropertyInfo[] pis = typeof(T).GetProperties();
+
+            foreach (DataRow dr in dt.Rows)
+            {
+                T t = new T();
+                foreach (PropertyInfo pi in pis)
+                {
+                    object val = dr[pi.Name] == DBNull.Value ? null : dr[pi.Name];
+                    t.GetType().GetProperty(pi.Name, flag).SetValue(t, val, null);
+                }
+
+                list.Add(t);
+            }
+
+            return list;
+        }
+
+        /// <summary>
+        /// 濉厖DataTable
+        /// </summary>
+        public static DataTable FillDataTable<T>(List<T> list) where T : new()
+        {
+            if (list == null || list.Count == 0)
+            {
+                return null;
+            }
+
+            DataTable dt = CreateDataTable<T>();
+            PropertyInfo[] pis = typeof(T).GetProperties();
+
+            foreach (T t in list)
+            {
+                DataRow dr = dt.NewRow();
+                foreach (PropertyInfo pi in pis)
+                {
+                    dr[pi.Name] = pi.GetValue(t, null);
+                }
+            }
+
+            return dt;
+        }
+
+        /// <summary>
+        /// 鍒涘缓DataTable
+        /// </summary>
+        public static DataTable CreateDataTable<T>() where T : new()
+        {
+            DataTable dt = new DataTable(typeof(T).Name);
+
+            PropertyInfo[] pis = typeof(T).GetProperties();
+            foreach (PropertyInfo pi in pis)
+            {
+                dt.Columns.Add(new DataColumn(pi.Name, pi.PropertyType));
+            }
+
+            return dt;
+        }
+    }
+}
diff --git a/MoonExp/Models/SysRes.cs b/MoonExp/Models/SysRes.cs
new file mode 100644
index 0000000..d83dc98
--- /dev/null
+++ b/MoonExp/Models/SysRes.cs
@@ -0,0 +1,18 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MoonExp.Models
+{
+    public class SysRes
+    {
+        public SysRes() { }
+
+        public int id { set; get; }
+
+        public string url { set; get; }
+
+        public string surl { set; get; }
+    }
+}
diff --git a/MoonExp/MoonExp.csproj b/MoonExp/MoonExp.csproj
index af941d5..50e9500 100644
--- a/MoonExp/MoonExp.csproj
+++ b/MoonExp/MoonExp.csproj
@@ -101,7 +101,9 @@
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
     <Compile Include="Models\ExportArgs.cs" />
+    <Compile Include="Models\ModelHandler.cs" />
     <Compile Include="Models\ResponseMsg.cs" />
+    <Compile Include="Models\SysRes.cs" />
     <Compile Include="Models\SysTask.cs" />
     <Compile Include="Models\XYZArgs.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
diff --git a/MoonExp/Tools.cs b/MoonExp/Tools.cs
index 35748c4..9417417 100644
--- a/MoonExp/Tools.cs
+++ b/MoonExp/Tools.cs
@@ -3,6 +3,7 @@
 using Npgsql;
 using System;
 using System.Collections.Generic;
+using System.Configuration;
 using System.Data.Common;
 using System.Diagnostics;
 using System.IO;
@@ -18,6 +19,14 @@
         /// </summary>
         public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
 
+        /// <summary>
+        /// 鑾峰彇璁剧疆
+        /// </summary>
+        public static string GetSetting(string key)
+        {
+            return ConfigurationManager.AppSettings[key];
+        }
+
         private static PostgreHelper _dbHelper;
 
         /// <summary>
diff --git a/MoonExp/cs/ExportUtil.cs b/MoonExp/cs/ExportUtil.cs
index 4bb0552..41173e7 100644
--- a/MoonExp/cs/ExportUtil.cs
+++ b/MoonExp/cs/ExportUtil.cs
@@ -3,6 +3,7 @@
 using System;
 using System.Collections.Generic;
 using System.Configuration;
+using System.Data;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -122,6 +123,10 @@
             return i.ToString();
         }
 
+        private static readonly string selectResSql = "select a.id, a.url, b.url || case when length(b.args) > 0 then '?' || b.args else '' end \"surl\" from lf.sys_layer a left join lf.sys_res b on a.resid = b.id where a.category = 3 and a.is_layer = 1 and a.id in ({0})";
+
+        public ExportUtil() { }
+
         /// <summary>
         /// 鐢熸垚
         /// </summary>
@@ -195,7 +200,7 @@
                 .Replace("{date}", DateTime.Now.ToString("yyyy.MM.dd"))
                 .Replace("{layers}", args.layers)
                 .Replace("{imgPath}", imgPath)
-                .Replace("{wmsUrl}", null == args.wmtsUrl ? string.Empty : args.wmtsUrl);
+                .Replace("{wmsUrl}", getWmtsUrl(args));
 
             File.WriteAllText(qptFile, xml);
         }
@@ -245,5 +250,66 @@
 
             return str;
         }
+
+        /// <summary>
+        /// 鑾峰彇WMTS鍦板潃锛屽涓互鑻辨枃閫楀彿闅斿紑
+        /// </summary>
+        public static string getWmtsUrl(ExportArgs args)
+        {
+            List<string> list = new List<string>();
+            foreach (int id in args.layerIds)
+            {
+                List<string> resList = SelectMapUrls(id);
+                if (null != resList && resList.Count > 0)
+                {
+                    list.AddRange(resList);
+                }
+            }
+
+            if (0 == list.Count)
+            {
+                string defaultUrl = Tools.GetSetting("wmtsUrl");
+                if (!string.IsNullOrEmpty(defaultUrl)) list.Add(defaultUrl);
+            }
+
+            string wmtsUrl = string.Join(",", list);
+
+            return wmtsUrl;
+        }
+
+        /// <summary>
+        /// 鏌ヨ鍦板浘Url
+        /// </summary>
+        public static List<string> SelectMapUrls(int id)
+        {
+            string sql = string.Format(selectResSql, id);
+            DataTable dt = Tools.DBHelper.GetDataTable(sql);
+            if (null == dt || 0 == dt.Rows.Count)
+            {
+                return null;
+            }
+
+            List<SysRes> resList = ModelHandler.FillModel<SysRes>(dt);
+            if (null == resList || 0 == resList.Count)
+            {
+                return null;
+            }
+
+            List<string> list = new List<string>();
+            foreach (SysRes res in resList)
+            {
+                if (!string.IsNullOrEmpty(res.surl))
+                {
+                    list.Add(res.surl);
+                    continue;
+                }
+                if (!string.IsNullOrEmpty(res.url))
+                {
+                    list.Add(res.url);
+                }
+            }
+
+            return list;
+        }
     }
 }
diff --git a/MoonExp/export.html b/MoonExp/export.html
index 3011a04..754a402 100644
--- a/MoonExp/export.html
+++ b/MoonExp/export.html
@@ -51,7 +51,8 @@
         ymin: 30.690466,
         ymax: 37.871048,
         xmax: 112.534648,
-        wmtsUrl: "http://219.153.49.10:7511/sj_raster/v6/wmts/service/system/10000201/1?ak=mf72ff9295c740ec0f37e61433e8a3ad8d"
+        //wmtsUrl: "http://219.153.49.10:7511/sj_raster/v6/wmts/service/system/10000201/1?ak=mf72ff9295c740ec0f37e61433e8a3ad8d"
+        layerIds: [82, 79, 87]
       };
 
       ajax("Export/Start", "POST", JSON.stringify(data), null, null, function (rs) {

--
Gitblit v1.9.3