You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2466 lines
123 KiB

using Aspose.Cells;
using DevExpress.XtraPrinting.Native;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.Geoprocessor;
using ExcelDataReader;
using KGIS.Framework.AE;
using KGIS.Framework.AE.Enum;
using KGIS.Framework.AE.GPHelper;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Platform.Helper;
using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using KUI.Windows;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Xml.Linq;
using WpfApp1.Helper;
using WpfApp1.Model;
namespace WpfApp1
{
/// <summary>
/// UserControl1.xaml 的交互逻辑
/// </summary>
public partial class UserControl1 : System.Windows.Controls.UserControl
{
List<TestData> list = new List<TestData>();
public UserControl1()
{
InitializeComponent();
list.Add(new TestData() { IsChecked = true, Descriction = "县级填报", ItemType = "1" });
list.Add(new TestData() { IsChecked = true, Descriction = "市级审核", ItemType = "2" });
list.Add(new TestData() { IsChecked = true, Descriction = "省级审核", ItemType = "3" });
list.Add(new TestData() { IsChecked = true, Descriction = "国家核查", ItemType = "4" });
list.Add(new TestData() { IsChecked = true, Descriction = "地类核查通过", ItemType = "5" });
//AttributeItemsSourse.ItemsSource = list;
RelatedCombox.DisplayMember = "Descriction";
RelatedCombox.ItemsSource = list;
}
private List<AnalysisExport> ListData { get; set; }
#region 选择变更图斑所在文件夹
private void SelectBGTB_Click(object sender, RoutedEventArgs e)
{
try
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择变更数据文件夹";
System.Windows.Forms.DialogResult dialogResult = dialog.ShowDialog();
if (dialogResult != System.Windows.Forms.DialogResult.OK && dialogResult != System.Windows.Forms.DialogResult.Yes)
{
return;
}
DirectorySecurity dirSec = new DirectorySecurity(dialog.SelectedPath, AccessControlSections.Access);
if (dirSec.AreAuditRulesProtected)
{
MessageHelper.ShowTips(string.Format("系统对路径[{0}]的读取权限不足无法读取!", dialog.SelectedPath));
return;
}
this.gvCtrl.ItemsSource = null;
this.bgfwpath.Text = dialog.SelectedPath;
if (cbSingle.IsChecked == true)
{
FindFile_Single(this.bgfwpath.Text);
}
else
{
FindmultipleFile(this.bgfwpath.Text);
}
this.gvCtrl.ItemsSource = ListData;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
MessageHelper.ShowTips("选择变更图斑文件异常:" + ex.Message);
}
}
public void FindFile_Single(string dirPath)
{
ListData = new List<AnalysisExport>();
IFeatureClass featureClass = null;
List<string> files = new List<string>();
FileInfo file = null;
List<string> xzqdms = new List<string>();
try
{
if (!Overlap_AfterTreatment.IsNullOrEmpty())
{
string gdbpath = Overlap_AfterTreatment.Replace(@"\AfterTreatment", "");
IWorkspaceAPI wsAPI = new WorkspaceAPI(gdbpath, WorkspaceTypeEnum.GDBFile);
IFeatureClassAPI classAPI = wsAPI.OpenFeatureClass("AfterTreatment");
featureClass = classAPI.FeatureClass;
xzqdms = GetLayerUniqueFieldValueByDataStatistics(featureClass, "xzqdm");
xzqdms = FilterateXZQ(xzqdms);
//变更数据
foreach (var item in xzqdms)
{
AnalysisExport AnalysisExport = new AnalysisExport();
AnalysisExport.ParengFolder = gdbpath;
AnalysisExport.FileName = "AfterTreatment";
AnalysisExport.IsChecked = false;
AnalysisExport.XZQDM = item;
AnalysisExport.ResultType = "gdb";
AnalysisExport.FullName = gdbpath;
AnalysisExport.BGFWName = "去重后数据";
AnalysisExport.BGFWPath = gdbpath;
AnalysisExport.OutputExcelPath = bgfwpath.Text;
AnalysisExport.JCSJPath = "";
AnalysisExport.JCSJName = "";
AnalysisExport.JCSJExcelName = "";
AnalysisExport.JCSJExcelPath = "";
ListData.Add(AnalysisExport);
}
}
else
{
var filesshp = System.IO.Directory.GetFiles(dirPath, "*.shp", SearchOption.AllDirectories);
files.AddRange(filesshp);
if (filesshp.Length == 0) return;
file = new FileInfo(files[0]);
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = wsf.OpenFromFile(file.DirectoryName, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
featureClass = pFeatureWorkspace.OpenFeatureClass(file.Name.Replace(".shp", ""));
if (featureClass == null) return;
xzqdms = GetLayerUniqueFieldValueByDataStatistics(featureClass, "xzqdm");
xzqdms = FilterateXZQ(xzqdms);
//变更数据
foreach (var item in xzqdms)
{
AnalysisExport AnalysisExport = new AnalysisExport();
AnalysisExport.ParengFolder = file.DirectoryName;
AnalysisExport.FileName = file.Name;
AnalysisExport.IsChecked = false;
AnalysisExport.XZQDM = item;
AnalysisExport.ResultType = file.Extension;
AnalysisExport.FullName = file.FullName;
AnalysisExport.BGFWName = file.Name;
AnalysisExport.BGFWPath = file.FullName;
AnalysisExport.OutputExcelPath = bgfwpath.Text;
AnalysisExport.JCSJPath = "";
AnalysisExport.JCSJName = "";
AnalysisExport.JCSJExcelName = "";
AnalysisExport.JCSJExcelPath = "";
ListData.Add(AnalysisExport);
}
}
files.Clear();
//基础报表
var filesxml = System.IO.Directory.GetFiles(dirPath, "*土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
files.AddRange(filesxml);
foreach (var item in files)
{
file = new FileInfo(item);
var analysisExport = ListData.Find(x => x.XZQDM == file.Name.Replace("(", "").Substring(0, 6));
if (analysisExport != null)
{
analysisExport.JCSJExcelName = file.Name;
analysisExport.JCSJExcelPath = file.FullName;
}
}
files.Clear();
//基础报表
filesxml = System.IO.Directory.GetFiles(dirPath, "土地利用现状分类面积汇总表*.xlsx", SearchOption.AllDirectories);
files.AddRange(filesxml);
if (files.Count == 1)
{
try
{
FileInfo excelfile = new FileInfo(files[0]);
using (var streamData = File.Open(excelfile.FullName, FileMode.Open, FileAccess.Read))
{
using (var readerData = ExcelReaderFactory.CreateReader(streamData))
{
var tjresult = readerData.AsDataSet();
DataTable tjdataTable = tjresult.Tables[0];
if (tjdataTable != null && tjdataTable.Rows.Count > 0)
{
foreach (var item in ListData)
{
var row = tjdataTable.Select($"column2='{item.XZQDM}' ");
if (row != null && row.Length > 0)
{
item.JCSJExcelName = excelfile.Name;
item.JCSJExcelPath = excelfile.FullName;
}
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("读取Excel数据异常:" + ex.Message);
LogAPI.Debug("读取Excel数据异常:" + ex.StackTrace);
}
}
files.Clear();
//基础数据
var filesgdb = System.IO.Directory.GetDirectories(dirPath, "*.gdb", SearchOption.AllDirectories);
files.AddRange(filesgdb);
foreach (var item in files)
{
file = new FileInfo(item);
var analysisExport = ListData.Find(x => x.XZQDM == file.Name.Substring(0, 6));
if (analysisExport != null)
{
analysisExport.JCSJName = file.Name;
analysisExport.JCSJPath = file.FullName;
if (!string.IsNullOrEmpty(analysisExport.JCSJName) && !string.IsNullOrEmpty(analysisExport.BGFWName) && !string.IsNullOrEmpty(analysisExport.JCSJExcelName))
{
analysisExport.IsChecked = true;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("读取文件异常:" + ex.Message);
LogAPI.Debug("读取文件异常:" + ex.StackTrace);
MessageHelper.ShowError("读取文件异常:" + ex.Message);
}
}
public void FindmultipleFile(string dirPath)
{
ListData = new List<AnalysisExport>();
DirectoryInfo FileDir = new DirectoryInfo(dirPath);
try
{
List<string> files = new List<string>();
//变更数据
var filesshp = System.IO.Directory.GetFiles(dirPath, "*.shp", SearchOption.AllDirectories);
files.AddRange(filesshp);
if (files.Count == 0)
{
filesshp = System.IO.Directory.GetDirectories(dirPath, "*.gdb", SearchOption.TopDirectoryOnly);
files.AddRange(filesshp);
}
foreach (var item in files)
{
FileInfo file = new FileInfo(item);
AnalysisExport AnalysisExport = new AnalysisExport();
AnalysisExport.ParengFolder = file.DirectoryName;
AnalysisExport.FileName = file.Name;
if (file.FullName.EndsWith(".gdb"))
AnalysisExport.FileSize = $"{Math.Round(Convert.ToDouble(GetDirectoryLength(file.FullName)) / 1024 / 1024, 2)}MB";
else
AnalysisExport.FileSize = $"{Math.Round(Convert.ToDouble(file.Length) / 1024 / 1024, 2)}MB";
AnalysisExport.IsChecked = false;
AnalysisExport.XZQDM = file.Name.Substring(0, 6);
AnalysisExport.ResultType = file.Extension;
AnalysisExport.FullName = file.FullName;
AnalysisExport.BGFWName = file.Name;
AnalysisExport.BGFWPath = file.FullName;
AnalysisExport.OutputExcelPath = bgfwpath.Text;
AnalysisExport.JCSJPath = "";
AnalysisExport.JCSJName = "";
AnalysisExport.JCSJExcelName = "";
AnalysisExport.JCSJExcelPath = "";
List<string> codes = KGIS.Framework.Core.Services.RunIDService2.Instance.Codes;
bool iscontinue = false;
foreach (var code in codes)
{
string c = code.Replace("00", "").Replace("00", "");
if (!AnalysisExport.XZQDM.StartsWith(c))
{
iscontinue = true;
break;
}
}
if (iscontinue) continue;
ListData.Add(AnalysisExport);
}
files.Clear();
//基础报表
var filesxml = System.IO.Directory.GetFiles(dirPath, "*土地利用现状分类面积汇总表.xlsx", SearchOption.AllDirectories);
files.AddRange(filesxml);
foreach (var item in files)
{
FileInfo file = new FileInfo(item);
var analysisExport = ListData.Find(x => x.XZQDM == file.Name.Replace("(", "").Substring(0, 6));
if (analysisExport != null)
{
analysisExport.JCSJExcelName = file.Name;
analysisExport.JCSJExcelPath = file.FullName;
}
}
files.Clear();
//基础报表
filesxml = System.IO.Directory.GetFiles(dirPath, "土地利用现状分类面积汇总表*.xlsx", SearchOption.AllDirectories);
files.AddRange(filesxml);
if (files.Count == 1)
{
try
{
FileInfo file = new FileInfo(files[0]);
using (var streamData = File.Open(file.FullName, FileMode.Open, FileAccess.Read))
{
using (var readerData = ExcelReaderFactory.CreateReader(streamData))
{
var tjresult = readerData.AsDataSet();
DataTable tjdataTable = tjresult.Tables[0];
if (tjdataTable != null && tjdataTable.Rows.Count > 0)
{
foreach (var item in ListData)
{
var row = tjdataTable.Select($"column2='{item.XZQDM}' ");
if (row != null && row.Length > 0)
{
item.JCSJExcelName = file.Name;
item.JCSJExcelPath = file.FullName;
}
}
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("读取Excel数据异常:" + ex.Message);
LogAPI.Debug("读取Excel数据异常:" + ex.StackTrace);
}
}
files.Clear();
//基础数据
var filesgdb = System.IO.Directory.GetDirectories(dirPath, "*.gdb", SearchOption.AllDirectories);
files.AddRange(filesgdb);
foreach (var item in files)
{
FileInfo file = new FileInfo(item);
var analysisExport = ListData.Find(x => x.XZQDM == file.Name.Substring(0, 6));
if (analysisExport != null)
{
analysisExport.JCSJName = file.Name;
analysisExport.JCSJPath = file.FullName;
if (!string.IsNullOrEmpty(analysisExport.JCSJName) && !string.IsNullOrEmpty(analysisExport.BGFWName) && !string.IsNullOrEmpty(analysisExport.JCSJExcelName))
{
analysisExport.IsChecked = true;
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("读取登记文件异常:" + ex.Message);
LogAPI.Debug("读取登记文件异常:" + ex.StackTrace);
MessageHelper.ShowError("读取登记文件异常:" + ex.Message);
}
}
/// <summary>
/// 过滤授权外的行政区代码
/// </summary>
/// <param name="xzqdms"></param>
private List<string> FilterateXZQ(List<string> xzqdms)
{
try
{
List<string> codes = KGIS.Framework.Core.Services.RunIDService2.Instance.Codes;
List<string> delxzq = new List<string>();
foreach (var item in xzqdms)
{
foreach (var code in codes)
{
string c = code.Replace("00", "").Replace("00", "");
if (!item.StartsWith(c))
{
delxzq.Add(item);
}
}
}
if (delxzq.Count > 0)
{
foreach (var code in delxzq)
{
xzqdms.Remove(code);
}
}
return xzqdms;
}
catch (Exception ex)
{
LogAPI.Debug("FilterateXZQ异常:" + ex.Message);
LogAPI.Debug("FilterateXZQ异常:" + ex.StackTrace);
throw ex;
}
}
public static long GetDirectoryLength(string dirPath)
{
//判断给定的路径是否存在,如果不存在则退出
if (!Directory.Exists(dirPath))
return -1;
long len = 0;
//定义一个DirectoryInfo对象
DirectoryInfo di = new DirectoryInfo(dirPath);
//通过GetFiles方法,获取di目录中的所有文件的大小
foreach (FileInfo fi in di.GetFiles())
{
len += fi.Length;
}
//获取di中所有的文件夹,并存到一个新的对象数组中,以进行递归
DirectoryInfo[] dis = di.GetDirectories();
if (dis.Length > 0)
{
for (int i = 0; i < dis.Length; i++)
{
len += GetDirectoryLength(dis[i].FullName);
}
}
return len;
}
#endregion
private void cbSingle_Checked(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(bgfwpath.Text) && bgfwpath.Text != "矢量数据中包含多个区县的变更范围,请先勾选下方复选框")
{
FindFile_Single(bgfwpath.Text);
this.gvCtrl.ItemsSource = ListData;
}
}
#region 确定
private void btn_oK_Click(object sender, RoutedEventArgs e)
{
try
{
if (ListData == null || ListData.Count == 0)
{
MessageHelper.ShowTips("请先选择需要分析的数据.");
return;
}
if (RelatedCombox.SelectedItems.Count == 0 && this.DLTBGXGC.IsChecked != true)
{
MessageHelper.ShowTips("请先选择数据阶段.");
return;
}
if (this.DLTBGXGC.IsChecked != true && this.JCTB.IsChecked != true && this.GTDCY.IsChecked != true)
{
MessageHelper.ShowTips("请先选择待分析数据类型.");
return;
}
btn_oK.IsEnabled = false;
btn_nO.IsEnabled = false;
int num = 0;
this.ShowLoading("正在进行分析", 0, 0);
foreach (var item in ListData)
{
if (!item.IsChecked) continue;
item.Prompt = "等待分析……";
}
foreach (var item in ListData)
{
if (!item.IsChecked) continue;
if (string.IsNullOrEmpty(item.BGFWName) || string.IsNullOrEmpty(item.JCSJExcelName) || string.IsNullOrEmpty(item.JCSJPath))
{
item.Prompt = "缺少数据,无法进行分析……";
continue;
}
try
{
this.UpdateMsg($"【{item.XZQDM}】正在生成变更成果,请稍后...");
ThreadParam pParm = new ThreadParam()
{
ThreadName = item.XZQDM,
analysisExport = item,
};
CustomIDGParm mIDGParm = null;
if (this.DLTBGXGC.IsChecked == true)
{
mIDGParm = InitData_DLTBGXGC(pParm);
}
//else if (this.DLTBGX.IsChecked == true)
//{
// mIDGParm = InitData_DLTBGX(pParm);
//}
else
{
mIDGParm = InitData(pParm);
}
item.Prompt = "正在分析……";
ThreadManager.Instance.QueueUserWorkItem(new System.Threading.WaitCallback(ExecuteBG), mIDGParm, new System.Threading.WaitCallback(ComplateCallBack));
num++;
if (num >= Environment.ProcessorCount - 2)
{
while (ThreadManager.Instance.ActiveCount >= 2) { }
num = ThreadManager.Instance.ActiveCount;
}
}
catch (Exception ex)
{
item.Prompt = ex.Message;
continue;
}
}
while (ThreadManager.Instance.ActiveCount > 0) { }
this.CloseLoading();
MessageHelper.ShowTips($"分析完成。");
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug("地类图斑数据提取失败" + ex.Message);
LogAPI.Debug("地类图斑数据提取失败" + ex.StackTrace);
MessageHelper.ShowError($"地类图斑数据提取失败:{ex.Message}");
}
finally
{
btn_oK.IsEnabled = true;
btn_nO.IsEnabled = true;
}
}
public void ComplateCallBack(object obj)
{
try
{
if (obj == null) return;
CustomIDGParm param = obj as CustomIDGParm;
param.analysisExport.Prompt = param.ErrorMessage;
}
catch (Exception ex)
{
throw ex;
}
}
public object locObj = new object();
private CustomIDGParm InitData(object pThreadParm)
{
IFeatureClass BGFeatureClass = null;
IFeatureClass tempBGFeatureClass = null;
IFeatureLayer JCFeatureLayer = null;
IFeatureClass outsideFeatureClass = null;
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = null;
IWorkspaceAPI JCAPI = null;
IWorkspaceAPI BGAPI = null;
IWorkspaceAPI tempBGAPI = null;
IWorkspaceAPI ZLAPI = null;
IFeatureLayer MultipartLayer = null;
IFeatureLayer UnionLayer = null;
IFeatureLayer BGLayer = null;
IFeatureLayer CZCDYDLayer = null;
GPParamClass gPParamClass = null;
IQueryFilter queryFilter = new QueryFilterClass() { };
try
{
ThreadParam param = pThreadParm as ThreadParam;
AnalysisExport analysisExport = param.analysisExport;
#region 初始化工程模版
//if (!Overlap_AfterTreatment.IsNullOrEmpty())
//{
// string gdbpath = Overlap_AfterTreatment.Replace(@"\AfterTreatment", "");
// IWorkspaceAPI wsAPI = new WorkspaceAPI(gdbpath, WorkspaceTypeEnum.GDBFile);
// IFeatureClassAPI classAPI = wsAPI.OpenFeatureClass("AfterTreatment");
// outsideFeatureClass = classAPI.FeatureClass;
//}
//else
//{
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
pWorkspace = wsf.OpenFromFile(analysisExport.ParengFolder, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
outsideFeatureClass = pFeatureWorkspace.OpenFeatureClass(analysisExport.FileName.Replace(".shp", ""));
//}
string temppath = analysisExport.OutputExcelPath + $"\\Temp\\{analysisExport.XZQDM}";
if (!Directory.Exists(temppath))
{
Directory.CreateDirectory(temppath);
}
else
{
try
{
DelectDirect(temppath);
}
catch (Exception ex) { }
}
JCAPI = new WorkspaceAPI(analysisExport.JCSJPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
JCFeatureLayer = new FeatureLayer() { FeatureClass = JCAPI.OpenFeatureClass("DLTB").FeatureClass };
//复制变更gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath);
string BGDatabase = System.IO.Path.Combine(temppath, "BGDB.gdb");
BGAPI = new WorkspaceAPI(BGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(BGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
//复制增量gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\ZLDB.gdb", temppath);
string ZLDatabase = System.IO.Path.Combine(temppath, "ZLDB.gdb");
//复制年末gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\NMDB.gdb", temppath);
string NMLDatabase = System.IO.Path.Combine(temppath, "NMDB.gdb");
ZLAPI = new WorkspaceAPI(ZLDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(ZLAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath);
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath + "\\BGTJ.sqlite", true);
//复制BG_GDLXConfig.xml
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BG_GDLXConfig.xml", temppath + "\\BG_GDLXConfig.xml", true);
#endregion
BGFeatureClass = BGAPI.OpenFeatureClass("DLTBBG").FeatureClass;
string nodeid = string.Empty;
foreach (TestData item in RelatedCombox.SelectedItems.ToList())
nodeid += $"'{item.ItemType}',";
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath + "\\temp");
string tempBGDatabase = System.IO.Path.Combine(temppath + "\\temp", "BGDB.gdb");
tempBGAPI = new WorkspaceAPI(tempBGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(tempBGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
IFeatureClassAPI fcSourceAPI = tempBGAPI.OpenFeatureClass("DLTBBG");
if (this.overlap.IsChecked == true)
{
if (GTDCY.IsChecked == true)
{
#region 根据sjdrly 擦除重复数据 1 国家提取 2自主提取 用sjdrly=1的 擦除sjdrly=2的数据 然后拆分多部件
IFeatureClassAPI sjdrly_1 = tempBGAPI.CreateFeatureClass("sjdrly1", fcSourceAPI.FeatureClass.FeatureDataset, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, esriGeometryType.esriGeometryPolygon, outsideFeatureClass.Fields);
IFeatureClassAPI sjdrly_2 = tempBGAPI.CreateFeatureClass("sjdrly2", fcSourceAPI.FeatureClass.FeatureDataset, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, esriGeometryType.esriGeometryPolygon, outsideFeatureClass.Fields);
IFeatureClassAPI fcAPI = new FeatureClassAPI(outsideFeatureClass);
queryFilter.WhereClause = $"sdxz = '3' and nodeid in({nodeid.Substring(0, nodeid.Length - 1)}) and xzqdm='{analysisExport.XZQDM}' and sjdrly='1' ";
fcAPI.FcToFc(sjdrly_1.FeatureClass, queryFilter, true);
RepairGeo(sjdrly_1.FeatureClass);
queryFilter.WhereClause = $"sdxz = '3' and nodeid in({nodeid.Substring(0, nodeid.Length - 1)}) and xzqdm='{analysisExport.XZQDM}' and sjdrly='2' ";
fcAPI.FcToFc(sjdrly_2.FeatureClass, queryFilter, true);
RepairGeo(sjdrly_2.FeatureClass);
gPParamClass = new GPParamClass
{
FirstFeatureLayer = new FeatureLayer() { FeatureClass = sjdrly_1.FeatureClass, Name = "sjdrly1" },
SecondFeatureLayer = new FeatureLayer() { FeatureClass = sjdrly_2.FeatureClass, Name = "sjdrly2" },
OutFeatureClassPath = $"{tempBGDatabase}\\UnionLayer",
IsGetOutPutFeature = true,
GPType = EnumGPType.Union,
};
GeoprocessorHelper.UnionAnalysis(gPParamClass, ref UnionLayer);
#region 拆分多部件
gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = UnionLayer;
gPParamClass.OutFeatureClassPath = $"{tempBGDatabase}\\AfterTreatment";
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.GPType = EnumGPType.MultipartToSinglePath;
GPHelper.Instance.ExeGPForProces(gPParamClass, ref MultipartLayer);
outsideFeatureClass = MultipartLayer.FeatureClass;
#endregion
#endregion
}
}
if (this.czc20x.IsChecked == true)
{
tempBGFeatureClass = tempBGAPI.OpenFeatureClass("DLTBBG").FeatureClass;
if (GTDCY.IsChecked == true)
{
queryFilter.WhereClause = $"sdxz = '3' and nodeid in({nodeid.Substring(0, nodeid.Length - 1)}) and xzqdm='{analysisExport.XZQDM}' ";
BGFWFcToFc(outsideFeatureClass, tempBGFeatureClass, queryFilter);
}
else if (this.JCTB.IsChecked == true)
{
queryFilter.WhereClause = $"xzqdm='{analysisExport.XZQDM}' ";//河北
BGFWFcToFc_0813(outsideFeatureClass, tempBGFeatureClass, queryFilter);
}
if (tempBGFeatureClass.FeatureCount(null) == 0) return null;
#region 与基础城镇村Union 赋值CZC20属性
string templeteGDBPath = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "Template", "TempGDB.gdb");
string resultPath = System.IO.Path.Combine(temppath, "BGTB_CZCDYD");
if (!Directory.Exists(resultPath))
{
Directory.CreateDirectory(resultPath);
}
string savePath = System.IO.Path.Combine(resultPath, "BGTB_CZCDYD" + ".gdb");
CopyDirectory(templeteGDBPath, savePath, true);
string outPath = System.IO.Path.Combine(savePath, "BGTB_CZCDYD");
BGLayer = new FeatureLayer() { FeatureClass = tempBGFeatureClass, Name = "变更图斑" };
CZCDYDLayer = new FeatureLayer() { FeatureClass = JCAPI.OpenFeatureClass("CZCDYD").FeatureClass, Name = "城镇村" };
gPParamClass = new GPParamClass
{
FirstFeatureLayer = BGLayer,
SecondFeatureLayer = CZCDYDLayer,
OutFeatureClassPath = outPath,
IsGetOutPutFeature = true,
GPType = EnumGPType.Union,
};
GPHelper.Instance.ExeGPForProces(gPParamClass, ref UnionLayer);
#endregion
#region 拆分多部件
MultipartLayer = null;
gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = UnionLayer;
gPParamClass.OutFeatureClassPath = $"{savePath}\\BGTB_Multipart";
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.GPType = EnumGPType.MultipartToSinglePath;
GPHelper.Instance.ExeGPForProces(gPParamClass, ref MultipartLayer);
#endregion
BGFcToFc(MultipartLayer.FeatureClass, BGFeatureClass, new QueryFilterClass() { WhereClause = $" FID_DLTBBG<>-1 and SHAPE_Area>1 " });
}
else
{
if (this.JCTB.IsChecked == true)
{
queryFilter.WhereClause = $"xzqdm='{analysisExport.XZQDM}' ";//河北
BGFWFcToFc_0813(outsideFeatureClass, BGFeatureClass, queryFilter);
}
else if (this.GTDCY.IsChecked == true)
{
queryFilter.WhereClause = $"sdxz = '3' and nodeid in({nodeid.Substring(0, nodeid.Length - 1)}) and xzqdm='{analysisExport.XZQDM}' ";
BGFWFcToFc(outsideFeatureClass, BGFeatureClass, queryFilter);
}
}
if (BGFeatureClass.FeatureCount(null) == 0) return null;
CustomIDGParm Parm = new CustomIDGParm();
IDGParameter mIDGParm = new IDGParameter();
ProjectInfo prjInfo = new ProjectInfo();
prjInfo.CODE = analysisExport.XZQDM;
prjInfo.ProjDir = temppath;
prjInfo.ProjName = analysisExport.XZQDM;
prjInfo.ProjSuffix = ".KBG";
prjInfo.ZLDatabase = ZLDatabase;
prjInfo.BGDatabase = BGDatabase;
prjInfo.NMDatabase = NMLDatabase;
prjInfo.JCKPath = analysisExport.JCSJPath;
prjInfo.Save();
mIDGParm.StrProjInfo = System.IO.Path.Combine(prjInfo.ProjDir, prjInfo.ProjName + prjInfo.ProjSuffix);
mIDGParm.ExeDLTB = true;
mIDGParm.AllowPDFZ = true;
mIDGParm.AllowUnion = true;
mIDGParm.AutoCalcGDKCSX = true;
mIDGParm.AutoSetGDLX = true;
mIDGParm.ExeGDDB = false;
mIDGParm.ExeZLHZ = true;
Parm.analysisExport = analysisExport;
Parm.PressParameter = mIDGParm;
return Parm;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
throw ex;
}
finally
{
if (outsideFeatureClass != null)
Marshal.ReleaseComObject(outsideFeatureClass);
if (BGFeatureClass != null)
Marshal.ReleaseComObject(BGFeatureClass);
if (BGLayer != null)
Marshal.ReleaseComObject(BGLayer);
if (JCFeatureLayer != null)
Marshal.ReleaseComObject(JCFeatureLayer);
if (pWorkspace != null)
Marshal.ReleaseComObject(pWorkspace);
if (UnionLayer != null)
Marshal.ReleaseComObject(UnionLayer);
if (MultipartLayer != null)
Marshal.ReleaseComObject(MultipartLayer);
JCAPI?.CloseWorkspace();
BGAPI?.CloseWorkspace();
ZLAPI?.CloseWorkspace();
}
}
private CustomIDGParm InitData_DLTBGXGC(object pThreadParm)
{
IFeatureClass BGFeatureClass = null;
IFeatureClass tempBGFeatureClass = null;
IFeatureLayer JCFeatureLayer = null;
IFeatureClass outsideFeatureClass = null;
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = null;
IWorkspaceAPI JCAPI = null;
IWorkspaceAPI BGAPI = null;
IWorkspaceAPI tempBGAPI = null;
IWorkspaceAPI ZLAPI = null;
IWorkspaceAPI outsideWorkspaceAPI = null;
ITable dltbgxTb = null;
IFeatureLayer MultipartLayer = null;
IFeatureLayer UnionLayer = null;
IFeatureLayer BGLayer = null;
IFeatureLayer CZCDYDLayer = null;
GPParamClass gPParamClass = null;
IQueryFilter queryFilter = new QueryFilterClass() { };
try
{
ThreadParam param = pThreadParm as ThreadParam;
AnalysisExport analysisExport = param.analysisExport;
#region 初始化工程模版
if (analysisExport.FileName.EndsWith(".shp"))
{
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
pWorkspace = wsf.OpenFromFile(analysisExport.ParengFolder, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
outsideFeatureClass = pFeatureWorkspace.OpenFeatureClass(analysisExport.FileName.Replace(".shp", ""));
}
else if (analysisExport.BGFWPath.EndsWith(".gdb"))
{
outsideWorkspaceAPI = new WorkspaceAPI(analysisExport.BGFWPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
outsideFeatureClass = outsideWorkspaceAPI.OpenFeatureClass("DLTBGXGC").FeatureClass;
}
string temppath = analysisExport.OutputExcelPath + $"\\Temp\\{analysisExport.XZQDM}";
if (!Directory.Exists(temppath))
{
Directory.CreateDirectory(temppath);
}
else
{
try
{
DelectDirect(temppath);
}
catch (Exception ex) { }
}
JCAPI = new WorkspaceAPI(analysisExport.JCSJPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
JCFeatureLayer = new FeatureLayer() { FeatureClass = JCAPI.OpenFeatureClass("DLTB").FeatureClass };
//复制变更gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath);
string BGDatabase = System.IO.Path.Combine(temppath, "BGDB.gdb");
BGAPI = new WorkspaceAPI(BGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(BGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
//复制增量gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\ZLDB.gdb", temppath);
string ZLDatabase = System.IO.Path.Combine(temppath, "ZLDB.gdb");
ZLAPI = new WorkspaceAPI(ZLDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(ZLAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath);
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath + "\\BGTJ.sqlite", true);
//复制BG_GDLXConfig.xml
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BG_GDLXConfig.xml", temppath + "\\BG_GDLXConfig.xml", true);
#endregion
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath + "\\temp");
string tempBGDatabase = System.IO.Path.Combine(temppath + "\\temp", "BGDB.gdb");
tempBGAPI = new WorkspaceAPI(tempBGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(tempBGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
IFeatureClassAPI fcAPI = new FeatureClassAPI(outsideFeatureClass);
IFeatureClassAPI DLTBGXGCAPI = ZLAPI.OpenFeatureClass("DLTBGXGC");
//fcAPI.FcToFc(DLTBGXGCAPI.FeatureClass, new QueryFilterClass() { WhereClause = $"xzqdm='{analysisExport.XZQDM}'" }, true);
fcAPI.FcToFc(DLTBGXGCAPI.FeatureClass, null, true);
CustomIDGParm Parm = new CustomIDGParm();
IDGParameter mIDGParm = new IDGParameter();
ProjectInfo prjInfo = new ProjectInfo();
prjInfo.CODE = analysisExport.XZQDM;
prjInfo.ProjDir = temppath;
prjInfo.ProjName = analysisExport.XZQDM;
prjInfo.ProjSuffix = ".KBG";
prjInfo.ZLDatabase = ZLDatabase;
prjInfo.BGDatabase = BGDatabase;
prjInfo.JCKPath = analysisExport.JCSJPath;
prjInfo.Save();
mIDGParm.StrProjInfo = System.IO.Path.Combine(prjInfo.ProjDir, prjInfo.ProjName + prjInfo.ProjSuffix);
mIDGParm.ExeDLTB = false;
mIDGParm.AllowPDFZ = false;
mIDGParm.AllowUnion = false;
mIDGParm.AutoCalcGDKCSX = false;
mIDGParm.AutoSetGDLX = false;
mIDGParm.ExeGDDB = false;
mIDGParm.ExeZLHZ = true;
Parm.analysisExport = analysisExport;
Parm.PressParameter = mIDGParm;
return Parm;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
throw ex;
}
finally
{
if (outsideFeatureClass != null)
Marshal.ReleaseComObject(outsideFeatureClass);
if (BGFeatureClass != null)
Marshal.ReleaseComObject(BGFeatureClass);
if (BGLayer != null)
Marshal.ReleaseComObject(BGLayer);
if (JCFeatureLayer != null)
Marshal.ReleaseComObject(JCFeatureLayer);
if (pWorkspace != null)
Marshal.ReleaseComObject(pWorkspace);
if (dltbgxTb != null)
Marshal.ReleaseComObject(dltbgxTb);
if (UnionLayer != null)
Marshal.ReleaseComObject(UnionLayer);
if (MultipartLayer != null)
Marshal.ReleaseComObject(MultipartLayer);
JCAPI?.CloseWorkspace();
BGAPI?.CloseWorkspace();
ZLAPI?.CloseWorkspace();
outsideWorkspaceAPI?.CloseWorkspace();
}
}
private CustomIDGParm InitData_DLTBGX(object pThreadParm)
{
IFeatureClass BGFeatureClass = null;
IFeatureLayer JCFeatureLayer = null;
IFeatureClass outsideFeatureClass = null;
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = null;
IWorkspaceAPI JCAPI = null;
IWorkspaceAPI BGAPI = null;
IWorkspaceAPI tempBGAPI = null;
IWorkspaceAPI ZLAPI = null;
IFeatureLayer BGLayer = null;
IQueryFilter queryFilter = new QueryFilterClass() { };
try
{
ThreadParam param = pThreadParm as ThreadParam;
AnalysisExport analysisExport = param.analysisExport;
#region 初始化工程模版
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
pWorkspace = wsf.OpenFromFile(analysisExport.ParengFolder, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
outsideFeatureClass = pFeatureWorkspace.OpenFeatureClass(analysisExport.FileName.Replace(".shp", ""));
string temppath = analysisExport.OutputExcelPath + $"\\Temp\\{analysisExport.XZQDM}";
if (!Directory.Exists(temppath))
{
Directory.CreateDirectory(temppath);
}
else
{
try
{
DelectDirect(temppath);
}
catch (Exception ex) { }
}
JCAPI = new WorkspaceAPI(analysisExport.JCSJPath, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile);
JCFeatureLayer = new FeatureLayer() { FeatureClass = JCAPI.OpenFeatureClass("DLTB").FeatureClass };
//复制变更gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath);
string BGDatabase = System.IO.Path.Combine(temppath, "BGDB.gdb");
BGAPI = new WorkspaceAPI(BGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile);
GeoDBAPI.SetGeoDatasetSpatialReference(BGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
//复制增量gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\ZLDB.gdb", temppath);
string ZLDatabase = System.IO.Path.Combine(temppath, "ZLDB.gdb");
ZLAPI = new WorkspaceAPI(ZLDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(ZLAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath);
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BGTJ.sqlite", temppath + "\\BGTJ.sqlite", true);
//复制BG_GDLXConfig.xml
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\BG_GDLXConfig.xml", temppath + "\\BG_GDLXConfig.xml", true);
//复制年末gdb
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\NMDB.gdb", temppath);
string NMLDatabase = System.IO.Path.Combine(temppath, "NMDB.gdb");
#endregion
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath + "\\temp");
string tempBGDatabase = System.IO.Path.Combine(temppath + "\\temp", "BGDB.gdb");
tempBGAPI = new WorkspaceAPI(tempBGDatabase, KGIS.Framework.AE.Enum.WorkspaceTypeEnum.GDBFile, true);
GeoDBAPI.SetGeoDatasetSpatialReference(tempBGAPI.CurrentWorkspace, (JCFeatureLayer.FeatureClass as IGeoDataset).SpatialReference, 0.0001);
IFeatureClassAPI fcAPI = new FeatureClassAPI(outsideFeatureClass);
IFeatureClassAPI IFeatureClassAPI = BGAPI.OpenFeatureClass("DLTBBG");
#region MyRegion
IFeatureCursor insertCur = IFeatureClassAPI.FeatureClass.Insert(true);
IFeatureBuffer gcBuf = IFeatureClassAPI.FeatureClass.CreateFeatureBuffer();
IFeature feature = null;
IFeatureCursor S_Cursor = fcAPI.FeatureClass.Search(new QueryFilterClass() { WhereClause = $"xzqdm='{analysisExport.XZQDM}'" }, true);
while ((feature = S_Cursor.NextFeature()) != null)
{
gcBuf.Shape = feature.ShapeCopy;
for (int i = 0; i < IFeatureClassAPI.FeatureClass.Fields.FieldCount; i++)
{
IField field = IFeatureClassAPI.FeatureClass.Fields.Field[i];
if (!field.Editable || field.Name.Contains("SHAPE")) continue;
string sFieldName = field.Name;
int idx = feature.Fields.FindField(sFieldName);
if (idx != -1)
gcBuf.Value[i] = feature.Value[idx];
}
insertCur.InsertFeature(gcBuf);
}
insertCur.Flush();
if (insertCur != null)
Marshal.ReleaseComObject(insertCur);
if (feature != null)
Marshal.ReleaseComObject(feature);
if (gcBuf != null)
Marshal.ReleaseComObject(gcBuf);
#endregion
//fcAPI.FcToFc(IFeatureClassAPI.FeatureClass, new QueryFilterClass() { WhereClause = $"xzqdm='{analysisExport.XZQDM}'" }, true);
IFeatureClassAPI.CloseFeatureClass();
CustomIDGParm Parm = new CustomIDGParm();
IDGParameter mIDGParm = new IDGParameter();
ProjectInfo prjInfo = new ProjectInfo();
prjInfo.CODE = analysisExport.XZQDM;
prjInfo.ProjDir = temppath;
prjInfo.ProjName = analysisExport.XZQDM;
prjInfo.ProjSuffix = ".KBG";
prjInfo.ZLDatabase = ZLDatabase;
prjInfo.BGDatabase = BGDatabase;
prjInfo.NMDatabase = NMLDatabase;
prjInfo.JCKPath = analysisExport.JCSJPath;
prjInfo.Save();
mIDGParm.StrProjInfo = System.IO.Path.Combine(prjInfo.ProjDir, prjInfo.ProjName + prjInfo.ProjSuffix);
mIDGParm.ExeDLTB = true;
mIDGParm.AllowPDFZ = true;
mIDGParm.AllowUnion = true;
mIDGParm.AutoCalcGDKCSX = true;
mIDGParm.AutoSetGDLX = true;
mIDGParm.ExeGDDB = false;
mIDGParm.ExeZLHZ = true;
Parm.analysisExport = analysisExport;
Parm.PressParameter = mIDGParm;
return Parm;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
throw ex;
}
finally
{
if (outsideFeatureClass != null)
Marshal.ReleaseComObject(outsideFeatureClass);
if (BGLayer != null)
Marshal.ReleaseComObject(BGLayer);
if (JCFeatureLayer != null)
Marshal.ReleaseComObject(JCFeatureLayer);
if (pWorkspace != null)
Marshal.ReleaseComObject(pWorkspace);
if (BGFeatureClass != null)
Marshal.ReleaseComObject(BGFeatureClass);
JCAPI?.CloseWorkspace();
BGAPI?.CloseWorkspace();
ZLAPI?.CloseWorkspace();
}
}
public void RepairGeo(IFeatureClass pFc)
{
Geoprocessor gp = new Geoprocessor();
try
{
RepairGeometry repairgeo = new RepairGeometry();
repairgeo.in_features = pFc;
//repairgeo.out_feature_class = outFC;
repairgeo.delete_null = "TRUE";
IGeoProcessorResult tGeoResult = (IGeoProcessorResult)gp.Execute(repairgeo, null);
if (tGeoResult == null || tGeoResult.Status != esriJobStatus.esriJobSucceeded)
{
//LogAPI.Debug("检查图形失败:");
throw new Exception(ReturnMessages(gp));
}
string msg = ReturnMessages(gp);
}
catch (Exception ex)
{
throw new Exception(ReturnMessages(gp));
}
}
/// <summary>
/// 获取GP任务执行信息
/// </summary>
/// <param name="gp"></param>
/// <returns></returns>
private string ReturnMessages(Geoprocessor gp)
{
string ms = "";
if (gp.MessageCount > 0)
{
for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
{
ms += "$" + gp.GetMessage(Count) + "\n\n";
}
}
return ms;
}
public static void CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
{
try
{
SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
if (Directory.Exists(SourcePath))
{
if (Directory.Exists(DestinationPath) == false)
Directory.CreateDirectory(DestinationPath);
foreach (string fls in Directory.GetFiles(SourcePath))
{
FileInfo flinfo = new FileInfo(fls);
flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
}
foreach (string drs in Directory.GetDirectories(SourcePath))
{
DirectoryInfo drinfo = new DirectoryInfo(drs);
CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void ExecuteBG(object pThreadParm)
{
IRDBHelper rdbHelper = null;
try
{
if (pThreadParm == null) return;
CustomIDGParm param = pThreadParm as CustomIDGParm;
ProcesHelper.Instance.ProgressHandle = (o) =>
{
//this.UpdateMsg(o.ToString());
};
string result = ProcesHelper.Instance.ExeGPForProces2(param.PressParameter);
if (result.Contains("Err"))
{
//throw new Exception(result);
param.ErrorMessage = result;
}
else
{
lock (locObj)
{
#region 导出土地利用现状变更表
StatisticalReportClass statistical = new StatisticalReportClass();
FileInfo proFile = new FileInfo(param.PressParameter.StrProjInfo);
//读取-导入年初数据报表
statistical.ExcelToDataTable(proFile.DirectoryName, param.analysisExport.JCSJExcelPath, param.analysisExport.XZQDM);
//导出报表
string outExcelPath = param.analysisExport.OutputExcelPath + "\\县级统计表";
if (!Directory.Exists(outExcelPath))
{
Directory.CreateDirectory(outExcelPath);
}
var outExcel = outExcelPath + $"\\2022({param.analysisExport.XZQDM})土地利用现状变更表.xlsx";
statistical.ExportTDLYXZBGB(outExcel, param.analysisExport, proFile.DirectoryName);
//2023耕地流向汇总统计表.xlsx
FileInfo fileInfo = new FileInfo(param.analysisExport.OutputExcelPath + "\\2023耕地流向汇总统计表.xlsx");
if (!fileInfo.Exists)
{
File.Copy(SysAppPath.GetCurrentAppPath() + "Template\\2023耕地流向汇总统计表.xlsx", param.analysisExport.OutputExcelPath + "\\2023耕地流向汇总统计表.xlsx");
}
#region 统计表写入
//获取当前区县在统计表中的位置
var ExcelCell_X = 0;
using (var streamData = File.Open(fileInfo.FullName, FileMode.Open, FileAccess.Read))
{
using (var readerData = ExcelReaderFactory.CreateReader(streamData))
{
var tjresult = readerData.AsDataSet();
DataTable tjdataTable = tjresult.Tables[0];
if (tjdataTable != null && tjdataTable.Rows.Count > 0)
{
foreach (DataRow item in tjdataTable.Rows)
{
if (param.analysisExport.XZQDM.ToTrim() == item["column0"].ToTrim())
{
ExcelCell_X = tjdataTable.Rows.IndexOf(item);
break;
}
}
}
}
}
#endregion
string dbPath = proFile.DirectoryName + @"\BGTJ.sqlite";
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
#region 默认
//DataTable table = rdbHelper.ExecuteDatatable("table", @" select substr(nyd,0,instr(nyd,'-'))|| '-' || sum(replace(nyd, rtrim(nyd, replace(nyd, '-', '')), '')) from (
// select
//case
//when bgh = '0201' then '9' || '-' || BGMJ
//when bgh = '0204' then '10' || '-' || BGMJ
//when bgh = '0301' then '12' || '-' || BGMJ
//when bgh = '0305' then '13' || '-' || BGMJ
//when bgh = '0307' then '14' || '-' || BGMJ
//when bgh = '1202' then '15' || '-' || BGMJ
//when bgh = '1006' then '16' || '-' || BGMJ
//when bgh = '0401' then '17' || '-' || BGMJ
//when bgh = '0403' then '18' || '-' || BGMJ
//when bgh = '0304' then '19' || '-' || BGMJ
//when bgh = '0306' then '20' || '-' || BGMJ
//when bgh = '0402' then '21' || '-' || BGMJ
//when bgh = '1103' then '22' || '-' || BGMJ
//when bgh = '1104' then '23' || '-' || BGMJ
//when bgh = '1107' then '24' || '-' || BGMJ
//when bgh = '201' then '27' || '-' || BGMJ
//when bgh = '202' then '28' || '-' || BGMJ
//when bgh = '203' then '29' || '-' || BGMJ
//when bgh = '204' then '30' || '-' || BGMJ
//when bgh = '205' then '31' || '-' || BGMJ
//when bgh = '1001' then '33' || '-' || BGMJ
//when bgh = '1002' then '34' || '-' || BGMJ
//when bgh = '1003' then '35' || '-' || BGMJ
//when bgh = '1007' then '36' || '-' || BGMJ
//when bgh = '1008' then '37' || '-' || BGMJ
//when bgh = '1009' then '38' || '-' || BGMJ
//when bgh = '1109' then '39' || '-' || BGMJ
//when bgh = '0404' then '41' || '-' || BGMJ
//when bgh = '1101' then '42' || '-' || BGMJ
//when bgh = '1102' then '43' || '-' || BGMJ
//when bgh = '1106' then '44' || '-' || BGMJ
//when bgh = '1108' then '45' || '-' || BGMJ
//when bgh = '1204' then '46' || '-' || BGMJ
//when bgh = '1205' then '47' || '-' || BGMJ
//when bgh = '1206' then '48' || '-' || BGMJ
//when bgh = '1207' then '49' || '-' || BGMJ
//else '' END NYD
// from(
// select bgq, bgh, SUM(BGMJ)BGMJ from(
// select bgq, bgh, SUM(BGMJ)BGMJ from
// (
// select
// --case when bgq in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgq, 1, 2) = '20' THEN 'JSYD' ELSE bgq END
// bgq,
// --case when bgh in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgh, 1, 2) = '20' THEN 'JSYD' ELSE bgh END
// bgh, BGMJ from
// (
// select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
// )A WHERE bgq<> bgh and(bgq = 'JSYD' OR bgh = 'JSYD') GROUP BY bgq,bgh
// union ALL
// select bgq,bgh,SUM(BGMJ)BGMJ from
// (
// select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
// )A WHERE bgq<> bgh GROUP BY bgq,bgh
// )A GROUP BY bgq, bgh
// )A WHERE substr(bgq, 1, 2) = '01' and substr(bgh, 1, 2)<> '01'
//)a WHERE length(nyd) > 0 GROUP by substr(nyd, 1, 2)
// union all
//select substr(nyd,0,instr(nyd,'-'))|| '-' || sum(replace(nyd, rtrim(nyd, replace(nyd, '-', '')), '')) from(
// select
//case
//when bgq = '0201' then '53' || '-' || BGMJ
//when bgq = '0204' then '54' || '-' || BGMJ
//when bgq = '0301' then '56' || '-' || BGMJ
//when bgq = '0305' then '57' || '-' || BGMJ
//when bgq = '0307' then '58' || '-' || BGMJ
//when bgq = '1202' then '59' || '-' || BGMJ
//when bgq = '1006' then '60' || '-' || BGMJ
//when bgq = '0401' then '61' || '-' || BGMJ
//when bgq = '0403' then '62' || '-' || BGMJ
//when bgq = '0304' then '63' || '-' || BGMJ
//when bgq = '0306' then '64' || '-' || BGMJ
//when bgq = '0402' then '65' || '-' || BGMJ
//when bgq = '1103' then '66' || '-' || BGMJ
//when bgq = '1104' then '67' || '-' || BGMJ
//when bgq = '1107' then '68' || '-' || BGMJ
//when bgq = '201' then '71' || '-' || BGMJ
//when bgq = '202' then '72' || '-' || BGMJ
//when bgq = '203' then '73' || '-' || BGMJ
//when bgq = '204' then '74' || '-' || BGMJ
//when bgq = '205' then '75' || '-' || BGMJ
//when bgq = '1001' then '77' || '-' || BGMJ
//when bgq = '1002' then '78' || '-' || BGMJ
//when bgq = '1003' then '79' || '-' || BGMJ
//when bgq = '1007' then '80' || '-' || BGMJ
//when bgq = '1008' then '81' || '-' || BGMJ
//when bgq = '1009' then '82' || '-' || BGMJ
//when bgq = '1109' then '83' || '-' || BGMJ
//when bgq = '0404' then '85' || '-' || BGMJ
//when bgq = '1101' then '86' || '-' || BGMJ
//when bgq = '1102' then '87' || '-' || BGMJ
//when bgq = '1106' then '88' || '-' || BGMJ
//when bgq = '1108' then '89' || '-' || BGMJ
//when bgq = '1204' then '90' || '-' || BGMJ
//when bgq = '1205' then '91' || '-' || BGMJ
//when bgq = '1206' then '92' || '-' || BGMJ
//when bgq = '1207' then '93' || '-' || BGMJ
//else '' END NYD
// from(
// select bgq, bgh, SUM(BGMJ)BGMJ from(
// select bgq, bgh, SUM(BGMJ)BGMJ from
// (
// select
// --case when bgq in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgq, 1, 2) = '20' THEN 'JSYD' ELSE bgq END
// bgq,
// --case when bgh in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgh, 1, 2) = '20' THEN 'JSYD' ELSE bgh END
// bgh, BGMJ from
// (
// select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
// )A WHERE bgq<> bgh and(bgq = 'JSYD' OR bgh = 'JSYD') GROUP BY bgq,bgh
// union ALL
// select bgq,bgh,SUM(BGMJ)BGMJ from
// (
// select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
// )A WHERE bgq<> bgh GROUP BY bgq,bgh
// )A GROUP BY bgq, bgh
// )A WHERE substr(bgq, 1, 2) <> '01' and substr(bgh, 1, 2)= '01'
//)a WHERE length(nyd) > 0 GROUP by substr(nyd, 1, 2) ", true);
#endregion
#region 宁波/陕西
DataTable table = rdbHelper.ExecuteDatatable("table", @" select substr(nyd,0,instr(nyd,'-'))|| '-' || sum(replace(nyd, rtrim(nyd, replace(nyd, '-', '')), '')) from (
select
case
when bgh = '0303' then '9' || '-' || BGMJ
when bgh = '0304' then '10' || '-' || BGMJ
when bgh = '0306' then '11' || '-' || BGMJ
when bgh = '0402' then '12' || '-' || BGMJ
when bgh = '0101' then '14' || '-' || BGMJ
when bgh = '0102' then '15' || '-' || BGMJ
when bgh = '0103' then '16' || '-' || BGMJ
when bgh = '0201' then '18' || '-' || BGMJ
when bgh = '0202' then '19' || '-' || BGMJ
when bgh = '0203' then '20' || '-' || BGMJ
when bgh = '0204' then '21' || '-' || BGMJ
when bgh = '0301' then '23' || '-' || BGMJ
when bgh = '0302' then '24' || '-' || BGMJ
when bgh = '0305' then '25' || '-' || BGMJ
when bgh = '0307' then '26' || '-' || BGMJ
when bgh = '0401' then '28' || '-' || BGMJ
when bgh = '0403' then '29' || '-' || BGMJ
when bgh = '1006' then '30' || '-' || BGMJ
when bgh = '1103' then '32' || '-' || BGMJ
when bgh = '1104' then '33' || '-' || BGMJ
when bgh = '1107' then '34' || '-' || BGMJ
when bgh = '1202' then '36' || '-' || BGMJ
when bgh = '1203' then '37' || '-' || BGMJ
when bgh = '201' then '40' || '-' || BGMJ
when bgh = '202' then '41' || '-' || BGMJ
when bgh = '203' then '42' || '-' || BGMJ
when bgh = '204' then '43' || '-' || BGMJ
when bgh = '205' then '44' || '-' || BGMJ
when bgh = '1001' then '46' || '-' || BGMJ
when bgh = '1002' then '47' || '-' || BGMJ
when bgh = '1003' then '48' || '-' || BGMJ
when bgh = '1007' then '49' || '-' || BGMJ
when bgh = '1008' then '50' || '-' || BGMJ
when bgh = '1009' then '51' || '-' || BGMJ
when bgh = '1109' then '52' || '-' || BGMJ
when bgh = '1105' then '55' || '-' || BGMJ
when bgh = '1106' then '56' || '-' || BGMJ
when bgh = '1108' then '57' || '-' || BGMJ
when bgh = '0404' then '58' || '-' || BGMJ
when bgh = '1101' then '60' || '-' || BGMJ
when bgh = '1102' then '61' || '-' || BGMJ
when bgh = '1110' then '62' || '-' || BGMJ
when bgh = '1204' then '64' || '-' || BGMJ
when bgh = '1205' then '65' || '-' || BGMJ
when bgh = '1206' then '66' || '-' || BGMJ
when bgh = '1207' then '67' || '-' || BGMJ
else '' END NYD
from(
select bgq, bgh, SUM(BGMJ)BGMJ from(
select bgq, bgh, SUM(BGMJ)BGMJ from
(
select
--case when bgq in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgq, 1, 2) = '20' THEN 'JSYD' ELSE bgq END
bgq,
--case when bgh in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgh, 1, 2) = '20' THEN 'JSYD' ELSE bgh END
bgh, BGMJ from
(
select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
)A WHERE bgq<> bgh and(bgq = 'JSYD' OR bgh = 'JSYD') GROUP BY bgq,bgh
union ALL
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
)A WHERE bgq<> bgh GROUP BY bgq,bgh
)A GROUP BY bgq, bgh
)A WHERE substr(bgq, 1, 2) = '01' and substr(bgh, 1, 2)<> '01'
)a WHERE length(nyd) > 0 GROUP by substr(nyd, 1, 2)
union all
select substr(nyd,0,instr(nyd,'-'))|| '-' || sum(replace(nyd, rtrim(nyd, replace(nyd, '-', '')), '')) from(
select
case
when bgq = '0303' then '71' || '-' || BGMJ
when bgq = '0304' then '70' || '-' || BGMJ
when bgq = '0306' then '73' || '-' || BGMJ
when bgq = '0402' then '74' || '-' || BGMJ
when bgq = '0101' then '76' || '-' || BGMJ
when bgq = '0102' then '77' || '-' || BGMJ
when bgq = '0103' then '78' || '-' || BGMJ
when bgq = '0201' then '80' || '-' || BGMJ
when bgq = '0202' then '81' || '-' || BGMJ
when bgq = '0203' then '82' || '-' || BGMJ
when bgq = '0204' then '83' || '-' || BGMJ
when bgq = '0301' then '85' || '-' || BGMJ
when bgq = '0302' then '86' || '-' || BGMJ
when bgq = '0305' then '87' || '-' || BGMJ
when bgq = '0307' then '88' || '-' || BGMJ
when bgq = '0401' then '90' || '-' || BGMJ
when bgq = '0403' then '91' || '-' || BGMJ
when bgq = '1006' then '92' || '-' || BGMJ
when bgq = '1103' then '94' || '-' || BGMJ
when bgq = '1104' then '95' || '-' || BGMJ
when bgq = '1107' then '96' || '-' || BGMJ
when bgq = '1202' then '98' || '-' || BGMJ
when bgq = '1203' then '99' || '-' || BGMJ
when bgq = '201' then '102' || '-' || BGMJ
when bgq = '202' then '103' || '-' || BGMJ
when bgq = '203' then '104' || '-' || BGMJ
when bgq = '204' then '105' || '-' || BGMJ
when bgq = '205' then '106' || '-' || BGMJ
when bgq = '1001' then '108' || '-' || BGMJ
when bgq = '1002' then '109' || '-' || BGMJ
when bgq = '1003' then '110' || '-' || BGMJ
when bgq = '1007' then '111' || '-' || BGMJ
when bgq = '1008' then '112' || '-' || BGMJ
when bgq = '1009' then '113' || '-' || BGMJ
when bgq = '1109' then '114' || '-' || BGMJ
when bgq = '1105' then '117' || '-' || BGMJ
when bgq = '1106' then '118' || '-' || BGMJ
when bgq = '1108' then '119' || '-' || BGMJ
when bgq = '0404' then '120' || '-' || BGMJ
when bgq = '1101' then '122' || '-' || BGMJ
when bgq = '1102' then '123' || '-' || BGMJ
when bgq = '1110' then '124' || '-' || BGMJ
when bgq = '1204' then '126' || '-' || BGMJ
when bgq = '1205' then '127' || '-' || BGMJ
when bgq = '1206' then '128' || '-' || BGMJ
when bgq = '1207' then '129' || '-' || BGMJ
else '' END NYD
from(
select bgq, bgh, SUM(BGMJ)BGMJ from(
select bgq, bgh, SUM(BGMJ)BGMJ from
(
select
--case when bgq in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgq, 1, 2) = '20' THEN 'JSYD' ELSE bgq END
bgq,
--case when bgh in ('1001', '1002', '1003', '1007', '1008', '1009', '1109')or substr(bgh, 1, 2) = '20' THEN 'JSYD' ELSE bgh END
bgh, BGMJ from
(
select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A )A
)A WHERE bgq<> bgh and(bgq = 'JSYD' OR bgh = 'JSYD') GROUP BY bgq,bgh
union ALL
select bgq,bgh,SUM(BGMJ)BGMJ from
(
select case when BGQCZCSXM = '空' then BGQDLBM else BGQCZCSXM end bgq,case when BGHCZCSXM = '空' then BGHDLBM else BGHCZCSXM end bgh,BGMJ from(select substr(BGQDLBM, 1, 4) BGQDLBM,substr(BGQCZCSXM, 1, 3) BGQCZCSXM, substr(BGHDLBM, 1, 4) BGHDLBM,substr(BGHCZCSXM, 1, 3) BGHCZCSXM,BGMJ, XZQTZLX from JCTJB_GQ )A
)A WHERE bgq<> bgh GROUP BY bgq,bgh
)A GROUP BY bgq, bgh
)A WHERE substr(bgq, 1, 2) <> '01' and substr(bgh, 1, 2)= '01'
)a WHERE length(nyd) > 0 GROUP by substr(nyd, 1, 3) ", true);
#endregion
Workbook workbook = new Workbook(fileInfo.FullName); //工作簿
Worksheet sheet = workbook.Worksheets[0]; //工作表
foreach (DataRow item in table.Rows)
{
var ExcelCell_Y = item[0].ToTrim().Split('-')[0].ToInt();
var Cells_Value = item[0].ToTrim().Split('-')[1].ToDouble();
Cells cells = sheet.Cells;//单元格
cells[ExcelCell_X, ExcelCell_Y].Value = Cells_Value;
}
workbook.Save(fileInfo.FullName);
#endregion
param.ErrorMessage = "完成";
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
LogAPI.Debug(ex.StackTrace);
throw ex;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
public static void SetFileToDisk(int Cells_X, int Cells_Y, string path, double Cells_Value)
{
try
{
Workbook workbook = new Workbook(path); //工作簿
Worksheet sheet = workbook.Worksheets[0]; //工作表
Cells cells = sheet.Cells;//单元格
cells[Cells_X, Cells_Y].Value = Cells_Value;
workbook.Save(path);
}
catch (Exception exc)
{
System.Windows.MessageBox.Show(exc.Message);
}
}
public static DataTable DtSelectTop(int TopItem, DataTable oDT)
{
if (oDT.Rows.Count < TopItem) return oDT;
DataTable NewTable = oDT.Clone();
DataRow[] rows = oDT.Select("1=1");
for (int i = 0; i < TopItem; i++)
{
NewTable.ImportRow((DataRow)rows[i]);
}
return NewTable;
}
#endregion
private void txt_execute_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
}
private void chkSelectedAll_EditValueChanged(object sender, DevExpress.Xpf.Editors.EditValueChangedEventArgs e)
{
try
{
if (this.ListData != null && this.ListData.Count > 0)
{
bool check = (sender as DevExpress.Xpf.Editors.CheckEdit).IsChecked == null ? false : bool.Parse((sender as DevExpress.Xpf.Editors.CheckEdit).IsChecked.Value.ToString());
this.ListData.ForEach(x => x.IsChecked = check);
}
}
catch (Exception ex)
{
MessageHelper.ShowError("全选发生异常:" + ex.Message);
}
}
/// <summary>
/// 通过IDataStatistics获取图层指定字段唯一值
/// </summary>
/// <param name="pFeatureLayer"></param>
/// <param name="fieldName"></param>
/// <returns>指定字段所有唯一值</returns>
private List<string> GetLayerUniqueFieldValueByDataStatistics(IFeatureClass featureClass, string fieldName)
{
try
{
List<string> arrValues = new List<string>();
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureCursor pFeatureCursor = null;
pQueryFilter.SubFields = fieldName;
pFeatureCursor = featureClass.Search(pQueryFilter, true);
IDataStatistics pDataStati = new DataStatisticsClass();
pDataStati.Field = fieldName;
pDataStati.Cursor = (ICursor)pFeatureCursor;
IEnumerator pEnumerator = pDataStati.UniqueValues;
pEnumerator.Reset();
while (pEnumerator.MoveNext())
{
object pObj = pEnumerator.Current;
arrValues.Add(pObj.ToString());
}
arrValues.Sort();
return arrValues;
}
catch (Exception ex)
{
LogAPI.Debug("GetLayerUniqueFieldValueByDataStatistics异常:" + ex.Message);
LogAPI.Debug("GetLayerUniqueFieldValueByDataStatistics异常:" + ex.StackTrace);
throw ex;
}
}
public bool DirectoryCopy(string sourceDir, string targetDirPath)
{
try
{
if (!Directory.Exists(sourceDir)) return false;
string targetDir = targetDirPath + "\\" + System.IO.Path.GetFileName(sourceDir);
if (!Directory.Exists(targetDir)) Directory.CreateDirectory(targetDir);
// 文件及文件夹名称数组
string[] dirColl = Directory.GetDirectories(sourceDir);
string[] fileColl = Directory.GetFiles(sourceDir);
// 便利所有文件
if (fileColl.Length > 0)
{
string fileName;
foreach (string fileDir in fileColl)
{
fileName = System.IO.Path.GetFileName(fileDir);
File.Copy(sourceDir + "\\" + fileName, targetDir + "\\" + fileName, true);
}
}
// 遍历所有文件夹
if (dirColl.Length > 0)
{
string folderName;
foreach (string dir in dirColl)
{
folderName = System.IO.Path.GetFileName(dir);
// 递归调用
Directory.CreateDirectory(targetDir + "\\" + folderName);
DirectoryCopy(dir, targetDir + "\\" + folderName);
}
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug("新建工程页面中,文件夹复制时失败,异常原因: " + ex + " ; ");
return false;
throw;
}
}
public virtual void DelectDirect(string srcPath)
{
try
{
DirectoryInfo dir = new DirectoryInfo(srcPath);
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
foreach (FileSystemInfo i in fileinfo)
{
if (i is DirectoryInfo) //判断是否文件夹
{
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
subdir.Delete(true); //删除子目录和文件
}
else
{
File.Delete(i.FullName); //删除指定文件
}
}
}
catch (Exception e)
{
throw;
}
}
/// <summary>
///
/// </summary>
/// <param name="sourceFeatureClass">数据源</param>
/// <param name="targetFeatureClass">目标数据</param>
/// <param name="pFilter">筛选条件</param>
/// <returns></returns>
public bool BGFWFcToFc(IFeatureClass sourceFeatureClass, IFeatureClass targetFeatureClass, IQueryFilter pFilter)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
try
{
if (sourceFeatureClass == null || targetFeatureClass == null) return false;
IFeatureClassLoad pFclsLoad = targetFeatureClass as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = sourceFeatureClass.Search(pFilter, true);
IFeature f = null;
T_Cursor = targetFeatureClass.Insert(true);
IFeatureBuffer buffer = targetFeatureClass.CreateFeatureBuffer();
var s_ihcbgdl = sourceFeatureClass.FindField("hcbgdl");
var s_idlbm = sourceFeatureClass.FindField("dlbm");
var s_ihcbgdl_1 = sourceFeatureClass.FindField("hcbgdl_1");
var s_izzsx = sourceFeatureClass.FindField("zzsx");
var s_izzsx_1 = sourceFeatureClass.FindField("zzsx_1");
var s_igdlx = sourceFeatureClass.FindField("gdlx");
var s_igdlx_1 = sourceFeatureClass.FindField("gdlx_1");
var s_ihfsx = sourceFeatureClass.FindField("hfsx");
var s_ihfsx_1 = sourceFeatureClass.FindField("hfsx_1");
var s_itblx = sourceFeatureClass.FindField("tblx");
var s_itblx_1 = sourceFeatureClass.FindField("tblx_1");
var s_itbbsm = sourceFeatureClass.FindField("tbbsm");
var s_itbbsm_1 = sourceFeatureClass.FindField("tbbsm_1");
var s_iczcsxm = sourceFeatureClass.FindField("czcsxm");
var s_iczcsxm_1 = sourceFeatureClass.FindField("czcsxm_1");
var s_isjdrly1 = sourceFeatureClass.FindField("FID_sjdrly1");
var t_idlbm = targetFeatureClass.FindField("dlbm");
var t_izzsxdm = targetFeatureClass.FindField("zzsxdm");
var t_igdlx = targetFeatureClass.FindField("gdlx");
var t_iBSM = targetFeatureClass.FindField("tbbsm");
var t_iCZCSXM = targetFeatureClass.FindField("czcsxm");
List<TBLXConvert> tBLXConverts = TBLXConvert();
while ((f = S_Cursor.NextFeature()) != null)
{
bool setdlbm = true;
string sjdrly1 = string.Empty;
if (s_isjdrly1 > 0)
{
sjdrly1 = f.Value[s_isjdrly1].ToTrim();
}
if (sjdrly1 == "-1")
{
if (s_itblx_1 > 0 && tBLXConverts.Count > 0)
{
string tblx = f.Value[s_itblx_1].ToTrim();
var _TBLXConvert = tBLXConverts.FirstOrDefault(x => x.FieldValue == tblx);
if (_TBLXConvert != null)
{
if (string.IsNullOrEmpty(f.Value[s_ihcbgdl_1].ToTrim()))
{
buffer.Value[t_idlbm] = _TBLXConvert.DLBM;
setdlbm = false;
}
}
}
buffer.Shape = f.ShapeCopy;
//hcbgdl---dlbm //zzsx ---zzsxdm //gdlx---gdlx //hfsx---zzsxdm
if (setdlbm)
buffer.Value[t_idlbm] = f.Value[s_ihcbgdl_1];
buffer.Value[t_igdlx] = f.Value[s_igdlx_1];
var zzsx = f.Value[s_izzsx_1].ToTrim();
if (!string.IsNullOrEmpty(zzsx))
buffer.Value[t_izzsxdm] = zzsx;
else
buffer.Value[t_izzsxdm] = f.Value[s_ihfsx_1];
if (s_iczcsxm_1 > 0)
{
buffer.Value[t_iCZCSXM] = f.Value[s_iczcsxm_1];
}
buffer.Value[t_iBSM] = f.Value[s_itbbsm_1];
}
else
{
if (s_itblx > 0 && tBLXConverts.Count > 0)
{
string tblx = f.Value[s_itblx].ToTrim();
var _TBLXConvert = tBLXConverts.FirstOrDefault(x => x.FieldValue == tblx);
if (_TBLXConvert != null)
{
if (s_ihcbgdl > 0)
{
if (string.IsNullOrEmpty(f.Value[s_ihcbgdl].ToTrim()))
{
buffer.Value[t_idlbm] = _TBLXConvert.DLBM;
setdlbm = false;
}
}
}
}
buffer.Shape = f.ShapeCopy;
//hcbgdl---dlbm //zzsx ---zzsxdm //gdlx---gdlx //hfsx---zzsxdm
if (setdlbm)
{
if (s_ihcbgdl > 0)
buffer.Value[t_idlbm] = f.Value[s_ihcbgdl];
}
if (s_idlbm > 0)
buffer.Value[t_idlbm] = f.Value[s_idlbm];
if (s_igdlx > 0)
buffer.Value[t_igdlx] = f.Value[s_igdlx];
var zzsx = string.Empty;
if (s_izzsx > 0)
zzsx = f.Value[s_izzsx].ToTrim();
if (!string.IsNullOrEmpty(zzsx))
buffer.Value[t_izzsxdm] = zzsx;
else if (s_ihfsx > 0)
buffer.Value[t_izzsxdm] = f.Value[s_ihfsx];
if (s_iczcsxm > 0)
buffer.Value[t_iCZCSXM] = f.Value[s_iczcsxm];
if (s_itbbsm > 0)
buffer.Value[t_iBSM] = f.Value[s_itbbsm];
}
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (T_Cursor != null)
{
Marshal.ReleaseComObject(T_Cursor);
}
}
}
public bool BGFWFcToFc_0813(IFeatureClass sourceFeatureClass, IFeatureClass targetFeatureClass, IQueryFilter pFilter)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
try
{
if (sourceFeatureClass == null || targetFeatureClass == null) return false;
IFeatureClassLoad pFclsLoad = targetFeatureClass as IFeatureClassLoad;
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = true;
//此处写编辑的代码
S_Cursor = sourceFeatureClass.Search(pFilter, true);
IFeature f = null;
T_Cursor = targetFeatureClass.Insert(true);
IFeatureBuffer buffer = targetFeatureClass.CreateFeatureBuffer();
var s_tblx = sourceFeatureClass.FindField("tblx");
var t_idlbm = targetFeatureClass.FindField("dlbm");
List<TBLXConvert> tBLXConverts = TBLXConvert();
while ((f = S_Cursor.NextFeature()) != null)
{
string tblx = string.Empty;
if (s_tblx > 0)
{
tblx = f.Value[s_tblx].ToTrim();
}
if (tBLXConverts.Count > 0)
{
var _TBLXConvert = tBLXConverts.FirstOrDefault(x => x.FieldValue == tblx);
if (_TBLXConvert != null)
{
buffer.Value[t_idlbm] = _TBLXConvert.DLBM;
}
}
#region 投影坐标
ISpatialReference s_spatialReference = f.ShapeCopy.SpatialReference;
ISpatialReference t_spatialReference = (targetFeatureClass.FeatureDataset as IGeoDataset).SpatialReference;
if (s_spatialReference.Name != t_spatialReference.Name)
{
IGeometry geo = null;
geo = f.ShapeCopy;
geo.SpatialReference = s_spatialReference;
geo.Project(t_spatialReference);
ITopologicalOperator topologicalOperator = geo as ITopologicalOperator;
topologicalOperator.Simplify();
buffer.Shape = geo;
}
else
{
buffer.Shape = f.ShapeCopy;
}
#endregion
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
if (pFclsLoad != null)
pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (T_Cursor != null)
{
Marshal.ReleaseComObject(T_Cursor);
}
}
}
public bool BGFcToFc(IFeatureClass sourceFeatureClass, IFeatureClass targetFeatureClass, IQueryFilter pFilter)
{
IFeatureCursor S_Cursor = null;
IFeatureCursor T_Cursor = null;
IFeature f = null;
try
{
if (sourceFeatureClass == null || targetFeatureClass == null) return false;
List<string> filedname = new List<string>() { "DLBM", "GDLX", "ZZSXDM" };
//IFeatureClassLoad pFclsLoad = targetFeatureClass as IFeatureClassLoad;
//if (pFclsLoad != null)
// pFclsLoad.LoadOnlyMode = true;
Dictionary<int, int> keyValuePairs = new Dictionary<int, int>();
for (int i = 0; i < targetFeatureClass.Fields.FieldCount; i++)
{
IField field = targetFeatureClass.Fields.Field[i];
if (field.Name == targetFeatureClass.ShapeFieldName || field.Name.Contains(targetFeatureClass.ShapeFieldName) || field.Name == targetFeatureClass.OIDFieldName || !field.Editable || !filedname.Contains(field.Name)) continue;
var sindex = sourceFeatureClass.Fields.FindField(field.Name);
if (sindex > 0)
keyValuePairs.Add(i, sindex);
}
//此处写编辑的代码
S_Cursor = sourceFeatureClass.Search(pFilter, true);
T_Cursor = targetFeatureClass.Insert(true);
var s_iCZCLX = sourceFeatureClass.FindField("CZCLX");
var s_iCZCSXM = sourceFeatureClass.FindField("CZCSXM");
var t_iczcsxm = targetFeatureClass.FindField("CZCSXM");
var s_idlbm = sourceFeatureClass.FindField("DLBM");
IFeatureBuffer buffer = targetFeatureClass.CreateFeatureBuffer();
while ((f = S_Cursor.NextFeature()) != null)
{
foreach (var item in keyValuePairs)
{
buffer.Value[item.Key] = f.Value[item.Value];
}
string dlbm = f.Value[s_idlbm].ToTrim();
//06类的为204,09类为205,0701为202,其余为203
List<string> jsyd = new List<string>() { "0508", "05H1", "0701", "0809", "0810", "0810A", "08H1", "08H2", "08H2A", "1004", "1005", "1201" };
string czcsxm = string.IsNullOrEmpty(f.Value[s_iCZCSXM].ToTrim()) ? f.Value[s_iCZCLX].ToTrim() : f.Value[s_iCZCSXM].ToTrim();
if (czcsxm.IsNullOrEmpty())
{
if (dlbm.StartsWith("06"))
czcsxm = "204";
if (dlbm.StartsWith("09"))
czcsxm = "205";
if (dlbm == "0702")
czcsxm = "202";
if (jsyd.Contains(dlbm))
czcsxm = "203";
}
buffer.Value[t_iczcsxm] = czcsxm;
buffer.Shape = f.ShapeCopy;
T_Cursor.InsertFeature(buffer);
}
T_Cursor.Flush();
//if (pFclsLoad != null)
// pFclsLoad.LoadOnlyMode = false;
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (T_Cursor != null)
Marshal.ReleaseComObject(T_Cursor);
if (f != null)
Marshal.ReleaseComObject(f);
}
}
/// <summary>
/// 获取转换关系
/// </summary>
/// <returns></returns>
private List<TBLXConvert> TBLXConvert()
{
List<TBLXConvert> tBLXConverts = new List<TBLXConvert>();
try
{
string strPath = SysAppPath.GetCurrentAppPath() + "Configs\\TBLX_Config.xml";
XDocument xDoc = XDocument.Load(strPath);
foreach (XElement xElement in xDoc.Descendants("Item"))
{
string FieldName = xElement.Attributes("FieldName").Single().Value;
string FieldValue = xElement.Attributes("FieldValue").Single().Value;
string DLBM = xElement.Attributes("DLBM").Single().Value;
string Iseffective = xElement.Attributes("Iseffective").Single().Value;
if (Iseffective != "true") continue;
tBLXConverts.Add(new WpfApp1.TBLXConvert() { FieldName = FieldName, FieldValue = FieldValue, DLBM = DLBM });
}
}
catch (Exception ex)
{
LogAPI.Debug("获取转换关系异常:" + ex.Message);
LogAPI.Debug("获取转换关系异常:" + ex.StackTrace);
}
return tBLXConverts;
}
private void btn_nO_Click(object sender, RoutedEventArgs e)
{
Process.GetCurrentProcess().Kill();
}
private void czc20x_Checked(object sender, RoutedEventArgs e)
{
}
private void CheckAll_Checked(object sender, RoutedEventArgs e)
{
try
{
list.ForEach(f => f.IsChecked = (sender as System.Windows.Controls.CheckBox).IsChecked == true);
}
catch (Exception ex)
{
}
}
private string Overlap_AfterTreatment { get; set; }
private void btn_overlap_Click(object sender, RoutedEventArgs e)
{
IQueryFilter queryFilter = null;
GPParamClass gPParamClass = null;
IFeatureLayer MultipartLayer = null;
FileInfo file = null;
IFeatureClass outsideFeatureClass = null;
List<string> files = new List<string>();
string temppath = string.Empty;
try
{
string filepath = bgfwpath.Text;
if (string.IsNullOrEmpty(filepath) || filepath == "矢量数据中包含多个区县的变更范围,请先勾选下方复选框")
{
MessageHelper.ShowTips("请先选择变更范围图斑.");
return;
}
if (Directory.Exists(filepath + "\\去重数据\\BGDB.gdb"))
{
if (MessageHelper.ShowYesNoAndTips("已存在去重数据,是否重新生成去重数据.") != System.Windows.Forms.DialogResult.Yes)
{
Overlap_AfterTreatment = $"{filepath + "\\\\BGDB.gdb\\AfterTreatment"}";
return;
}
}
if (!string.IsNullOrEmpty(filepath))
{
var filesshp = System.IO.Directory.GetFiles(filepath, "*.shp", SearchOption.AllDirectories);
files.AddRange(filesshp);
if (filesshp.Length == 0) return;
this.ShowLoading("正在处理重叠数据", 0, 0);
file = new FileInfo(files[0]);
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = wsf.OpenFromFile(file.DirectoryName, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
outsideFeatureClass = pFeatureWorkspace.OpenFeatureClass(file.Name.Replace(".shp", ""));
if (outsideFeatureClass == null)
{
MessageHelper.ShowTips("变更范围图斑读取失败,请检查数据是否正确.");
return;
}
temppath = filepath + "\\去重数据";
if (!Directory.Exists(temppath))
{
Directory.CreateDirectory(temppath);
}
else
{
try
{
DelectDirect(temppath);
}
catch (Exception ex) { }
}
DirectoryCopy(SysAppPath.GetCurrentAppPath() + "Template\\BGDB.gdb", temppath);
temppath = $"{temppath}\\BGDB.gdb";
#region 根据sjdrly 擦除重复数据 1 国家提取 2自主提取 用sjdrly=1的 擦除sjdrly=2的数据 然后拆分多部件
IWorkspaceAPI wsAPI = new WorkspaceAPI(temppath, WorkspaceTypeEnum.GDBFile);
GeoDBAPI.SetGeoDatasetSpatialReference(wsAPI.CurrentWorkspace, GeoDBAPI.GetGeoDatasetSpatialReference(pWorkspace), 0.0001);
IFeatureClassAPI sjdrly_1 = wsAPI.CreateFeatureClass("sjdrly1", (outsideFeatureClass as IGeoDataset).SpatialReference, outsideFeatureClass.Fields);
IFeatureClassAPI sjdrly_2 = wsAPI.CreateFeatureClass("sjdrly2", (outsideFeatureClass as IGeoDataset).SpatialReference, outsideFeatureClass.Fields);
IFeatureClassAPI fcAPI = new FeatureClassAPI(outsideFeatureClass);
queryFilter = new QueryFilter() { };
queryFilter.WhereClause = $"sdxz = '3' and sjdrly='1' ";
fcAPI.FcToFc(sjdrly_1.FeatureClass, queryFilter, true);
queryFilter.WhereClause = $"sdxz = '3' and sjdrly='2' ";
fcAPI.FcToFc(sjdrly_2.FeatureClass, queryFilter, true);
IFeatureLayer EraseLayer = null;
gPParamClass = new GPParamClass
{
FirstFeatureLayer = new FeatureLayer() { FeatureClass = sjdrly_1.FeatureClass, Name = "sjdrly1" },
SecondFeatureLayer = new FeatureLayer() { FeatureClass = sjdrly_2.FeatureClass, Name = "sjdrly2" },
OutFeatureClassPath = $"{temppath}\\shapeErase",
IsGetOutPutFeature = true,
GPType = EnumGPType.Erase,
};
GPHelper.Instance.ExeGPForProces(gPParamClass, ref EraseLayer);
#region 拆分多部件
gPParamClass = new GPParamClass();
gPParamClass.FirstFeatureLayer = EraseLayer;
gPParamClass.OutFeatureClassPath = $"{temppath}\\AfterTreatment";
gPParamClass.IsGetOutPutFeature = true;
gPParamClass.GPType = EnumGPType.MultipartToSinglePath;
GPHelper.Instance.ExeGPForProces(gPParamClass, ref MultipartLayer);
#endregion
#endregion
}
Overlap_AfterTreatment = $"{temppath}\\AfterTreatment";
this.CloseLoading();
MessageHelper.ShowTips("重叠数据处理完成.");
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug(ex.Message + ex.StackTrace);
MessageHelper.ShowError("重叠图斑处理失败:" + ex.Message);
}
}
private void Overlap_Checked(object sender, RoutedEventArgs e)
{
}
#region 流量分析数据为DLTBGXGC层数据
private void DLTBGXGC_Checked(object sender, RoutedEventArgs e)
{
if (DLTBGXGC.IsChecked == true)
{
GTDCY.IsChecked = false;
JCTB.IsChecked = false;
}
}
#endregion
private void btn_FG_Click(object sender, RoutedEventArgs e)
{
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = null;
IFeatureClass outsideFeatureClass = null;
try
{
if (ListData == null || ListData.Count == 0)
{
MessageHelper.ShowTips("请先选择需要分析的数据.");
return;
}
this.ShowLoading("正在进行拆分...", 0, 0);
List<string> files = new List<string>();
var filesshp = System.IO.Directory.GetFiles(bgfwpath.Text, "*.shp", SearchOption.AllDirectories);
files.AddRange(filesshp);
if (filesshp.Length == 0) return;
FileInfo file = new FileInfo(files[0]);
IWorkspaceFactory wsf = new ShapefileWorkspaceFactory();
pWorkspace = wsf.OpenFromFile(file.DirectoryName, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
outsideFeatureClass = pFeatureWorkspace.OpenFeatureClass(file.Name.Replace(".shp", ""));
if (outsideFeatureClass == null) return;
foreach (var item in ListData)
{
if (item.XZQDM == null) continue;
string gdbFolder = bgfwpath.Text + $"\\分县导出\\{item.XZQDM}";
if (!Directory.Exists(gdbFolder))
Directory.CreateDirectory(gdbFolder);
try
{
DelectDirect(gdbFolder);
}
catch
{
//删除临时数据异常 不做处理
}
ExportFeaturesToShp(outsideFeatureClass, new QueryFilterClass() { WhereClause = $"xzqdm='{item.XZQDM}'" }, gdbFolder, item.XZQDM);
}
this.CloseLoading();
MessageHelper.ShowTips($"分县导出完成。");
}
catch (Exception ex)
{
this.CloseLoading();
LogAPI.Debug("分县导出失败" + ex.Message + ex.StackTrace);
MessageHelper.ShowError($"地类图斑数据提取失败:{ex.Message}");
}
finally
{
btn_oK.IsEnabled = true;
btn_nO.IsEnabled = true;
}
}
/// <summary>
/// 导出SHP数据
/// </summary>
/// <param name="pSourceFeatureClass"></param>
/// <param name="pQueryFilter"></param>
/// <param name="forlder"></param>
/// <param name="fileName"></param>
public static void ExportFeaturesToShp(IFeatureClass pSourceFeatureClass, IQueryFilter pQueryFilter, string forlder, string fileName)
{
IWorkspaceFactory workFactory = null;
IFeatureWorkspace pFeatureWorkspace = null;
IFeatureCursor pFeatureCursor = null;
IFeatureClass pFeatureClass = null;
IFeatureCursor pInsertFeatureCursor = null;
int count = 0;
try
{
if (!System.IO.Directory.Exists(forlder))
{
System.IO.Directory.CreateDirectory(forlder);
}
count = pSourceFeatureClass.FeatureCount(pQueryFilter);
pFeatureCursor = pSourceFeatureClass.Search(pQueryFilter, true);
workFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
pFeatureWorkspace = workFactory.OpenFromFile(forlder, 0) as IFeatureWorkspace;
//创建字段信息
IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
List<string> fieldNames = new List<string>();
for (int i = 0; i < pSourceFeatureClass.Fields.FieldCount; i++)
{
IField field = pSourceFeatureClass.Fields.get_Field(i);
if ((field.Type == esriFieldType.esriFieldTypeBlob || field.Type == esriFieldType.esriFieldTypeRaster) && field.Type != esriFieldType.esriFieldTypeGeometry)
continue;
if (field.Type == esriFieldType.esriFieldTypeGeometry)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "Shape";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
IGeometryDef pGeometryDef = new GeometryDef();
IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
pGeometryDefEdit.GeometryType_2 = pSourceFeatureClass.ShapeType;//pFeature.Shape.GeometryType;
if ((pSourceFeatureClass as IGeoDataset) != null)
{
pGeometryDefEdit.SpatialReference_2 = (pSourceFeatureClass as IGeoDataset).SpatialReference;//pFeature.Shape.SpatialReference;
}
pFieldEdit.GeometryDef_2 = pGeometryDef;
pFieldsEdit.AddField(pField);
}
else
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Length_2 = field.Length;
if (field.AliasName == "种植属性名称")
{
pFieldEdit.Length_2 = field.Length + 10;
}
if (field.Name.Length > 10)
{
string fname = field.Name.Substring(0, 10);
int n = 1;
while (fieldNames.Contains(fname))
{
string end = n.ToString();
fname = fname.Remove(10 - end.Length) + end;
n++;
}
pFieldEdit.Name_2 = fname;
}
else
{
pFieldEdit.Name_2 = field.Name;
}
fieldNames.Add(pFieldEdit.Name);
pFieldEdit.AliasName_2 = field.AliasName;
pFieldEdit.Type_2 = field.Type;
pFieldsEdit.AddField(pField);
}
}
pFeatureClass = pFeatureWorkspace.CreateFeatureClass(fileName, pFields, null, null, pSourceFeatureClass.FeatureType, "SHAPE", "");
pInsertFeatureCursor = pFeatureClass.Insert(true);
int num = 0;
ProgressHelper.CountProgress = count;
Dictionary<int, int> dicMatchFields = new Dictionary<int, int>();
GetMatchFieldsDirectory(pSourceFeatureClass, pFeatureClass, ref dicMatchFields, true);
IFeatureBuffer featureAdd = pFeatureClass.CreateFeatureBuffer();
IFeature pFeature = null;
while ((pFeature = pFeatureCursor.NextFeature()) != null)
{
featureAdd.Shape = pFeature.Shape;
foreach (KeyValuePair<int, int> kvpMatchField in dicMatchFields)
{
if (pFeature.Value[kvpMatchField.Value] != DBNull.Value)
{
featureAdd.set_Value(kvpMatchField.Key, pFeature.get_Value(kvpMatchField.Value));
}
else
{
featureAdd.set_Value(kvpMatchField.Key, null);
}
}
pInsertFeatureCursor.InsertFeature(featureAdd);
num++;
if (num % 100 == 0 || num == count)
{
ProgressHelper.CurrentProgress = num;
}
}
pInsertFeatureCursor.Flush();
ProgressHelper.CloseProcessBar();
//关闭lock
IWorkspaceFactoryLockControl ipWsFactoryLock = (IWorkspaceFactoryLockControl)workFactory;
if (ipWsFactoryLock.SchemaLockingEnabled)
{
ipWsFactoryLock.DisableSchemaLocking();
}
}
catch (Exception ex)
{
ProgressHelper.CloseProcessBar();
MessageHelper.ShowError("导出SHAPE文件出错:" + ex.Message);
LogAPI.Debug("导出SHAPE文件出错,可能的原因是:" + ex.Message);
}
finally
{
if (pFeatureCursor != null)
{
Marshal.ReleaseComObject(pFeatureCursor);
}
if (pFeatureClass != null)
{
Marshal.ReleaseComObject(pFeatureClass);
}
if (pInsertFeatureCursor != null)
{
Marshal.ReleaseComObject(pInsertFeatureCursor);
}
if (pFeatureWorkspace != null)
{
Marshal.ReleaseComObject(pFeatureWorkspace);
}
if (workFactory != null)
{
Marshal.ReleaseComObject(workFactory);
}
}
}
/// <summary>
/// 获得匹配的字段索引集合
/// </summary>
/// <param name="pSourceFeatureClass">源要素类</param>
/// <param name="pTargetClass">目标要素类</param>
/// <param name="dicMatchFields">匹配字段集合-KEY为目标图层字段,VALUE为源图层字段</param>
/// <param name="isGetRequired">是否获取必须字段</param>
public static void GetMatchFieldsDirectory(IClass pSourceClass, IClass pTargetClass, ref Dictionary<int, int> dicMatchFields, bool isGetRequired = false)
{
for (int i = 0; i < pTargetClass.Fields.FieldCount; i++)
{
IField pTargetField = pTargetClass.Fields.get_Field(i);
//目标图层的字段必须为可编辑并且不是必须字段
if (pTargetField.Required == false && pTargetField.Editable == true)
{
int iSourceFeatureClassIndex = pSourceClass.Fields.FindField(pTargetField.Name);
if (pTargetField.Name == "SHAPE_Leng")
{
iSourceFeatureClassIndex = pSourceClass.Fields.FindField("SHAPE_Length");
}
//源要素类中该字段存在
if (iSourceFeatureClassIndex > -1)
{
IField pSourceField = pSourceClass.Fields.get_Field(iSourceFeatureClassIndex);
//目标图层的字段也必须为可编辑并且不是必须字段
if (pSourceField.Required == false && pSourceField.Editable == true)
{
//添加到字段匹配集合中
dicMatchFields.Add(i, iSourceFeatureClassIndex);
}
else if (isGetRequired)
{
dicMatchFields.Add(i, iSourceFeatureClassIndex);
}
}
}
//此处为了保留原有要素ObjectID字段值
if (pTargetField.Name.Equals("OIDCOPY", StringComparison.CurrentCultureIgnoreCase))
{
dicMatchFields.Add(i, pSourceClass.FindField(pSourceClass.OIDFieldName));
}
}
}
public virtual string CreateTempDB(string pType, string pSubType = "")
{
string result = string.Empty;
try
{
string gdbFolder = Directory.GetCurrentDirectory() + "\\Temp\\" + pType;
if (!Directory.Exists(gdbFolder))
Directory.CreateDirectory(gdbFolder);
try
{
DelectDirect(gdbFolder);
}
catch
{
//删除临时数据异常 不做处理
}
//IWorkspaceFactory pFtWsFct = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory();
string gdbFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");// Guid.NewGuid().ToString().Replace("-", "");
string path = System.IO.Path.Combine(gdbFolder, string.IsNullOrWhiteSpace(pSubType) ? gdbFileName : pSubType);
//pFtWsFct.Create(path, "TempGDB", null, 0);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string savePath = System.IO.Path.Combine(path, "TempGDB.gdb");
string templeteGDBPath = System.IO.Path.Combine(SysAppPath.GetCurrentAppPath(), "Template", "TempGDB.gdb");
CopyDirectory(templeteGDBPath, savePath, true);
result = path;// System.IO.Path.Combine(path, "TempGDB.gdb");//临时数据存放路径
}
catch (Exception ex)
{
Console.WriteLine("创建临时数据库失败!" + ex.Message);
throw ex;
}
return result;
}
private void DLTBGX_Checked(object sender, RoutedEventArgs e)
{
}
private void JCTB_Checked(object sender, RoutedEventArgs e)
{
if (JCTB.IsChecked == true)
{
this.GTDCY.IsChecked = false;
this.DLTBGXGC.IsChecked = false;
}
}
private void GTDCY_Checked(object sender, RoutedEventArgs e)
{
if (GTDCY.IsChecked == true)
{
this.JCTB.IsChecked = false;
this.DLTBGXGC.IsChecked = false;
}
}
}
public class ThreadParam
{
public string ThreadName { get; set; }
public List<string> Codes { get; set; }
public ProjectInfo ProjInfo { get; set; }
public string StrBgTbLayer { get; set; }
public string StrJcTbLayer { get; set; }
public List<LayerCfg> Layers { get; set; }
public AnalysisExport analysisExport { get; set; }
public string nodeid { get; set; }
}
public class CustomIDGParm
{
public AnalysisExport analysisExport { get; set; }
public IDGParameter PressParameter { get; set; }
public string ErrorMessage { get; set; }
}
public class TBLXConvert
{
/// <summary>
/// 字段名称
/// </summary>
public string FieldName { get; set; }
/// <summary>
/// 字段值
/// </summary>
public string FieldValue { get; set; }
/// <summary>
/// 对应的地类编码
/// </summary>
public string DLBM { get; set; }
/// <summary>
/// 是否转换
/// </summary>
public bool Iseffective { get; set; }
}
public class TestData : INotifyPropertyChanged
{
private bool _IsChecked;
public bool IsChecked
{
get { return _IsChecked; }
set
{
_IsChecked = value;
RaisePropertyChanged("IsChecked");
}
}
public string ItemType { get; set; }
public string Descriction { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}