本文整理汇总了C#中AxMapControl.AddLayer方法的典型用法代码示例。如果您正苦于以下问题:C# AxMapControl.AddLayer方法的具体用法?C# AxMapControl.AddLayer怎么用?C# AxMapControl.AddLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AxMapControl
的用法示例。
在下文中一共展示了AxMapControl.AddLayer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadGeoData
public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN)
{
string strFExtenN = System.IO.Path.GetExtension(strFileN);
switch (strFExtenN)
{
case ".shp":
{
string strPath = System.IO.Path.GetDirectoryName(strFileN);
string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN);
axMapControl1.AddShapeFile(strPath, strFile);
axMapControl2.ClearLayers();
axMapControl2.AddShapeFile(strPath, strFile);
axMapControl2.Extent = axMapControl2.FullExtent;
break;
}
case ".bmp":
case ".tif":
case ".jpg":
case ".img":
{
IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass();
string pathName = System.IO.Path.GetDirectoryName(strFileN);
string fileName = System.IO.Path.GetFileName(strFileN);
IWorkspace pWS = pWSF.OpenFromFile(pathName, 0);
IRasterWorkspace pRWS = pWS as IRasterWorkspace;
IRasterDataset pRasterDataSet = pRWS.OpenRasterDataset(fileName);
IRasterPyramid pRasPyramid = pRasterDataSet as IRasterPyramid;
if (pRasPyramid != null)
{
if (!(pRasPyramid.Present))
{
pRasPyramid.Create();
}
}
IRaster pRaster = pRasterDataSet.CreateDefaultRaster();
IRasterLayer pRasterLayer = new RasterLayerClass();
pRasterLayer.CreateFromRaster(pRaster);
ILayer pLayer = pRasterLayer as ILayer;
axMapControl1.AddLayer(pLayer, 0);
axMapControl2.ClearLayers();
axMapControl2.AddLayer(pLayer, 0);
axMapControl2.Extent = axMapControl2.FullExtent;
break;
}
case ".mxd":
{
if (axMapControl1.CheckMxFile(strFExtenN))
{
axMapControl1.LoadMxFile(strFExtenN);
}
else
MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息");
break;
}
default:
break;
}
}
示例2: Connect2WMS
/// <summary>
/// 连接到WMS服务器,载入WMS图层
/// </summary>
/// <param name="axMapControl1">axMapControl控件</param>
/// <param name="url">WMS服务器地址</param>
public static void Connect2WMS(AxMapControl axMapControl1, string url)
{
#region 初始化环境
IPropertySet pPropertyset = new PropertySetClass();
pPropertyset.SetProperty("url", url);
IWMSConnectionName pWMSConnectionName = new WMSConnectionNameClass();
pWMSConnectionName.ConnectionProperties = pPropertyset;
ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();//Provides access to members that control the creation of layers through a factory.
IWMSGroupLayer pWmsMapLayer = new WMSMapLayerClass();
IDataLayer pDataLayer = pWmsMapLayer as IDataLayer;
pDataLayer.Connect(pWMSConnectionName as IName);
IWMSServiceDescription pWmsServiceDesc = pWmsMapLayer.WMSServiceDescription;
#endregion
#region 获取WMS图层
for (int i = 0; i < pWmsServiceDesc.LayerDescriptionCount; i++)
{
IWMSLayerDescription pWmsLayerDesc = pWmsServiceDesc.get_LayerDescription(i);
ILayer pNewLayer = null;
if (pWmsLayerDesc.LayerDescriptionCount == 0)
{
IWMSLayer pWmsLayer = pWmsMapLayer.CreateWMSLayer(pWmsLayerDesc);
pNewLayer = pWmsLayer as ILayer;
}
else
{
IWMSGroupLayer pWmsGroupLayer = pWmsMapLayer.CreateWMSGroupLayers(pWmsLayerDesc);
for (int j = 0; j < pWmsGroupLayer.Count; j++)
{
ILayer layer = pWmsGroupLayer.get_Layer(j);
if (layer.Name != "admin")
{
pWmsMapLayer.InsertLayer(layer, 0);
layer.Visible = true;
}
}
}
}
#endregion
#region 收尾工作
ILayer pLayer = pWmsMapLayer as ILayer;
pLayer.Name = pWmsServiceDesc.WMSTitle;
pLayer.Visible = true;
axMapControl1.AddLayer(pLayer, 0);
IEnvelope pEnv = axMapControl1.FullExtent;
pEnv.Expand(0.8, 0.8, true);
axMapControl1.Extent = pEnv;
#endregion
}
示例3: init
public void init(int programID, AxMapControl mc, Intersect.ProgramStepUserControl.OnFinish of, MainWindow mw)
{
inited = true;
if (program == null)
program = new Program();
program.id = programID;
program.select();
if (project == null)
project = new Project();
project.id = program.projectID;
project.select();
NetSizeUserControl.init(program.id);
ConditionUserControl.init(program.id);
mapControl = mc;
onFinish = of;
mainWindow = mw;
mapControlMouseDown = null;
//在初始化时就要对valid进行判断.
Thread t = new Thread(delegate()
{
System.Threading.Thread.Sleep(500);
Dispatcher.BeginInvoke((ThreadStart)delegate()
{
if (isValid())
{
valid = true;
onFinish(true);
IFeatureClass resultFeatureClass;
if ((resultFeatureClass = GisUtil.getFeatureClass(System.IO.Path.GetDirectoryName(project.path), "评价结果.shp")) != null)
{
IFeatureLayer resultFeatureLayer = new FeatureLayerClass();
resultFeatureLayer.FeatureClass = resultFeatureClass;
mapControl.AddLayer(resultFeatureLayer);
}
else
{
SiteSelector siteSelector = new SiteSelector(mapControl, program.id);
siteSelector.startSelectSite();
}
}
});
});
t.Start();
}
示例4: AddLayersToEagleEye
public static void AddLayersToEagleEye(AxMapControl axMapControl1,AxMapControl axMapControl2)
{
// 当主地图显示控件的地图更换时,鹰眼中的地图也跟随更换
axMapControl2.Map = new MapClass();
axMapControl2.ClearLayers();
// 添加主地图控件中的所有图层到鹰眼控件中
for (int i = axMapControl1.LayerCount - 1; i >= 0; i--)
{
axMapControl2.AddLayer(axMapControl1.get_Layer(i));
}
// 设置 MapControl 显示范围至数据的全局范围
axMapControl2.Extent = axMapControl1.Extent;
// 刷新鹰眼控件地图
axMapControl2.Refresh();
}
示例5: UpStreamFindParcels
//��˷�ٲ��ҹ����漰�ĵؿ�
public static void UpStreamFindParcels(AxMapControl ppAxMapControl, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork)
{
try
{
IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", ppAxMapControl);
IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", ppAxMapControl);
//����ѡ���Sewer�������д������ΰ�
IGeometryCollection pGeomBag = new GeometryBagClass();
object missing = Type.Missing;
int lEID;
int iUserClassID;
int iUserID;
int iUserSubID;
INetElements pNetElements = pGeoNetwork.Network as INetElements;
pEnumResultEdges.Reset();
IFeature pFeature;
for (int j = 0; j <= pEnumResultEdges.Count - 1; j++)
{
lEID = pEnumResultEdges.Next();
pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID);
pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID);
pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing);
// MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString());
}
//���пռ����˵��Ӳ��������ڲ��ҵؿ���Ϣ
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeomBag as IGeometry;
pSpatialFilter.GeometryField = "Shape";
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;
//��ý��浽�ĵؿ���Ϣ
IFeatureCursor pFeatCursor = pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false);
//���ӱ�ѡ��ĵؿ����ݵ���ͼ��ͼ��ͼ��������
ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass();
ILayer pLayer = pComGraphicLayer as ILayer;
pLayer.Name = "��Ӱ��ĵؿ�";
IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer;
//������ѡ��ĵؿ鵽ͼ��������
ISimpleFillSymbol pSymFill = new SimpleFillSymbolClass();
IFillSymbol pFillSymbol = pSymFill as IFillSymbol;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 0;
pRgbColor.Green = 200;
pRgbColor.Blue = 100;
pFillSymbol.Color = pRgbColor as IColor;
ICartographicLineSymbol pCartoLine = new CartographicLineSymbolClass();
IRgbColor pRgbColor2 = new RgbColorClass();
pRgbColor2.Red = 100;
pRgbColor2.Green = 200;
pRgbColor2.Blue = 100;
pCartoLine.Width = 2;
pCartoLine.Color = pRgbColor2 as IColor;
pFillSymbol.Outline = pCartoLine;
//����������еؿ�����������
IArray pFeatArray = new ArrayClass();
pFeature = pFeatCursor.NextFeature();
while (pFeature != null)
{
IElement pPolyElement = new PolygonElementClass();
IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement;
pPolyElement.Geometry = pFeature.Shape;
pFillShapeElement.Symbol = pFillSymbol;
pGraphicContainer.AddElement(pPolyElement, 0);
pFeatArray.Add(pFeature);
pFeature = pFeatCursor.NextFeature();
}
ppAxMapControl.AddLayer(pGraphicContainer as ILayer);
ppAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
//ma
//frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(ppAxMapControl,pFeatLayerParcels, pFeatArray);
//frmUpstreamCreateOwnerList1.Show();
}
catch (Exception eX)
{
MessageBox.Show(eX.Message);
}
}
示例6: OutPut
public void OutPut(AxMapControl pMapControl, String Path,String Name)
{
// set output featureclass name and shape type
IFeatureClassName pOutName;
pOutName = new FeatureClassNameClass();
pOutName.FeatureType = esriFeatureType.esriFTSimple;
pOutName.ShapeFieldName = "Shape";
pOutName.ShapeType = this.pFeatureClass1.ShapeType;
//set output location and feature class name
IWorkspaceName pWsN;
pWsN = new WorkspaceNameClass();
pWsN.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
//IWorkspaceFactory pWFC;����Factoryʵ�֣�����Щ�����Ĺ�ϵ���е�ģ����
// pWFC = new WorkspaceFactoryClass();
// pWsN = pWFC.Create(Path, "Test", null, 0);
// IFeatureWorkspace pShape;
pWsN.PathName = Path;
IDatasetName pDN;
pDN = pOutName as IDatasetName;
pDN.Name = Name;
pDN.WorkspaceName = pWsN;
//set tolerence
double tol = 0.1;
IBasicGeoprocessor pBGP;
pBGP = new BasicGeoprocessorClass();
pBGP.SpatialReference = pMapControl.Map.SpatialReference;
IFeatureClass pOutClass;
pOutClass = pBGP.Intersect(this.pTable1, false, this.pTable2, false, tol, pOutName);
// pOutClass = pBGP.Union(this.pTable1, false, this.pTable2, false, tol, pOutName);
// pOutClass= pBGP.Clip(this.pTable1, false, this.pTable2, false, tol, pOutName);
/* IArray pArry;
pArry = new ArrayClass();
pArry.Add(pTable1);
pArry.Add(this.pTable2);
pOutClass = pBGP.Merge(pArry, this.pTable1, pOutName);
*/
//ITable pToutTable;
// pToutTable = new TableClass();
//IField pField;
// pField =pFeatureLayer1 .FeatureClass .Fields .get_Field (pFeatureClass1 .FindField ("name"));
IFeatureLayer pOutLayer;
pOutLayer = new FeatureLayerClass();
pOutLayer.FeatureClass = pOutClass;
pOutLayer.Name = pOutClass.AliasName;
pMapControl.AddLayer(pOutLayer);
}
示例7: loadNetworkData
/// <summary>
/// ������������ӵ���ͼ��
/// </summary>
/// <param name="dataPath">��������·��</param>
/// <param name="_mapControl">��ͼ�ؼ�</param>
/// <param name="_pNAContext">INAContext</param>
/// <param name="cmbCost">��ȡ�������ݼ�����Ĵ����ֶ�</param>
/// <param name="isRoute">�Ƿ�ʹ��route</param>
public void loadNetworkData(string dataPath,AxMapControl _mapControl,ref INAContext _pNAContext,ComboBox cmbCost,bool isRoute)
{
IFeatureWorkspace pFWorkspace;
INetworkDataset pNetworkDataset;
INetworkAttribute pNetworkAttribute;
int i;
IFeatureClass pInputFClass;
//��workspace
pFWorkspace=OpenWorkspace(dataPath) as IFeatureWorkspace;
//��network Dataset
pNetworkDataset=OpenNetworkDataset(pFWorkspace as IWorkspace,"Streets_nd");
if(isRoute==false)
_pNAContext=CreateSolverContext(pNetworkDataset);
else
_pNAContext=CreateRouteSolverContext(pNetworkDataset);
// Get Cost Attributes
for(i=0;i<pNetworkDataset.AttributeCount;i++)
{
//get the attribute of the network dataset
pNetworkAttribute=pNetworkDataset.get_Attribute(i);
//if it is a cost attribute,add it to combo box
if(pNetworkAttribute.UsageType==esriNetworkAttributeUsageType.esriNAUTCost)
{
cmbCost.Items.Add(pNetworkAttribute.Name);
}
}
cmbCost.SelectedIndex=0;
if(isRoute==false)
{
pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaIncident");
LoadNANetworkLocations("Incidents",pInputFClass, 100,ref _pNAContext);
}
else
{
}
pInputFClass = pFWorkspace.OpenFeatureClass("BayAreaLocations");
if(isRoute==false)
{
LoadNANetworkLocations("Facilities", pInputFClass, 100,ref _pNAContext);
}
else
{
LoadNANetworkLocations("Stops", pInputFClass, 100,ref _pNAContext);
}
//'Create Layer for Network Dataset and add to ArcMap
ILayer pLayer;
INetworkLayer pNetworkLayer=new NetworkLayerClass();
pNetworkLayer.NetworkDataset = pNetworkDataset;
pLayer = pNetworkLayer as ILayer;
pLayer.Name = "Network Dataset";
_mapControl.AddLayer(pLayer,0);
//Create a Network Analysis Layer and add to ArcMap
INALayer pNALayer=_pNAContext.Solver.CreateLayer(_pNAContext);
pLayer = pNALayer as ILayer;
pLayer.Name = _pNAContext.Solver.DisplayName;
_mapControl.AddLayer(pLayer,0);
}
示例8: OpenRasterDataset
public static void OpenRasterDataset(AxMapControl MapControl,
IRasterDatasetName pRdName, ListView listview1)
{
MapControl.ClearLayers();
MapControl.SpatialReference = null;
listview1.Items.Clear();
listview1.Columns.Clear();
IDatasetName pDsName = pRdName as IDatasetName;
string sName = pDsName.Name;
IName pName = pRdName as IName;
IRasterDataset pRds = pName.Open() as IRasterDataset;
IRasterLayer pRL = new RasterLayerClass();
pRL.CreateFromDataset(pRds);
pRL.Name = sName;
MapControl.AddLayer(pRL as ILayer);
MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
示例9: OpenMosaicDataset
public static void OpenMosaicDataset(AxMapControl MapControl,
IMosaicDatasetName pMdName, ListView listview1)
{
MapControl.ClearLayers();
MapControl.SpatialReference = null;
listview1.Items.Clear();
listview1.Columns.Clear();
IDatasetName pDsName = pMdName as IDatasetName;
string sName = pDsName.Name;
IName pName = pMdName as IName;
IMosaicDataset pMds = pName.Open() as IMosaicDataset;
IFeatureClass pFc = pMds.Catalog;
listview1.Items.Clear();
listview1.Columns.Clear();
LoadListView(pFc, listview1);
IFeatureCursor pCursor = pFc.Search(null, false);
IFeature pfea = pCursor.NextFeature();
int j = 0;
while (pfea != null)
{
ListViewItem lv = new ListViewItem();
for (int i = 0; i < pfea.Fields.FieldCount; i++)
{
string sFieldName = pfea.Fields.get_Field(i).Name;
lv.SubItems.Add(FeatureHelper.GetFeatureValue(pfea, sFieldName).ToString());
}
lv.Tag = pfea;
if (j % 2 == 0)
{
lv.BackColor = System.Drawing.Color.GreenYellow;
}
listview1.Items.Add(lv);
pfea = pCursor.NextFeature();
j++;
}
LSGISHelper.OtherHelper.ReleaseObject(pCursor);
IMosaicLayer pML = new MosaicLayerClass();
pML.CreateFromMosaicDataset(pMds);
MapControl.AddLayer(pML as ILayer);
MapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}