private void VectorCoordTransform(string physicsFilePath, string OutCoordFile, string newFile) { try { GdalHelp.InitGdal(); ShpReader sr = new ShpReader(physicsFilePath); string csSrc = sr.GetSridWkt(); string csDest = File.ReadAllText(OutCoordFile); iTelluro.DataTools.Utility.GIS.CoordTransform.Ogrtransform(csSrc, csDest, physicsFilePath, newFile); if (File.Exists(newFile)) { Info(UtilityMessageConvert.Get("转换成功")); } else { Error(UtilityMessageConvert.Get("转换失败")); } } catch (Exception ex) { Abp.Logging.LogHelper.LogException(ex); throw; } }
/// <summary> /// 下载缩略图 /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="bbox"></param> public void ThumbnailCreate(string name, string type, string bbox) { try { ThumbnailHelper tbh = new ThumbnailHelper(); string imagePath = tbh.CreateThumbnail(name, type, bbox); } catch (Exception ex) { logger.Info(UtilityMessageConvert.Get("缩略图下载异常:图层名称") + "(" + name + ")" + ex.Message); } }
/// <summary> /// 数据检查 /// </summary> /// <param name="fileList">文件列表</param> /// <returns>转换信息</returns> public DataCheckResult DataCheck(List <string> fileList, bool IsExcel) { List <LayerArgs> _lyrArgsList = new List <LayerArgs>(); if (fileList.Count <= 0) { return(null); } List <DataChackLog> _checkLogs = new List <DataChackLog>(); foreach (string s in fileList) { if (ExtCheck(s, "DataCheckExtension") == false) { _checkLogs.Add(new DataChackLog(s, new List <string> { UtilityMessageConvert.Get("属性检查:文件类型错误") })); continue; } string Lyr = GetlyrTypeByFile(s); //if (Lyr == "") //{ // Lyr = GetlyrTypeByFolder(s); //} if (Lyr == "") { _checkLogs.Add(new DataChackLog(s, new List <string> { UtilityMessageConvert.Get("属性检查:不在检查范围内") })); continue; } string[] arr = Lyr.Split('/'); LayerArgs args = new LayerArgs() { TxName = arr[0], TjName = arr[1], LayerName = arr[2], LayerPath = s, DataLayer = arr[3] }; _lyrArgsList.Add(args); } DicInfoReader _dicReader = new DicInfoReader(); List <string> errorInfo = new List <string>(); for (int i = 0; i < _lyrArgsList.Count; i++) { try { List <string> rlts = LayerAttChecker.CheckLayer(_lyrArgsList[i], _dicReader); if (rlts != null && rlts.Count > 0) { _checkLogs.Add(new DataChackLog(_lyrArgsList[i].LayerPath, rlts)); } } catch (Exception ex) { _checkLogs.Add(new DataChackLog(_lyrArgsList[i].LayerPath, new List <string> { "属性检查:" + ex.Message })); } } DataCheckResult ret = new DataCheckResult(); ret.CheckInfoList = _checkLogs; if (IsExcel == true) { string ExcelFile = ExprotCheck(_checkLogs, _lyrArgsList); ret.ExcelFile = ExcelFile; } else { ret.ExcelFile = ""; } return(ret); }
/// <summary> /// 数据转换 /// </summary> /// <param name="fileList"></param> /// <param name="IsZip"></param> /// <returns></returns> public ConvertResult DataConvert(List <ConvertFileList> fileList, string UserID, string OutputCoordName, bool IsZip) { if (fileList == null || fileList.Count <= 0) { return(new ConvertResult()); } string ConvertFolder = ConfigurationManager.AppSettings["ConvertExprotPath"] + Guid.NewGuid().ToString(); string ConvertTypeName = ""; string OutCoordFile = ""; if (OutputCoordName.ToUpper() != "NULL") { OutCoordFile = GetCoordName(OutputCoordName); } // var fileTypeList = _IDicDataCodeRepository.GetAllList().Where(q => q.DataTypeID == "25159792-cdba-11e7-a735-005056bb1c7e").ToList(); foreach (ConvertFileList f in fileList) { FileInfo ff = new FileInfo(f.PhysicsFilePath); f.ID = Guid.NewGuid().ToString(); f.LogicFileName = ff.Name; f.ConvertResult = 0; try { // 检测文件是否存在 if (!File.Exists(f.PhysicsFilePath)) { f.ConvertMsg = UtilityMessageConvert.Get("转换文件不存在!"); f.ConvertResult = 0; continue; } FileInfo fi = null; // 创建转换保存目录 Directory.CreateDirectory(ConvertFolder); if (!Directory.Exists(ConvertFolder)) { Directory.CreateDirectory(ConvertFolder); } string newFile = ""; // 转换文件 switch (f.FileType) { case 1: ConvertTypeName = UtilityMessageConvert.Get("格式转换").Trim(); try { string[] Files = (string.IsNullOrEmpty(f.ConvertKey)) ? Mapgis2Arcgis(f.PhysicsFilePath) : FileFormatConvert(ff, f.ConvertKey, OutputFormats.ToList()); if (Files != null) { foreach (string s in Files) { fi = new FileInfo(s); if (fi.Extension.ToUpper() != ".LOG") { newFile = ConvertFolder + "\\" + fi.Name; if (f.ConvertFilePath != "") { newFile = f.ConvertFilePath + "\\" + fi.Name; } File.Copy(s, ConvertFolder + "\\" + fi.Name, true); File.Copy(s, newFile, true); } try { File.Delete(s); } catch { } } if (f.ConvertFilePath != "") { f.ConvertFilePath = f.ConvertFilePath + "\\" + f.LogicFileName.Substring(0, f.LogicFileName.IndexOf('.')); } else { f.ConvertFilePath = ConvertFolder + "\\" + f.LogicFileName.Substring(0, f.LogicFileName.IndexOf('.')); } f.ConvertFolder = ConvertFolder; f.ConvertResult = 1; f.ConvertMsg = UtilityMessageConvert.Get("转换成功"); // _logger.Debug(f.LogicFileName + "转换成功"); } else { f.ConvertResult = 0; f.ConvertMsg = UtilityMessageConvert.Get("转换文件失败"); // _logger.Debug(f.LogicFileName + "转换文件失败"); } } catch (Exception ex) { f.ConvertResult = 0; f.ConvertMsg = UtilityMessageConvert.Get("shp文件错误"); // ex.Message; // _logger.Debug(f.LogicFileName + "shp文件错误"); } break; case 2: // 坐标 ConvertTypeName = UtilityMessageConvert.Get("坐标转换").Trim(); fi = new FileInfo(f.PhysicsFilePath); newFile = ConvertFolder + "\\" + fi.Name; if (f.ConvertFilePath != "") { newFile = f.ConvertFilePath + "\\" + fi.Name; } if (f.CoordPoint != null && f.CoordPoint.Length > 0) { CoordTransformHelper ctf = new CoordTransformHelper(); if (f.CoordPoint[0].Contains(',')) { ErrorMsg = (!ctf.ControlPointTransform(f.PhysicsFilePath, newFile, f.CoordName, f.CoordPoint)) ? UtilityMessageConvert.Get("转换失败") : ""; } else { ErrorMsg = (!ctf.SevenParameterTransform(f.PhysicsFilePath, newFile, f.CoordName, f.CoordPoint)) ? UtilityMessageConvert.Get("转换失败") : ""; } } else //维持以前逻辑 { VectorCoordTransform(f.PhysicsFilePath, OutCoordFile, newFile); } if (ErrorMsg.Trim().Length > 0 || InfoMsg.Trim() == UtilityMessageConvert.Get("转换失败")) { f.ConvertFilePath = ""; f.ConvertMsg = UtilityMessageConvert.Get("shp文件错误");// ErrorMsg != "" ? ErrorMsg : InfoMsg; f.ConvertResult = 0; } else { f.ConvertFilePath = newFile; f.ConvertResult = 1; f.ConvertMsg = UtilityMessageConvert.Get("转换成功"); } ErrorMsg = ""; break; case 3: // 投影 ConvertTypeName = UtilityMessageConvert.Get("投影转换".Trim()); fi = new FileInfo(f.PhysicsFilePath); newFile = ConvertFolder + "\\" + fi.Name; if (f.ConvertFilePath != "") { newFile = f.ConvertFilePath + "\\" + fi.Name; } VectorCoordTransform(f.PhysicsFilePath, OutCoordFile, newFile); //iTelluro.DataTools.PrjTransform.VectorCoordTransform(f.PhysicsFilePath, OutCoordFile, newFile, Error, Info); if (ErrorMsg.Trim().Length > 0 || InfoMsg.Trim() == UtilityMessageConvert.Get("转换失败")) { f.ConvertFilePath = ""; f.ConvertMsg = UtilityMessageConvert.Get("shp文件错误"); // ErrorMsg != "" ? ErrorMsg : InfoMsg; f.ConvertResult = 0; } else { f.ConvertFilePath = newFile; f.ConvertResult = 1; f.ConvertMsg = UtilityMessageConvert.Get("转换成功"); } ErrorMsg = ""; break; default: f.ConvertMsg = ""; f.ConvertResult = 0; continue; } } catch (Exception ex) { f.ConvertMsg = ex.Message; f.ConvertResult = 0; } } ConvertResult ret = new ConvertResult(); ret.fileList = fileList; bool bAllFail = true; foreach (var v in fileList) { if (v.ConvertResult == 1) { bAllFail = false; break; } } if (IsZip == true && bAllFail == false) { string DownFile = ConvertTypeName.Replace(" ", "") + "_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".ZIP"; // Guid.NewGuid().ToString() + ".ZIP"; // 压缩转换成功文件 ZipFile.CreateFromDirectory(ConvertFolder, ConfigurationManager.AppSettings["ConvertExprotPath"] + DownFile); try { Directory.Delete(ConvertFolder, true); } catch { } ret.ZipFileName = DownFile; InfoEarthFrame.Core.ConvertFile entity = new ConvertFile(); entity.Id = Guid.NewGuid().ToString(); entity.UserID = UserID; entity.PhysicsFilePath = ConfigurationManager.AppSettings["ConvertExprotPath"] + DownFile; FileInfo fi = new FileInfo(ConfigurationManager.AppSettings["ConvertExprotPath"] + DownFile); entity.FileName = ConvertTypeName + "_" + DateTime.Now.ToString("yyyyMMdd HH:mm"); foreach (ConvertFileList r in ret.fileList) { if (r.ConvertResult == 1) { FileInfo rFi = new FileInfo(r.PhysicsFilePath); entity.ConvertFileNames += rFi.Name.Substring(0, rFi.Name.IndexOf('.')) + ","; } } if (entity.ConvertFileNames.Length > 0) { entity.ConvertFileNames = entity.ConvertFileNames.Remove(entity.ConvertFileNames.Length - 1); } entity.CreateTime = DateTime.Now; entity.FileType = ret.fileList[0].FileType;// FileTypeToNumber(); try { Insert(entity); } catch (Exception ex) { throw ex; } } if (IsZip == true) { // 添加空间参考 for (int i = 0; i < fileList.Count; i++) { if (fileList[i].ConvertResult == 1) { string ff = fileList[i].ConvertFilePath; if (fileList[i].ConvertFilePath.Substring(fileList[i].ConvertFilePath.Length - 3).ToUpper() != "SHP") { ff += ".shp"; } try { ShpReader sr = new ShpReader(ff); string wkt = sr.GetSridWkt(); if (!string.IsNullOrEmpty(wkt)) { SpatialReference srf = new SpatialReference(wkt); string strHTML = srf.__str__().Replace("\n", "<br/>").Replace("[\"", ":").Replace("]", ""); fileList[i].CoordName = wkt.Substring(wkt.IndexOf("\"") + 1, wkt.IndexOf(",") - wkt.IndexOf("\"") - 2); fileList[i].WKT = strHTML; } } catch { fileList[i].CoordName = ""; fileList[i].WKT = ""; } } } } return(ret); }