ArcEngine部分工作总结
Arcengine工作总结
地物点查询
本部分可以在一个窗体中实现,也可以在两个窗体中实现。由于工作要求本人是在两个窗体中实现的:
弹出窗体的名称为FormQuery
主窗体单机查询时间的代码
FormQuery qu = new FormQuery(axMapControl);
qu.TopMost = true;
qu.Show();
FormQuery中要有
public FormQuery(ESRI.ArcGIS.Controls.AxMapControl axMapControl1)
{
// TODO: Complete member initialization
m_axMapControl = axMapControl1;
InitializeComponent();
}
在formload中
private void Query_Load(object sender, EventArgs e)
{
RefreshLayer();
}
加载图层部分的函数,建议写在类中
private void RefreshLayer()
{
layerComboBox.Items.Clear();
for (int i = 0; i < m_axMapControl.LayerCount; i++)
{
//判断是否为矢量图层
if (m_axMapControl.get_Layer(i) is IFeatureLayer)
layerComboBox.Items.Add(m_axMapControl.get_Layer(i).Name);
else
return;
}
layerComboBox.Text = layerComboBox.Items[0].ToString();
}
弹出窗体设置为:(控件和名称请自行设置)
查询条件可以使字段或者其他属性信息。
坐标定位
在主窗体的单机事件中
private void menuCoordinatePosition_Click(object sender, EventArgs e)
{
FormFixedPosition fp = new FormFixedPosition(g_MapControl);
fp.TopMost = true;
fp.Show();
}
FixedPosition为弹出窗体的名称。
在弹出窗体中设置字段:
string strTxtInputX = "";
string strTxtInputY = "";
弹出窗体的构造函数
public FormFixedPosition(IMapControl4 MapControl)
{
InitializeComponent();
m_MapControl = MapControl;
}
弹出窗体的formload事件
private void FixedPosition_Load(object sender, EventArgs e)
{
pMap = m_MapControl.Map;
pActiveView = pMap as IActiveView;
pGraContainer = pMap as IGraphicsContainer;
}
弹出窗体格局:
Txtbox的keypress事件:
//Y坐标
private void txtY_KeyPress(object sender, KeyPressEventArgs e)
{
if (pElement != null)
{
pGraContainer.DeleteAllElements();
}
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && (e.KeyChar != 46))
{
e.Handled = true;
}
if (e.KeyChar == (char)13)
{
strTxtInputX = txtX.Text;
strTxtInputY = txtY.Text;
if (strTxtInputX == "" || strTxtInputY == "")
{
MessageBox.Show("请输入XY坐标!");
}
else
{
dleTxtInputX = System.Convert.ToDouble(strTxtInputX);//获取输入X坐标
dleTxtInputY = System.Convert.ToDouble(strTxtInputY);//获取输入Y坐标
IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.X = dleTxtInputX;
pPoint.Y = dleTxtInputY;
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Blue = 0;
pColor.Green = 0;
ISimpleMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass();
pMarkerSym.Color = pColor;
pMarkerSym.Size = 8;
pMarkerSym.Style = esriSimpleMarkerStyle.esriSMSCircle;
IMarkerElement pMarkerEle = new MarkerElementClass();
pMarkerEle.Symbol = pMarkerSym;
pElement = pMarkerEle as IElement;
pElement.Geometry = pPoint;
pGraContainer.AddElement(pElement, 0);
m_MapControl.CenterAt(pPoint);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
Marshal.ReleaseComObject(pPoint);
Marshal.ReleaseComObject(pColor);
Marshal.ReleaseComObject(pMarkerSym);
Marshal.ReleaseComObject(pMarkerEle);
}
}
}
//X坐标
private void txtX_KeyPress(object sender, KeyPressEventArgs e)
{
if (pElement != null)
{
pGraContainer.DeleteAllElements();
}
if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (e.KeyChar != 13) && (e.KeyChar != 46))
{
e.Handled = true;
}
if (e.KeyChar == (char)13)
{
strTxtInputX = txtX.Text;
strTxtInputY = txtY.Text;
if (strTxtInputX == "" || strTxtInputY == "")
{
MessageBox.Show("请输入XY坐标!");
}
else
{
dleTxtInputX = System.Convert.ToDouble(strTxtInputX);//获取输入X坐标
dleTxtInputY = System.Convert.ToDouble(strTxtInputY);//获取输入Y坐标
IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.X = dleTxtInputX;
pPoint.Y = dleTxtInputY;
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
pColor.Blue = 0;
pColor.Green = 0;
ISimpleMarkerSymbol pMarkerSym = new SimpleMarkerSymbolClass();
pMarkerSym.Color = pColor;
pMarkerSym.Size = 8;
pMarkerSym.Style = esriSimpleMarkerStyle.esriSMSCircle;
IMarkerElement pMarkerEle = new MarkerElementClass();
pMarkerEle.Symbol = pMarkerSym;
pElement = pMarkerEle as IElement;
pElement.Geometry = pPoint;
pGraContainer.AddElement(pElement, 0);
m_MapControl.CenterAt(pPoint);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
Marshal.ReleaseComObject(pPoint);
Marshal.ReleaseComObject(pColor);
Marshal.ReleaseComObject(pMarkerSym);
Marshal.ReleaseComObject(pMarkerEle);
}
}
}
定位效果。
若想实现地物点定位,需要明确地物点的坐标进行参数传递即可。
图幅号定位
主窗体的单击事件调出FormSheetNoPosition窗体:
FormSheetNoPosition form = new FormSheetNoPosition(axMapControl);
form.TopMost = true;
form.Show();
然后FormSheetNoPosition窗体的代码具体如下:
(本部分要添加g_MapControl.Update();避免会出现先闪烁后刷新的情况)
public partial class FormSheetNoPosition : Form
{
public int iLayerIndex;
private IMap m_Map;
IFeatureLayer featurelayer1;//用于闪烁
IFeature feature1;//用于闪烁
AxMapControl g_MapControl;
int i = 0;
public FormSheetNoPosition(AxMapControl axMapControl)
{
InitializeComponent();
this.g_MapControl = axMapControl;
}
private void btnOK_Click(object sender, EventArgs e)
{
positon();
}
public void positon()
{
if (layercmb.Text == "")
{
MessageBox.Show("请选择类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (filecmb.Text == "")
{
MessageBox.Show("请选择名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
//单点定位
IActiveView pActiveView;
pActiveView = (IActiveView)m_Map;
m_Map.ClearSelection();
pActiveView.Refresh();
IQueryFilter pQueryFilter = new QueryFilterClass();
IFeatureLayer pFeatureLayer;
pFeatureLayer = (IFeatureLayer)m_Map.get_Layer(iLayerIndex);
IFields pFields;
pFields = pFeatureLayer.FeatureClass.Fields;
IField pField;
pField = pFields.get_Field(3);
string str;
str = pFields.get_Field(3).Name;
IFeatureCursor pFeatureCursor1;
pFeatureCursor1 = pFeatureLayer.FeatureClass.Search(null, false);
IFeature pFeature1;
pFeature1 = pFeatureCursor1.NextFeature();
switch (pField.Type)
{
case esriFieldType.esriFieldTypeString:
pQueryFilter.WhereClause = str + " = '" + filecmb.Text + "'";
break;
case esriFieldType.esriFieldTypeDouble:
case esriFieldType.esriFieldTypeInteger:
case esriFieldType.esriFieldTypeSingle:
case esriFieldType.esriFieldTypeSmallInteger:
pQueryFilter.WhereClause = str + " = " + filecmb.Text;
break;
}
IFeatureCursor pFeatureCursor;
pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
m_Map.SelectFeature(pFeatureLayer, pFeature);
filecmb.Text = pFeature.get_Value(3).ToString();//用于显示文本框内容
//居中显示
IPoint pPoint = new PointClass();
pPoint.X = (pFeature.Extent.XMin + pFeature.Extent.XMax) / 2;
pPoint.Y = (pFeature.Extent.YMin + pFeature.Extent.YMax) / 2;
this.g_MapControl.CenterAt(pPoint);
this.g_MapControl.MapScale = 500000;
g_MapControl.MapScale = 500000;
featurelayer1 = pFeatureLayer;
feature1 = pFeature;
pFeature = pFeatureCursor.NextFeature();
g_MapControl.Update();//关键语句
g_MapControl.FlashShape(feature1.Shape);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
private void layercmb_SelectedIndexChanged(object sender, EventArgs e)
{
iLayerIndex = layercmb.Items.IndexOf(layercmb.Text);
filecmb.Text = "";
filecmb.Items.Clear();
if (layercmb.Text == "")
{
MessageBox.Show("请选择图层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
//地点名称添加到列表框
IFeatureLayer pFeatureLayer;
pFeatureLayer = (IFeatureLayer)m_Map.get_Layer(iLayerIndex);
//string a;
//a =Convert.ToString(m_Map.LayerCount);
IFeatureCursor pFeatureCursor;
pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);
IFeature pFeature;
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
string fldValue;
fldValue = Convert.ToString(pFeature.get_Value(3));
filecmb.Items.Add(fldValue);
pFeature = pFeatureCursor.NextFeature();
}
}
private void clearbtn_Click(object sender, EventArgs e)
{
//清除已选择要素
filecmb.Text = "";
layercmb.Text = "";
ControlsClearSelectionCommand clscmd = new ControlsClearSelectionCommandClass();
clscmd.OnCreate(g_MapControl.Object);
clscmd.OnClick();
//全图
ControlsMapFullExtentCommand mfecmd = new ControlsMapFullExtentCommandClass();
mfecmd.OnCreate(g_MapControl.Object);
mfecmd.OnClick();
}
private void AddLayername()
{
m_Map = g_MapControl.Map;
ILayer pLayer;
for (int i = 0; i < m_Map.LayerCount; i++)
{
pLayer = m_Map.get_Layer(i);
if (i >= 0 && i <= m_Map.LayerCount)
{
this.layercmb.Items.Add(pLayer.Name);
}
}
}
private void filecmb_DropDown(object sender, EventArgs e)
{
}
private void layercmb_DropDown(object sender, EventArgs e)
{
layercmb.Items.Clear();
AddLayername();
}
}
Shp数据的导入与导出
Shp数据导入SDE数据库
首先是要连接SDE然后要确定函数shpFeatureClassToGeodatabase(string inputPath, string sdePath)的两个路径。电脑上需要有E:\arcgis-test\test这个路径。其中axlisensecontrol的属性要做一些改动,只能是这种选择,不要多也不要少,不然会出现转换失败等各种问题。
private void menuImportSHP_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "(*.shp)|*.shp";
dlg.Title = "打开shp文件路径";
if (DialogResult.OK == dlg.ShowDialog())
{
string shpPath = dlg.FileName;
//string shpPath = @"C:\Users\dpd\Desktop\California\test\GolfCourses.shp";
//string sdePath = @"C:\Users\dpd\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Connection to 192.168.159.186.sde";
IPropertySet pProSet = new PropertySet();
try
{
pProSet.SetProperty("Server", "192.168.159.186");
pProSet.SetProperty("Instance", "sde:oracle11g:192.168.159.186/orcl");
pProSet.SetProperty("Database", "orcl");
pProSet.SetProperty("user", "sde");
pProSet.SetProperty("password", "sde");
pProSet.SetProperty("version", "SDE.DEFAULT");
}
catch (Exception ex)
{
string msg = ex.Message;
}
string path = @"E:\arcgis-test\test";
string sdeName = @"test.sde";
string sdePath = path + "\\" + sdeName;
if (File.Exists(sdePath))
{
File.Delete(sdePath);
}
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();
IWorkspaceName workspaceName = workspaceFactory.Create(path, sdeName, pProSet, 0);
shpFeatureClassToGeodatabase(shpPath, sdePath);
}
}
public static void shpFeatureClassToGeodatabase(string inputPath, string sdePath)
{
ESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabase featureClassToGeodatabase = new ESRI.ArcGIS.ConversionTools.FeatureClassToGeodatabase();
featureClassToGeodatabase.Output_Geodatabase = sdePath;
featureClassToGeodatabase.Input_Features = inputPath;
featureClassToGeodatabase.Derived_Geodatabase = "";
Geoprocessor geoprocessor = new Geoprocessor();
geoprocessor.OverwriteOutput = true;
try
{
geoprocessor.Execute(featureClassToGeodatabase, null);
string mess = null;
for (int k = 0; k < geoprocessor.MessageCount; k++)
{
mess += geoprocessor.GetMessage(k) + "\n";
}
MessageBox.Show(mess);
}
catch (Exception ex)
{
string mess = null;
for (int k = 0; k < geoprocessor.MessageCount; k++)
{
mess += geoprocessor.GetMessage(k) + "\n";
}
}
}
导出为shp数据
本部分分为整个shp图层数据导出,和可视范围内的数据导出两部分
主窗体的单机事件:
private void exportshpToolStripMenuItem_Click(object sender, EventArgs e)
{
if (layerCurrent != null)
{
FormExportVector fev = new FormExportVector(axMapControl, layerCurrent);
fev.Show();
}
else
{
MessageBox.Show("请选择一个图层!","提示!");
}
}
FormExportVector窗体的主要代码:
public partial class FormExportVector : Form
{
private ESRI.ArcGIS.Controls.AxMapControl axMapControl;
SaveFileDialog dlg = new SaveFileDialog();
ILayer layerCurrent = null;
public FormExportVector(ESRI.ArcGIS.Controls.AxMapControl axMapControl,ILayer layer)
{
// TODO: Complete member initialization
this.axMapControl = axMapControl;
this.layerCurrent = layer;
InitializeComponent();
}
private void FormExportVector_Load(object sender, EventArgs e)
{
cbExtent.SelectedIndex = 0;
}
private void btnOK_Click(object sender, EventArgs e)
{
//导出所有要素
if (cbExtent.Text == "所有要素")
{
if (layerCurrent != null)
{
try
{
if (layerCurrent != null)
{
IFeatureLayer pFeatureLayer = layerCurrent as IFeatureLayer;
if (pFeatureLayer.Visible)
{
ExportFeature(pFeatureLayer.FeatureClass, dlg.FileName);
}
MessageBox.Show("导出成功");
this.Close();
}
}
catch
{
MessageBox.Show("导出失败!");
this.Close();
}
}
}
//导出窗体范围内的要素
else if (cbExtent.Text == "窗口范围")
{
try
{
if (layerCurrent != null)
{
IEnvelope pEnvelope = axMapControl.Extent;
IFeatureLayer pFeatureLayer = layerCurrent as IFeatureLayer;
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pEnvelope as IGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
//IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter as IQueryFilter, false);
//IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
//IFeature pFeature = pFeatureCursor.NextFeature();
//while (pFeature != null)
//{
// //pFeatures.Add(pFeature);
// pFeature = pFeatureCursor.NextFeature();
//}
//System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
if (pFeatureLayer.Visible)
{
ExportFeatureByFilter(pFeatureLayer.FeatureClass, dlg.FileName, pSpatialFilter as IQueryFilter);
}
MessageBox.Show("导出成功");
this.Close();
}
}
catch
{
MessageBox.Show("导出失败!");
this.Close();
}
}
else
{
MessageBox.Show("请选择一个矢量图层");
}
}
public void ExportFeature(IFeatureClass pInFeatureClass, string pPath)
{
// 创建工作空间
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
string parentPath = pPath.Substring(0, pPath.LastIndexOf('\\'));
string fileName = pPath.Substring(pPath.LastIndexOf('\\') + 1, pPath.Length - pPath.LastIndexOf('\\') - 1);
IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create(parentPath, fileName, null, 0);
// Cast for IName
IName name = (IName)pWorkspaceName;
//Open a reference to the access workspace through the name object
IWorkspace pOutWorkspace = (IWorkspace)name.Open();
IDataset pInDataset = pInFeatureClass as IDataset;
IFeatureClassName pInFCName = pInDataset.FullName as IFeatureClassName;
IWorkspace pInWorkspace = pInDataset.Workspace;
IDataset pOutDataset = pOutWorkspace as IDataset;
IWorkspaceName pOutWorkspaceName = pOutDataset.FullName as IWorkspaceName;
IFeatureClassName pOutFCName = new FeatureClassNameClass();
IDatasetName pDatasetName = pOutFCName as IDatasetName;
pDatasetName.WorkspaceName = pOutWorkspaceName;
pDatasetName.Name = pInFeatureClass.AliasName;
IFieldChecker pFieldChecker = new FieldCheckerClass();
pFieldChecker.InputWorkspace = pInWorkspace;
pFieldChecker.ValidateWorkspace = pOutWorkspace;
IFields pFields = pInFeatureClass.Fields;
IFields pOutFields;
IEnumFieldError pEnumFieldError;
pFieldChecker.Validate(pFields, out pEnumFieldError, out pOutFields);
IFeatureDataConverter pFeatureDataConverter = new FeatureDataConverterClass();
pFeatureDataConverter.ConvertFeatureClass(pInFCName, null, null, pOutFCName, null, pOutFields, "", 100, 0);
}
public void ExportFeatureByFilter(IFeatureClass pInFeatureClass, string pPath, IQueryFilter pQueryFilter)
{
// 创建工作空间
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
string parentPath = pPath.Substring(0, pPath.LastIndexOf('\\'));
string fileName = pPath.Substring(pPath.LastIndexOf('\\') + 1, pPath.Length - pPath.LastIndexOf('\\') - 1);
IWorkspaceName pWorkspaceName = pWorkspaceFactory.Create(parentPath, fileName, null, 0);
// Cast for IName
IName name = (IName)pWorkspaceName;
//Open a reference to the access workspace through the name object
IWorkspace pOutWorkspace = (IWorkspace)name.Open();
IDataset pInDataset = pInFeatureClass as IDataset;
IFeatureClassName pInFCName = pInDataset.FullName as IFeatureClassName;
IWorkspace pInWorkspace = pInDataset.Workspace;
IDataset pOutDataset = pOutWorkspace as IDataset;
IWorkspaceName pOutWorkspaceName = pOutDataset.FullName as IWorkspaceName;
IFeatureClassName pOutFCName = new FeatureClassNameClass();
IDatasetName pDatasetName = pOutFCName as IDatasetName;
pDatasetName.WorkspaceName = pOutWorkspaceName;
pDatasetName.Name = pInFeatureClass.AliasName;
IFieldChecker pFieldChecker = new FieldCheckerClass();
pFieldChecker.InputWorkspace = pInWorkspace;
pFieldChecker.ValidateWorkspace = pOutWorkspace;
IFields pFields = pInFeatureClass.Fields;
IFields pOutFields;
IEnumFieldError pEnumFieldError;
pFieldChecker.Validate(pFields, out pEnumFieldError, out pOutFields);
IFeatureDataConverter pFeatureDataConverter = new FeatureDataConverterClass();
pFeatureDataConverter.ConvertFeatureClass(pInFCName, pQueryFilter, null, pOutFCName, null, pOutFields, "", 100, 0);
}
private void btnBrowser_Click(object sender, EventArgs e)
{
if (DialogResult.OK == dlg.ShowDialog())
{
string file = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\'));
txtPath.Text = file;
if (!System.IO.Directory.Exists(file))
{
System.IO.Directory.CreateDirectory(file);
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
右键菜单
本部分涉及了右键菜单可以实现添加shp、lyr数据到TOC,删除图层,移除所有图层,点击查看属性等。
使用到的字段
private IActiveView pActiveView;
private IMap pMap;
private IElement pElement;
private IGraphicsContainer pGraContainer;
private IMapControl4 g_MapControl;//地图控件对象
private int j = 0;
double x=0, y=0;
private int m = 0, n = 0;
private IToolbarMenu mapMenu = null;
private ITOCControl mTOCControl;//更改图层的图例样式,changeLegend为4时更改,为0时不能
private static int deleteLayer = 0;//删除选中图层,deleteLayer为4时可删除图层,为0时不能
private static int changeLegend = 0;
//点击地图要素,显示相关属性,viewFeature为4时可以查看要素属性,为0时不能
private static int viewFeature = 0;
核心代码在TOC的mousedown事件中
private void axTOCControl1_OnMouseDown_1(object sender, ITOCControlEvents_OnMouseDownEvent e)
{
m = e.x;
n = e.y;
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
int pLayerIndex = 0;
//返回单击在TOCControl中位置
axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (layer != null)
{
layerCurrent = layer;
}
//单击鼠标左键
if (e.button == 1)
{
IMap pMap = axTOCControl1.ActiveView.FocusMap;
//更改图层图例
if (changeLegend == 4)
{
//判断是否单击图层或图例
if (item == esriTOCControlItem.esriTOCControlItemLegendClass || item == esriTOCControlItem.esriTOCControlItemLayer)
{
ILayer pTempLayer;
for (int i = 0; i < pMap.LayerCount; i++)
{
pTempLayer = pMap.get_Layer(i);
if (pTempLayer == layer)
{
pLayerIndex = i;
break;
}
}
//声明要更改图例的图层位置
ISymbolSelector pSymbolSelector;
pSymbolSelector = new SymbolSelectorClass();
IGeoFeatureLayer pGeoFeatureLayer;
pGeoFeatureLayer = this.axMapControl.get_Layer(pLayerIndex) as IGeoFeatureLayer;
//要更改图层图例的图例类型的类的定义
IFeatureLayer pFeatureLayer;
pFeatureLayer = this.axMapControl.get_Layer(pLayerIndex) as IFeatureLayer;
esriGeometryType pType;
try
{
IFeatureClass pFeatureClass;
pFeatureClass = pFeatureLayer.FeatureClass;
pType = pFeatureClass.ShapeType;
switch (pType)
{
//定义点的简单符号样式对话框
case esriGeometryType.esriGeometryPoint:
//MessageBox.Show("point");
ISimpleMarkerSymbol pSimpleMarkerSymbol;
pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
pSymbolSelector.AddSymbol(pSimpleMarkerSymbol as ISymbol);
break;
//定义线的简单符号样式对话框
case esriGeometryType.esriGeometryPolyline:
//MessageBox.Show("line");
ISimpleLineSymbol pSimpleLineSymbol;
pSimpleLineSymbol = new SimpleLineSymbolClass();
pSymbolSelector.AddSymbol(pSimpleLineSymbol as ISymbol);
break;
//定义面得简单符号样式对话框
case esriGeometryType.esriGeometryPolygon:
//MessageBox.Show("polygon");
ISimpleFillSymbol pSimpleFillSymbol;
pSimpleFillSymbol = new SimpleFillSymbolClass();
pSymbolSelector.AddSymbol(pSimpleFillSymbol as ISymbol);
break;
default:
MessageBox.Show("未知的图例类型!", "错误");
return;
}
}
catch
{
MessageBox.Show("不是带图例的图层!", "提示");
}
//判断图例的类型:点,线,面
//当选择对话框的图例对象时进入,再更改所在图例样式
if (pSymbolSelector.SelectSymbol(0))
{
ISymbol pSymbol;
ISimpleRenderer pRenderer;
pSymbol = pSymbolSelector.GetSymbolAt(0);
pRenderer = new SimpleRendererClass();
pRenderer.Symbol = pSymbol;
pGeoFeatureLayer.Renderer = pRenderer as IFeatureRenderer;
this.axMapControl.Refresh();
this.axTOCControl1.Update();
pGeoFeatureLayer.GetType();
}
changeLegend = 0;
}
}
//删除单个图层
else if (deleteLayer == 4)
{
//确保有项目被选择
if (item == esriTOCControlItem.esriTOCControlItemMap)
{
//ILayer l = null;
if (MessageBox.Show("确实要删除地图 " + map.Name + " 吗?", "删除地图", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
pMap.ClearLayers();
axMapControl.ActiveView.Refresh();
mTOCControl.Update();
}
}
else if (item == esriTOCControlItem.esriTOCControlItemLayer)
{
if (MessageBox.Show("确实要删除图层 " + layer.Name + " 吗?", "删除图层", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
pMap.DeleteLayer(layer);
axMapControl.ActiveView.Refresh();
//mTOCControl.Update();//mTOCControl为null异常
}
}
else
MessageBox.Show("未选择任何内容!", "错误");
deleteLayer = 0;
}
j++;
}
else if (e.button == 2)//右键弹出菜单
{
contextMenuStrip1.Show(axTOCControl1, e.x, e.y);
}
}
Mapcontrol的mousedown事件实现查询Identify
private void axMapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 1)
{
if (viewFeature == 4)
{
//myMapControl1.MousePointer = esriControlsMousePointer.esriPointerArrow;
IActiveView activeview = axMapControl.ActiveView;
IEnumLayer pEnumLayer;
IIdentifyDialogProps pIdentifyDialogProps;
IIdentifyDialog pIdentifyDialog = new IdentifyDialogClass();
pIdentifyDialog.Map = axMapControl.Map;
pIdentifyDialog.Display = activeview.ScreenDisplay;
pIdentifyDialog.ClearLayers();
pIdentifyDialogProps = pIdentifyDialog as IIdentifyDialogProps;
pEnumLayer = pIdentifyDialogProps.Layers;
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
pIdentifyDialog.AddLayerIdentifyPoint(pLayer, e.x, e.y);
pLayer = pEnumLayer.Next();
}
pIdentifyDialog.Show();
}
}
else if (e.button == 2)
{
}
}
移除所有图层
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
{
IMap myMap = axMapControl.Map;
myMap.ClearLayers();
axTOCControl1.Update();
axMapControl.ActiveView.Refresh();
}
更改图例
private void changestyleToolStripMenuItem_Click(object sender, EventArgs e)
{
changeLegend = 4;
MessageBox.Show("请选择要更改样式的图层!", "样式更改");
}
结合TOC的mousedown事件实现。
删除图层
deleteLayer = 4;
MessageBox.Show("请选择要删除的图层!", "删除");
添加shp图层
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
openFileDialog1.Filter = "(*.shp)|*.shp";
openFileDialog1.InitialDirectory = @"C:";
openFileDialog1.Multiselect = false;
DialogResult pDialogResult = openFileDialog1.ShowDialog();
if (pDialogResult != DialogResult.OK)
return;
string pPath = openFileDialog1.FileName;
string pFilePath = System.IO.Path.GetDirectoryName(pPath);
string pFileName = System.IO.Path.GetFileName(pPath);
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFilePath, 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFC = pFeatureWorkspace.OpenFeatureClass(pFileName);
IFeatureLayer pFlayer = new FeatureLayerClass();
pFlayer.FeatureClass = pFC;
pFlayer.Name = pFC.AliasName;
ILayer pLayer = pFlayer as ILayer;
IMap pMap = axMapControl.Map;
pMap.AddLayer(pLayer);
axMapControl.ActiveView.Refresh();
添加lyr图层
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
openFileDialog1.Filter = "(*.lyr)|*.lyr";
openFileDialog1.InitialDirectory = @"D:";
openFileDialog1.Multiselect = false;
DialogResult pDialogResult = openFileDialog1.ShowDialog();
if (pDialogResult != DialogResult.OK)
return;
string pFileName = openFileDialog1.FileName;
axMapControl.AddLayerFromFile(pFileName);
axMapControl.ActiveView.Refresh();
ArcEngine部分工作总结的更多相关文章
- C#+ArcEngine中com对象的释放问题
1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...
- ArcEngine 连接sql server sde
前言 本想在soe中进行sde for sqlserver数据获取.由于soe的调试不方便,为了测试的简便,先在桌面上写了个arcengine连接sde for sqlserver的程序,但是本以为是 ...
- C# + ArcEngine 常用方法(不定时更新)
1.Arcengine调用GP服务,抛出异常方法 object sev = null; try { Application.DoEvents(); gp.Execute(gpBuildPyramids ...
- ArcEngine影像图配准
转自原文ArcEngine影像图配准 影像图配准主要包括以下几个方面 1.打开影像图 2.配准 3.影像图入库/保存 1.打开影像图的代码以前已经写过了. 2.配准 配准 主要使用IGeoRefe ...
- ArcEngine 数据导入经验(转载)
转自原文ArcEngine 数据导入经验(转载) (一) GIS系统数据是基础,想必大家在做ArcEngine二次开发的过程中都会遇到向MDB和SDE写入数据的工作,我们将会通过几个篇幅,从大数据量导 ...
- ArcEngine中最短路径的实现
原文 ArcEngine中最短路径的实现 最短路径分析属于ArcGIS的网络分析范畴.而ArcGIS的网络分析分为两类,分别是基于几何网络和网络数据集的网络分析.它们都可以实现最短路径功能.下面先介绍 ...
- ArcEngine打开本地数据库
先看一下GeoDatabase核心结构模型图: 1 工作空间工厂WorkspaceFactory对象 WorkspaceFactory是GeoDatabase的入口,是一个抽象类,拥有很多子类,例如 ...
- ArcEngine介绍
一.ArcEngine简介ArcEngine被定位为一个嵌入式的产品,它并非面向最终用户,而是一个面向开发者的产品.对于繁冗的GIS开发工作而言,理想的解决方案是一个基于组件的实用的开发框架,且该框架 ...
- ArcEngine版本管理(Version)项目总结
需求: 在ArcGIS项目中,大型的数据库都是使用ArcSDE进行连接管理.使用的数据版本(Version)都是默认版本(sde.default).这样多个人员在编辑的过程中就直接编辑的是默认版本数据 ...
随机推荐
- Django Template模板
Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def ind ...
- iOS中的代理和Block
一.代理(Delegate) 1)含义 iOS中的代理,比如父母要去上班,到中午12点了,需要给宝宝喂饭吃,但是父母正在上班,这时需要有一个人来帮忙完成一些事情(需要有个保姆来帮忙给宝宝喂饭),此时, ...
- MySql 插入10位以上长度的字符报错or截断
当a字段为int类型时: 如果用MyBatis向MySql插入10个字符以上长度的字符串,则会报错. 如果直接在MySql中用sql语句插入10个字符以上长度的字符串,则会变成最大的int类型数值:2 ...
- table详解
1.tr 元素定义表格行,th 元素定义表头,td 元素定义表格单元. tr内是th还是td可由自己定义,th,td可存在于任一行,th与td的区别在与th字体更粗 2.定义一个table默认有bor ...
- 【最长下降子序列的长度和个数】 poj 1952
转自http://blog.csdn.net/zhang360896270/article/details/6701589 这题要求最长下降子序列的长度和个数,我们可以增加数组maxlen[size] ...
- 织梦DEDE文章列表前面自动加递增数字标签
实现的办法很简单,只须要在序号递增的处所加上这段代码就行 [field:global runphp=""yes"" name=autoindex][/field ...
- 【转】从1到N这N个数中1的出现了多少次?
给定一个十进制整数N,求出从1到N的所有整数中出现"1"的个数. 例如:N=2,1,2出现了1个"1". N=12,1,2,3,4,5,6,7,8,9,10,1 ...
- AI 人工智能 探索 (三)
三类子弹的设计 using UnityEngine; using System.Collections; public class AI : AssembleModel { private Hasht ...
- Python实现删除目录下相同文件
让我们来分析一下这个问题:首先,文件个数非常多,手工查找是不现实的,再说,单凭我们肉眼,在几千张图片或文件里面找到完全相同的难度也是很大的.所以要用程序实现.那么用程序怎么实现呢?根据什么判断两个文件 ...
- LoadRunner监控Unix、Windows方法及常用性能指标
目 录 一.LoadRunner监控Linux资源.... 3 (一).准备工作... 3 1.可以通过两种方法验证服务器上是否配置了rstatd守护程序:... 3 (2)使用find命令... ...