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; }
void coorParaFrm_OnTransParamSaved(CoordTrancParamClass trancparam) { //throw new NotImplementedException(); this._trancParamClass.ID = trancparam.ID; this._trancParamClass.WKID = trancparam.WKID; this._wkid = trancparam.WKID; }
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); }
private void transBtn_Click(object sender, EventArgs e) { if (sourDataGridControl.DataSource == null || (sourDataGridControl.DataSource as List <string>).Count == 0) { MessageBox.Show("请选择待转换数据", "提示"); return; } if (this.btnEditTarPrj.EditValue == null || this.cmbTransPara.EditValue == null) { MessageBox.Show("请选择坐标系和转换参数", "提示"); return; } string tarFolder = this.tarLocationBtnEdit.Text; tarFolder = System.IO.Path.Combine(tarFolder, "转换后"); if (string.IsNullOrWhiteSpace(tarFolder) || System.IO.Directory.Exists(tarFolder)) { MessageBox.Show("前选择空文件夹作为转换目标文件夹!", "提示"); return; } System.IO.Directory.CreateDirectory(tarFolder); CoordTrancParamClass paramClass = this.cmbTransPara.SelectedItem as CoordTrancParamClass; if (paramClass.Defined) { if (!CreateTranseFile(paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, this.txtMidProj.Visible? (this.txtMidProj.Tag as CoordProjClass).DEFINITION: (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION)) { return; } } CoordTrancParamClass paramClass2 = this.cmbTransPara2.SelectedItem as CoordTrancParamClass; if (this.txtMidProj.Visible && paramClass2.Defined) { if (!CreateTranseFile(paramClass2, (this.txtMidProj.Tag as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION)) { return; } } List <string> sourceFiles = sourDataGridControl.DataSource as List <string>; for (int i = 0; i < sourceFiles.Count; i++) { string filename = sourceFiles[i]; string tarFilename = System.IO.Path.Combine(tarFolder, System.IO.Path.GetFileName(filename)); if (System.IO.Path.GetExtension(filename).Equals(".txt", StringComparison.OrdinalIgnoreCase) || System.IO.Path.GetExtension(filename).Equals(".csv", StringComparison.OrdinalIgnoreCase)) { string tempshpfile = System.IO.Path.Combine(Application.StartupPath, "lsdata", DateTime.Now.ToString("yyMMddHHmmss") + ".shp"); IFeatureClass tempFeatureclass = CreateShapeFile(tempshpfile, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION); InsertPointToShape(tempFeatureclass, filename, true, true); ComReleaser.ReleaseCOMObject(tempFeatureclass); string tempPrjshpfile = System.IO.Path.Combine(Application.StartupPath, "lsdata", DateTime.Now.ToString("yyMMddHHmmss") + "_prj.shp"); if (this.txtMidProj.Visible) { string midprjfile = System.IO.Path.Combine(Application.StartupPath, "lsdata", DateTime.Now.ToString("yyMMddHHmmss") + "_midprj.shp"); TrancShape(tempshpfile, midprjfile, paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, (this.txtMidProj.Tag as CoordProjClass).DEFINITION); TrancShape(midprjfile, tempPrjshpfile, paramClass2, (this.txtMidProj.Tag as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION); } else { TrancShape(tempshpfile, tempPrjshpfile, paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION); } OutputTxt(tempPrjshpfile, tarFilename); } else { if (this.txtMidProj.Visible) { string midprjfile = System.IO.Path.Combine(Application.StartupPath, "lsdata", DateTime.Now.ToString("yyMMddHHmmss") + "_midprj.shp"); TrancShape(filename, midprjfile, paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, (this.txtMidProj.Tag as CoordProjClass).DEFINITION); TrancShape(midprjfile, tarFilename, paramClass2, (this.txtMidProj.Tag as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION); } else { TrancShape(filename, tarFilename, paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION); } } } MessageBox.Show("转换完成"); //TrancShape(@"C:\Users\Administrator\Desktop\大羊村042-04-040(040\大羊村042-04-040(040\030合并小班)\f0d9cbb1-b7ad-4f88-8e05-a39d19fc456f.mdb\ZYXB_PY", // @"C:\Users\Administrator\Desktop\大羊村042-04-040(040\大羊村042-04-040(040\030合并小班)\f0d9cbb1-b7ad-4f88-8e05-a39d19fc456f.mdb\ZYXB_PY_80", paramClass, (this.btnEditSouPrj.EditValue as CoordProjClass).DEFINITION, (this.btnEditTarPrj.EditValue as CoordProjClass).DEFINITION); }
private void simpleButton1_Click(object sender, EventArgs e) { DataTable posDt = this.ucPosPair1.GetPosPair(); if (posDt == null || posDt.Rows.Count < 3) { MessageBox.Show("请输入至少三组数据"); return; } CoordTrans7Param calparam = new CoordTrans7Param(); //double[,] souPos = new double[9, 1] { { 111.11},{ 39.12}, {12 }, { 118.345}, {40.123},{ 4 }, { 123.111}, {24.334},{ 2 } }; //double[,] tarPos = new double[9, 1] { { 111.22}, {39.16}, {12 }, { 118.123}, {40.345},{ 6 }, { 123.104}, {24.304},{ 8 } }; double[,] souPos = new double[posDt.Rows.Count * 3, 1]; double[,] tarPos = new double[posDt.Rows.Count * 3, 1]; double sx, sy, sz, tx, ty, tz; for (int i = 0; i < posDt.Rows.Count; i++) { if (!double.TryParse(posDt.Rows[i]["SOU_X"].ToString(), out sx)) { sx = 0; } if (!double.TryParse(posDt.Rows[i]["SOU_Y"].ToString(), out sy)) { sy = 0; } if (!double.TryParse(posDt.Rows[i]["SOU_Z"].ToString(), out sz)) { sz = 0; } if (!double.TryParse(posDt.Rows[i]["TAR_X"].ToString(), out tx)) { tx = 0; } if (!double.TryParse(posDt.Rows[i]["TAR_Y"].ToString(), out ty)) { ty = 0; } if (!double.TryParse(posDt.Rows[i]["TAR_Z"].ToString(), out tz)) { tz = 0; } souPos[i * 3, 0] = sx; souPos[i * 3 + 1, 0] = sy; souPos[i * 3 + 2, 0] = sz; tarPos[i * 3, 0] = tx; tarPos[i * 3 + 1, 0] = ty; tarPos[i * 3 + 2, 0] = tz; } double result = calparam.CalculateTrans7Param(souPos, tarPos); this._trancParamClass = new CoordTrancParamClass(); this._trancParamClass.DX = calparam.dx; this._trancParamClass.DY = calparam.dy; this._trancParamClass.DZ = calparam.dz; this._trancParamClass.DS = calparam.k; this._trancParamClass.RX = calparam.rx; this._trancParamClass.RY = calparam.ry; this._trancParamClass.RZ = calparam.rz; this._trancParamClass.Accuracy = result; this.memoEdit1.Text = string.Format("dx:{0} dy:{1} dz:{2}\r\nrx:{3} ry:{4} rz:{5}\r\nds:{6}" , calparam.dx, calparam.dy, calparam.dz, calparam.rx, calparam.ry, calparam.rz, calparam.k); MessageBox.Show("参数计算完成"); }
private void saveBtn_Click(object sender, EventArgs e) { CheckBeforeSave(); object CoorTranName = tranNameTxtEdit.Text, Accuracy = AccurCalcEdit.EditValue, WKID = WKIDCalcEdit.EditValue, AreaofUse = useAreaTxtEdit.Text, //Method = tranMethodTxtEdit.Text, MaximumLatitude = maxLatCalcEdit.EditValue, MinimumLatitude = minLatCalcEdit.EditValue, MaximumLongitude = maxLonCalcEdit.EditValue, MinimumLongitude = minLonCalcEdit.EditValue, dx = dxCalcEdit.EditValue, dy = dyCalcEdit.EditValue, dz = dzCalcEdit.EditValue, rx = rxCalcEdit.EditValue = rxCalcEdit.Enabled ? rxCalcEdit.EditValue : "null", ry = ryCalcEdit.EditValue = ryCalcEdit.Enabled ? ryCalcEdit.EditValue : "null", rz = rzCalcEdit.EditValue = rzCalcEdit.Enabled ? rzCalcEdit.EditValue : "null", ds = dsCalcEdit.EditValue = dsCalcEdit.Enabled ? dsCalcEdit.EditValue : "null", X0 = X0CalcEdit.EditValue = X0CalcEdit.Enabled ? X0CalcEdit.EditValue : "null", Y0 = Y0CalcEdit.EditValue = Y0CalcEdit.Enabled ? Y0CalcEdit.EditValue : "null", Z0 = Z0CalcEdit.EditValue = Z0CalcEdit.Enabled ? Z0CalcEdit.EditValue : "null"; string countryName = string.Empty, sou_prj = string.Empty, tar_prj = string.Empty; int sou_wkid = 0, tar_wkid = 0; if (this.btnEditCountry.EditValue != null && (CountryClass)this.btnEditCountry.EditValue != null) { countryName = ((CountryClass)this.btnEditCountry.EditValue).NAME; } if (this.btnEditSou.EditValue != null && (CoordProjClass)this.btnEditSou.EditValue != null) { sou_prj = ((CoordProjClass)this.btnEditSou.EditValue).NAME; sou_wkid = ((CoordProjClass)this.btnEditSou.EditValue).WKID; } if (this.btnEditTar.EditValue != null && (CoordProjClass)this.btnEditTar.EditValue != null) { tar_prj = ((CoordProjClass)this.btnEditTar.EditValue).NAME; tar_wkid = ((CoordProjClass)this.btnEditTar.EditValue).WKID; } string Method = string.Empty; switch (paraTypeCmb.EditValue.ToString()) { case "三参": Method = "3"; break; case "七参": Method = "7"; break; case "十参": Method = "10"; break; } try { string sqlStr = ""; if (iParamId <= 0) { object maxId = AccessHelper.ExecuteScalar("select max(id) + 1 from CoordinatePara", null); iParamId = (int)maxId; sqlStr = string.Format("INSERT INTO CoordinatePara (CoorTranName,Accuracy,WKID,AreaofUse,Method,MaximumLatitude,MinimumLatitude,MaximumLongitude,MinimumLongitude,dx,dy,dz,rx,ry,rz,ds,X0,Y0,Z0,Defined,ID , PARAM_TYPE,SOU_PRJ,SOU_WKID,TAR_PRJ,TAR_WKID,COUNTRYNAME)" + "VALUES('{0}',{1},{2},'{3}','{4}',{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},'{21}','{22}',{23},'{24}',{25},'{26}')", CoorTranName, Accuracy, WKID, AreaofUse, Method, MaximumLatitude, MinimumLatitude, MaximumLongitude, MinimumLongitude, dx, dy, dz, rx, ry, rz, ds, X0, Y0, Z0, true, Convert.ToInt32(maxId), Method, sou_prj, sou_wkid, tar_prj, tar_wkid, countryName); } else { sqlStr = string.Format("UPDATE CoordinatePara SET CoorTranName = '{0}'," + "Accuracy = {1}," + "WKID = {2}," + "AreaofUse = = '{3}'," + "method = = '{4}'," + "MaximumLatitude = {5}," + "MinimumLatitude = {6}," + "MaximumLongitude = {7}," + "MinimumLongitude = {8}," + "dx = {9}," + "dy = {10}," + "dz = {11}," + "rx = {12}," + "ry = {13}," + "rz = {14}," + "ds = {15}," + "X0 = {16}," + "Y0 = {17}," + "Z0 = {18}, " + "PARAM_TYPE = '{20}', " + "SOU_PRJ = '{21}', " + "SOU_WKID = {22}, " + "TAR_PRJ = '{23}', " + "TAR_WKID = {24}, " + "COUNTRYNAME = '{25}' " + "WHERE ID={19}", CoorTranName, Accuracy, WKID, AreaofUse, Method, MaximumLatitude, MinimumLatitude, MaximumLongitude, MinimumLongitude, dx, dy, dz, rx, ry, rz, ds, X0, Y0, Z0, iParamId, Method, sou_prj, sou_wkid, tar_prj, tar_wkid, countryName); } if (AccessHelper.ExecuteNonQuery(sqlStr, null) == 1) { this.Text = "编辑 转换参数"; if (this.OnTransParamSaved != null) { CoordTrancParamClass trancparam = new CoordTrancParamClass(); trancparam.WKID = Convert.ToInt32(WKID); trancparam.ID = iParamId; this.OnTransParamSaved(trancparam); } MessageBox.Show("保存成功!", "提示"); } else { MessageBox.Show("保存失败!", "提示"); if (this.Text.Contains("新增")) { iParamId = 0; } } } catch (Exception err) { MessageBox.Show("保存失败!\t\n" + err.Message, "提示"); if (this.Text.Contains("新增")) { iParamId = 0; } } }