ArcGIS Server 中画点、线、多边形、圆等的重要代码

public void ServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs args)    
{
     ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;

}
1、 点
PointEventArgs  pointEventArgs = (PointEventArgs)args;    
System.Drawing.Point  screenPoint = pointEventArgs.ScreenPoint;
         //屏幕坐标转成地理坐标
 ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenPoint.X, screenPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
 
2、 线
LineEventArgs  lineEventArgs = (LineEventArgs)args;
                //屏幕点
              //屏幕坐标转成地理坐标
 ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.BeginPoint.X, lineEventArgs.BeginPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
                //屏幕坐标转成地理坐标
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.EndPoint.X, lineEventArgs.EndPoint.Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
 ESRI.ArcGIS.ADF.Web.Geometry.Path pa=new ESRI.ArcGIS.ADF.Web.Geometry.Path();
 pa.Points.Add(adfPoint1);
 pa.Points.Add(adfPoint2);
  ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();
 Line.Paths.Add(pa);
 
3、多义线
PolylineEventArgs  lineEventArgs = (PolylineEventArgs)args;
    ESRI.ArcGIS.ADF.Web.Geometry.Path pa = new ESRI.ArcGIS.ADF.Web.Geometry.Path();
  for (int i = 0; i <= lineEventArgs.Vectors.Length - 1; i++)
   {    ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(lineEventArgs.Vectors[i].X, lineEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
         pa.Points.Add(point);
   }              
 ESRI.ArcGIS.ADF.Web.Geometry.Polyline Line = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();
     Line.Paths.Add(pa);
    
4、多边形
 PolygonEventArgs  polygonEventArgs = (PolygonEventArgs)args;            
 ESRI.ArcGIS.ADF.Web.Geometry.Ring points = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();    
 for (int i = 0; i <= polygonEventArgs.Vectors.Length - 1; i++)
  {          ESRI.ArcGIS.ADF.Web.Geometry.Point point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(polygonEventArgs.Vectors[i].X, polygonEventArgs.Vectors[i].Y, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
                   points.Points.Add(point);
  }
    ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
     polygon.Rings.Add(points);
    
5、圆
CircleEventArgs   circleEventArgs = (CircleEventArgs)args;
   ESRI.ArcGIS.ADF.Web.Geometry.PointCollection pc = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
      double degree;
     double rad  = circleEventArgs.Radius;
   for (int i = 0; i < 359; i++)
    {
        degree = i * (Math.PI / 180);                  
      double x = circleEventArgs.CenterPoint.X + Math.Cos(degree) * rad;        
           double y = circleEventArgs.CenterPoint.Y + Math.Sin(degree) * rad;
      ESRI.ArcGIS.ADF.Web.Geometry.Point nPoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint((int)Math.Round(x),(int)Math.Round(y), adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
      pc.Add(nPoint);
     }              
    ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
   ring.Points = pc;             
  ESRI.ArcGIS.ADF.Web.Geometry.RingCollection rings = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
  rings.Add(ring);
   ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
   polygon.Rings = rings;
  
6、矩形
 RectangleEventArgs rectargs = (RectangleEventArgs)args;            
System.Drawing.Rectangle myrect = rectargs.ScreenExtent;
 //矩形左下定点坐标转换成地理坐标
 ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left, myrect.Bottom, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
//矩形右上定点坐标转换成地理坐标             
  ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top, adfMap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap))              
 ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);

 

 

你可能感兴趣的:(server)