arcgis server 9.2代码阅读笔记一:在图层中增加一个点

 

代码来源 ARCGIS 9.2例子 

 

// Copyright 2006 ESRI 

// 

// All rights reserved under the copyright laws of the United States 

// and applicable international laws, treaties, and conventions. 

// 

// You may freely redistribute and use this sample code, with or 

// without modification, provided you include the original copyright 

// notice and use restrictions. 

// AUTHER:糊涂虫 2007.9.19 

// See use restrictions at /arcgis/developerkit/userestrictions. 

 

using System; 

using System.Data; 

using System.Configuration; 

using System.Web; 

using System.Web.Security; 

using System.Web.UI; 

using System.Web.UI.WebControls; 

using System.Web.UI.WebControls.WebParts; 

using System.Web.UI.HtmlControls; 

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools; 

using ESRI.ArcGIS.ADF.Web.UI.WebControls; 

using ESRI.ArcGIS.ADF.ArcGISServer; 

using ESRI.ArcGIS.Server; 

using ESRI.ArcGIS.Carto; 

using ESRI.ArcGIS.Geometry; 

using ESRI.ArcGIS.esriSystem; 

using ESRI.ArcGIS.Display; 

using System.Collections; 

using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer; 

 

public class PointTool : IMapServerToolAction 

public void ServerAction(ToolEventArgs args) 

//获得图层控制 

ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl; 

mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map) args.Control; 

//获得屏幕上点的集合 

PointEventArgs pea = (PointEventArgs)args; 

System.Drawing.Point screen_point = pea.ScreenPoint; 

//获得图层的能力 

MapFunctionality mf = (MapFunctionality) mapctrl.GetFunctionality(0); 

//获得图层的描述 

ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription = mf.MapDescription; 

//把屏幕上的点转换为ADF点 

ESRI.ArcGIS.ADF.Web.Geometry.Point adf_map_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point, mapctrl.Extent, mf.DisplaySettings.ImageDescriptor.Width, mf.DisplaySettings.ImageDescriptor.Height); 

//定义点对象 

PointN ags_map_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_map_point); 

//设置点的颜色 

ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor(); 

rgb.Red = 0; 

rgb.Green = 255; 

rgb.Blue = 0; 

rgb.AlphaValue = 255; 

//设置点的标识符 

ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol sms = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol(); 

sms.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleMarkerStyle.esriSMSDiamond; 

sms.Color = rgb; 

sms.Size = 20.0; 

//设置点 

ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement marker = new ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement(); 

marker.Symbol = sms; 

marker.Point = ags_map_point; 

 

if (mapDescription.CustomGraphics != null) 

//获得该图层上的所有对象 

GraphicElement[] oldges = mapDescription.CustomGraphics; 

//对象的个数 

int cnt = oldges.Length; 

//对象个数加一,并把新的对象(点)放进去 

GraphicElement[] newges = new GraphicElement[cnt + 1]; 

oldges.CopyTo(newges, 0); 

newges[cnt] = marker; 

mapDescription.CustomGraphics = newges; 

else 

GraphicElement[] ges = new GraphicElement[1]; 

ges[0] = marker; 

mapDescription.CustomGraphics = ges; 

 

mapctrl.Refresh(); 

 

这是一个在图层中添加点的例子,添加线段 图形和文字的代码基本上和这差不错,

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangjie_xiaoke/archive/2008/03/05/2150725.aspx

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 ArcGIS Engine 编写代码确定某一个点是否在某个要素类文件的示例: 1. 首先,需要添加以下引用: ```C# using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; ``` 2. 获取要素类文件的 FeatureLayer 对象,可以通过以下方式: ```C# // 打开要素类文件 IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace workspace = workspaceFactory.OpenFromFile("要素类文件路径", 0); IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("要素类名称"); // 创建 FeatureLayer IFeatureLayer featureLayer = new FeatureLayer(); featureLayer.FeatureClass = featureClass; featureLayer.Name = "要素类名称"; ``` 3. 创建一个空间查询过滤器 SpatialFilter,并设置查询条件为点的几何形状与要素类的空间范围相交,可以使用以下代码: ```C# // 创建 SpatialFilter ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = point; // point 为要查询的点 spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; // 设置查询条件为相交 // 设置查询条件为要素类的空间范围 IEnvelope envelope = featureLayer.AreaOfInterest.Envelope; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.SpatialReference = envelope.SpatialReference; spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.WhereClause = featureClass.ShapeFieldName + " intersects " + envelope.XMin + "," + envelope.YMin + "," + envelope.XMax + "," + envelope.YMax; ``` 4. 使用 FeatureLayer 的 Select 方法进行查询,返回的结果是符合条件的要素集合,可以使用以下代码: ```C# // 查询符合条件的要素集合 IFeatureSelection featureSelection = featureLayer as IFeatureSelection; featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); // 获取符合条件的要素集合 IFeatureCursor featureCursor = featureSelection.SelectionSet.Search(null, false); IFeature feature = featureCursor.NextFeature(); ``` 5. 遍历要素集合,判断每个要素的几何形状是否包含该点,可以使用以下代码: ```C# // 判断每个要素的几何形状是否包含该点 while (feature != null) { IGeometry geometry = feature.Shape; if (geometry.Contains(point)) { // 要素类文件存在该点 break; } feature = featureCursor.NextFeature(); } ``` 注意:以上代码仅为示例,实际使用时需要根据具体情况进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值