ArcServer中的Ao编程--几何体Convert转换
(转mytudousi技术文档:http://hi.baidu.com/mytudousipro/blog)
下面就是从ArcGIS开发帮助上找到的各种转换方法,很全面。这些转换有的并不只是和AO相关。
在说这些转换之间还是先把正题说了,那就是Value object和Com Object之间的转换。
[C#]
ESRI.ArcGIS.ADF.ArcGISServer.PolylineN value_polyline = (ESRI.ArcGIS.ADF.ArcGISServer.PolylineN) ESRI.ArcGIS.ADF.ArcGISServer.Converter.ComObjectToValueObject(com_polyline, servercontext, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolylineN));
[C#]
ESRI.ArcGIS.Geometry.IPolyline com_polyline = (ESRI.ArcGIS.Geometry.IPolyline) ESRI.ArcGIS.ADF.ArcGISServer.Converter.ValueObjectToComObject(value_polyline, servercontext);
我们有几个下面要用到的名词需要解释:(只针对几何体)
Screen :就是.net中的几何体类型,包括点线面等,位于System.Drawing里面。
Web ADF :通用数据源ADF中通用的几何体对象,位于ESRI.ArcGIS.ADF.Web.Geometry里面。
ArcGIS Server SOAP :特殊数据源ArcServer数据源中的几何体类型,位于ESRI.ArcGIS.ADF.ArcGISServer 里面。
ArcGIS Server ArcObjects:就是ArcServer使用的AO远程代理对象,也就是我们平常说的Com对象。
ArcIMS:特殊数据源ArcIMS中的几何体类型,位于ESRI.ArcGIS.ADF.IMS.Geometry中。
Namespace |
Description |
ESRI.ArcGIS.ADF.ArcGISServer.Converter |
Work with ArcGIS Server Web service and Dcom proxy classes and the Value objects shared by both. Convert from Value object to COM object and vise versa. Serialize and deserialize Value objects. |
ESRI.ArcGIS.ADF.Converter |
Work with Web ADF types. Encrypt Identity and manage image bitmap creation. |
ESRI.ArcGIS.ADF.Web.Converter |
Work with Web ADF types. Convert a .NET DataSet to a Web ADF graphics data set. |
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter |
Work with the ArcGIS Server COM and Value object types. Convert to/from Web ADF geometry types, graphics layers, and .NET DataTables. |
ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter |
Work with ArcIMS types. Convert to/from Web ADF geometry types and units. |
ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter |
Used internally for Web ADF controls. Same capabilities as ESRI.ArcGIS.ADF.Web.Converter and ESRI.ArcGIS.ADF.Converter classes. |
ArcServer中各种转换类的功能,这样我们能对ArcServer中的Convert有一个整体的认识。
下面就是各种类型进行转换的具体代码:
Screen to Web ADF
PointEventArgs pointargs = (PointEventArgs)tooleventargs; System.Drawing.Point screen_point = pointargs.ScreenPoint; ESRI.ArcGIS.ADF.Web.Geometry.Point adf_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point.X, screen_point.Y, adf_map.Extent, adf_map.GetTransformationParams(TransformationDirection.ToMap));
Screen to ArcGIS Server SOAP
ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay imgDisp = new ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay(); imgDisp.ImageHeight = (int)adf_map.Height.Value; imgDisp.ImageWidth = (int)adf_map.Width.Value; int[] xvalues = new int[1]; xvalues[0] = screen_point.X; int[] yvalues = new int[1];
Screen to ArcIMS
ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality ims_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality)adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.IMS.Carto.MapView mapview = ims_mapfunctionality.MapView; ESRI.ArcGIS.ADF.IMS.Geometry.Envelope ims_extent = mapview.Extent; ESRI.ArcGIS.ADF.IMS.Geometry.Point ims_point = ESRI.ArcGIS.ADF.IMS.Geometry.Point.ToMapPoint(screen_point, ims_extent, mapview.ImageDescriptor.Width, mapview.ImageDescriptor.Height);
Web ADF to ArcGIS Server SOAP
ESRI.ArcGIS.ADF.ArcGISServer.PointN value_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_point);
Web ADF to ArcGIS Server ArcObjects
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)adf_map.GetFunctionality(ags_local_resource_index); ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mapresourcelocal = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mapfunctionality.Resource; ESRI.ArcGIS.Geometry.IPoint com_point = (ESRI.ArcGIS.Geometry.IPoint) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToIGeometry(adf_point, ags_mapresourcelocal.ServerContextInfo.ServerContext);
Web ADF to ArcIMS
ESRI.ArcGIS.ADF.IMS.Geometry.Point ims_point = (ESRI.ArcGIS.ADF.IMS.Geometry.Point) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToIMSGeometry(adf_point);
ArcGIS Server SOAP to Web ADF
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPoint(value_point);
ArcGIS Server ArcObjects to Web ADF
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPoint(com_point);
ArcIMS to Web ADF
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point = (ESRI.ArcGIS.ADF.Web.Geometry.Point) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToADFGeometry(ims_point);
Polyline
Screen to Web ADF
VectorEventArgs vectorargs = (VectorEventArgs)tooleventargs; System.Drawing.Point[] screen_points = vectorargs.Vectors; ESRI.ArcGIS.ADF.Web.Geometry.PointCollection adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection(); foreach (System.Drawing.Point screen_point in screen_points) { adf_pointcollection.Add(ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint (screen_point, adf_map.Extent, adf_map.GetTransformationParams(TransformationDirection.ToMap)); } ESRI.ArcGIS.ADF.Web.Geometry.Path adf_path = new ESRI.ArcGIS.ADF.Web.Geometry.Path(); adf_path.Points = adf_pointcollection; ESRI.ArcGIS.ADF.Web.Geometry.PathCollection adf_paths = new ESRI.ArcGIS.ADF.Web.Geometry.PathCollection(); adf_paths.Add(adf_path); ESRI.ArcGIS.ADF.Web.Geometry.Polyline adf_polyline = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline(); adf_polyline.Paths = adf_paths;
Screen to ArcGIS Server SOAP
ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay imgDisp = new ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay(); imgDisp.ImageHeight = (int)adf_map.Height.Value; imgDisp.ImageWidth = (int)adf_map.Width.Value; int[] xvalues = new int[screen_points.Length]; int[] yvalues = new int[screen_points.Length]; for (int i = 0; i < screen_points.Length; i++) { xvalues[i] = screen_points[i].X; yvalues[i] = screen_points[i].Y; } ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mapresource = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)ags_mapfunctionality.Resource; ESRI.ArcGIS.ADF.ArcGISServer.MapServerProxy ags_mapserverproxy = ags_mapresource.MapServerProxy; ESRI.ArcGIS.ADF.ArcGISServer.MultipointN value_multipoint = (ESRI.ArcGIS.ADF.ArcGISServer.MultipointN) ags_mapserverproxy.ToMapPoints(ags_mapfunctionality.MapDescription, imgDisp, xvalues, yvalues); ESRI.ArcGIS.ADF.ArcGISServer.Path value_path = new ESRI.ArcGIS.ADF.ArcGISServer.Path(); value_path.PointArray = value_multipoint.PointArray; ESRI.ArcGIS.ADF.ArcGISServer.Path[] value_paths = new ESRI.ArcGIS.ADF.ArcGISServer.Path[1]; value_paths.SetValue(value_path, 0); ESRI.ArcGIS.ADF.ArcGISServer.PolylineN value_polyline = new ESRI.ArcGIS.ADF.ArcGISServer.PolylineN(); value_polyline.PathArray = value_paths;
Screen to ArcIMS[C#]ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality ims_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality) adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.IMS.Carto.MapView mapview = ims_mapfunctionality.MapView; ESRI.ArcGIS.ADF.IMS.Geometry.Envelope ims_extent = mapview.Extent; ESRI.ArcGIS.ADF.IMS.Geometry.PointCollection ims_pointcollection = new ESRI.ArcGIS.ADF.IMS.Geometry.PointCollection(); foreach (System.Drawing.Point screen_point in screen_points) { ESRI.ArcGIS.ADF.IMS.Geometry.Point ims_point = ESRI.ArcGIS.ADF.IMS.Geometry.Point.ToMapPoint(screen_point, ims_extent, mapview.ImageDescriptor.Width, mapview.ImageDescriptor.Height); ims_pointcollection.Add(ims_point); } ESRI.ArcGIS.ADF.IMS.Geometry.Path ims_path = new ESRI.ArcGIS.ADF.IMS.Geometry.Path(); ims_path.Points = ims_pointcollection; ESRI.ArcGIS.ADF.IMS.Geometry.Polyline ims_polyline = new ESRI.ArcGIS.ADF.IMS.Geometry.Polyline(); ims_polyline.Paths.Add(ims_path);
Web ADF to ArcGIS Server SOAP[C#]ESRI.ArcGIS.ADF.ArcGISServer.PolylineN value_polyline = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPolyline(adf_polyline);
Web ADF to ArcGIS Server ArcObjects[C#]ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality) adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mapresourcelocal = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal) ags_mapfunctionality.Resource; ESRI.ArcGIS.Geometry.IPointCollection com_polyline_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection) ags_mapresourcelocal.ServerContextInfo.ServerContext.CreateObject("esriGeometry.Polyline"); object Missing = Type.Missing; foreach (ESRI.ArcGIS.ADF.Web.Geometry.Path new_adf_path in adf_polyline.Paths) { ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection) ags_mapresourcelocal.ServerContextInfo.ServerContext.CreateObject("esriGeometry.Path"); foreach (ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point in new_adf_path.Points) { ESRI.ArcGIS.Geometry.IPoint com_point = (ESRI.ArcGIS.Geometry.IPoint) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToIGeometry(new_adf_point, ags_mapresourcelocal.ServerContextInfo.ServerContext); com_pointcollection.AddPoint(com_point, ref Missing, ref Missing); } com_polyline_pointcollection.AddPointCollection(com_pointcollection); } ESRI.ArcGIS.Geometry.IPolyline com_polyline = (ESRI.ArcGIS.Geometry.IPolyline)com_polyline_pointcollection;
Web ADF to ArcIMS[C#]ESRI.ArcGIS.ADF.IMS.Geometry.Polyline ims_polyline = (ESRI.ArcGIS.ADF.IMS.Geometry.Polyline) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToIMSGeometry(adf_polyline);
ArcGIS Server SOAP to Web ADF[C#]ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_polyline = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolyline(value_polyline);
ArcGIS Server ArcObjects to Web ADF[C#]ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)com_polyline; ESRI.ArcGIS.ADF.Web.Geometry.Point[] new_adf_points = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPointCollection(com_pointcollection); ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
ArcIMS to Web ADF[C#]ESRI.ArcGIS.ADF.Web.Geometry.Polyline new_adf_polyline = (ESRI.ArcGIS.ADF.Web.Geometry.Polyline) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToADFGeometry(ims_polyline);
Polygon
Screen to Web ADF[C#]VectorEventArgs vectorargs = (VectorEventArgs)tooleventargs; System.Drawing.Point[] screen_points = vectorargs.Vectors; ESRI.ArcGIS.ADF.Web.Geometry.PointCollection adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection(); foreach (System.Drawing.Point screen_point in screen_points) { adf_pointcollection.Add(ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point, adf_map.Extent, adf_map.GetTransformationParams(TransformationDirection.ToMap)); } ESRI.ArcGIS.ADF.Web.Geometry.Ring adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring(); adf_ring.Points = adf_pointcollection; ESRI.ArcGIS.ADF.Web.Geometry.RingCollection adf_rings = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection(); adf_rings.Add(adf_ring); ESRI.ArcGIS.ADF.Web.Geometry.Polygon adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon(); adf_polygon.Rings = adf_rings;
Screen to ArcGIS Server SOAP[C#]ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay imgDisp = new ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay(); imgDisp.ImageHeight = (int)adf_map.Height.Value; imgDisp.ImageWidth = (int)adf_map.Width.Value; int[] xvalues = new int[screen_points.Length]; int[] yvalues = new int[screen_points.Length]; for (int i = 0; i < screen_points.Length; i++) { xvalues[i] = screen_points[i].X; yvalues[i] = screen_points[i].Y; } ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality) adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mapresource = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase) ags_mapfunctionality.Resource; ESRI.ArcGIS.ADF.ArcGISServer.MapServerProxy ags_mapserverproxy =ags_mapresource.MapServerProxy; ESRI.ArcGIS.ADF.ArcGISServer.MultipointN value_multipoint = (ESRI.ArcGIS.ADF.ArcGISServer.MultipointN) ags_mapserverproxy.ToMapPoints(ags_mapfunctionality.MapDescription,imgDisp, xvalues, yvalues); ESRI.ArcGIS.ADF.ArcGISServer.Ring value_ring = new ESRI.ArcGIS.ADF.ArcGISServer.Ring(); value_ring.PointArray = value_multipoint.PointArray; ESRI.ArcGIS.ADF.ArcGISServer.Ring[] value_rings = new ESRI.ArcGIS.ADF.ArcGISServer.Ring[1]; value_rings.SetValue(value_ring, 0); ESRI.ArcGIS.ADF.ArcGISServer.PolygonN value_polygon = new ESRI.ArcGIS.ADF.ArcGISServer.PolygonN(); value_polygon.RingArray = value_rings;
Screen to ArcIMS[C#]ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality ims_mapfunctionality =(ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapFunctionality) adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.IMS.Carto.MapView mapview = ims_mapfunctionality.MapView; ESRI.ArcGIS.ADF.IMS.Geometry.Envelope ims_extent = mapview.Extent; ESRI.ArcGIS.ADF.IMS.Geometry.PointCollection ims_pointcollection = new ESRI.ArcGIS.ADF.IMS.Geometry.PointCollection(); foreach (System.Drawing.Point screen_point in screen_points) { ESRI.ArcGIS.ADF.IMS.Geometry.Point ims_point = ESRI.ArcGIS.ADF.IMS.Geometry.Point.ToMapPoint(screen_point, ims_extent, mapview.ImageDescriptor.Width, mapview.ImageDescriptor.Height); ims_pointcollection.Add(ims_point); } ESRI.ArcGIS.ADF.IMS.Geometry.Ring ims_ring = new ESRI.ArcGIS.ADF.IMS.Geometry.Ring(); ims_ring.Points = ims_pointcollection; ESRI.ArcGIS.ADF.IMS.Geometry.Polygon ims_polygon = new ESRI.ArcGIS.ADF.IMS.Geometry.Polygon(); ims_polygon.Rings.Add(ims_ring);
Web ADF to ArcGIS Server SOAP[C#]ESRI.ArcGIS.ADF.ArcGISServer.PolygonN value_polygon = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPolygon(adf_polygon);
Web ADF to ArcGIS Server ArcObjects
[C#]ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality) adf_map.GetFunctionality(0); ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mapresourcelocal = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal) ags_mapfunctionality.Resource; ESRI.ArcGIS.Geometry.IPolygon com_polygon = (ESRI.ArcGIS.Geometry.IPolygon) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToIGeometry(adf_polygon, ags_mapresourcelocal.ServerContextInfo.ServerContext);
Web ADF to ArcIMS[C#]ESRI.ArcGIS.ADF.IMS.Geometry.Polygon ims_polygon = (ESRI.ArcGIS.ADF.IMS.Geometry.Polygon) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToIMSGeometry(adf_polygon);
ArcGIS Server SOAP to Web ADF[C#]ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(value_polygon);
ArcGIS Server ArcObjects to Web ADF
Note: If the ArcObjects polygon was generated using the ITopologicalOperator.Buffer() method, call IPolygon.Densify() to generate an adequate point collection for the Web ADF polygon.[C#]// com_polygon.Densify(0,0); ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)com_polygon; ESRI.ArcGIS.ADF.Web.Geometry.Point[] new_adf_points = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPointCollection(com_pointcollection); ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection(); for (int i = 0; i < new_adf_points.Length - 1; i++) { new_adf_pointcollection.Add(new_adf_points[i]); } ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring(); new_adf_ring.Points = new_adf_pointcollection; ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection(); new_adf_ringcollection.Add(new_adf_ring); ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon(); new_adf_polygon.Rings = new_adf_ringcollection;
ArcIMS to Web ADF[C#]ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = (ESRI.ArcGIS.ADF.Web.Geometry.Polygon) ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter.ToADFGeometry(ims_polygon);