class RangeManager
{
#region 类成员变量
public bool oprFlag
= false;
static private string pFilePath
= null;
static private string rangeName
= null;
static private string listName
= "";
static private AxMapControl MapControl
= null;
static private List
<string> List_village
= new List<string>();
#endregion
#region 类构造方法
public static Response OpenFile(AxMapControl mapControl
)
{
MapControl
= mapControl
;
OpenFileDialog openFileDialog
= new OpenFileDialog();
openFileDialog
.Title
= "打开文件";
openFileDialog
.Filter
= "shp文件(*.shp)|*.shp";
openFileDialog
.Multiselect
= true;
openFileDialog
.InitialDirectory
= Configuration
.Environment
.WorkPath
;
if (openFileDialog
.ShowDialog() == DialogResult
.OK
)
{
string path
= "";
IWorkspaceFactory pWorkspaceFactory
= new ShapefileWorkspaceFactory();
for (int i
= 0; i
< openFileDialog
.FileNames
.Length
; i
++)
{
path
= openFileDialog
.FileNames
.GetValue(i
).ToString();
pFilePath
= System
.IO
.Path
.GetDirectoryName(path
);
string pFileName
= System
.IO
.Path
.GetFileName(path
);
IFeatureWorkspace pFeaWorkspace
= pWorkspaceFactory
.OpenFromFile(pFilePath
, 0) as IFeatureWorkspace
;
IFeatureClass pFeatureClass
= pFeaWorkspace
.OpenFeatureClass(pFileName
);
AddLayerToMap(pFeatureClass
);
}
return new Response(Constant
.Success
, "");
}
return new Response(Constant
.Nothing
, "");
}
public static Response DrawRange()
{
ILayer pLayer
= GetLayerByName(MapControl
, Constant
.Range_DLTB
);
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
if (pFeatureClass
!= null)
{
MainForm frmMain
= new MainForm();
BarButtonItem btiDrawBoundary
= frmMain
.btiDrawBoundary
;
if (btiDrawBoundary
.Caption
== "绘范围线")
{
btiDrawBoundary
.Caption
= "停止绘线";
oprFlag
= true;
}
else
{
btiDrawBoundary
.Caption
= "绘范围线";
oprFlag
= false;
}
MapControl
.MousePointer
= esriControlsMousePointer
.esriPointerCrosshair
;
}
else
{
MessageBox
.Show("未发现可编辑图层!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
public static Response CreateDrawPolygon()
{
MapControl
.CurrentTool
= null;
IGeometry pGeometry
= MapControl
.TrackLine();
AddFeature("DLTB", pGeometry
);
return new Response(Constant
.Success
, "");
}
private void AddFeature(string layerName
, IGeometry pGeometry
)
{
ILayer pLayer
= MapControl
.get_Layer(0);
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
if (pFeatureLayer
!= null)
{
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
IWorkspaceEdit pWorkspaceEdit
= (pFeatureClass
as IDataset
).Workspace as IWorkspaceEdit
;
IFeature pFeature
;
pWorkspaceEdit
.StartEditing(false);
pWorkspaceEdit
.StartEditOperation();
IFeatureBuffer pFeatureBuffer
= pFeatureClass
.CreateFeatureBuffer();
IFeatureCursor pFtCursor
;
pFtCursor
= pFeatureClass
.Search(null, true);
pFeature
= pFtCursor
.NextFeature();
pFtCursor
= pFeatureClass
.Insert(true);
try
{
pFeatureBuffer
.Shape
= pGeometry
;
}
catch (COMException ex
)
{
MessageBox
.Show("绘制的几何图形超出了边界!");
return;
}
object featureOID
= pFtCursor
.InsertFeature(pFeatureBuffer
);
pFtCursor
.Flush();
pWorkspaceEdit
.StopEditOperation();
pWorkspaceEdit
.StopEditing(true);
Marshal
.ReleaseComObject(pFtCursor
);
MapControl
.ActiveView
.PartialRefresh(esriViewDrawPhase
.esriViewGeography
, pLayer
, null);
oprFlag
= false;
}
else
{
MessageBox
.Show("未发现" + layerName
+ "图层");
}
}
public static Response LocationRange()
{
if(MapControl
!= null)
{
ILayer pLayer
= GetLayerByName(Constant
.Range_DLTB
);
if (pLayer
!= null)
{
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
int Judge
= 0;
IFields pFields
= pFeatureClass
.Fields
;
for (int i
= 0; i
< pFields
.FieldCount
; i
++)
{
IField ifield
= pFields
.get_Field(i
);
if (ifield
.Name
== Constant
.Range_Shp_Field
)
{
Judge
= 1;
List
<string> List
= new List<string>();
IFeatureCursor pFeaCursor
= pFeatureClass
.Search(null, true);
IFeature pFeature
= pFeaCursor
.NextFeature();
while (pFeature
!= null)
{
string fieldValue
= pFeature
.get_Value(i
).ToString();
List
.Add(fieldValue
);
pFeature
= pFeaCursor
.NextFeature();
}
List
= List
.Distinct().ToList();
SelectRange selectRange
= new SelectRange(List
);
selectRange
.ShowDialog();
}
}
if (Judge
== 0)
{
MessageBox
.Show("未找到村落名称字段,请重新加载地图!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加DLTB!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载数据!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
public static Response drawLocationRange(List
<string> List
)
{
listName
= null;
rangeName
= null;
List_village
.Clear();
ProcessBar processBar
= new ProcessBar();
ILayer pLayer
= GetLayerByName(Constant
.Range_DLTB
);
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
IFeatureSelection pFeatureSelection
= pFeatureLayer
as IFeatureSelection
;
IQueryFilter queryFilter
= new QueryFilterClass();
for (int i
= 0; i
< List
.Count
; i
++)
{
queryFilter
.WhereClause
= Constant
.Range_Shp_Field
+ Constant
.File_Ext_equal
+ "'" + List
[i
] + "'";
pFeatureSelection
.SelectFeatures(queryFilter
, esriSelectionResultEnum
.esriSelectionResultAdd
, false);
listName
+= Constant
.File_Ext_Char1
+ List
[i
];
List_village
.Add(List
[i
]);
}
rangeName
= Constant
.Project_File_Range
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
;
string pPath
= pFilePath
+ Constant
.File_Ext_Char2
;
IWorkspaceFactory pWorkspaceFactory
= new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeaWorkspace
= pWorkspaceFactory
.OpenFromFile(pFilePath
, 0) as IFeatureWorkspace
;
if (System
.IO
.File
.Exists(pPath
+ rangeName
))
{
if (MessageBox
.Show("文件已存在,是否覆盖?", "提示", MessageBoxButtons
.YesNo
, MessageBoxIcon
.Asterisk
) == DialogResult
.Yes
)
{
IFeatureClass pFCChecker
= pFeaWorkspace
.OpenFeatureClass(rangeName
);
if (pFCChecker
!= null)
{
IDataset pds
= pFCChecker
as IDataset
;
pds
.Delete();
}
}
else
{
MapControl
.Map
.ClearSelection();
return new Response(Constant
.Nothing
, "");
}
}
processBar
.Show();
processBar
.Update();
Geoprocessor GP_Tool
= new Geoprocessor();
ESRI.ArcGIS.DataManagementTools.Dissolve GP_Dissolve
= new Dissolve();
GP_Dissolve
.in_features
= pFeatureSelection
as FeatureClass
;
GP_Dissolve
.out_feature_class
= pPath
+ rangeName
;
try
{
GP_Tool
.Execute(GP_Dissolve
, null);
}
catch (Exception ex
)
{
MessageBox
.Show(ex
.Message
, "GP Error");
System.Text.StringBuilder sb
= new System.Text.StringBuilder();
for (int i
= 0; i
< GP_Tool
.MessageCount
; i
++)
sb
.AppendLine(GP_Tool
.GetMessage(i
));
if (sb
.Capacity
> 0) MessageBox
.Show(sb
.ToString(), "GP Messages");
}
MapControl
.Map
.ClearSelection();
IFeatureClass lFeatureClass
= pFeaWorkspace
.OpenFeatureClass(rangeName
);
processBar
.Close();
AddLayerToMap(lFeatureClass
);
return new Response(Constant
.Success
, "");
}
public static Response CreateFrame()
{
CreateEnvelope(pFilePath
, rangeName
, 1000, 1000);
return new Response(Constant
.Success
, "");
}
public static Response CreateEnvelope(String pFilePath
, String rangeName
, double x
, double y
)
{
if (pFilePath
!= null)
{
if (rangeName
!= null)
{
IWorkspaceFactory pWorkspaceFactory
= new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeaWorkspace
= pWorkspaceFactory
.OpenFromFile(pFilePath
, 0) as IFeatureWorkspace
;
IFeatureClass lFeatureClass
= pFeaWorkspace
.OpenFeatureClass(rangeName
);
if (System
.IO
.File
.Exists(pFilePath
+ Constant
.File_Ext_Char2
+ Constant
.Project_File_Envelope
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
))
{
if (MessageBox
.Show("文件已存在,是否覆盖?", "提示", MessageBoxButtons
.YesNo
, MessageBoxIcon
.Asterisk
) == DialogResult
.Yes
)
{
IFeatureClass pFCChecker
= pFeaWorkspace
.OpenFeatureClass(Constant
.Project_File_Envelope
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
);
if (pFCChecker
!= null)
{
IDataset pds
= pFCChecker
as IDataset
;
pds
.Delete();
}
}
else
{
return new Response(Constant
.Nothing
, "");
}
}
ProcessBar processBar
= new ProcessBar();
processBar
.Show();
processBar
.Update();
IFeature pFeature
= lFeatureClass
.GetFeature(0);
IPolygon pPolygon
= pFeature
.ShapeCopy as IPolygon
;
IEnvelope envelope
= pPolygon
.Envelope
;
envelope
.Expand(x
, y
, false);
IPolygon pPolygon_E
= EnvelopeToPolygon(envelope
);
IGeometry pGeometry
= pPolygon_E
;
ITopologicalOperator2 pTopoOperator
= pGeometry
as ITopologicalOperator2
;
pTopoOperator
.IsKnownSimple_2
= false;
pTopoOperator
.Simplify();
IFields pFields
= lFeatureClass
.Fields
;
IFeatureClass eFeatureClass
= pFeaWorkspace
.CreateFeatureClass(Constant
.Project_File_Envelope
+ listName
, pFields
, null, null, esriFeatureType
.esriFTSimple
, "SHAPE", null);
IFeature pFeature1
= eFeatureClass
.CreateFeature();
pFeature1
.Shape
= pGeometry
;
pFeature1
.Store();
processBar
.Close();
AddLayerToMap(eFeatureClass
);
}
else
{
MessageBox
.Show("请先绘制范围线!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载数据!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
public static Response DataProcessor()
{
if (pFilePath
!= null)
{
IWorkspaceFactory pWorkspaceFactory
= new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeaWorkspace
= pWorkspaceFactory
.OpenFromFile(pFilePath
, 0) as IFeatureWorkspace
;
ILayer pLayer
= GetLayerByName(Constant
.Range_DLTB
);
if (pLayer
!= null)
{
string pPath
= pFilePath
+ Constant
.File_Ext_Char2
;
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
if (rangeName
!= null)
{
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
IFeatureClass lFeatureClass
= pFeaWorkspace
.OpenFeatureClass(rangeName
);
if (System
.IO
.File
.Exists(pPath
+ Constant
.Project_File_Envelope
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
))
{
IFeatureClass eFeatureClass
= pFeaWorkspace
.OpenFeatureClass(Constant
.Project_File_Envelope
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
);
if (System
.IO
.File
.Exists(pPath
+ pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
))
{
if (MessageBox
.Show("文件已存在,是否覆盖?", "提示", MessageBoxButtons
.YesNo
, MessageBoxIcon
.Asterisk
) == DialogResult
.Yes
)
{
IFeatureClass pFCChecker
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
);
if (pFCChecker
!= null)
{
IDataset pds
= pFCChecker
as IDataset
;
pds
.Delete();
}
}
else
{
return new Response(Constant
.Nothing
, "");
}
}
ProcessBar processBar
= new ProcessBar();
processBar
.Show();
DeleteLayerByName(lFeatureClass
.AliasName
);
ClipTool(pFeaWorkspace
, pFeatureClass
, lFeatureClass
, eFeatureClass
, pPath
, listName
);
DeleteLayerByName(Constant
.Range_DLTB
);
AddLayer(pFeaWorkspace
, pFeatureClass
);
ILayer pLayer1
= GetLayerByName(Constant
.Range_XZDW
);
if (pLayer1
!= null)
{
IFeatureLayer pFeatureLayer1
= pLayer1
as IFeatureLayer
;
IFeatureClass pFeatureClass1
= pFeatureLayer1
.FeatureClass
;
ClipTool(pFeaWorkspace
, pFeatureClass1
, lFeatureClass
, eFeatureClass
, pPath
, listName
);
DeleteLayerByName(Constant
.Range_XZDW
);
AddLayer(pFeaWorkspace
, pFeatureClass1
);
}
ILayer pLayer2
= GetLayerByName(Constant
.Range_XZQJX
);
if (pLayer2
!= null)
{
IFeatureLayer pFeatureLayer2
= pLayer2
as IFeatureLayer
;
IFeatureClass pFeatureClass2
= pFeatureLayer2
.FeatureClass
;
ClipTool(pFeaWorkspace
, pFeatureClass2
, lFeatureClass
, eFeatureClass
, pPath
, listName
);
DeleteLayerByName( Constant
.Range_XZQJX
);
AddLayer(pFeaWorkspace
, pFeatureClass2
);
}
processBar
.Close();
AddLayerToMap(lFeatureClass
);
}
else
{
MessageBox
.Show("请先绘制图框!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先绘制范围线!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载地图!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载数据!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
private static void ClipTool(IFeatureWorkspace pFeaWorkspace
, IFeatureClass pFeatureClass
, IFeatureClass lFeatureClass
, IFeatureClass eFeatureClass
, string pPath
, string listName
)
{
if (System
.IO
.File
.Exists(pPath
+ pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
))
{
IFeatureClass pFCChecker
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
);
if (pFCChecker
!= null)
{
IDataset pds
= pFCChecker
as IDataset
;
pds
.Delete();
}
}
Geoprocessor GP_Tool
= new Geoprocessor();
ESRI.ArcGIS.AnalysisTools.Clip GP_Clip
= new ESRI.ArcGIS.AnalysisTools.Clip();
GP_Clip
.clip_features
= eFeatureClass
;
GP_Clip
.in_features
= pFeatureClass
;
GP_Clip
.out_feature_class
= pPath
+ pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
;
try
{
GP_Tool
.Execute(GP_Clip
, null);
}
catch (Exception ex
)
{
MessageBox
.Show(ex
.Message
, "GP_Clip_envelope Error");
System.Text.StringBuilder sb
= new System.Text.StringBuilder();
for (int i
= 0; i
< GP_Tool
.MessageCount
; i
++)
sb
.AppendLine(GP_Tool
.GetMessage(i
));
if (sb
.Capacity
> 0) MessageBox
.Show(sb
.ToString(), "GP Messages");
}
IFeatureClass eFeatureClass_out
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
);
if (System
.IO
.File
.Exists(pPath
+ pFeatureClass
.AliasName
+ Constant
.File_Ext_Char1
+ listName
+ Constant
.File_Ext_Char
+ Constant
.Project_File_Shp
))
{
IFeatureClass pFCChecker
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.File_Ext_Char1
+ listName
);
if (pFCChecker
!= null)
{
IDataset pds
= pFCChecker
as IDataset
;
pds
.Delete();
}
}
ESRI.ArcGIS.AnalysisTools.Clip GP_Clip1
= new ESRI.ArcGIS.AnalysisTools.Clip();
GP_Clip1
.clip_features
= lFeatureClass
;
GP_Clip1
.in_features
= eFeatureClass_out
;
GP_Clip1
.out_feature_class
= pPath
+ pFeatureClass
.AliasName
+ Constant
.File_Ext_Char1
+ listName
;
try
{
GP_Tool
.Execute(GP_Clip1
, null);
}
catch (Exception ex
)
{
MessageBox
.Show(ex
.Message
, "GP_Clip_Range Error");
System.Text.StringBuilder sb
= new System.Text.StringBuilder();
for (int i
= 0; i
< GP_Tool
.MessageCount
; i
++)
sb
.AppendLine(GP_Tool
.GetMessage(i
));
if (sb
.Capacity
> 0) MessageBox
.Show(sb
.ToString(), "GP Messages");
}
ISpatialFilter pSpatialFilter
= new SpatialFilterClass();
IGeometry pGeometry
= lFeatureClass
.GetFeature(0).ShapeCopy as IGeometry
;
pSpatialFilter
.Geometry
= pGeometry
;
pSpatialFilter
.SpatialRel
= esriSpatialRelEnum
.esriSpatialRelIntersects
;
IFeatureCursor pFeatureCursor
= eFeatureClass_out
.Search(pSpatialFilter
, false);
IFeature pFeature
= pFeatureCursor
.NextFeature();
while (pFeature
!= null)
{
IGeometry tGeo
= pFeature
.ShapeCopy
;
ITopologicalOperator tTope
= tGeo
as ITopologicalOperator
;
tTope
.Simplify();
IGeometry tGeoDe
= tTope
.Difference(pGeometry
);
pFeature
.Shape
= tGeoDe
;
pFeature
.Store();
pFeature
= pFeatureCursor
.NextFeature();
}
}
public static Response AreaSum()
{
if(MapControl
!= null)
{
ILayer pLayer
= GetLayerByName(Constant
.Range_DLTB
);
if (pLayer
!= null)
{
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
int Judge
= 0;
IFields pFields
= pFeatureClass
.Fields
;
for (int i
= 0; i
< pFields
.FieldCount
; i
++)
{
IField ifield
= pFields
.get_Field(i
);
if (ifield
.Name
== Constant
.Range_Field_DLMC
)
{
Judge
= 1;
List
<string> List
= new List<string>();
IFeatureCursor pFeaCursor
= pFeatureClass
.Search(null, true);
IFeature pFeature
= pFeaCursor
.NextFeature();
while (pFeature
!= null)
{
string fieldValue
= pFeature
.get_Value(i
).ToString();
List
.Add(fieldValue
);
pFeature
= pFeaCursor
.NextFeature();
}
List
= List
.Distinct().ToList();
AreaSum areaSum
= new AreaSum(List
);
areaSum
.ShowDialog();
}
}
if (Judge
== 0)
{
MessageBox
.Show("未找到地类名称字段,请重新加载地图!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载DLTB!", "提示");
return new Response(Constant
.Nothing
, "");
}
}
else
{
MessageBox
.Show("请先加载数据!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
public static Response AreaShow(List
<string> List
)
{
AreaShow areaShow
= new AreaShow();
GridControl gridControl
= areaShow
.dataGrid
;
GridView gridView
= areaShow
.gridView
;
DataTable dataTable
= new DataTable();
gridControl
.DataSource
= dataTable
;
ILayer pLayer
= GetLayerByName(Constant
.Range_DLTB
);
IFeatureLayer pFeatureLayer
= pLayer
as IFeatureLayer
;
IFeatureClass pFeatureClass
= pFeatureLayer
.FeatureClass
;
IFeatureSelection pFeatureSelection
= pFeatureLayer
as IFeatureSelection
;
if (List
.Count
!= 0)
{
dataTable
.Columns
.Add("村名", typeof(string));
for (int l
= 0; l
< List_village
.Count
+1; l
++)
{
dataTable
.Rows
.Add();
}
for (int i
= 0; i
< List
.Count
; i
++)
{
dataTable
.Columns
.Add(List
[i
], typeof(string));
IDataStatistics dataStatistics
= new DataStatisticsClass();
IQueryFilter queryFilter
= new QueryFilterClass();
queryFilter
.WhereClause
= Constant
.Range_Field_DLMC
+ Constant
.File_Ext_equal
+ "'" + List
[i
] + "'";
ICursor cursor
= pFeatureClass
.Search(queryFilter
, false) as ICursor
;
dataStatistics
.Field
= Constant
.Range_Field_TBMJ
;
dataStatistics
.Cursor
= cursor
;
IStatisticsResults results
= dataStatistics
.Statistics
;
double sum
= results
.Sum
;
double Sum
= Math
.Round(sum
, 2);
dataTable
.Rows
[List_village.Count][0] = "总计:";
dataTable
.Rows
[List_village.Count][i
+1] = Sum
;
}
if (List_village
.Count
!= 0)
{
for (int l
= 0; l
< List_village
.Count
; l
++)
{
dataTable
.Rows
[l
][0] = List_village
[l
];
for (int i
= 0; i
< List
.Count
; i
++)
{
IDataStatistics dataStatistics
= new DataStatisticsClass();
IQueryFilter queryFilter
= new QueryFilterClass();
string SQL
= Constant
.Range_Shp_Field
+ Constant
.File_Ext_equal
+ "'" + List_village
[l
] + "'" + "AND" + ' ' + Constant
.Range_Field_DLMC
+ Constant
.File_Ext_equal
+ "'" + List
[i
] + "'";
queryFilter
.WhereClause
= SQL
;
ICursor cursor
= pFeatureClass
.Search(queryFilter
, false) as ICursor
;
dataStatistics
.Field
= Constant
.Range_Field_TBMJ
;
dataStatistics
.Cursor
= cursor
;
IStatisticsResults results
= dataStatistics
.Statistics
;
double sum
= results
.Sum
;
double Sum
= Math
.Round(sum
, 2);
dataTable
.Rows
[l
][i
+1] = Sum
;
}
}
}
gridView
.PopulateColumns();
areaShow
.ShowDialog();
}
else
{
MessageBox
.Show("请勾选地类!", "提示");
return new Response(Constant
.Nothing
, "");
}
return new Response(Constant
.Success
, "");
}
private static void AddLayerToMap(IFeatureClass pFeatureClass
)
{
String LayerName
= pFeatureClass
.AliasName
;
LayerName
= LayerName
.Split('_')[0];
IFeatureLayer pFeatureLyr
= new FeatureLayer();
pFeatureLyr
.FeatureClass
= pFeatureClass
;
pFeatureLyr
.Name
= LayerName
;
if (LayerName
== Constant
.Project_File_Range
|| LayerName
== Constant
.Project_File_Envelope
)
{
SimpleFillSymbol(pFeatureLyr
, esriSimpleFillStyle
.esriSFSHollow
, null, new RgbColorClass() { Red
= 255, Green
= 0, Blue
= 0 }, 2);
}
MapControl
.Map
.AddLayer(pFeatureLyr
);
MapControl
.ActiveView
.Refresh();
}
private static void AddLayer(IFeatureWorkspace pFeaWorkspace
, IFeatureClass pFeatureClass
)
{
IFeatureClass open_pFeatureClass
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.File_Ext_Char1
+ listName
);
IFeatureClass open_pFeatureClass_out
= pFeaWorkspace
.OpenFeatureClass(pFeatureClass
.AliasName
+ Constant
.Project_File_Range_out
+ listName
);
AddLayerToMap(open_pFeatureClass
);
AddLayerToMap(open_pFeatureClass_out
);
}
private static ILayer GetLayerByName(string IN_LayerName
)
{
ILayer pLayer
= null;
for (int i
= 0; i
< MapControl
.LayerCount
; i
++)
{
if (MapControl
.get_Layer(i
).Name
== IN_LayerName
)
{
pLayer
= MapControl
.get_Layer(i
);
break;
}
}
return pLayer
;
}
private static void DeleteLayerByName(string Delete_LayerName
)
{
for (int i
= 0; i
< MapControl
.LayerCount
; i
++)
{
if (MapControl
.get_Layer(i
).Name
== Delete_LayerName
)
{
MapControl
.DeleteLayer(i
);
}
}
}
private static void SimpleFillSymbol(IFeatureLayer pFeatureLayer
, esriSimpleFillStyle FillStyle
, IColor pFillColor
, IColor pOutLineColor
, int nOutLineWidth
= 1)
{
ISimpleFillSymbol pSimpleFillSymbol
= new SimpleFillSymbolClass
{
Style
= FillStyle
};
if (null != pFillColor
)
{
pSimpleFillSymbol
.Color
= pFillColor
;
}
ISimpleLineSymbol pSimpleLineSymbol
= new SimpleLineSymbolClass
{
Style
= esriSimpleLineStyle
.esriSLSSolid
,
Color
= pOutLineColor
,
Width
= nOutLineWidth
> 0 ? nOutLineWidth
: 1
};
pSimpleFillSymbol
.Outline
= pSimpleLineSymbol
;
ISimpleRenderer simpleRender
= new SimpleRendererClass
{
Symbol
= pSimpleFillSymbol
as ISymbol
,
};
IGeoFeatureLayer geoLayer
= pFeatureLayer
as IGeoFeatureLayer
;
if (geoLayer
!= null)
{
geoLayer
.Renderer
= simpleRender
as IFeatureRenderer
;
}
}
private static IPolygon EnvelopeToPolygon(IEnvelope envelope
)
{
IPointCollection pointColl
= new PolygonClass();
IPoint point
= new PointClass();
point
.PutCoords(envelope
.XMin
, envelope
.YMin
);
pointColl
.AddPoint(point
);
point
= new PointClass();
point
.PutCoords(envelope
.XMax
, envelope
.YMin
);
pointColl
.AddPoint(point
);
point
= new PointClass();
point
.PutCoords(envelope
.XMax
, envelope
.YMax
);
pointColl
.AddPoint(point
);
point
= new PointClass();
point
.PutCoords(envelope
.XMin
, envelope
.YMax
);
pointColl
.AddPoint(point
);
point
= new PointClass();
point
.PutCoords(envelope
.XMin
, envelope
.YMin
);
pointColl
.AddPoint(point
);
return pointColl
as IPolygon
;
}
#endregion
}
}
转载请注明原文地址: https://lol.8miu.com/read-19958.html