using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace sjk
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string pTransPath = "";
private string path = "";
OpenFileDialog openFileDialog = new OpenFileDialog();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click_1(object sender, EventArgs e)
{
openFileDialog.DefaultExt = "shp";
openFileDialog.Filter = "shp文件(*.shp)|*.shp";
path = textBox1.Text;
if (openFileDialog.ShowDialog() != DialogResult.Cancel)
{
pTransPath = openFileDialog.FileName;
textBox1.Text = openFileDialog.FileName;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
pTransPath = textBox1.Text;
path = textBox1.Text + ".sql";
System.Diagnostics.Process p = new System.Diagnostics.Process();
if (radioButton1.Checked)
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine(@" D:\PostgreSQL\9.3\bin\shp2pgsql.exe C:\Users\Administrator\Desktop\实验1\shapefiles\airports.shp > C:\Users\Administrator\Desktop\实验1\shapefiles\airports.sql ");
p.StandardInput.WriteLine("exit");
//string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
MessageBox.Show("转换成功", "转换提示");
}
else
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
p.StandardInput.WriteLine(@" D:\MySQL\Mysql\shp2mysql.exe C:\Users\Administrator\Desktop\实验1\shapefiles\airports.shp > C:\Users\Administrator\Desktop\实验1\shapefiles\airports.sql ");
p.StandardInput.WriteLine("exit");
//string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
MessageBox.Show("转换成功", "转换提示");
}
}
}
}
如何解决shape文件转sql文件中属性的中文乱码问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- 憧憬blog 2023-03-15 07:24关注
你好,针对你的问题,中文乱码问题,可能是由于数据源文件中的字符集和转换后的 SQL 文件的字符集不一致导致的。你可以尝试在命令行窗口中使用 -W 参数指定字符集,例如 -W "GB2312"。
另外,需要确保系统、数据库、数据库表和字段的字符集都相同,否则可能会出现乱码等问题。
同时,你的代码中似乎没有对读取的 shape 文件进行编码设置,你可以在读取 shape 文件时,使用相关的编码设置,例如:StreamReader reader = new StreamReader(pTransPath, System.Text.Encoding.Default);
希望这些信息可以帮助你解决问题。
解决 无用评论 打赏 举报
悬赏问题
- ¥15 python的qt5界面
- ¥15 无线电能传输系统MATLAB仿真问题
- ¥50 如何用脚本实现输入法的热键设置
- ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀
- ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100