|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using ESRI.ArcGIS.DataSourcesFile;
|
|
|
|
|
using ESRI.ArcGIS.DataSourcesGDB;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Kingo.Plugin.MakeTaskPackage.Entity;
|
|
|
|
|
//using Kingo.Mobile.Shape2KOTool.XSDClass;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.MakeTaskPackage.Common
|
|
|
|
|
{
|
|
|
|
|
public class LayerComm
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置分组显示
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="map"></param>
|
|
|
|
|
/// <param name="groupName"></param>
|
|
|
|
|
/// <param name="isVisble"></param>
|
|
|
|
|
public void SetLayerGroupVisble(IMap map, string groupName, bool isVisble)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < map.LayerCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (map.get_Layer(i) is IGroupLayer)
|
|
|
|
|
{
|
|
|
|
|
if ((map.get_Layer(i) as ILayerGeneralProperties).LayerDescription == groupName)
|
|
|
|
|
{
|
|
|
|
|
map.get_Layer(i).Visible = isVisble;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 判断是否存在分组
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="map"></param>
|
|
|
|
|
/// <param name="groupName"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public ILayer ExistLayerGroupByName(IMap map, string groupName)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ILayer layer = null;
|
|
|
|
|
for (int i = 0; i < map.LayerCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (map.get_Layer(i) is IGroupLayer)
|
|
|
|
|
{
|
|
|
|
|
if (map.get_Layer(i).Name == groupName)
|
|
|
|
|
{
|
|
|
|
|
layer = map.get_Layer(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return layer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 找到顶层节点
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tn"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private TreeNode FindTopNode(TreeNode tn)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
return tn;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FindTopNode(tn.Parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 属性信息转换
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<Kingo.Mobile.Shape2KOTool.XSDClass.Field> GetListField(ILayerFields fields)
|
|
|
|
|
{
|
|
|
|
|
List<Kingo.Mobile.Shape2KOTool.XSDClass.Field> lstRst = new List<Mobile.Shape2KOTool.XSDClass.Field>();
|
|
|
|
|
|
|
|
|
|
IAttributeTable attrTable = fields as IAttributeTable;
|
|
|
|
|
for (int i = 0; i < attrTable.AttributeTable.Fields.FieldCount; i++)
|
|
|
|
|
{
|
|
|
|
|
IField field = attrTable.AttributeTable.Fields.get_Field(i);
|
|
|
|
|
int index = fields.FindField(field.Name);
|
|
|
|
|
IFieldInfo fieldInfo = fields.get_FieldInfo(index);
|
|
|
|
|
if (!fieldInfo.Visible)
|
|
|
|
|
continue;
|
|
|
|
|
if (field.Name.ToUpper() == "SHAPE") continue;
|
|
|
|
|
lstRst.Add(new Kingo.Mobile.Shape2KOTool.XSDClass.FieldNomal()
|
|
|
|
|
{
|
|
|
|
|
Alias = fieldInfo.Alias,
|
|
|
|
|
Name = field.Name
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return lstRst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Kingo.Mobile.Shape2KOTool.XSDClass.ItemInfo FeatureLayerToEntity(IFeatureLayer Layer)
|
|
|
|
|
{
|
|
|
|
|
Mobile.Shape2KOTool.XSDClass.ItemInfo result = new Mobile.Shape2KOTool.XSDClass.ItemInfo();
|
|
|
|
|
//if (selectLayerEntity == null)
|
|
|
|
|
// selectLayerEntity = new Kingo.Mobile.Common.Entity.LayerEntity();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ESRI.ArcGIS.Carto.FeatureLayerClass layerFeatureClass = Layer as ESRI.ArcGIS.Carto.FeatureLayerClass;
|
|
|
|
|
//selectLayerEntity.LayerName = Layer.Name;
|
|
|
|
|
//selectLayerEntity.LayerCaption = (Layer as ILayerGeneralProperties).LayerDescription;
|
|
|
|
|
//selectLayerEntity.LayerVisible = Layer.Visible;
|
|
|
|
|
//selectLayerEntity.LayerSource = (Layer as IDataset).Workspace.PathName + "\\" + (Layer as IDataset).BrowseName;
|
|
|
|
|
|
|
|
|
|
LabelStyleConvert styleConvert = new LabelStyleConvert();
|
|
|
|
|
result.DrawingInfo.LabelingInfo = styleConvert.EsriLabelToCustomLabels((Layer as IGeoFeatureLayer).AnnotationProperties);
|
|
|
|
|
result.DisplayField = Layer.DisplayField;
|
|
|
|
|
IGeoDataset geoLayer = Layer as IGeoDataset;
|
|
|
|
|
result.Extent = new Mobile.Shape2KOTool.XSDClass.Extent()
|
|
|
|
|
{
|
|
|
|
|
SpatialReference = new Mobile.Shape2KOTool.XSDClass.SpatialReference()
|
|
|
|
|
{
|
|
|
|
|
LatestWkid = geoLayer.SpatialReference.FactoryCode,
|
|
|
|
|
Wkid = geoLayer.SpatialReference.FactoryCode
|
|
|
|
|
},
|
|
|
|
|
Xmax = geoLayer.Extent.XMax,
|
|
|
|
|
Xmin = geoLayer.Extent.XMin,
|
|
|
|
|
Ymax = geoLayer.Extent.YMax,
|
|
|
|
|
Ymin = geoLayer.Extent.YMin
|
|
|
|
|
};
|
|
|
|
|
result.Fields = GetListField(Layer as ILayerFields);
|
|
|
|
|
result.GeometryType = (Kingo.Mobile.Shape2KOTool.XSDClass.esriGeometryType)((int)geoLayer.Extent.GeometryType);
|
|
|
|
|
result.MaxScale = (int)Layer.MaximumScale;
|
|
|
|
|
result.MinScale = (int)Layer.MinimumScale;
|
|
|
|
|
result.Name = Layer.Name;
|
|
|
|
|
//selectLayerEntity.LayerWhere = (Layer as IFeatureLayerDefinition).DefinitionExpression;
|
|
|
|
|
result.DrawingInfo.Transparency = (Layer as ILayerEffects).Transparency;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 打开ShapeFile数据源
|
|
|
|
|
public IDatasetName GetShapeFileDatasetName(string FileFullPath)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IEnumDatasetName name = this.OpenShapeFileWorkSpace(System.IO.Path.GetDirectoryName(FileFullPath)).get_DatasetNames(esriDatasetType.esriDTFeatureClass);
|
|
|
|
|
for (IDatasetName name2 = name.Next(); name2 != null; name2 = name.Next())
|
|
|
|
|
{
|
|
|
|
|
if (name2.Name.ToUpper() == System.IO.Path.GetFileNameWithoutExtension(FileFullPath).ToUpper())
|
|
|
|
|
{
|
|
|
|
|
return name2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
throw exception;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWorkspace OpenShapeFileWorkSpace(string filePath)
|
|
|
|
|
{
|
|
|
|
|
IWorkspaceFactory factory = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
factory = null;
|
|
|
|
|
factory = new ShapefileWorkspaceFactoryClass();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
throw exception;
|
|
|
|
|
}
|
|
|
|
|
return factory.OpenFromFile(filePath, 0);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 打开mdb数据源
|
|
|
|
|
public IWorkspace OpenMDBWorkspace(string PersonalDBFile)
|
|
|
|
|
{
|
|
|
|
|
IWorkspaceFactory factory = null;
|
|
|
|
|
IWorkspace workspace = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
factory = null;
|
|
|
|
|
factory = new AccessWorkspaceFactoryClass();
|
|
|
|
|
workspace = factory.OpenFromFile(PersonalDBFile, 0);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
{
|
|
|
|
|
throw exception;
|
|
|
|
|
}
|
|
|
|
|
return workspace;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFeatureClass GetFeatureClass(IWorkspace pWorkspace, string FeaClsName)
|
|
|
|
|
{
|
|
|
|
|
IFeatureWorkspace workspace = (IFeatureWorkspace)pWorkspace;
|
|
|
|
|
return workspace.OpenFeatureClass(FeaClsName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IFeatureClass GetFeatureClass(string PersonalDBFile, string FeaClsName)
|
|
|
|
|
{
|
|
|
|
|
PersonalDBFile = PersonalDBFile.Substring(0, PersonalDBFile.LastIndexOf("\\"));
|
|
|
|
|
return GetFeatureClass(OpenMDBWorkspace(PersonalDBFile), FeaClsName);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 处理信息的方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 找最顶层的节点名字
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tn"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private object FindTopParentName(TreeNode tn)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Parent == null)
|
|
|
|
|
return tn.Text;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FindTopParentName(tn.Parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//设置子节点状态
|
|
|
|
|
private void SetChildNodeCheckedState(TreeNode currNode, bool isCheckedOrNot)
|
|
|
|
|
{
|
|
|
|
|
if (currNode.Nodes == null) return; //没有子节点返回
|
|
|
|
|
foreach (TreeNode tmpNode in currNode.Nodes)
|
|
|
|
|
{
|
|
|
|
|
tmpNode.Checked = isCheckedOrNot;
|
|
|
|
|
SetChildNodeCheckedState(tmpNode, isCheckedOrNot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//设置父节点状态
|
|
|
|
|
private void SetParentNodeCheckedState(TreeNode currNode, bool isCheckedOrNot)
|
|
|
|
|
{
|
|
|
|
|
if (currNode.Parent == null) return; //没有父节点返回
|
|
|
|
|
if (isCheckedOrNot) //如果当前节点被选中,则设置所有父节点都被选中
|
|
|
|
|
{
|
|
|
|
|
currNode.Parent.Checked = isCheckedOrNot;
|
|
|
|
|
SetParentNodeCheckedState(currNode.Parent, isCheckedOrNot);
|
|
|
|
|
}
|
|
|
|
|
else //如果当前节点没有被选中,则当其父节点的子节点有一个被选中时,父节点被选中,否则父节点不被选中
|
|
|
|
|
{
|
|
|
|
|
bool checkedFlag = false;
|
|
|
|
|
foreach (TreeNode tmpNode in currNode.Parent.Nodes)
|
|
|
|
|
{
|
|
|
|
|
if (tmpNode.Checked)
|
|
|
|
|
{
|
|
|
|
|
checkedFlag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
currNode.Parent.Checked = checkedFlag;
|
|
|
|
|
SetParentNodeCheckedState(currNode.Parent, checkedFlag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|