static void Main(string[] args) { _cpi.Database.Log = Console.WriteLine; RainwaterDitch(); _cpi.SaveChanges(); Console.WriteLine("OK"); Console.Read(); }
/// <summary> /// 轉換程式 /// 資料庫的 TWD97的X,Y => WGS84的 X,Y 並寫回對應欄位 /// </summary> private static void GetWorksheetCp() { var query = _cpi.RainCompletedManhole.Where(a => a.Wgs84X == null && a.Wgs84Y == null).ToList(); //var query = _cpi.RainCompletedPipeline.Where(a => (a.US_84X == null && a.US_84Y == null) || (a.DS_84X == null && a.DS_84Y == null)); //.Where(a => a.targetId == 27); //var query = _cpi.RainwaterDitch.Where(a => (!string.IsNullOrEmpty(a.STR_X) && !string.IsNullOrEmpty(a.STR_Y)) //&& (!string.IsNullOrEmpty(a.END_X) && !string.IsNullOrEmpty(a.END_Y))).ToList(); //var query = _cpi.SetWells.Where(a => a.Wgs84X == null && a.Wgs84Y == null).ToList(); foreach (var item in query) { //RainCompletedManhole double x = Convert.ToDouble(item.X); double y = Convert.ToDouble(item.Y); double[] coordinate = new double[] { x, y }; var cor = xy_2_lnglat(coordinate); item.Wgs84X = cor[0].ToString(); item.Wgs84Y = cor[1].ToString(); ////RainCompletedPipeline //if (string.IsNullOrEmpty(item.US_X)) continue; //double x = Convert.ToDouble(item.US_X); //double y = Convert.ToDouble(item.US_Y); //double[] coordinate = new double[] { x, y }; //var cor = xy_2_lnglat(coordinate); //item.US_84X = cor[0].ToString(); //item.US_84Y = cor[1].ToString(); //x = Convert.ToDouble(item.DS_X); //y = Convert.ToDouble(item.DS_Y); //coordinate[0] = x; coordinate[1] = y; //cor = xy_2_lnglat(coordinate); //item.DS_84X = cor[0].ToString(); //item.DS_84Y = cor[1].ToString(); ////RainwaterDitch //if (string.IsNullOrEmpty(item.STR_X)) continue; //double x = Convert.ToDouble(item.STR_X); //double y = Convert.ToDouble(item.STR_Y); //double[] coordinate = new double[] { x, y }; //var cor = xy_2_lnglat(coordinate); //item.STR_84X = cor[0].ToString(); //item.STR_84Y = cor[1].ToString(); //x = Convert.ToDouble(item.END_X); //y = Convert.ToDouble(item.END_Y); //coordinate[0] = x; coordinate[1] = y; //cor = xy_2_lnglat(coordinate); //item.END_84X = cor[0].ToString(); //item.END_84Y = cor[1].ToString(); ////SetWells //if (string.IsNullOrEmpty(item.X)) continue; //double x = Convert.ToDouble(item.X); //double y = Convert.ToDouble(item.Y); //double[] coordinate = new double[] { x, y }; //var cor = xy_2_lnglat(coordinate); //item.Wgs84X = cor[0].ToString(); //item.Wgs84Y = cor[1].ToString(); } _cpi.Database.Log = Console.WriteLine; _cpi.SaveChanges(); }