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.
183 lines
7.3 KiB
183 lines
7.3 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using System; |
|
using System.Data; |
|
using System.Runtime.InteropServices; |
|
|
|
namespace Kingo.PluginServiceInterface.Helper |
|
{ |
|
/// <summary> |
|
/// AE开发公共类 |
|
/// </summary> |
|
public static class AECommonHelper |
|
{ |
|
public static DataTable GetTableByFeatureClass(IFeatureClass featureClass, IQueryFilter queryFilter = null) |
|
{ |
|
DataTable dataTable = new DataTable(); |
|
ITable tableTemp = featureClass as ITable; |
|
int fieldCount = tableTemp.Fields.FieldCount; |
|
try |
|
{ |
|
for (int i = 0; i < fieldCount; i++) |
|
{ |
|
IField field = tableTemp.Fields.Field[i]; |
|
dataTable.Columns.Add(field.Name, GetSystemType(field.Type)); |
|
} |
|
ICursor cursor = tableTemp.Search(queryFilter, true); |
|
IRow row = null; |
|
while ((row = cursor.NextRow()) != null) |
|
{ |
|
DataRow dataRow = dataTable.NewRow(); |
|
for (int i = 0; i < fieldCount; i++) |
|
{ |
|
object value = row.Value[i]; |
|
dataRow[i] = value; |
|
} |
|
dataTable.Rows.Add(dataRow); |
|
} |
|
if (cursor != null) |
|
Marshal.ReleaseComObject(cursor); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("GetTableByFeatureClass异常:" + ex.Message); |
|
LogAPI.Debug("GetTableByFeatureClass异常:" + ex.StackTrace); |
|
} |
|
return dataTable; |
|
} |
|
|
|
private static Type GetSystemType(esriFieldType fieldType) |
|
{ |
|
switch (fieldType) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
case esriFieldType.esriFieldTypeInteger: |
|
return typeof(int); |
|
case esriFieldType.esriFieldTypeSingle: |
|
return typeof(float); |
|
case esriFieldType.esriFieldTypeDouble: |
|
return typeof(double); |
|
case esriFieldType.esriFieldTypeDate: |
|
return typeof(DateTime); |
|
default: |
|
return typeof(string); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 获取图层的容差 |
|
/// </summary> |
|
/// <param name="layer">要输入的图层</param> |
|
/// <returns></returns> |
|
public static double GetLayerTolerance(IFeatureClass layerFC) |
|
{ |
|
try |
|
{ |
|
if (layerFC != null) |
|
{ |
|
IGeoDataset geoDataset = layerFC as IGeoDataset; |
|
ISpatialReferenceTolerance spatialReferenceTolerance = geoDataset.SpatialReference as ISpatialReferenceTolerance; |
|
return spatialReferenceTolerance.XYTolerance; |
|
} |
|
return -1; |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowTips("获取图层的容差失败:" + ex.Message); |
|
return -1; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 设置数据库容差 |
|
/// </summary> |
|
/// <param name="pWS"></param> |
|
/// <param name="pSR"></param> |
|
/// <param name="pTolerance"></param> |
|
public static void SetGeoDatasetSpatialReference(IWorkspace pWS, ISpatialReference pSR, double pTolerance) |
|
{ |
|
try |
|
{ |
|
//KGIS.Framework.AE.GeoDBAPI.SetGeoDatasetSpatialReference(pWS, pSR, pTolerance); |
|
if (pSR != null) |
|
{ |
|
ISpatialReferenceResolution toleranceResolution = pSR as ISpatialReferenceResolution; |
|
//toleranceResolution.ConstructFromHorizon(); |
|
//toleranceResolution.SetDefaultXYResolution(); |
|
toleranceResolution.set_XYResolution(true, 0.00005); |
|
if (pSR is ISpatialReferenceTolerance tolerance) |
|
{ |
|
tolerance.XYTolerance = pTolerance; |
|
tolerance.ZTolerance = pTolerance; |
|
tolerance.MTolerance = pTolerance; |
|
} |
|
} |
|
IEnumDataset pEnumDataset = pWS.Datasets[esriDatasetType.esriDTFeatureDataset]; |
|
IDataset ds = null; |
|
if (pEnumDataset != null) |
|
{ |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
} |
|
|
|
} |
|
} |
|
pEnumDataset = pWS.Datasets[ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass]; |
|
if (pEnumDataset == null) |
|
{ |
|
return; |
|
} |
|
while ((ds = pEnumDataset.Next()) != null) |
|
{ |
|
if (ds is IGeoDataset) |
|
{ |
|
if ((ds as IGeoDataset).SpatialReference != pSR) |
|
(ds as IGeoDatasetSchemaEdit).AlterSpatialReference(pSR); |
|
} |
|
} |
|
try |
|
{ |
|
pWS.ExecuteSQL(string.Format("UPDATE GDB_SpatialRefs SET XYUnits = 20000 ,XYTolerance = {0}", pTolerance)); |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("设置坐标参考坐标精度和容差异常:" + ex.Message); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
throw new Exception("设置坐标参考坐标精度和容差异常:" + ex.Message); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 开启图层编辑 |
|
/// </summary> |
|
/// <param name="StartEngineEditor"></param> |
|
/// <param name="StartEditFeatureLayer"></param> |
|
private static void StartEditForFeatureLayer(IEngineEditor StartEngineEditor, IFeatureLayer StartEditFeatureLayer) |
|
{ |
|
if (StartEngineEditor == null) |
|
StartEngineEditor = new EngineEditorClass(); |
|
if (StartEditFeatureLayer == null) |
|
return; |
|
IEngineEditLayers pEditLayer = StartEngineEditor as IEngineEditLayers; |
|
if (pEditLayer.TargetLayer != null && pEditLayer.TargetLayer.Equals(StartEditFeatureLayer)) |
|
return;//前后编辑的图层相同则不再重复开启编辑 |
|
else if ((pEditLayer.TargetLayer != null && !pEditLayer.TargetLayer.Equals(StartEditFeatureLayer)) || StartEngineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) |
|
StartEngineEditor.StopEditing(true);//切换编辑时,保存停止; |
|
StartEngineEditor.StartEditing((StartEditFeatureLayer.FeatureClass as FeatureClass).Workspace, MapsManager.Instance.MapService.getAxMapControl().Map); |
|
pEditLayer.SetTargetLayer(StartEditFeatureLayer, 0); |
|
} |
|
|
|
} |
|
}
|
|
|