Arcgis engine开发
来源:互联网 发布:有关狐狸的网络电视剧 编辑:程序博客网 时间:2024/04/29 07:58
0颜色方法
public IRgbColor GetRgbColor(intintR, int intG, int intB)
{
IRgbColor pRgbColor =null;
if (intR < 0 || intR > 255 || intG < 0 ||intG > 255 || intB < 0 || intB > 255)
{
return pRgbColor;
}
pRgbColor = new RgbColorClass();
pRgbColor.Red = intR;
pRgbColor.Green = intG;
pRgbColor.Blue = intB;
return pRgbColor;
}
1IMapdocument加载mxd
if (openFileDialog.ShowDialog() ==DialogResult.OK)
{
string sFileName =openFileDialog.FileName;
if(string.IsNullOrEmpty(sFileName))
{
return;
}
if(axMapControl.CheckMxFile(sFileName))
{
ClearAllData();
IMapDocument pMapDoc =new MapDocumentClass();
pMapDoc.Open(sFileName,"");
axMapControl.Map =pMapDoc.ActiveView.FocusMap;
axMapControl.ActiveView.Refresh();
}
else
{
MessageBox.Show("选择了无效的地图文档【"+ sFileName + "】!");
}
2加载mdb文件
private void AddMdbFile(string sAccessFilePath)
{
if (string.IsNullOrEmpty(sAccessFilePath))
return;
ry
{
IWorkspaceFactory pWksFac =new AccessWorkspaceFactory();
IWorkspace pWks =pWksFac.OpenFromFile(sAccessFilePath, 0);
IEnumDataset pEnumDs = pWks.get_Datasets(esriDatasetType.esriDTAny);
pEnumDs.Reset();
IDatasetpDs = pEnumDs.Next();
while (pDs != null)
{
if (pDs isIFeatureDataset)
{
IEnumDataset pEnumDs2 = pDs.Subsets;
pEnumDs2.Reset();
IDataset pDs2 = pEnumDs2.Next();
while (pDs2 !=null)
{
IFeatureClass pFeaCls = pDs2as IFeatureClass;
IFeatureLayerpFeaLyr = new FeatureLayerClass();
pFeaLyr.FeatureClass = pFeaCls;
pFeaLyr.Name =pFeaCls.AliasName;
axMapControl.Map.AddLayer(pFeaLyr);
pDs2 =pEnumDs2.Next();
}
}
else if(pDs is IFeatureClass)
{
IFeatureClass pFeaCls = pDsas IFeatureClass;
IFeatureLayer pFeaLyr =new FeatureLayerClass();
pFeaLyr.FeatureClass =pFeaCls;
pFeaLyr.Name =pFeaCls.AliasName;
axMapControl.Map.AddLayer(pFeaLyr);
}
pDs = pEnumDs.Next();
}
axMapControl.ActiveView.Refresh();
}
catch (Exceptionex)
{
}
3加载shapfile
private void AddShapeFile(stringsShpFilePath)
{
if (string.IsNullOrEmpty(sShpFilePath))
{
return;
}
try
{
string sFolderPath =sShpFilePath.Substring(0, sShpFilePath.LastIndexOf("\\"));
tring sFeaClsName =sShpFilePath.Substring(sShpFilePath.LastIndexOf("\\")+ 1);
IWorkspaceFactory pWksFac =new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeaWks = (IFeatureWorkspace)pWksFac.OpenFromFile(sFolderPath,0);
IFeatureClass pFeaCls =pFeaWks.OpenFeatureClass(sFeaClsName);
IFeatureLayer pFeaLyr = newFeatureLayerClass();
pFeaLyr.FeatureClass = pFeaCls;
pFeaLyr.Name = pFeaCls.AliasName;
axMapControl.Map.AddLayer(pFeaLyr);
axMapControl.ActiveView.Refresh();
}
catch (Exceptionex)
{
}
3右击Toc
private IFeatureLayerm_SelectFeatureLayer =null;
privatevoid axTOCControl_OnMouseDown(objectsender,toCControlEvents_OnMouseDownEvent e)
{
try
{
if (e.button == 2)
{
esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap pMap = null;
ILayer pLayer = null;
object unk = null;
object data = null;
axTOCControl.HitTest(e.x, e.y, refpItem, ref pMap, refpLayer, ref unk, refdata);
if (pItem ==esriTOCControlItem.esriTOCControlItemLayer && pLayer !=null)
{
m_SelectFeatureLayer =pLayer as IFeatureLayer;
btnCanSelect.Enabled =!m_SelectFeatureLayer.Selectable;
btnNotCanSelect.Enabled= m_SelectFeatureLayer.Selectable;
contextMenuStrip.Show(Control.MousePosition);
}
}
}
catch (Exceptionex)
{
MessageBox.Show("TOCControl MouseDown Error:êo" + ex.Message);
}
}
private voidbtnAttributeTable_Click(object sender, EventArgs e)
{
if (m_SelectFeatureLayer == null)
{
return;
}
frmAttributeTable frmAttribute = new frmAttributeTable();
frmAttribute.FromLoad(m_SelectFeatureLayer);
frmAttribute.ShowDialog();
}
private void btnCanSelect_Click(objectsender, EventArgs e)
{
if (m_SelectFeatureLayer != null)
{
m_SelectFeatureLayer.Selectable= true;
btnCanSelect.Enabled = false;
btnNotCanSelect.Enabled = true;
}
}
private void btnNotCanSelect_Click(objectsender, EventArgs e)
{
if (m_SelectFeatureLayer != null)
{
m_SelectFeatureLayer.Selectable= false;
btnCanSelect.Enabled = true;
btnNotCanSelect.Enabled =false;
}
}
private void btnRemoveLayer_Click(objectsender, EventArgs e)
{
try
{
if (m_SelectFeatureLayer !=null)
{
if (MessageBox.Show("是否删除【" +m_SelectFeatureLayer.Name + "】图层", "移除图层", MessageBoxButtons.OKCancel,MessageBoxIcon.Information) == DialogResult.OK)
{
axMapControl.Map.DeleteLayer(m_SelectFeatureLayer as ILayer);
}
axMapControl.ActiveView.Refresh();
m_SelectFeatureLayer =null;
////鹰眼同步
SynchronizeEagleEye();
}
}
catch(Exception ex)
{
MessageBox.Show("移除图层出现异常:"+ ex.Message);
}
}
private void btnPanToLayer_Click(objectsender, EventArgs e)
{
if (m_SelectFeatureLayer != null)
{
axMapControl.ActiveView.Extent= m_SelectFeatureLayer.AreaOfInterest;
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,null, null);
}
}
4符号化选择图层
public partialclass frmFeatureLayerSelect : DevExpress.XtraEditors.XtraForm
{
///<summary>
///选?择?的Ì?图ª?形?
///</summary>
private IFeatureLayer m_FeatureLayer =null;
public IFeatureLayer SelectFeatureLayer
{
get
{
return m_FeatureLayer;
}
}
public frmFeatureLayerSelect()
{
InitializeComponent();
}
///窗ä¡ã体¬?初?始º?化¡¥
///</summary>
///<param name="Map">地Ì?图ª?窗ä¡ã口¨²</param>
///<param name="featureType">要°a素?类¤¨¤型¨ª</param>
///<param name="geometryType">图ª?形?类¤¨¤型¨ª</param>
publicvoid FormLoad(IMap Map, esriFeatureType featureType, esriGeometryTypegeometryType)
{
if (Map == null ||Map.LayerCount == 0)
{
return;
}
this.cboLayer.Properties.Items.Clear();
for (int i = 0; i< Map.LayerCount; i++)
{
IFeatureLayer pFeaLyr = Map.get_Layer(i) asIFeatureLayer;
if (pFeaLyr == null|| pFeaLyr.FeatureClass == null)
{
continue;
}
if (featureType ==esriFeatureType.esriFTAnnotation &&pFeaLyr.FeatureClass.FeatureType ==esriFeatureType.esriFTAnnotation)
{
LayerFun pLyrFun =new LayerFun();
pLyrFun.FeaClsName = (pFeaLyr.FeatureClass asIDataset).Name;
pLyrFun.AliasName = pFeaLyr.FeatureClass.AliasName;
pLyrFun.FeatureLayer = pFeaLyr;
this.cboLayer.Properties.Items.Add(pLyrFun);
}
else if(featureType== esriFeatureType.esriFTSimple)
{
if (pFeaLyr.FeatureClass.ShapeType ==geometryType)
{
LayerFunpLyrFun =new LayerFun();
pLyrFun.FeaClsName =(pFeaLyr.FeatureClassas IDataset).Name;
pLyrFun.AliasName =pFeaLyr.FeatureClass.AliasName;
pLyrFun.FeatureLayer =pFeaLyr;
this.cboLayer.Properties.Items.Add(pLyrFun);
}
}
}
if (this.cboLayer.Properties.Items.Count> 0)
{
this.cboLayer.SelectedIndex = 0;
}
}
private voidfrmFeatureLayerSelect_FormClosing(object sender, FormClosingEventArgs e)
{
if (this.DialogResult==DialogResult.OK)
{
object obj = this.cboLayer.SelectedItem;
if(obj == null)
{
MessageBox.Show("请?选?择?需¨¨要°a符¤?号?化¡¥的Ì?图ª?层?。¡ê");
e.Cancel = true;
return;
}
m_FeatureLayer = (obj asLayerFun).FeatureLayer;
}
}
}
}
5多图层符号化
privatevoid btnMultiLayerPoint_ItemClick(object sender, ItemClickEventArgs e)
{
frmFeatureLayerSelect frm =new frmFeatureLayerSelect();
frm.FormLoad(axMapControl.Map, esriFeatureType.esriFTSimple,esriGeometryType.esriGeometryPoint);
if (frm.ShowDialog() ==DialogResult.OK)
{
IFeatureLayer pFeaLyr = frm.SelectFeatureLayer;
SymbolMultiLayerPoint(pFeaLyr);
}
}
private voidSymbolMultiLayerPoint(IFeatureLayer pFeaLyr)
{
if (pFeaLyr == null|| pFeaLyr.FeatureClass == null)
{
return;
}
try
{
IGeoFeatureLayer pGeoFeaLyr = pFeaLyr asIGeoFeatureLayer;
////创ä¡ä建¡§字Á?符¤?符¤?号?
ICharacterMarkerSymbol pCharacterMarkerSymbol = newCharacterMarkerSymbolClass();
IRgbColor pRgbColor = GetRgbColor(0, 0, 0);
IFontDisp pFontDisp = (IFontDisp)(newStdFontClass());
pFontDisp.Name = "arial";
pFontDisp.Italic = true;
pFontDisp.Size = 12;
pCharacterMarkerSymbol.Angle = 0;
pCharacterMarkerSymbol.CharacterIndex = 97;
pCharacterMarkerSymbol.Color = pRgbColor;
pCharacterMarkerSymbol.Font = pFontDisp;
pCharacterMarkerSymbol.Size = 24;
////创ä¡ä建¡§图ª?片?符¤?号?
IPictureMarkerSymbol pPictureMarkerSymbol = newPictureMarkerSymbolClass();
string sFilePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
sFilePath = sFilePath + @"..\..\res\bmp\city.bmp";
if (!File.Exists(sFilePath))
{
return;
} pPictureMarkerSymbol.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap,sFilePath);
pPictureMarkerSymbol.Angle = 0;
pPictureMarkerSymbol.BitmapTransparencyColor = pRgbColor;
pPictureMarkerSymbol.Size = 10;
////创ä¡ä建¡§叠Ìt加¨®符¤?号?
IMultiLayerMarkerSymbol pMultiLayerMarkerSymbol = new MultiLayerMarkerSymbolClass();
pMultiLayerMarkerSymbol.AddLayer(pCharacterMarkerSymbol);
pMultiLayerMarkerSymbol.AddLayer(pPictureMarkerSymbol);
pMultiLayerMarkerSymbol.Angle = 0;
pMultiLayerMarkerSymbol.Size = 20;
pMultiLayerMarkerSymbol.XOffset = 5;
pMultiLayerMarkerSymbol.YOffset = 5;
////更¨¹改?符¤?号?样¨´式º?
ISymbol pSymbol = (ISymbol)pMultiLayerMarkerSymbol;
ISimpleRenderer pSimpleRender = newSimpleRendererClass();
pSimpleRender.Symbol = pSymbol;
pGeoFeaLyr.Renderer = pSimpleRender asIFeatureRenderer;
axMapControl.Refresh();
axTOCControl.Update();
}
catch (Exceptionex)
{
MessageBox.Show(符号化失败+ ex.Message);
}
}
6多图层线符号化
private voidSymbolMultiLayerLine(IFeatureLayer pFeaLyr)
{
if (pFeaLyr == null|| pFeaLyr.FeatureClass == null)
{
return;
}
IGeoFeatureLayer pGeoFeaLyr = pFeaLyr asIGeoFeatureLayer;
////创ä¡ä建¡§简¨°单Ì£¤符¤?号?
////创ä¡ä建¡§制?图ª?符¤?号?
ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbolClass();
pCartographicLineSymbol.Cap = esriLineCapStyle.esriLCSRound;
pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound;
pCartographicLineSymbol.Width = 2;
pRgbColor = GetRgbColor(0, 255, 0);
pCartographicLineSymbol.Color = pRgbColor;
////设¦¨¨置?线?要°a素?符¤?号?模¡ê板ã?
ILineProperties pLineProperties = pCartographicLineSymbolas ILineProperties;
pLineProperties.Offset = 0;
double[] dob = newdouble[6];
dob[0] = 0;
dob[1] = 1;
dob[2] = 2;
dob[3] = 3;
dob[4] = 4;
dob[5] = 5;
ITemplate pTemplate = newTemplateClass();
pTemplate.Interval = 1;
for (inti = 0; i < dob.Length; i = i + 2)
{
pTemplate.AddPatternElement(dob[i], dob[i+ 1]);
}
pLineProperties.Template = pTemplate;
////创ä¡ä建¡§多¨¤图ª?层?符¤?号?
IMultiLayerLineSymbol pMultiLayerLineSymbol = newMultiLayerLineSymbolClass();
pMultiLayerLineSymbol.AddLayer(pSimpleLineSymbol);
pMultiLayerLineSymbol.AddLayer(pCartographicLineSymbol);
////更¨¹改?符¤?号?样¨´式º?
ISymbol pSymbol = (ISymbol)pMultiLayerLineSymbol;
ISimpleRenderer pSimpleRender = newSimpleRendererClass();
pSimpleRender.Symbol = pSymbol;
pGeoFeaLyr.Renderer = pSimpleRender asIFeatureRenderer;
////刷¡é新?
axMapControl.Refresh();
axTOCControl.Update();
}
7唯一值渲染
private voidbtnSimpleRender_ItemClick(object sender, ItemClickEventArgs e)
{
frmFeatureLayerSelect frm =new frmFeatureLayerSelect();
frm.FormLoad(axMapControl.Map, esriFeatureType.esriFTSimple,esriGeometryType.esriGeometryPolygon);
if (frm.ShowDialog() ==DialogResult.OK)
{
IFeatureLayer pFeaLyr = frm.SelectFeatureLayer;
UniqueValueRender(pFeaLyr,pFeaLyr.FeatureClass.FeatureCount(null),pFeaLyr.FeatureClass.OIDFieldName);
}
}
private void UniqueValueRender(IFeatureLayerpFtLayer, int pCount, string pFieldName)
{
IGeoFeatureLayer pGeoFeaturelayer = pFtLayer asIGeoFeatureLayer;
IUniqueValueRenderer pUnique = newUniqueValueRendererClass();
pUnique.FieldCount = 1;
pUnique.set_Field(0, pFieldName);
ISimpleFillSymbol pSimFill = newSimpleFillSymbolClass();
//给?颜?色¦?内¨²部?文?档̦Ì,ê?请?勿e外ªa传ä?
IFeatureCursor pFtCursor =pFtLayer.FeatureClass.Search(null,false);
IFeature pFt = pFtCursor.NextFeature();
IFillSymbol pFillSymbol1;
IRandomColorRamp pColorRamp = newRandomColorRampClass();
pColorRamp.StartHue = 0;
pColorRamp.MinValue = 20;
pColorRamp.MinSaturation = 15;
pColorRamp.EndHue = 360;
pColorRamp.MaxValue = 100;
pColorRamp.MaxSaturation = 30;
pColorRamp.Size = pCount;
bool ok = true;
pColorRamp.CreateRamp(out ok);
IEnumColors pEnumRamp = pColorRamp.Colors;
intpIndex = pFt.Fields.FindField(pFieldName);
while (pFt != null)
{
IColor pColor = pEnumRamp.Next();
if (pColor == null)
{
pEnumRamp.Reset();
pColor = pEnumRamp.Next();
}
pFillSymbol1 = newSimpleFillSymbolClass();
pFillSymbol1.Color = pColor;
pUnique.AddValue(Convert.ToString(pFt.get_Value(pIndex)),pFieldName, pFillSymbol1as ISymbol);
pFt = pFtCursor.NextFeature();
}
pGeoFeaturelayer.Renderer = pUnique asIFeatureRenderer;
axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,null,null);
axTOCControl.Update();
}
9另存为数据
privatevoid btnSaveAsMap_ItemClick(object sender, ItemClickEventArgs e)
{
try
{
SaveFileDialog saveFileDialog =new SaveFileDialog();
saveFileDialog.Title = "另¢¨ª存ä?为a";
saveFileDialog.OverwritePrompt = true;
saveFileDialog.Filter = "ArcMap文?档̦Ì(*.mxd)|*.mxd|ArcMap模¡ê板ã?(*.mxt)|*.mxt";
saveFileDialog.RestoreDirectory = true;
if (saveFileDialog.ShowDialog() ==DialogResult.OK)
{
string sFilePath =saveFileDialog.FileName;
IMapDocument pMapDoc = newMapDocumentClass();
pMapDoc.New(sFilePath);
pMapDoc.ReplaceContents(axMapControl.Map asIMxdContents);
pMapDoc.Save(true,true);
pMapDoc.Close();
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pMapDoc);
}
}
catch (Exceptionex)
{
MessageBox.Show("另¢¨ª存ä?为a失º¡ì败㨹:êo" + ex.Message);
}
}
10保存数据
privatevoid btnSaveMxd_ItemClick(object sender, ItemClickEventArgs e)保存mxd文档
{
try
{
string sFilePath =axMapControl.DocumentFilename;
if (string.IsNullOrEmpty(sFilePath))
{
return;
}
IMapDocument pMapDoc = newMapDocumentClass();
if (axMapControl.CheckMxFile(sFilePath))
{
if (pMapDoc.get_IsReadOnly(sFilePath))
{
MessageBox.Show("本À?文?档̦Ì是º?只?读¨¢的Ì?,ê?不?能¨¹保À¡ê存ä?。¡ê");
return;
}
}
pMapDoc.New(sFilePath);
pMapDoc.ReplaceContents(axMapControl.Map asIMxdContents);
pMapDoc.Save(pMapDoc.UsesRelativePaths, true);
pMapDoc.Close();
ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pMapDoc);
}
}
11 选择图层
using System.Windows.Forms;
usingESRI.ArcGIS.Carto;
usingESRI.ArcGIS.Geodatabase;
usingESRI.ArcGIS.Geometry;
namespace 实º¦Ì验¨¦课?
{
public partial class frmFeatureLayerSelect: DevExpress.XtraEditors.XtraForm
{
///<summary>
///选?择?的Ì?图ª?形?
///</summary>
private IFeatureLayer m_FeatureLayer =null;
public IFeatureLayer SelectFeatureLayer
{
get
{
return m_FeatureLayer;
}
}
public frmFeatureLayerSelect()
{
InitializeComponent();
}
///<summary>
///窗ä¡ã体¬?初?始º?化¡¥
///</summary>
///<param name="Map">地Ì?图ª?窗ä¡ã口¨²</param>
///<param name="featureType">要°a素?类¤¨¤型¨ª</param>
///<param name="geometryType">图ª?形?类¤¨¤型¨ª</param>
public voidFormLoad(IMap Map, esriFeatureTypefeatureType, esriGeometryType geometryType)
{
if (Map == null ||Map.LayerCount == 0)
{
return;
}
this.cboLayer.Properties.Items.Clear();
for (int i = 0; i < Map.LayerCount; i++)
{
IFeatureLayer pFeaLyr = Map.get_Layer(i) asIFeatureLayer;
if (pFeaLyr == null|| pFeaLyr.FeatureClass == null)
{
continue;
}
if (featureType ==esriFeatureType.esriFTAnnotation &&pFeaLyr.FeatureClass.FeatureType ==esriFeatureType.esriFTAnnotation)
{
LayerFun pLyrFun =new LayerFun();
pLyrFun.FeaClsName = (pFeaLyr.FeatureClass asIDataset).Name;
pLyrFun.AliasName = pFeaLyr.FeatureClass.AliasName;
pLyrFun.FeatureLayer = pFeaLyr;
this.cboLayer.Properties.Items.Add(pLyrFun);
}
else if(featureType== esriFeatureType.esriFTSimple)
{
if (pFeaLyr.FeatureClass.ShapeType ==geometryType)
{
LayerFun pLyrFun =new LayerFun();
pLyrFun.FeaClsName =(pFeaLyr.FeatureClassas IDataset).Name;
pLyrFun.AliasName =pFeaLyr.FeatureClass.AliasName;
pLyrFun.FeatureLayer =pFeaLyr;
this.cboLayer.Properties.Items.Add(pLyrFun);
}
}
}
if (this.cboLayer.Properties.Items.Count> 0)
{
this.cboLayer.SelectedIndex = 0;
}
}
private void frmFeatureLayerSelect_FormClosing(object sender,FormClosingEventArgse)
{
if (this.DialogResult==DialogResult.OK)
{
object obj = this.cboLayer.SelectedItem;
if (obj == null)
{
MessageBox.Show("请?选?择?需¨¨要°a符¤?号?化¡¥的Ì?图ª?层?。¡ê");
e.Cancel = true;
return;
}
m_FeatureLayer = (obj asLayerFun).FeatureLayer;
}
}
}
}
- arcgis engine开发学习
- vc arcgis engine开发
- ArcGIS Engine开发入门教程
- Arcgis Engine 开发初步
- Arcgis engine开发
- arcgis engine 基础开发
- ArcGis Engine 开发
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- ArcGIS Engine+C#实例开发
- arcgis 10 engine 开发资源
- arcgis engine 开发 工作空间
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- C#,ArcGIS Engine开发入门教程
- SVN学习(二)-下载与安装
- 测试hadoop安装是否成功
- 开启新的学习之旅
- 菜鸡的从零开始的web笔记-img标签
- 关键字enum
- Arcgis engine开发
- MySQL--使用xtrabackup进行备份还原
- 基于Linux的聊天室(服务器)初成版
- myeclipse导出war包,并把war部署tomcat上运行
- NumPy中的乘法运算符 * 指示按元素计算,矩阵乘法可以使用 dot 函数或创建矩阵对象实现
- BZOJ2669: [cqoi2012]局部极小值
- Leetcode——228. Summary Ranges
- maven 使用本地jar
- shell 读取文件行