基于gdal的geojson转shapefile的C#实现
来源:互联网 发布:java视频播放器 编辑:程序博客网 时间:2024/05/07 06:53
里面东西有点杂,包括了进度条代码,gdal环境的安装可以参考百度上的教程。直接复制代码没法运行,另外,文件夹1装的是转化后的shp,文件夹2装的是需要转化的geojson.这样做主要是为了批量处理大量geojson文件。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Diagnostics;using System.IO;namespace dos{ public partial class Form1 : Form { private my_processbar progressForm = new my_processbar(); // 代理定义,可以在Invoke时传入相应的参数 private delegate void funHandle(int nValue); private funHandle myHandle = null; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // 启动线程 System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadFun)); thread.Start(); /* DirectoryInfo theFolder = new DirectoryInfo(@"F:\GDAL\bin\1\"); FileInfo[] f = theFolder.GetFiles(); for (int i = 0; i < f.Count(); i++) { string command = "ogr2ogr -f \"ESRI Shapefile\" 2\\"; command += Path.GetFileNameWithoutExtension(f[i].FullName); command += ".shp "; command += "1\\"; command += f[i].Name; textBox1.Text+= Execute(command,10); //command += f[i].Name; }*/ } private void ShowProgressBar() { myHandle = new funHandle(progressForm.SetProgressValue); progressForm.ShowDialog(); } private void ThreadFun() { MethodInvoker mi = new MethodInvoker(ShowProgressBar); this.BeginInvoke(mi); //System.Threading.Thread.Sleep(1000); // sleep to show window DirectoryInfo theFolder = new DirectoryInfo(@"F:\GDAL\bin\1\"); FileInfo[] f = theFolder.GetFiles(); for (int i = 0; i < f.Count(); i++) { string command = "ogr2ogr -f \"ESRI Shapefile\" 2\\"; command += Path.GetFileNameWithoutExtension(f[i].FullName); command += ".shp "; command += "1\\"; command += f[i].Name; textBox1.Text += Execute(command, 10); this.Invoke(this.myHandle, new object[] { (Convert.ToInt32( Convert.ToDouble(i+1) / Convert.ToDouble(f.Count()) * 100.0)) }); } /* for (int i = 0; i < 1000; ++i) { System.Threading.Thread.Sleep(5); // 这里直接调用代理 this.Invoke(this.myHandle, new object[] { (i / 10) }); }*/ } public static string Execute(string command, int seconds) { string output = ""; //输出字符串 if (command != null && !command.Equals("")) { Process process = new Process();//创建进程对象 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe";//设定需要执行的命令 startInfo.WorkingDirectory = @"F:\GDAL\bin\"; startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出 startInfo.UseShellExecute = false;//不使用系统外壳程序启动 startInfo.RedirectStandardInput = false;//不重定向输入 startInfo.RedirectStandardOutput = true; //重定向输出 startInfo.CreateNoWindow = true;//不创建窗口 process.StartInfo = startInfo; try { if (process.Start())//开始进程 { if (seconds == 0) { process.WaitForExit();//这里无限等待进程结束 } else { process.WaitForExit(seconds); //等待进程结束,等待时间为指定的毫秒 } output = process.StandardOutput.ReadToEnd();//读取进程的输出 } } catch { } finally { if (process != null) process.Close(); } } return output; } }}进度条框的代码
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace dos{ public partial class my_processbar : Form { public my_processbar() { InitializeComponent(); } public void SetProgressValue(int value) { this.progressBar1.Value = value; this.label1.Text = value.ToString() + "%"; // 这里关闭,比较好,呵呵! if (value == this.progressBar1.Maximum) this.Close(); } }}1 0
- 基于gdal的geojson转shapefile的C#实现
- Gdal中SHP转GeoJson
- 使用gdal的ogr创建shapefile文件(c++)
- 基于ArcGIS Server对ShapeFile文件的编辑功能实现
- 基于ArcGIS Server对ShapeFile文件的编辑功能实现 .
- echarts之基于geojson的自定义地图
- c#配置GDAL环境,按照步骤一步一步肯定成功,代码为测试shp转Geojson
- 基于GDAL的遥感影像显示(C#版)
- 基于GDAL的遥感影像显示(C#版) .
- 基于GDAL的遥感影像显示(C#版)
- Cesium之3D拉伸显示行政区含GeoJSON数据生成过程GDAL的ogr2ogr
- 基于GDAL实现的PCA变换(主成分分析)
- 读写ESRI Shapefile格式的C#代码
- 使用GDAL的ogr2ogr.py将shapefile插入到mysql中(一)
- 使用GDAL的ogr2ogr.py将shapefile插入到mysql中(二)
- GDAL与shapefile
- 基于GDAL的点数据保存
- 基于GDAL的线数据保存
- csan博客 I am coming
- storm 集成kafka时遇见的问题
- Android Studio如何把自己的工程变成第三方库,如何导入第三方库和删除第三方库
- Weex的体验和环境搭建
- BZOJ 1283 费用流
- 基于gdal的geojson转shapefile的C#实现
- windows server 2008搭建原生的VPN服务器
- do...while(0)的好处和用法
- hokuyo激光雷达跑cartographer
- Cento7+Nginx反向代理实现多域名跳转
- AndroidManifest.xml 中的intent-filter
- TensorFlow24: GANs-生成对抗网络 (生成明星脸)
- 列表全家桶之刷新、加载更多、悬浮、左滑删除
- LoRaWAN介绍8 QoS