7 abr. 2008

SHP2XML converter using Dundas WebControl



Find here a script in C# to convert Shapefile to XML, using Dundas webcontrol.
This utility permits to read map from Dundas.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Dundas.Maps.WebControl;
namespace shp2xml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string dir = textBox1.Text;
DirectoryInfo path = new DirectoryInfo(dir);
string pathDestination = textBox2.Text;
string filename = "";
FileInfo[] shpfiles = path.GetFiles("*.shp");
foreach( FileInfo f in shpfiles)
{
System.Diagnostics.Debug.WriteLine(f.Name);
filename = f.Name.Replace(".shp","");
MapControl MapControl1 = new MapControl();
MapControl1.Shapes.Clear();
MapControl1.LoadFromShapeFile(path + "\\" + filename + ".shp", String.Empty, true);
MapControl1.Serializer.Format = Dundas.Maps.WebControl.SerializationFormat.Xml;
MapControl1.Serializer.Save(pathDestination +"\\" + filename + ".xml");
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = folderBrowserDialog1.SelectedPath;
}
}
}
}

No hay comentarios: