private void InitDataTable() { this.dataTable = AsposeCellsHelper.ExportToDataTable(this.path, true); //SVCHelper.readCSVFile(this.path); //dataTable.Columns.Add("WGS84_X", Type.GetType("System.String")); //dataTable.Columns.Add("WGS84_Y", Type.GetType("System.String")); //dataTable.Rows.Clear(); }
private void btnCoverter_Click(object sender, EventArgs e) { this.path = this.txbPath.Text.Trim(); if (!System.IO.File.Exists(this.path)) { MessageBox.Show("文件不存在"); return; } FileInfo file = new FileInfo(this.path); //if (file.Extension != ".csv") //{ // MessageBox.Show("不支持改文件类型"); // return; //} IntPtr vHandle = _lopen(this.path, OF_READWRITE | OF_SHARE_DENY_NONE); if (vHandle == HFILE_ERROR) { MessageBox.Show(this.path + "被其他程序占用!"); return; } CloseHandle(vHandle); //if (!SVCHelper.isContainsCloumnName(this.path, "x") || !SVCHelper.isContainsCloumnName(this.path, "y")) //{ // MessageBox.Show("文件中没有同时包含x和y列,大小写不区分"); // return; //} string[] columns = AsposeCellsHelper.GetFileColumns(this.path); if (!columns.Contains("X") || !columns.Contains("Y")) // (!SVCHelper.isContainsCloumnName(this.path, "x") || !SVCHelper.isContainsCloumnName(this.path, "y")) { MessageBox.Show("文件中没有同时包含x和y列,大小写不区分"); return; } btnCoverter.Enabled = false; btnStop.Enabled = true; if (checkBoxX1.Checked) { this.isCreateShp = true; } this.isStop = false; this.InitDataTable(); this.outPutPath = file.DirectoryName; if (this.outPutPath.Substring(this.outPutPath.Length - 1, 1) == "\\") { this.outPutPath = this.outPutPath.Substring(0, this.outPutPath.Length - 1); } this.outputFileName = file.Name.Split('.')[0] + "_WGS84.csv"; SVCHelper.ExportToSvc(this.dataTable, this.outPutPath + "\\" + this.outputFileName); this.thread = new System.Threading.Thread(this.converteData); thread.Start(); }
private void convertor() { DataTable dataTable = MapDataTools.ShpFileHelper.GetData(this.filepath); //MapDataTools.SVCHelper.ExportToSvc(dataTable, savePath); AsposeCellsHelper.ExportToExcel(dataTable, savePath); if (this.coverterEndHandler != null) { this.coverterEndHandler(); } }
private void converteData() { // DataTable tempDataTable = AsposeCellsHelper.ExportToDataTable(this.path,true); //SVCHelper.readCSVFile(this.path); int k = 0; foreach (DataRow row in this.dataTable.Rows) { if (!this.isStop) { k++; DataRow newRow = row; //for (int i = 0; i < row.ItemArray.Length; i++) //{ // newRow[i] = row[i]; //} string xString = row["X"] != null ? row["X"].ToString() : "0"; string yString = row["Y"] != null ? row["Y"].ToString() : "0"; double x = 0.0, y = 0.0; double.TryParse(xString, out x); double.TryParse(yString, out y); if (x == 0 || y == 0) { continue; } Coord coord = new Coord(x, y); switch (this.covertType) { case CovertType.WGS2GCJ02: coord = CoordHelper.Transform(x, y); newRow["GDJ_X"] = coord.lon; newRow["GDJ_Y"] = coord.lat; break; case CovertType.BAIDU2GCJ02: coord = CoordHelper.BdDecrypt(y, x); newRow["GDJ_X"] = coord.lon; newRow["GDJ_Y"] = coord.lat; break; case CovertType.LONLAT2MOCTOR: coord = CoordHelper.WebMoctorJw2Pm(x, y); newRow["PM_X"] = coord.lon; newRow["PM_Y"] = coord.lat; break; case CovertType.GCJ022BAIDU: coord = CoordHelper.BdEncrypt(y, x); newRow["BD_X"] = coord.lon; newRow["BD_Y"] = coord.lat; break; case CovertType.WGS2BAIDU: coord = CoordHelper.Transform(x, y); coord = CoordHelper.BdEncrypt(coord.lat, coord.lon); newRow["BD_X"] = coord.lon; newRow["BD_Y"] = coord.lat; break; case CovertType.MOCTOR2LONLAT: coord = CoordHelper.Mercator2lonLat(x, y); newRow["JW_X"] = coord.lon; newRow["JW_Y"] = coord.lat; break; case CovertType.WGS2MOCTOR: coord = CoordHelper.Transform(x, y); coord = CoordHelper.WebMoctorJw2Pm(coord.lon, coord.lat); newRow["PM_X"] = coord.lon; newRow["PM_Y"] = coord.lat; break; } //if (this.convertHandler != null) //{ // this.convertHandler(newRow, k, tempDataTable.Rows.Count); //} } } AsposeCellsHelper.ExportToExcel(this.dataTable, this.outPutPath + "\\" + this.outputFileName); if (this.converteEndHandler != null) { this.converteEndHandler(); } }
private void btnCoverter_Click(object sender, EventArgs e) { filepath = this.txbFilePath.Text.Trim(); if (!System.IO.File.Exists(filepath)) { MessageBox.Show("文件不存在"); return; } System.IO.FileInfo file = new System.IO.FileInfo(filepath); if (file.Extension != ".xls") { MessageBox.Show("不支持" + file.Extension + "文件"); return; } this.savePath = this.txbDirctoryPath.Text.Trim(); if (!System.IO.Directory.Exists(savePath)) { MessageBox.Show("保存路径不存在"); return; } this.savePath = this.savePath + "\\" + file.Name.Split('.')[0] + ".shp"; type = this.cmbType.SelectedItem.ToString(); string[] columns = AsposeCellsHelper.GetFileColumns(filepath); if (type == "点") { if (!columns.Contains("X") && !columns.Contains("Y")) { MessageBox.Show("文件未同时包含X,Y列"); return; } } else if (type == "线" || type == "面") { if (!columns.Contains("PATH")) { MessageBox.Show("文件不未包含PATH列"); return; } } btnCoverter.Enabled = false; btnStop.Enabled = true; var project = this.projectCombox.SelectedItem.ToString(); switch (project) { case "百度转WGS经纬度": convert = ProjectConvert.BAIDU_WGS; break; case "火星转WGS经纬度": convert = ProjectConvert.GCJ_WGS; break; case "高德84转WGS经纬度": convert = ProjectConvert.GAODE84_WGS; break; default: convert = ProjectConvert.NONE; break; } this.progressBar.Text = "正在转换..."; this.progressBar.ProgressType = eProgressItemType.Marquee; this.thread = new System.Threading.Thread(this.convertor); this.thread.Start(); }