- 积分
- 106
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-4-29
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 xyangtian 于 2016-12-11 10:59 编辑
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using Surfer;
- using System.IO;
- namespace surfer
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- }
- string levelFilePath;
- string[] fileName = new string[] { };
- string[] blankFileName = new string[] { };
- string[] baseMapFileName = new string[] { };
- List<string > listFile = new List<string>();
- List<string> listFileName = new List<string>();
- List<string> strListFileName = new List<string>();
- List<string> blankFile = new List<string>();
- List<string> baseMap = new List<string>();
- public void button_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog ofdName = new OpenFileDialog();
- ofdName.Title = "选择网格文件";
- ofdName.Filter = "dat文件|*.dat|所有文件|*.*";
- ofdName.FileName = string.Empty;
- ofdName.RestoreDirectory = true;
- ofdName.DefaultExt = "dat";
- ofdName.Multiselect = true;
- ofdName.ShowDialog();
- fileName = ofdName.FileNames;
- for (int i = 0; i < fileName.Length; i++)
- {
- listFile.Add(fileName[i]);
-
- strListFileName.Add( fileName[i].Substring(fileName[i].LastIndexOf("\") + 1, (fileName[i].LastIndexOf(".") - fileName[i].LastIndexOf("\") - 1)));
- try
- {
- listFileName.Add(fileName[i].Remove(fileName[i].LastIndexOf(".")));//移除文件后缀
- }
- catch (Exception)
- {
- MessageBox.Show("请选择文件");
- }
-
- }
- }
-
- private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
- {
- }
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < listFile.LongCount(); i++)
- {
- Surfer.Application surfer = new Surfer.Application();
- surfer.Visible = false;
- IDocuments docs = surfer.Documents;
- IWksDocument wks = (IWksDocument)docs.Open(listFile[i]); //打开dat文件
- dynamic maxidh = wks.Columns(2).Statistics().Maximum;//统计第二列的最大值
- dynamic minidh = wks.Columns(2).Statistics().Minimum;
- dynamic maxigc = wks.Columns(4).Statistics().Maximum;
- int maxiint = Convert.ToInt32(maxigc);
- wks.Close();
- surfer.GridData(DataFile: listFile[i], //数据文件地址
- xCol: 2, //x为第一列数据
- yCol: 6, //y为第二列数据
- zCol: 3, //z为第三列数据
- ExclusionFilter: Filter.Text,
- DupMethod: Surfer.SrfDupMethod.srfDupFirst,
- NumCols: (maxidh - minidh) / Convert.ToInt32(NumCols.Text), //x方向插值数据量
- NumRows: (maxiint - Convert.ToInt32(yMinBox.Text)) / Convert.ToInt32(NumRows.Text), //y方向插值数据量
- xMin: minidh, //x最小值
- xMax: maxidh, //x最大者
- yMin: Convert.ToInt32(yMinBox.Text), //y最小值
- yMax: maxiint, //y最大值
- Algorithm: Surfer.SrfGridAlgorithm.srfKriging, //插值算法Kriging
- OutGrid: listFileName[i] + ".grd", //返回文件为gridfile
- OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary); //返回文件编码为Ascii
- try
- {
- surfer.GridFilter(listFileName[i] + ".grd", Filter: SrfFilter.srfFilterGaussianLP, EdgeOp: SrfFilterEdge.srfFltEdgeReplicate, BlankOp: SrfFilterBlank.srfFltBlankLeave, OutGrid: listFileName[i] + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- //surfer.GridSplineSmooth(listFileName[i] + ".grd", nRow: 2, nCol: 2, Method: SrfSplineMethod.srfSplineInsert, OutGrid: textBox.Text + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- surfer.GridBlank(InGrid: listFileName[i] + ".grd", BlankFile: blankFile[i], OutGrid: listFileName[i] + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- IPlotDocument Doc = (IPlotDocument)docs.Add(SrfDocTypes.srfDocPlot); //创建一个空白绘图文档
- IShapes Shapes = Doc.Shapes;
- IMapFrame contourMapFrame = Shapes.AddContourMap(listFileName[i] + ".grd"); //加载网格文件
- IMapFrame boundryMapFrame = Shapes.AddBaseMap(baseMap[i]); //加载基面图
- Doc.Shapes.SelectAll();
- Surfer.ISelection sel = Doc.Selection;
- sel.OverlayMaps();
- contourMapFrame.xMapPerPU = 127; //设置比例
- contourMapFrame.yMapPerPU = 127; //设置比例
- contourMapFrame.Axes.Item(4).ShowLabels = true; //显示标注
- contourMapFrame.Axes.Item(4).SetScale(LastMajorTick: maxiint, MajorInterval: 50);//设置标注最后值和间距
- contourMapFrame.Axes.Item(4).MinorTickType = SrfTickType.srfTickOut; ;//设置副刻度为out
- contourMapFrame.Axes.Item(4).MinorTicksPerMajor = 4;//设置副刻度个数4
- contourMapFrame.Axes.Item(3).SetScale(LastMajorTick: maxiint, MajorInterval: 50);//设置标注最后值和间距
- contourMapFrame.Axes.Item(3).MinorTickType = SrfTickType.srfTickOut;//设置副刻度为out
- contourMapFrame.Axes.Item(3).MinorTicksPerMajor = 4;//设置副刻度个数4
- contourMapFrame.Axes.Item(2).MajorTickType = SrfTickType.srfTickNone;//设置主刻度为none
- contourMapFrame.Axes.Item(2).Title = "标高/m";//设置定边轴标题
- contourMapFrame.Axes.Item(2).TitleFont.Size = 14;
- contourMapFrame.Axes.Item(2).TitleOffset1 = -3.4;//设置标题位置
- contourMapFrame.Axes.Item(2).TitleOffset2 = -0.3;
- contourMapFrame.Axes.Item(1).SetScale(LastMajorTick: maxidh, MajorInterval: 20);
- contourMapFrame.Axes.Item(1).Title = "测点号/m";//设置底边轴标题
- contourMapFrame.Axes.Item(1).TitleFont.Size = 14;
- contourMapFrame.Axes.Item(1).TitleOffset1 = -3.5;//设置标题位置
- contourMapFrame.Axes.Item(1).TitleOffset2 = -0.3;
- //1为底边轴,2为顶边轴,3为左边轴,4为右边轴;
- IContourMap contourMap = (IContourMap)contourMapFrame.Overlays.Item(1);
- contourMap.SmoothContours = SrfConSmoothType.srfConSmoothHigh; //平滑等值线边界
- contourMap.FillContours = true;
- ILevels levels = contourMap.Levels;
- levels.LoadFile(levelFilePath);
- Surfer.IText Text1 = Doc.Shapes.AddText(contourMap.Left + 2, contourMap.Top + 0.5, strListFileName[i] + "" + "线视电阻率拟断面图");
- Text1.Font.Size = 14;
- Doc.SaveAs(listFileName[i] + ".srf");
- Doc.Close();
- surfer.Quit();
- System.GC.Collect(System.GC.GetGeneration(surfer));
- }
- catch
- {
-
- }
- finally
- {
- surfer.GridFilter(listFileName[i] + ".grd", Filter: SrfFilter.srfFilterGaussianLP, EdgeOp: SrfFilterEdge.srfFltEdgeReplicate, BlankOp: SrfFilterBlank.srfFltBlankLeave, OutGrid: listFileName[i] + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- //surfer.GridSplineSmooth(listFileName[i] + ".grd", nRow: 2, nCol: 2, Method: SrfSplineMethod.srfSplineInsert, OutGrid: textBox.Text + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- //surfer.GridBlank(InGrid: listFileName[i] + ".grd", BlankFile: blankFile[i], OutGrid: listFileName[i] + ".grd", OutFmt: Surfer.SrfGridFormat.srfGridFmtBinary);
- IPlotDocument Doc = (IPlotDocument)docs.Add(SrfDocTypes.srfDocPlot); //创建一个空白绘图文档
- IShapes Shapes = Doc.Shapes;
- IMapFrame contourMapFrame = Shapes.AddContourMap(listFileName[i] + ".grd"); //加载网格文件
- //IMapFrame boundryMapFrame = Shapes.AddBaseMap(baseMap[i]); //加载基面图
- //Doc.Shapes.SelectAll();
- //Surfer.ISelection sel = Doc.Selection;
- //sel.OverlayMaps();
- contourMapFrame.xMapPerPU = 127; //设置比例
- contourMapFrame.yMapPerPU = 127; //设置比例
- contourMapFrame.Axes.Item(4).ShowLabels = true; //显示标注
- contourMapFrame.Axes.Item(4).SetScale(LastMajorTick: maxiint, MajorInterval: 50);//设置标注最后值和间距
- contourMapFrame.Axes.Item(4).MinorTickType = SrfTickType.srfTickOut; ;//设置副刻度为out
- contourMapFrame.Axes.Item(4).MinorTicksPerMajor = 4;//设置副刻度个数4
- contourMapFrame.Axes.Item(3).SetScale(LastMajorTick: maxiint, MajorInterval: 50);//设置标注最后值和间距
- contourMapFrame.Axes.Item(3).MinorTickType = SrfTickType.srfTickOut;//设置副刻度为out
- contourMapFrame.Axes.Item(3).MinorTicksPerMajor = 4;//设置副刻度个数4
- contourMapFrame.Axes.Item(2).MajorTickType = SrfTickType.srfTickNone;//设置主刻度为none
- contourMapFrame.Axes.Item(2).Title = "标高/m";//设置定边轴标题
- contourMapFrame.Axes.Item(2).TitleFont.Size = 14;
- contourMapFrame.Axes.Item(2).TitleOffset1 = -3.4;//设置标题位置
- contourMapFrame.Axes.Item(2).TitleOffset2 = -0.3;
- contourMapFrame.Axes.Item(1).SetScale(LastMajorTick: maxidh, MajorInterval: 20);
- contourMapFrame.Axes.Item(1).Title = "测点号/m";//设置底边轴标题
- contourMapFrame.Axes.Item(1).TitleFont.Size = 14;
- contourMapFrame.Axes.Item(1).TitleOffset1 = -3.5;//设置标题位置
- contourMapFrame.Axes.Item(1).TitleOffset2 = -0.3;
- //1为底边轴,2为顶边轴,3为左边轴,4为右边轴;
- IContourMap contourMap = (IContourMap)contourMapFrame.Overlays.Item(1);
- contourMap.SmoothContours = SrfConSmoothType.srfConSmoothHigh; //平滑等值线边界
- contourMap.FillContours = true;
- ILevels levels = contourMap.Levels;
- levels.LoadFile(levelFilePath);
- Surfer.IText Text1 = Doc.Shapes.AddText(contourMap.Left + 2, contourMap.Top + 0.5, strListFileName[i] + "" + "线视电阻率拟断面图");
- Text1.Font.Size = 14;
- Doc.SaveAs(listFileName[i] + ".srf");
- Doc.Close();
- surfer.Quit();
- System.GC.Collect(System.GC.GetGeneration(surfer));
- }
-
- }
-
- MessageBox.Show("OK!");
- }
- private void baihua_Click(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < listFile.LongCount(); i++)
- {
- Surfer.Application surfer = new Surfer.Application();
- surfer.Visible = false;
- IDocuments docs = surfer.Documents;
- IWksDocument wks = (IWksDocument)docs.Open(listFile[i]); //打开dat文件
- wks.Activate();
- dynamic x = wks.Columns(2).Count; //统计一列的个数
- wks.Columns(1).Delete(); //删除第一列
- dynamic y = wks.Columns(2).Statistics().Maximum; //统计第二列的最大值
- dynamic firstValue = wks.Cells(1, 1).Value; //获取第一行第一列的值
- dynamic firstValueTwo = wks.Cells(1, 2).Value;
- dynamic lastValue = wks.Cells(x, 1).Value;
- wks.Cells(x + 1, 1).Value = lastValue; //设置第x+1行第一列的值
- wks.Cells(x + 1, 2).Value = y;
- wks.Cells(x + 2, 1).Value = firstValue;
- wks.Cells(x + 2, 2).Value = y;
- wks.Cells(x + 3, 1).Value = firstValue;
- wks.Cells(x + 3, 2).Value = firstValueTwo;
- wks.Rows(1).Insert();
- wks.Cells(1, 1).Value = x + 3;
- wks.Cells(1, 2).Value = 1;
- wks.SaveAs(listFileName[i] + ".bln"); //保存为bln文件
- surfer.Quit();
- System.GC.Collect(System.GC.GetGeneration(surfer));
- }
-
-
-
- MessageBox.Show("OK!");
- }
- private void diban_Click(object sender, RoutedEventArgs e)
- {
- for (int i = 0; i < listFile.LongCount(); i++)
- {
- Surfer.Application surfer = new Surfer.Application();
- surfer.Visible = false;
- IDocuments docs = surfer.Documents;
- IWksDocument wks = (IWksDocument)docs.Open(listFile[i]); //打开dat文件
- dynamic countX = wks.Rows(1).Count; //统计一列的个数
- if (countX==3)
- {
- wks.Columns(1).Delete(); //删除第一列
- dynamic fistx = wks.Columns(1).Count; //统计第一列的个数
- wks.Rows(1).Insert();
- wks.Cells(1, 1).Value = fistx;
- wks.Cells(1, 2).Value = 1;
- wks.SaveAs(listFileName[i] + ".bln"); //保存为bln文件
- surfer.Quit();
- System.GC.Collect(System.GC.GetGeneration(surfer));
- }
- else
- {
- dynamic x = wks.Columns(1).Count; //统计第一列的个数
- wks.Rows(1).Insert();
- wks.Cells(1, 1).Value = x;
- wks.Cells(1, 2).Value = 1;
- wks.SaveAs(listFileName[i] + ".bln"); //保存为bln文件
- surfer.Quit();
- System.GC.Collect(System.GC.GetGeneration(surfer));
- }
-
- }
-
- MessageBox.Show("OK!");
- }
- private void baihuawenjian_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog ofdName2 = new OpenFileDialog();
- ofdName2.Title = "选择文件";
- ofdName2.Filter = "白化文件|*.bln|所有文件|*.*";
- ofdName2.FileName = string.Empty;
- ofdName2.RestoreDirectory = true;
- ofdName2.DefaultExt = "bln";
- ofdName2.Multiselect = true;
- ofdName2.ShowDialog();
-
- blankFileName = ofdName2.FileNames;
- for (int i = 0; i < blankFileName.Length; i++)
- {
- blankFile.Add(blankFileName[i]);
- }
-
- }
- private void xzdb_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog ofdName3 = new OpenFileDialog();
- ofdName3.Title = "选择文件";
- ofdName3.Filter = "底板文件|*.bln|所有文件|*.*";
- ofdName3.FileName = string.Empty;
- ofdName3.RestoreDirectory = true;
- ofdName3.DefaultExt = "bln";
- ofdName3.Multiselect = true;
- ofdName3.ShowDialog();
-
- baseMapFileName = ofdName3.FileNames;
- for (int i = 0; i < baseMapFileName.Length; i++)
- {
- baseMap.Add(baseMapFileName[i]);
- }
-
- }
- private void levelFile_Click(object sender, RoutedEventArgs e)
- {
- OpenFileDialog ofdName4 = new OpenFileDialog();
- ofdName4.Title = "选择填充文件";
- ofdName4.Filter = "填充文件|*.lvl|所有文件|*.*";
- ofdName4.FileName = string.Empty;
- ofdName4.RestoreDirectory = true;
- ofdName4.DefaultExt = "lvl";
- ofdName4.Multiselect = true;
- ofdName4.ShowDialog();
- try
- {
- levelFilePath = ofdName4.FileName;
- }
- catch (Exception)
- {
-
- MessageBox.Show("请选择lvl文件");
- }
- }
- }
- }
复制代码- <Window x:Class="surfer.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:surfer"
- mc:Ignorable="d"
- Title="辅助工具" Height="400" Width="210">
- <StackPanel HorizontalAlignment="Center">
- <Grid VerticalAlignment="Top" Background="Azure" >
- <Grid.RowDefinitions>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="50"/>
- <ColumnDefinition Width="50"/>
- <ColumnDefinition Width="50"/>
- <ColumnDefinition Width="50"/>
- </Grid.ColumnDefinitions>
- <TextBlock x:Name="textBlock2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="0" Grid.Column="2" TextWrapping="Wrap" Text="Y最小值" RenderTransformOrigin="1.659,0.879"/>
- <TextBox x:Name="yMinBox" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="3" TextWrapping="Wrap" Text="" />
- <TextBlock x:Name="textBlock4" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" TextWrapping="Wrap" Text="X间距" RenderTransformOrigin="0.562,1.111" Margin="8,10,10,14"/>
- <TextBox x:Name="NumCols" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap" Text=""/>
- <TextBlock x:Name="textBlock5" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" TextWrapping="Wrap" Text="Y间距" />
- <TextBox x:Name="NumRows" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" TextWrapping="Wrap" Text="" RenderTransformOrigin="1.08,-0.478"/>
- <TextBlock x:Name="textBlock7" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2" TextWrapping="Wrap" Text="滤波Z" />
- <TextBox x:Name="Filter" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="3" TextWrapping="Wrap" Text="" RenderTransformOrigin="-0.4,-0.913"/>
- </Grid>
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- <RowDefinition Height="40"/>
- </Grid.RowDefinitions>
- <Button x:Name="button" Content="选择文件" Background="Cyan" Click="button_Click" HorizontalAlignment="Stretch" Grid.Row="0"/>
- <Button x:Name="xzdb" Content="选择底板" Background="Salmon" Grid.Row="2" Click="xzdb_Click" />
- <Button x:Name="baihuawenjian" Content="白化文件" Background="WhiteSmoke" HorizontalAlignment="Stretch" Click="baihuawenjian_Click" Grid.Row="1" />
- <Button x:Name="levelFile" Content="选择填充文件" Background="Gray" HorizontalAlignment="Stretch" Grid.Row="3" Click="levelFile_Click"/>
- <Button x:Name="grid" Content="生成srf" Background="SeaShell" Grid.Row="4" HorizontalAlignment="Stretch" Click="button1_Click"/>
- <Button x:Name="blank" Content="地表" Background="GreenYellow" Grid.Row="5" HorizontalAlignment="Stretch" Click="baihua_Click"/>
- <Button x:Name="diban" Content="底板" Background="Gray" Grid.Row="6" HorizontalAlignment="Stretch" Click="diban_Click"/>
- </Grid>
- </StackPanel>
- </Window>
复制代码 请注意本程序为WPF程序。 |
|