ArcGIS Server .Net Web ADF之几何类型的相互转换(转)

 

数据类型之间的转换来源于Web ADF支持多元数据。支持多种数据源表示web应用可能会在同一个应用中和不同的数据源打交道。总的来说,每一中数据源都可以脱离Web ADF而独立进行工作,只需要维护自己的Specific APIs。但是由于Web ADF把他们结合在了一起,因此不同数据类型之间的转换就会频繁的在开发中遇到。
Web ADF中提供了各种转换类,在不同的命名空间中以静态方法的方式提供。

ESRI.ArcGIS.ADF.ArcGISServer.Converter 提供从Com对象到Value对象之间的转换。
ESRI.ArcGIS.ADF.Converter
ESRI.ArcGIS.ADF.Web.Converter
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter
ESRI.ArcGIS.ADF.Web.DataSources.IMS.Converter
ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter

因为GIS应用和服务的功能都是和空间数据相关的,都是处理和分析空间数据为主的。比如获得鼠标点击的点,或者是获得空间的要素等,那在实现这些功能的过程中,经常会和geometry打交道,而且geometry也将会是在应用的各个层中互相转换。本文中就主要来介绍web adfCommon APIs和各个specific APIs之间的几何类型的转换。
1  这里有好几种转换,参与的三方有:
.net的几何类型,
web adf的几何类型:这里的web adf的几何类型是指的adf中的common api中的几何类型。
specific api的几何类型。
对于ArcGIS Server来说,对应的Specific api中的对象有两种:一种是是指的ESRI.ArcGIS.ADF.ArcGISServer中的value objects,另一种是arcobjects中的对象。

各种类型之间的转换下面都有详细的例子,先来看看点:
点:
.net drawingweb adf
System.Drawing.Point DotNet_point;。。。。。。。。。
ESRI.ArcGIS.ADF.Web.Geometry.Point adf_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(DotNet _point.X,     DotNet _point.Y, adf_map.Extent, (int)adf_map.Width.Value, (int)adf_map.Height.Value);

.net drawingArcGIS 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] = DotNet _point.X;
int[] yvalues = new int[1];
yvalues[0] = DotNet _point.Y;
//获得mapfuntionality
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality =    (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)adf_map.GetFunctionality(0);
//获得Resource
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mapresource =(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)ags_mapfunctionality.Resource;
//获得MapProxy
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.PointN value_point = (ESRI.ArcGIS.ADF.ArcGISServer.PointN)value_multipoint.PointArray[0];

.net drawingArcIMS
//获得MapFunctionality
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(DotNet _point, ims_extent,     mapview.ImageDescriptor.Width, mapview.ImageDescriptor.Height);

Web ADFArcGIS Server SOAP

ESRI.ArcGIS.ADF.ArcGISServer.PointN value_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_point);

Web ADFArcGIS Server ArcObjects

//获得MapFunctionality

ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mapfunctionality =(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)adf_map.GetFunctionality(ags_local_resource_index);

//获得Resouce

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.WebDataSources.ArcGISServer.Converter.ToIGeometry(adf_point,ags_mapresourcelocal.ServerContextInfo.ServerContext);


Web ADFArcIMS
//直接进行转换
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 SOAPWeb ADF
//直接进行转换
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPoint(value_point);

ArcGIS Server ArcObjectsWeb ADF
//直接进行转换
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point =  ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPoint(com_point);

ArcIMSWeb 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);

 

线:
.net drawing到web adf
ESRI.ArcGIS.ADF.Web.Geometry.PointCollection adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();

foreach (System.Drawing.Point DotNet_point in DotNet_points)
{
adf_pointcollection.Add(ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint
        (DotNet_point, map.Extent, (int)map.Width.Value, (int)map.Height.Value));
}
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;
               
.net drawing 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[DotNet_points.Length];
int[] yvalues = new int[DotNet_points.Length];

for (int i = 0; i < DotNet_points.Length; i++)
{
    xvalues = DotNet_points.X;
    yvalues = DotNet_points.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;

.net drawing到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.PointCollection ims_pointcollection =
    new ESRI.ArcGIS.ADF.IMS.Geometry.PointCollection();

foreach (System.Drawing.Point DotNet_point in DotNet_points)
{
    ESRI.ArcGIS.ADF.IMS.Geometry.Point ims_point =
        ESRI.ArcGIS.ADF.IMS.Geometry.Point.ToMapPoint(DotNet_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
ESRI.ArcGIS.ADF.ArcGISServer.PolylineN value_polyline = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPolyline(adf_polyline);
               
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(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
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
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
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();

for (int i = 0; i < new_adf_points.Length - 1; i++)
{
    new_adf_pointcollection.Add(new_adf_points);
}
ESRI.ArcGIS.ADF.Web.Geometry.Path new_adf_path = new ESRI.ArcGIS.ADF.Web.Geometry.Path();

new_adf_path.Points = new_adf_pointcollection;

ESRI.ArcGIS.ADF.Web.Geometry.PathCollection new_adf_pathcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PathCollection();
adf_pathcollection.Add(new_adf_path);

ESRI.ArcGIS.ADF.Web.Geometry.Polyline new_adf_polyline = new ESRI.ArcGIS.ADF.Web.Geometry.Polyline();
new_adf_polyline.Paths = new_adf_pathcollection;

ArcIMS to Web ADF
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);

posted @ 2009-03-28 13:37  周文  阅读(491)  评论(0编辑  收藏  举报