| | |
| | | { |
| | | private static int terrainMaxLevel = 0; |
| | | |
| | | private const string EPSG4326 = "EPSG:4326"; |
| | | |
| | | /// <summary> |
| | | /// 地形最大级别 |
| | | /// </summary> |
| | |
| | | /// <returns>数据发布ID集合</returns> |
| | | public static List<int> Generate(XYZArgs args, ref string err) |
| | | { |
| | | string tifFile = null; |
| | | try |
| | | { |
| | | List<SysMeta> metas = XYZUtils.SelectMetas(args.ids, "and type in ('tif', 'tiff')"); |
| | |
| | | int pubid = PubDBHelper.GetPushlishId(args.dircode, "DEM"); |
| | | List<int> metsIds = PubDBHelper.GetPublishMetaId(pubid); |
| | | |
| | | List<string> files = new List<string>(); |
| | | string uploadFolder = Tools.GetSetting("uploadFolder"); |
| | | foreach (SysMeta meta in metas) |
| | | { |
| | |
| | | if (!File.Exists(sourceFile)) return PrintInfo("元数据[" + meta.id + "] 不存在。"); |
| | | |
| | | string targetFile = Path.Combine(subPath, meta.name); |
| | | Reproject(sourceFile, targetFile, "", "EPSG:4326"); |
| | | ConvertRaster(sourceFile, targetFile); |
| | | if (File.Exists(targetFile)) |
| | | { |
| | | files.Add(targetFile); |
| | | CreateTerrain(args, targetFile, ref err); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /*tifFile = Merge(metas, args, ref err); |
| | | if (!File.Exists(tifFile)) |
| | | { |
| | | LogOut.Info("TerraUtils:找不到tifFile数据。"); |
| | | return null; |
| | | } |
| | | string vrt = CreateLayerJson(args, files, ref err); |
| | | |
| | | string json = Path.Combine(dirPath, "layer.json"); |
| | | if (File.Exists(json)) File.Delete(json); |
| | | //Generate(args, tifFile, ref err); |
| | | CreateTerrain(args, tifFile, ref err); |
| | | |
| | | if (!File.Exists(json)) |
| | | { |
| | | LogOut.Info("TerraUtils:找不到layer.json文件。"); |
| | | return null; |
| | | }*/ |
| | | if (!File.Exists(json)) return PrintInfo("找不到layer.json文件"); |
| | | |
| | | Complement(args); |
| | | pubid = InsertToDB(metas, args); |
| | |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转换栅格文件 |
| | | /// </summary> |
| | | private static void ConvertRaster(string sourceFile, string targetFile) |
| | | { |
| | | if (File.Exists(targetFile)) return; |
| | | |
| | | string epsg = Tools.GetEPSG(sourceFile); |
| | | if (epsg == EPSG4326) |
| | | { |
| | | File.Copy(sourceFile, targetFile); |
| | | return; |
| | | } |
| | | |
| | | Reproject(sourceFile, targetFile, epsg, EPSG4326); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建高程切片 |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建layer.json |
| | | /// </summary> |
| | | private static string CreateLayerJson(XYZArgs args, List<string> files, ref string err) |
| | | { |
| | | string dirPath = GetTerrainPath(args.dircode); |
| | | string vrt = Path.Combine(dirPath, "subs", "dem.vrt"); |
| | | CreateVrt(files, vrt); |
| | | if (!File.Exists(vrt)) return null; |
| | | |
| | | string ctbPath = Tools.GetSetting("ctbPath"); |
| | | string gdal_data = string.Format("set GDAL_DATA={0}\\data", ctbPath); |
| | | string createLayer = string.Format("{0}\\ctb-tile.exe -l -o \"{1}\" -f Mesh \"{2}\"", ctbPath, dirPath, vrt); |
| | | Tools.ExecCmd(new List<string>() { gdal_data, createLayer }); |
| | | |
| | | return vrt; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建VRT |
| | | /// </summary> |
| | | private static void CreateVrt(List<string> files, string vrt) |
| | | { |
| | | string str = string.Join("\r\n", files); |
| | | string filelist = vrt.Replace("dem.vrt", "list.txt"); |
| | | File.WriteAllText(filelist, str); |
| | | |
| | | string gdalPath = Tools.GetSetting("gdalPath"); |
| | | string cmd = string.Format("\"{0}\\gdalbuildvrt.exe\" -input_file_list \"{1}\" \"{2}\" -overwrite", gdalPath, filelist, vrt); |
| | | Tools.ExecCmd(new List<string> { cmd }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取地形最大级别 |
| | | /// </summary> |
| | | private static int GetTerrainMaxLevel(XYZArgs args, string tifFile) |