using ESRI.ArcGIS.Carto; using Kingo.Plugin.RasterToKOTilesApp.KoDataBase; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.Management; using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Threading; namespace Kingo.Plugin.RasterToKOTilesApp { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GdalConfiguration.ConfigureGdal(); GdalConfiguration.ConfigureOgr(); if (!KGIS.Framework.AE.AELicense.AoInit()) { return; } // args = new string[] { @"F:\研发产品文档\02年度变更外业调绘助手\余杭区全部数据shape\切割后影像\c04_2000_Project_Clip11.tif;F:\研发产品文档\02年度变更外业调绘助手\余杭区全部数据shape\切割后影像\c04_2000_Project_Clip21.tif", "影像数据", @"G:\a\", @"G:\余杭无人机任务制作\余杭区(330110)\工程目录\举证任务\BGDB.gdb\变更数据\CJDCQ", "CJDCQ","BSM='{0}'" , "330110107000000005", "png","7","512" ,"6", "0" };//;F:\研发产品文档\02年度变更外业调绘助手\余杭区全部数据shape\切割后影像\c04_2000_Project_Clip21.tif //F:\研发产品文档\02年度变更外业调绘助手\余杭区全部数据shape\切割后影像\c04_2000_Project_Clip81.tif c04_2000_Project_Clip81.tif G:\余杭无人机任务制作\余杭区(330110)\外业调绘成果\20221202161703\Kingoit\phonemap_wydh\projects\县级数据\Source null null null 县级数据 png 7 512 6 0 // args = new string[] { @"F:\研发产品文档\02年度变更外业调绘助手\余杭区全部数据shape\切割后影像\c04_2000_Project_Clip11.tif", "c04_2000_Project_Clip11.tif", @"G:\余杭无人机任务制作\余杭区(330110)\外业调绘成果\20221202161703\Kingoit\phonemap_wydh\projects\县级数据\Source", "null", "null", "null", "县级数据", "png", "7", "512", "6", "0" }; if (args.Length != 12) { Console.WriteLine("生成KO文件失败,参数错误"); return; } string strLayerPath = args[0]; string strFileName = args[1]; string strOutputPath = args[2]; string customLayerPath = args[3]; string customLayerName = args[4]; string customstrWhere = args[5]; string customKeyValue = args[6]; string tilesType = args[7]; int sectionlevel =Convert.ToInt32(args[8]); int tileSize = Convert.ToInt32(args[9]); int threadNum = Convert.ToInt32(args[10]); string strConvertWebMercator = args[11]; bool convertWebMercator = false; if (strConvertWebMercator == "1") convertWebMercator = true; else convertWebMercator = false; Envelope envelopeCut = null; List files = new List(); if (strLayerPath.Contains(";")) { string[] filePathArr = strLayerPath.Split(';'); if (filePathArr != null && filePathArr.Length != 0) { for (int i = 0; i < filePathArr.Length; i++) { files.Add(filePathArr[i]); } } } else { files.Add(strLayerPath); } if (!string.IsNullOrWhiteSpace(customLayerPath) && customLayerPath!= "null"&& !string.IsNullOrWhiteSpace(customLayerName) && customLayerName != "null" && !string.IsNullOrWhiteSpace(customstrWhere) && customstrWhere != "null" && !string.IsNullOrWhiteSpace(customKeyValue) && customKeyValue != "null") { envelopeCut = GetCustomEnvelope(customLayerPath, customLayerName, customstrWhere, customKeyValue); } MultRaster2MBTiles pMergeRaster = new MultRaster2MBTiles(); int nThread = 1; try { System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg; if (tilesType.ToString().ToLower() == "png") { imgFormat = System.Drawing.Imaging.ImageFormat.Png; } pMergeRaster.ImgFormat = imgFormat; pMergeRaster.Level = sectionlevel; pMergeRaster.TiledSize = tileSize; pMergeRaster.MBTilesPath = strOutputPath + "\\" + strFileName + ".kotiles"; pMergeRaster.SaveType = EnumSaveType.Level; nThread =threadNum; nThread = nThread <= 0 ? 1 : nThread; } catch (Exception ex) { Console.WriteLine("制作失败!原因:" + ex.Message); return; } DateTime dt1 = DateTime.Now; pMergeRaster.CreatDown += (s, e1) => { DateTime dt3 = DateTime.Now; string make="完成,共用时" + dt3.Subtract(dt1).TotalSeconds.ToString("0.0") + "秒"; string msg = string.Format("{0};{1};{2}", make, 100, 100); Console.WriteLine(msg); }; pMergeRaster.Report += (s, c) => { string make= string.Format("{0}/{1}", c, s); string msg = string.Format("{0};{1};{2}", make, c, s); Console.WriteLine(msg); }; try { pMergeRaster.CreateMulFilesKOTiles(files, nThread, convertWebMercator, envelopeCut); } catch (Exception ex) { Console.WriteLine(ex.Message); } } static Envelope GetCustomEnvelope(string customLayerPath, string customLayerName ,string customstrWhere, string customKeyValue ) { Envelope envelopeCut = null; double distance = 100.0; OSGeo.OGR.Layer toplayer = null; try { DataTable dtLayer = null; if (customLayerPath.ToLower().Contains(".gdb") || customLayerPath.ToLower().Contains(".mdb")) { if (customLayerPath.ToLower().Contains(".gdb")) customLayerPath = customLayerPath.Substring(0, customLayerPath.LastIndexOf(".gdb") + 4); dtLayer = GdalShapeOperate.Instance.GDBToDataTable(customLayerPath, customLayerName); } else { dtLayer = GdalShapeOperate.Instance.ShapeToDataTable(customLayerPath); } if (dtLayer != null && dtLayer.Rows.Count!=0) { DataRow[] rows = dtLayer.Select(string.Format(customstrWhere, customKeyValue)); if (rows != null && rows.Count() != 0) { OSGeo.OGR.Geometry geometryValue = rows[0]["SHAPE"] as OSGeo.OGR.Geometry; if (geometryValue != null) { List list = new List() { geometryValue.Clone() }; toplayer = UnionVector.CreateLayer(list, distance); OSGeo.OGR.Geometry geometry = null; foreach (OSGeo.OGR.Geometry geo in list) { geometry = UnionVector.UnionGeometry(geometry, geo); } OSGeo.OGR.Envelope envelope = new OSGeo.OGR.Envelope(); geometry.GetEnvelope(envelope); envelopeCut = new Envelope { XMax = envelope.MaxX, XMin = envelope.MinX, YMax = envelope.MaxY, YMin = envelope.MinY }; } } } } catch (Exception ex) { Console.WriteLine("获取自定义范围失败:" + ex); } return envelopeCut; } } }