放縱與他溫馨 2019-05-14 21:00 采纳率: 0%
浏览 377

如何解决shape文件转sql文件中属性的中文乱码问题

图片说明

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("转换成功", "转换提示");
            }
        }
    }
}
  • 写回答

1条回答 默认 最新

  • 憧憬blog 2023-03-15 07:24
    关注

    你好,针对你的问题,中文乱码问题,可能是由于数据源文件中的字符集和转换后的 SQL 文件的字符集不一致导致的。你可以尝试在命令行窗口中使用 -W 参数指定字符集,例如 -W "GB2312"。
    另外,需要确保系统、数据库、数据库表和字段的字符集都相同,否则可能会出现乱码等问题。
    同时,你的代码中似乎没有对读取的 shape 文件进行编码设置,你可以在读取 shape 文件时,使用相关的编码设置,例如:

    StreamReader reader = new StreamReader(pTransPath, System.Text.Encoding.Default);
    

    希望这些信息可以帮助你解决问题。

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP