管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2023-10-12 7e063d4b2812aeaabc247c2c3f0fc5b12b5478e8
出图底图允许添加多个
已添加2个文件
已修改9个文件
213 ■■■■■ 文件已修改
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Sources/Moon.qpt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/Sources/MoonExp.py 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ExportMap/cs/PyLasUtils.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Models/ExportArgs.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Models/ModelHandler.cs 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Models/SysRes.cs 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/MoonExp.csproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/Tools.cs 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/cs/ExportUtil.cs 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
MoonExp/export.html 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -27,3 +27,4 @@
/MySqlCtrl
/CutTiles
/MoonExp/Sources/Test.png
/MoonExp/Sources/log.txt
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>
ExportMap/Sources/MoonExp.py
@@ -58,16 +58,15 @@
# æ·»åŠ åº•å›¾ï¼šlayer.isValid(),layer.metadataUri(),layer.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)
# åˆå§‹åŒ–
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);
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);
        }
MoonExp/Models/ModelHandler.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,85 @@
using 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;
        }
    }
}
MoonExp/Models/SysRes.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
using 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; }
    }
}
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" />
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>
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;
        }
    }
}
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) {