arcgis 多边形查询

在default.aspx页面添加多边形控件:

<esri:Tool ClientAction="Polygon" Name="PolygonIdentify" DefaultImage="Images/MapTool/polyquery1.gif"
                    HoverImage="Images/MapTool/polyquery2.gif" SelectedImage="Images/MapTool/polyquery2.gif"
                    ServerActionAssembly="App_Code" ServerActionClass="IdentifyPolygon" Text="PolygonIdentify"
                    ToolTip="多边形查询" />

在app_code里面添加IdentifyPolygon类,实现代码如下:

//添加的命名空间
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.Geometry;

/// <summary>
///IdentifyPolygon 实现多边形查询
/// </summary>
public class IdentifyPolygon : IMapServerToolAction
{
    public IdentifyPolygon()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    void IMapServerToolAction.ServerAction(ToolEventArgs args)
    {
        Map map = args.Control as Map;
        PolygonEventArgs polyArgs = (PolygonEventArgs)args;
        Polygon mapPoly = IdentifyHelper.GetMapPolygon(map, polyArgs);
        IdentifyHelper.IdentifyRectangle(map, mapPoly);
    }

在IdentifyHelper类中添加GetMapPolygon方法:

/// <summary>
    /// 多边形查询
    /// </summary>
    /// <param name="map"></param>
    /// <param name="polyArgs"></param>
    /// <returns></returns>
    public static ESRI.ArcGIS.ADF.Web.Geometry.Polygon GetMapPolygon(Map map, PolygonEventArgs polyArgs)
    {
        System.Drawing.Point[] screenpoly = polyArgs.Vectors;
        PointCollection pc = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
        foreach (System.Drawing.Point dpnt in screenpoly)
        {
            pc.Add(ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(dpnt, map.Extent, (int)map.Width.Value, (int)map.Height.Value));
        }
        ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
        ring.Points = pc;
        RingCollection rings = new RingCollection();
        rings.Add(ring);
        ESRI.ArcGIS.ADF.Web.Geometry.Polygon mapPoly = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
        mapPoly.Rings = rings;
        return mapPoly;
    }

IdentifyRectangle方法在矩形查询里已有了喔!

原文地址:https://www.cnblogs.com/lff255356/p/2737681.html