年度变更建库软件5.0版本
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.
 
 

775 lines
37 KiB

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Drawing;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using Kingo.Plugin.MakeTaskPackage.Model;
using Kingo.PluginServiceInterface;
namespace Kingo.Plugin.MakeTaskPackage.Common
{
public class FunctionOutXml
{
public void SaveConfig1(bool IsAnalysis, bool IsComparativeAnalysis, List<MakeTaskPackageModel> exportDataList, bool isCustom, string exportFolder, List<string> selectedXzq, string dbPath)
{
try
{
LayerConfig cfg_JZRW = new LayerConfig();
LayerConfig cfg_OneMap = new LayerConfig();
string m_outPath = string.Empty;
string savePath = string.Empty;//System.IO.Path.Combine(dirPath, item.OutPath);
string savePath2 = string.Empty;//System.IO.Path.Combine(dirPath, item.OutPath);
string tempName = string.Empty;
//List<MakeTaskPackageModel> VectorModelList = exportDataList.FindAll(x => x.Type.Contains("瓦片"));
//if (VectorModelList != null)
//{
// cfg_JZRW = new LayerConfig();
// foreach (var item in VectorModelList)
// {
// if (!item.IsCheck) continue;
// LayerInfo layerInfo = new Model.LayerInfo();
// layerInfo.IsSurvey = false;
// layerInfo.IsVisible = true;
// layerInfo.GroupIndex = item.MapGroupIndex;
// layerInfo.GroupName = item.MapGroupName;
// layerInfo.TableName = item.Type == "矢量" ? "KOFDT" : "";
// layerInfo.LayerName = item.FileAliasName;
// layerInfo.LayerType = item.Type == "矢量" ? "local_feature" : "kotile";
// layerInfo.LayerIndex = item.LayerIndex;
// layerInfo.LayerUrl = item.OutFilePath;
// if (!string.IsNullOrWhiteSpace(layerInfo.LayerUrl))
// layerInfo.LayerUrl = layerInfo.LayerUrl.Replace(@"\", "/");
// SaveLayerStyleConfing(item, layerInfo);
// cfg_JZRW.layers.LayerInfo.Add(layerInfo);
// // savePath2 = System.IO.Path.Combine(exportFolder, item.OutPath);
// }
//}
List<string> jzrwNameList = new List<string>();
List<MakeTaskPackageModel> jzrwModelList = exportDataList.FindAll(x => !x.Type.Contains("举证任务"));
if (jzrwModelList != null)
{
foreach (var item in jzrwModelList)
{
if (!jzrwNameList.Contains(item.Type))
jzrwNameList.Add(item.Type);
}
if (jzrwNameList.Count != 0)
{
for (int i = 0; i < jzrwNameList.Count; i++)
{
string name = jzrwNameList[i];
List<MakeTaskPackageModel> modelList = exportDataList.FindAll(x => x.Type == name);
if (modelList != null)
{
// cfg_JZRW = new LayerConfig();
foreach (var item in modelList)
{
if (!item.IsCheck) continue;
Model.LayerInfo layerInfo = new Model.LayerInfo();
layerInfo.IsSurvey = true;
layerInfo.IsVisible = true;
layerInfo.GroupIndex = item.MapGroupIndex;
layerInfo.GroupName = item.MapGroupName;
layerInfo.TableName = item.Type == "矢量" ? "KOFDT" : "";
if (item.FileAliasName.Contains("_"))
{
layerInfo.LayerName = item.FileAliasName.Substring(0, item.FileAliasName.IndexOf("_"));
}
else
{
layerInfo.LayerName = item.FileAliasName;
}
layerInfo.LayerType = item.Type == "矢量" ? "local_feature" : "kotile";
layerInfo.LayerIndex = item.LayerIndex;
layerInfo.LayerUrl = item.OutFilePath;
if (!string.IsNullOrWhiteSpace(layerInfo.LayerUrl))
layerInfo.LayerUrl = layerInfo.LayerUrl.Replace(@"\", "/");
layerInfo.queryUrl = layerInfo.LayerUrl;
if (item.Type == "矢量")
{
layerInfo.queryTableName = "KOFDT";
layerInfo.SFJZ = "";
layerInfo.PrimaryKey = "JCBH";
layerInfo.HeaderField = "JCBH";
layerInfo.SecondField = "";
if (item.FileName.Contains("_"))
{
layerInfo.LayerDbName = item.FileName.Substring(0, item.FileName.IndexOf("_"));
}
else
{
layerInfo.LayerDbName = item.FileName;
}
}
SaveLayerStyleConfing(item, layerInfo);
cfg_JZRW.layers.LayerInfo.Add(layerInfo);
if (!string.IsNullOrWhiteSpace(item.TaskName))
{
tempName = item.TaskName;
}
savePath = System.IO.Path.Combine(exportFolder, item.OutPath);
}
}
}
string cfg = cfg_JZRW.ToXML();
if (string.IsNullOrWhiteSpace(tempName))
tempName = "Data";
string wyjzPath = System.IO.Path.Combine(savePath, tempName);
if (!Directory.Exists(wyjzPath))
Directory.CreateDirectory(wyjzPath);
savePath = System.IO.Path.Combine(savePath, tempName, "wyjzLayerConfig.xml");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(cfg);
xmlDoc.Save(savePath);
}
}
#region 分析配置
//统计分析配置
string layerConfigsPath = System.IO.Path.Combine((MapsManager.Instance.CurrProjectInfo as ProjectInfo).ProjDir, "layerConfigs.xml");
if (File.Exists(layerConfigsPath))
{
XDocument xDoc = XDocument.Load(layerConfigsPath);
XElement configelement = xDoc.Element("config");
if (IsAnalysis)
{
XElement statisticsement = configelement.Element("statistics");
if (statisticsement != null)
{
foreach (var item in statisticsement.Elements("item"))
{
string tableName = item.Attribute("tableName").Value;
var model = exportDataList.Find(x => x.FileName == tableName);
string dbpath = string.Empty;
if (model != null)
{
if (model.OutFilePath != null && !string.IsNullOrWhiteSpace(model.OutFilePath))
{
dbpath = model.OutFilePath;
}
else if (model.OutPath != null && !string.IsNullOrWhiteSpace(model.OutPath))
{
dbpath = System.IO.Path.Combine(model.OutPath, "Data", "Source", item.Attribute("tableName").Value + ".ko");
}
else
{
dbpath = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
}
else
{
dbpath = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
//string dbpath = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
if (!string.IsNullOrWhiteSpace(dbpath))
dbpath = dbpath.Replace(@"\", "/");
cfg_OneMap.AnalysisCig.Items.Add(new AnalysisInfo()
{
name = item.Attribute("name").Value,
tableName = "KOFDT",
dbPath = dbpath,
jbnt = item.Attribute("jbnt").Value,
price = item.Attribute("price").Value
});
}
}
}
//对比分析配置
if (IsComparativeAnalysis)
{
if (configelement != null)
{
XElement compareElment = configelement.Element("compareAnalyse");
if (compareElment != null)
{
foreach (XElement group in compareElment.Elements("analyseGroup"))
{
string itemName1 = string.Empty;
string itemtableName1 = string.Empty;
string itemDbPath1 = string.Empty;
string itemJbnt1 = string.Empty;
string itemValues1 = string.Empty;
string itemName2 = string.Empty;
string itemtableName2 = string.Empty;
string itemDbPath2 = string.Empty;
string itemJbnt2 = string.Empty;
string itemValues2 = string.Empty;
int count = 0;
foreach (XElement item in group.Elements("item"))
{
count++;
if (count == 1)
{
itemName1 = item.Attribute("name").Value;
var model = exportDataList.Find(x => x.FileName == itemName1);
if (model != null)
{
if (model.OutFilePath != null && !string.IsNullOrWhiteSpace(model.OutFilePath))
{
itemDbPath1 = model.OutFilePath;
}
else if (model.OutPath != null && !string.IsNullOrWhiteSpace(model.OutPath))
{
itemDbPath1 = System.IO.Path.Combine(model.OutPath, "Data", "Source", item.Attribute("tableName").Value + ".ko");
}
else
{
itemDbPath1 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
}
else
{
itemDbPath1 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
itemtableName1 = "KOFDT";
//itemDbPath1 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
if (!string.IsNullOrWhiteSpace(itemDbPath1))
itemDbPath1 = itemDbPath1.Replace(@"\", "/");
itemJbnt1 = item.Attribute("jbnt").Value;
itemValues1 = item.Attribute("values").Value;
}
else
{
itemName2 = item.Attribute("name").Value;
var model = exportDataList.Find(x => x.FileName == itemName2);
if (model != null)
{
if (model.OutFilePath != null && !string.IsNullOrWhiteSpace(model.OutFilePath))
{
itemDbPath2 = model.OutFilePath;
}
else if (model.OutPath != null && !string.IsNullOrWhiteSpace(model.OutPath))
{
itemDbPath2 = System.IO.Path.Combine(model.OutPath, "Data", "Source", item.Attribute("tableName").Value + ".ko");
}
else
{
itemDbPath2 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
}
else
{
itemDbPath2 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
}
itemtableName2 = "KOFDT";
//itemDbPath2 = System.IO.Path.Combine(dbPath, item.Attribute("tableName").Value + ".ko");
if (!string.IsNullOrWhiteSpace(itemDbPath1))
itemDbPath2 = itemDbPath2.Replace(@"\", "/");
itemJbnt2 = item.Attribute("jbnt").Value;
itemValues2 = item.Attribute("values").Value;
}
}
cfg_OneMap.CompAnalyse.Groups.Add(new AnalysisConfig()
{
Name = group.Attribute("name").Value,
Items = new List<AnalysisInfo>() {
new AnalysisInfo() {
name=itemName1,
tableName=itemtableName1,
dbPath=itemDbPath1,
jbnt=itemJbnt1,
values=itemValues1
} ,
new AnalysisInfo (){
name=itemName2,
tableName=itemtableName2,
dbPath=itemDbPath2,
jbnt=itemJbnt2,
values=itemValues2
} }
});
}
}
}
}
}
#endregion
// string cfg2 = cfg_OneMap.ToXML();
if (isCustom)
{
//savePath = System.IO.Path.Combine(savePath, selectedXzq[model.CurrentIndex], "Source");
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
for (int i = 0; i < selectedXzq.Count; i++)
{
if (!string.IsNullOrWhiteSpace(m_outPath))
{
foreach (var item in cfg_JZRW.layers.LayerInfo)
{
item.LayerUrl = System.IO.Path.Combine(m_outPath, selectedXzq[i], "Source", item.LayerDbName + ".ko");
item.LayerUrl = item.LayerUrl.Replace(@"\", "/");
item.queryUrl = item.LayerUrl;
}
}
string cfg = cfg_JZRW.ToXML();
string newSavePath = System.IO.Path.Combine(savePath, selectedXzq[i], "wyjzLayerConfig.xml");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(cfg);
xmlDoc.Save(newSavePath);
}
// savePath2 = System.IO.Path.Combine(exportFolder, "Kingoit", "phonemap_landsurvey", "LayerConfig.xml");
}
else
{
// savePath2 = System.IO.Path.Combine(exportFolder, "Kingoit", "phonemap_landsurvey", "LayerConfig.xml");
}
//XmlDocument xmlDoc2 = new XmlDocument();
// xmlDoc2.LoadXml(cfg2);
//xmlDoc2.Save(savePath2);
}
catch (Exception ex)
{
LogAPI.Debug("配置文件保存失败:" + ex);
}
}
public void SaveConfig( List<MakeTaskPackageModel> exportDataList, bool isCustom, string exportFolder, List<string> selectedXzq)
{
try
{
LayerConfig cfg_JZRW = new LayerConfig();
LayerConfig cfg_OneMap = new LayerConfig();
string m_outPath = string.Empty;
string savePath = string.Empty;//System.IO.Path.Combine(dirPath, item.OutPath);
string tempName = string.Empty;
string cfgFileName = string.Empty;
List<string> jzrwNameList = new List<string>();
List<MakeTaskPackageModel> jzrwModelList = exportDataList.FindAll(x => !x.Type.Contains("图层组"));
if (jzrwModelList != null)
{
foreach (var item in jzrwModelList)
{
if (!jzrwNameList.Contains(item.Type))
jzrwNameList.Add(item.Type);
}
if (jzrwNameList.Count != 0)
{
for (int i = 0; i < jzrwNameList.Count; i++)
{
string name = jzrwNameList[i];
List<MakeTaskPackageModel> modelList = exportDataList.FindAll(x => x.Type == name);
if (modelList != null)
{
foreach (var item in modelList)
{
if (!item.IsCheck) continue;
Model.LayerInfo layerInfo = new Model.LayerInfo();
layerInfo.IsSurvey = false;
layerInfo.IsVisible = true;
layerInfo.GroupIndex = item.MapGroupIndex;
layerInfo.GroupName = item.MapGroupName;
if ((item.Type == "矢量" || item.Type == "举证任务")&& item.Layer is IFeatureLayer)
{
layerInfo.TableName = "KOFDT";
}
else
{
layerInfo.TableName = "";
}
//layerInfo.TableName = item.Type == "矢量" ? "KOFDT" : "";
//if (item.FileAliasName.Contains("_"))
//{
// layerInfo.LayerName = item.FileAliasName.Substring(0, item.FileAliasName.IndexOf("_"));
//}
//else
//{
layerInfo.LayerName = item.FileAliasName;
// }
if ((item.Type == "矢量" || item.Type == "举证任务") && item.Layer is IFeatureLayer)
{
layerInfo.LayerType = "local_feature";
}
else
{
layerInfo.LayerType = "kotile";
}
//layerInfo.LayerType = item.Type == "矢量" ? "local_feature" : "kotile";
layerInfo.LayerIndex = item.LayerIndex;
layerInfo.LayerUrl = item.OutFilePath;
if (!string.IsNullOrWhiteSpace(layerInfo.LayerUrl))
layerInfo.LayerUrl = layerInfo.LayerUrl.Replace(@"\", "/");
layerInfo.queryUrl = layerInfo.LayerUrl;
layerInfo.queryTableName = "KOFDT";
if ((item.Type == "举证任务") && item.Layer is IFeatureLayer)//&& item.MapGroupName == "监测数据"
{
layerInfo.IsSurvey = true;
layerInfo.queryTableName = "KOFDT";
layerInfo.SFJZ = "";
layerInfo.PrimaryKey = "JCBH";
layerInfo.HeaderField = "JCBH";
layerInfo.SecondField = "";
}
//if (item.FileName.Contains("_"))
//{
// layerInfo.LayerDbName = item.FileName.Substring(0, item.FileName.IndexOf("_"));
//}
//else
//{
layerInfo.LayerDbName = item.FileName;
// }
SaveLayerStyleConfing(item, layerInfo);
cfg_JZRW.layers.LayerInfo.Add(layerInfo);
if (!string.IsNullOrWhiteSpace(item.CfgFileName))
{
cfgFileName = item.CfgFileName;
}
if (!string.IsNullOrWhiteSpace(item.TaskName))
{
tempName = item.TaskName;
}
if (string.IsNullOrWhiteSpace(m_outPath))
{
m_outPath = item.OutPath;
}
savePath = System.IO.Path.Combine(exportFolder, item.OutPath);
}
}
}
if (isCustom)
{
if (!Directory.Exists(savePath))
Directory.CreateDirectory(savePath);
for (int i = 0; i < selectedXzq.Count; i++)
{
if (!string.IsNullOrWhiteSpace(m_outPath))
{
foreach (var item in cfg_JZRW.layers.LayerInfo)
{
if (item.LayerType.ToLower() == "local_feature")
{
item.LayerUrl = System.IO.Path.Combine(m_outPath, selectedXzq[i], "Source", item.LayerDbName + ".ko");
}
else if (item.LayerType.ToLower() == "kotile")
{
item.LayerUrl = System.IO.Path.Combine(m_outPath, selectedXzq[i], "Source", item.LayerDbName + ".kotiles");
}
item.LayerUrl = item.LayerUrl.Replace(@"\", "/");
item.queryUrl = item.LayerUrl;
}
}
string cfg = cfg_JZRW.ToXML();
string newSavePath = System.IO.Path.Combine(savePath, selectedXzq[i], cfgFileName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(cfg);
xmlDoc.Save(newSavePath);
}
}
else
{
string cfg = cfg_JZRW.ToXML();
if (string.IsNullOrWhiteSpace(tempName))
tempName = "Data";
string wyjzPath = System.IO.Path.Combine(savePath, tempName);
if (!Directory.Exists(wyjzPath))
Directory.CreateDirectory(wyjzPath);
string newSavePath = System.IO.Path.Combine(wyjzPath, cfgFileName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(cfg);
xmlDoc.Save(newSavePath);
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("配置文件保存失败:" + ex);
}
}
private void SaveLayerStyleConfing(MakeTaskPackageModel item,LayerInfo layerInfo)
{
try
{
if (item.Layer is IFeatureLayer)
{
IFillSymbol fillSymbol = getLayerFillSymbol(item.Layer as ILayer);
if (fillSymbol != null)
{
System.Drawing.Color fillColor = Converter.FromRGBColor(fillSymbol.Color as IRgbColor);
System.Drawing.Color borderColor = Converter.FromRGBColor(fillSymbol.Outline.Color as IRgbColor);
layerInfo.layerBorderColor = System.Windows.Media.Color.FromArgb(borderColor.A, borderColor.R, borderColor.G, borderColor.B).ToString();
layerInfo.layerFillColor = System.Windows.Media.Color.FromArgb(fillColor.A, fillColor.R, fillColor.G, fillColor.B).ToString();
if (fillSymbol.Outline is ISimpleLineSymbol)
{
ISimpleLineSymbol esriSymbol = fillSymbol.Outline as ISimpleLineSymbol;
if (esriSymbol != null)
{
layerInfo.LayerBorderStyle = (int)esriSymbol.Style;
layerInfo.layerBorderWidth = esriSymbol.Width;
}
}
}
IGeoFeatureLayer geolayer = item.Layer as IGeoFeatureLayer;
if (geolayer != null)
{
IElementCollection ec;
IAnnotateLayerProperties pAnnoLayerProps;
geolayer.AnnotationProperties.QueryItem(0, out pAnnoLayerProps, out ec, out ec);
ILabelEngineLayerProperties pLabelEngineLayerProps = (ILabelEngineLayerProperties)pAnnoLayerProps;
if (pLabelEngineLayerProps != null && geolayer.DisplayAnnotation)
{
if (!string.IsNullOrWhiteSpace(pLabelEngineLayerProps.Expression))
{
layerInfo.layerLabelName = pLabelEngineLayerProps.Expression.Substring(1, pLabelEngineLayerProps.Expression.Length - 2);
}
System.Drawing.Color lableColor = Converter.FromRGBColor(pLabelEngineLayerProps.Symbol.Color as IRgbColor);
layerInfo.LayerLableColor = System.Windows.Media.Color.FromArgb(lableColor.A, lableColor.R, lableColor.G, lableColor.B).ToString();
}
else
{
layerInfo.layerLabelName = "";
layerInfo.LayerLableColor = "#FF000000";
}
}
//if (item.Type.Contains("举证任务"))
if (layerInfo.IsSurvey)
{
IFeatureLayer layer = item.Layer as IFeatureLayer;
IFields fields = layer.FeatureClass.Fields;
int pIndex = fields.FindField("JCBH");
if (pIndex != -1)
{
layerInfo.PrimaryKey = "JCBH";
layerInfo.HeaderField = "JCBH";
}
else if (pIndex != -1)
{
layerInfo.PrimaryKey = "DKBH";
layerInfo.HeaderField = "DKBH";
}
else if (pIndex != -1)
{
layerInfo.PrimaryKey = "XMBH";
layerInfo.HeaderField = "XMBH";
}
else
{
pIndex = fields.FindField("TBBH");
if (pIndex != -1)
{
layerInfo.PrimaryKey = "TBBH";
layerInfo.HeaderField = "TBBH";
}
}
for (int i = 0; i < fields.FieldCount; i++)
{
IField field = fields.Field[i];
string fieldName = field.Name;
if (field.Name.ToUpper() == "SHAPE")
{
fieldName = "Shape";
continue;
}
layerInfo.LayerFields.Add(new Model.FieldInfo()
{
Name = fieldName,
Alias = field.AliasName,
Index = i
});
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug("保存图层样式设置失败:" + ex);
}
}
private IFillSymbol getLayerFillSymbol(ILayer pLayer)
{
IFillSymbol fillSymbol = null;
try
{
IStyleGalleryClass symbologyStyleClass = null;
ISymbol symbol = null;
IFeatureLayer2 featureLayer = pLayer as IFeatureLayer2;
if (featureLayer != null)
{
esriGeometryType geometryType = featureLayer.ShapeType;
switch (geometryType)
{
case esriGeometryType.esriGeometryPoint:
symbologyStyleClass = new MarkerSymbolStyleGalleryClassClass();
break;
case esriGeometryType.esriGeometryPolyline:
symbologyStyleClass = new LineSymbolStyleGalleryClassClass();
break;
case esriGeometryType.esriGeometryPolygon:
symbologyStyleClass = new FillSymbolStyleGalleryClassClass();
break;
}
ISimpleRenderer simpleRenderer = (featureLayer as IGeoFeatureLayer).Renderer as ISimpleRenderer;
if (simpleRenderer != null)
{
symbol = simpleRenderer.Symbol;
}
else
{
symbol = GetDefaultSymbol(geometryType);
}
fillSymbol = (symbol as IFillSymbol);
}
return fillSymbol;
}
catch (Exception ex)
{
LogAPI.Debug("保存图层样式配置失败:" + ex);
return fillSymbol;
}
}
private ISymbol GetDefaultSymbol(esriGeometryType geometryType)
{
try
{
ISymbol result = null;
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = 184;
rgbColor.Green = 242;
rgbColor.Blue = 200;
switch (geometryType)
{
case esriGeometryType.esriGeometryPoint:
result = (new SimpleMarkerSymbolClass
{
Color = rgbColor,
Style = esriSimpleMarkerStyle.esriSMSCircle
} as ISymbol);
goto IL_B3;
case esriGeometryType.esriGeometryMultipoint:
goto IL_B3;
case esriGeometryType.esriGeometryPolyline:
break;
case esriGeometryType.esriGeometryPolygon:
result = (new SimpleFillSymbolClass
{
Color = rgbColor,
Style = esriSimpleFillStyle.esriSFSSolid
} as ISymbol);
goto IL_B3;
default:
if (geometryType != esriGeometryType.esriGeometryLine)
{
goto IL_B3;
}
break;
}
result = (new SimpleLineSymbolClass
{
Color = rgbColor,
Width = 1.0,
Style = esriSimpleLineStyle.esriSLSSolid
} as ISymbol);
IL_B3:
return result;
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
return null;
}
}
}