最近在研究ArcGIS Server方面的知識,看了好幾本書,查找了好些資料(說實話在網上找關于GIS方面的資料真的很少),今天花了一個上午的時間把各種圖形選擇工具都研究了一遍,把我的研究結果拿出來跟大家分享分享。
1、單擊選擇:進行單擊選擇的時候,需要把螢幕上的點對象轉換成ADF中的幾何對象(ADF中的點)
2、矩形選擇:矩形選擇就是将螢幕中的矩形轉換成ADF中的矩形對象,也就是把螢幕矩形的點轉換成ADF中的點,然後在把點組裝成ADF中的矩形
3、折線選擇:
4、多邊形選擇
6、圓圈選擇
//一、單擊選擇工具
//進行單擊選擇的時候,需要将螢幕上的點對象轉換成ADF上的幾何對象,轉換程式如下
private ESRI.ArcGIS.ADF.Web.Geometry.Geometry ConvertToADFGeometry(PointEventArgs args, Map adfmap)
{
//1、獲得螢幕上單擊的點對象
System.Drawing.Point screenPoint = args.ScreenPoint;
//2、将螢幕點對象轉換成ADF中的幾何對象
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));
//ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint =ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screenPoint.X,screenPoint.Y,adfmap.Extent,adfmap.Width,adfmap.Height);
//傳回ADF幾何對象
return adfPoint;
}
//二、矩形選擇工具
//矩形選擇也需要把螢幕上的矩形對象轉換成ADF幾何對象(矩形對象),也就是把螢幕矩形的點轉換成ADF的點,然後再構成ADF的矩形,轉換方式如下
// 把螢幕上行的點轉換成ADF矩形對象
private ESRI.ArcGIS.ADF.Web.Geometry.Geometry ConvertToADFGeometry(RectangleEventArgs args,Map adfmap)
{
//1、獲得螢幕矩形對象
System.Drawing.Rectangle screeRectangle = args.ScreenExtent;
//2、将螢幕矩形對象的左上坐标和左下坐标轉換成ADF中的幾何圖形的坐标
ESRI.ArcGIS.ADF.Web.Geometry.Point point1 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screeRectangle.Left, screeRectangle.Bottom, adfmap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
//3、将螢幕矩形對象的右下坐标和右上坐标轉換成ADF中的幾何圖像的坐标
ESRI.ArcGIS.ADF.Web.Geometry.Point point2 = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screeRectangle.Right, screeRectangle.Top, adfmap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
//4、将轉換後的ADF幾何點坐标組裝成ADF中的矩形圖形
ESRI.ArcGIS.ADF.Web.Geometry.Envelope envelope =new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(point1, point2);
//5、傳回ADF中的矩形
return envelope;
}
//折線選擇工具
//折線的轉換方式和矩形的類似
private ESRI.ArcGIS.ADF.Web.Geometry.Geometry ConvertToADFGeometry(PolylineEventArgs args, Map adfmap)
{
//ESRI.ArcGIS.ADF.Web.Geometry.Point adfpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(args.BeginPoint.X,args.BeginPoint.Y,adfmap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
ESRI.ArcGIS.ADF.Web.Geometry.Path path = new ESRI.ArcGIS.ADF.Web.Geometry.Path();
for (int i = 0; i < args.Vectors.Length;i++ )
{
ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = Point.ToMapPoint(args.Vectors[i].X, args.Vectors[i].Y, adfmap.GetTransformationParams(TransformationDirection.ToMap));
path.Points.Add(adfPoint);
}
Polyline polyline = new Polyline();
polyline.Paths.Add(path);
return polyline;
}
//多邊形選擇工具
//多邊形的轉換方式與折線的相似,轉換方式如下
//把螢幕上的點轉換成ADF中的多邊形
private Geometry ConvertToADFGetmetry(PolygonEventArgs args,Map adfmap)
{
//ESRI.ArcGIS.ADF.Web.Geometry.Point adfpoint = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(args.BeginPoint.X,args.BeginPoint.Y,adfmap.GetTransformationParams(ESRI.ArcGIS.ADF.Web.Geometry.TransformationDirection.ToMap));
Ring ring = new Ring();
for (int i = 0; i < args.Vectors.Length;i++ )
{
Point adfPoint = Point.ToMapPoint(args.Vectors[i].X, args.Vectors[i].Y, adfmap.GetTransformationParams(TransformationDirection.ToMap));
ring.Points.Add(adfPoint);
}
Polygon polygon = new Polygon();
polygon.Rings.Add(ring);
return polygon;
}
//圓圈選擇工具
//圓的轉換與上面提到的轉換方式有些差別,因為ADF中麼有圓的對象,是以隻能把圓轉換成多邊形對象。在把圓轉換成多邊形對象的時候,根據圓心、半徑,并在一定的角度取點後,把這些點轉換成ADF中的點,再把ADF中的點轉換成多邊形,轉換方式如下
private Geometry ConvertToADFGetmetry(CircleEventArgs args,Map adfmap)
{
PointCollection pc = new PointCollection();
double degress;
double red = args.Radius;
for (int i = 0; i < 360; i++)
{
degress = i * (Math.PI / 180);
double x = args.CenterPoint.X + Math.Cos(degress) * red;
double y = args.CenterPoint.Y + Math.Sin(degress) * red;
ESRI.ArcGIS.ADF.Web.Geometry.Point point = Point.ToMapPoint((int)Math.Round(x), (int)Math.Round(y), adfmap.GetTransformationParams(TransformationDirection.ToMap));
pc.Add(point);
}
ESRI.ArcGIS.ADF.Web.Geometry.Ring ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
ring.Points = pc;
Polygon polygon = new Polygon();
polygon.Rings.Add(ring);
return polygon;
}