private bool TrancShape(string sourceShape, string tarShape, CoordTrancParamClass paramClass, string sourcProj, string tarProj) { string errLog; if (!UtilArcgisClass.GPGeoTransformation(sourceShape, sourcProj.Replace("\"", "'"), tarShape, tarProj.Replace("\"", "'"), paramClass.CoorTranName, out errLog)) { MessageBox.Show(errLog); return(false); } return(true); //string lsDir = System.IO.Path.Combine(Application.StartupPath, "lsdata"); //if (!System.IO.Directory.Exists(lsDir)) // Directory.CreateDirectory(lsDir); //string pyFile = System.IO.Path.Combine(lsDir, "坐标转化方法.py"); //File.Copy("坐标转化方法.py", pyFile, true); //string pyStr = File.ReadAllText(pyFile); //pyStr = pyStr.Replace("@转换名称", paramClass.CoorTranName); //pyStr = pyStr.Replace("@源坐标系", sourcProj.Replace("\"", "'")); //pyStr = pyStr.Replace("@目标坐标系", tarProj.Replace("\"", "'")); //pyStr = pyStr.Replace("@源数据", sourceShape); //pyStr = pyStr.Replace("@投影后数据", tarShape); //File.WriteAllText(pyFile, pyStr, Encoding.Default); //if (!GoPythonProcess(pyFile, out errLog)) //{ // MessageBox.Show(errLog); // return false; //} //return true; }
private bool CreateTranseFile(CoordTrancParamClass paramClass, string sourcProj, string tarProj) { string trancFile = System.IO.Path.Combine(Application.StartupPath, "config", "trancFilePath.txt"); string TrancFolder = string.Empty; // @"C:\Users\Administrator\AppData\Roaming\Esri\Desktop10.2\ArcToolbox\CustomTransformations" ; if (System.IO.File.Exists(trancFile)) { string temp = System.IO.File.ReadAllText(trancFile); if (System.IO.Directory.Exists(temp)) { TrancFolder = temp; } } if (!string.IsNullOrEmpty(TrancFolder)) //删除已有的转换 { if (System.IO.File.Exists(System.IO.Path.Combine(TrancFolder, paramClass.CoorTranName + ".gtf"))) { try { System.IO.File.Delete(System.IO.Path.Combine(TrancFolder, paramClass.CoorTranName + ".gtf")); } catch {} } } double X_Axis = paramClass.DX, Y_Axis = paramClass.DY, Z_Axis = paramClass.DZ; double xr = paramClass.RX, yr = paramClass.RY, zr = paramClass.RZ, scale = paramClass.DS; string paramStr = string.Empty; if (xr == 0 && yr == 0 && zr == 0 && scale == 0) { paramStr = string.Format("GEOGTRAN[METHOD['Geocentric_Translation'],PARAMETER['X_Axis_Translation',{0}],PARAMETER['Y_Axis_Translation',{1}],PARAMETER['Z_Axis_Translation',{2}]]", X_Axis, Y_Axis, Z_Axis); } else { paramStr = string.Format("GEOGTRAN[METHOD['Position_Vector'],PARAMETER['X_Axis_Translation',{0}],PARAMETER['Y_Axis_Translation',{1}],PARAMETER['Z_Axis_Translation',{2}],PARAMETER['X_Axis_Rotation',{3}],PARAMETER['Y_Axis_Rotation',{4}],PARAMETER['Z_Axis_Rotation',{5}],PARAMETER['Scale_Difference',{6}]]" , X_Axis, Y_Axis, Z_Axis, xr, yr, zr, scale); } //pyStr = pyStr.Replace("@转换方式", paramStr); string errLog; if (!UtilArcgisClass.GPCreateCustomGeoTransformation(paramClass.CoorTranName, sourcProj.Replace("\"", "'"), tarProj.Replace("\"", "'"), paramStr, out errLog)) { if (errLog.Contains("ERROR 000258")) //已存在,则记录gtf的存储位置,然后重新创建一次 { string gtfFile = errLog.Substring(errLog.IndexOf(": 输出 ") + 5, errLog.IndexOf(" 已存在")); System.IO.File.WriteAllText(trancFile, new System.IO.FileInfo(gtfFile.Trim()).DirectoryName); return(CreateTranseFile(paramClass, sourcProj, tarProj)); } else { MessageBox.Show(errLog); return(false); } } return(true); }