Converting between data types

The multi-source nature of the Web ADF means that Web ADF applications may work with one or more different data sources in the same application.  Each data source may operate independently of the Web ADF and maintains its own unique API.  Since the Web ADF integrates and consolidates client-tier interaction with a Web-tier application that works with data sources that are often in the server-tier, converting between data types is often the responsiblity of the Web ADF developer.   This topic covers a number of conversion tasks and capabilities of the Web ADF.  The general topics are geometry, ArcGIS Server COM and Value objects, and datasets. 

The Web ADF maintains multiple Converter classes, each in a different namespace, all with static methods.  The namespace provides an indication of which APIs the Converter class will work with.  These classes are designed to make the conversion process easier and are by no means comprehensive.  

Here is a brief summary of the capabilities of each Converter class:
NamespaceDescription
ESRI.ArcGIS.ADF.ArcGISServer.ConverterWork 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.ConverterWork with Web ADF types.  Encrypt Identity and manage image bitmap creation.
ESRI.ArcGIS.ADF.Web.ConverterWork with Web ADF types.  Convert a .NET DataSet to a Web ADF graphics data set.  Convert a .NET DataTable to a Web ADF graphics layer type.
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.ConverterWork 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.ConverterWork with ArcIMS types.  Convert to/from Web ADF geometry types and units.
ESRI.ArcGIS.ADF.Web.UI.WebControls.ConverterUsed internally for Web ADF controls.  Same capabilities as ESRI.ArcGIS.ADF.Web.Converter and ESRI.ArcGIS.ADF.Converter classes.

Note that some data source APIs maintain their own converter classes.  The ArcWeb Service conversion samples in the geometry section below will provide an example.
Geometry
A core task of a GIS application or service is to work with spatial data - such as retrieving the location of user interaction in a client or defining a spatial filter to select a subset of feature data.  In each tier and for each data source, spatial information must be managed.  As a result, each tier and data source also provides a means for storing and working with geometry.   
The following scenario simulates a process in which multiple geometry types must be utilized.  The goal of this scenario is to buffer a point from a user click on a map in a browser, display the buffer in the map, and use it to display a subset of features in a feature layer.  The process is divided into four steps, each is discussed below:
1) Get the location of a user click on the map in a browser
|
The user entered point in the browser is provided to the Web ADF application in screen units (browser display).  The native .NET drawing library (System.Drawing) is used to store the screen geometry.  The Web ADF converts the geometry from screen units to map units.  The Web ADF maintains its own geometry library to both work with Web ADF specific capabilities (such as GraphicsElementLayer or SpatialFilter) and act as an intermediate type for geometry defined in the client and server tiers.  In this case, the Web ADF geometry is a link between screen geometry and ArcGIS Server geometry. 

2) Use ArcGIS Server local service to buffer the point

The Web ADF cannot buffer a point.  ArcGIS Server local data source can buffer geometry and return the buffer polygon geometry.   In order to work with buffer capabilities in ArcGIS Server local services, we need to convert the Web ADF point to an ArcObjects COM object type point.  
  
3) Display the buffer in a Web ADF graphics layer on the map

The ArcGIS Server local service returns an ArcObjects COM polygon type.  To render this in a Web ADF graphics layer, it needs to be converted to Web ADF polygon. 

4) Use the buffer to select features in an ArcIMS service

To use the Web ADF buffer polygon to display a subset of features in a layer in an ArcIMS service, it needs to be converted to an ArcIMS polygon type.  If we merely needed to query a layer and return a set of features, we can use the Web ADF buffer polygon with IQueryFunctionality.  Since we are attempting to apply a definition to a layer, we must work with the ArcIMS API.    

In this scenario, we traversed three tiers and four different APIs to work with geometry: .NET Framework, Web ADF, ArcGIS Server - ArcObjects COM, and ArcIMS.   All API's were required based on the requirements of the scenario and capabilities of each API.   The Web ADF provides the focal point for API interaction, thus it must provide the means to integrate types from multiple source in a single application.  

The following code snippets provide examples of converting geometry types between different APIs.   They are organized by geometry type: point, polyline, polygon.  Each type includes conversion examples from screen (.NET Framework) to Web ADF and Web ADF to data source API, and data source API to Web ADF.   Converting between ArcGIS Server ArcObjects-COM and SOAP-Value object types is covered in the next section. 

For the sample code snippets below, two variables are assumed to be available:

VariableDescription
tooleventargsWeb ADF ToolEventArgs argument for a custom tool
adf_mapWeb ADF Map control

Notes:

  • ArcGIS Server curve-based geometry types are not supported in the Web ADF geometry model.  To prepare ArcGIS Server curve types, you can use the ArcObjects API to densify or generalize the curve and generate geometry defined by a point collection.  To do this, use the Densify() or Generalize() method on the ArcObjects curve. 
  • A set of static methods on the Web ADF Geometry, Point and Envelope classes (in ESRI.ArcGIS.ADF.Web.Geometry) used to convert to and from screen and map units have been overloaded to support map rotation.  Some methods of the same name but a different signature have been marked obsolete because they do not support rotated maps. Obsolete methods will still work with unrotated map content.  The overloads provide a more efficient pattern for transforming Web ADF geometry via the TransformationParams class.

    TransformationParams stores parameters needed to convert coordinates between screen and map units. The Map control has a GetTransformationParams() method to return a TransformationParams instance set up using Map properties. The TransformationDirection enumeration allows you to select which direction the tranform will take place: either screen to map units (ToMap) or map to screen units (ToScreen). The RotationParams class stores parameters associated with a rotated map extent. The TransformationParams class uses the RotatedParams class to account for rotation when converting coordinates between screen and map units. 

    A single TransformationParams instance can be created from scratch or retrieved from a Map control and used in multiple geometry conversion calls. TransformationDirection.ToMap should be used for ToMap_ methods while TransformationDirection.ToScreen should be used with ToScreen_ methods.
 Point

Screen to Web ADF
  [C#]
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.GetTransformationParams(TransformationDirection.ToMap));
		

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[1];
xvalues[0] = screen_point.X;

int[] yvalues = new int[1];
yvalues[0] = screen_point.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.PointN value_point = (ESRI.ArcGIS.ADF.ArcGISServer.PointN)value_multipoint.PointArray[0];
    

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.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
  [C#]
ESRI.ArcGIS.ADF.ArcGISServer.PointN value_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_point);		
		

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(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
  [C#]
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
  [C#]
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
  [C#]
ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_point =
    ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPoint(com_point);

ArcIMS to Web ADF
  [C#]
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
  [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.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
  [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.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();

for (int i = 0; i < new_adf_points.Length - 1; i++)
{
    new_adf_pointcollection.Add(new_adf_points[i]);
}
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
  [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);


  ArcGIS Server: COM and Value objects
When working with ArcGIS Server, the Web ADF controls and Common API use the inherently stateless ArcGIS Server SOAP API, which includes a set of Value objects and proxies.   An ArcGIS Server Internet data source uses a Web service proxy to serialize Value objects to SOAP and work with an ArcGIS Server Web service endpoint.  An ArcGIS Server local data source uses a DCOM proxy to serialize Value objects to SOAP and work with a server object via the IRequestHandler interface directly.   Whether accessing the SOAP interface of a server object via an Internet or local connection, the the use and limitations of the stateless ArcGIS Server SOAP API are the same.   However, if you are working with an ArcGIS Server local data source, you have access to the server context, and thus the ArcObjects API, via COM on the GIS server.  

The ArcGIS Server ArcObjects API has a rich and comprehensive set of the capabilities.  The ArcGIS Server SOAP API only exposes a portion of ArcObjects capability (via a SOAP interface).  To utilize ArcObjects and work with the Web ADF implementation of ArcGIS Server data sources, which uses the SOAP API, a conversion between ArcObjects COM and SOAP Value objects must occur.   Two converter methods are available in the ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter class to accomplish this:

Converter. COMObjectToValueObject(object, ESRI.ArcGIS.Server.IServerContext, System.Type) returns an ArcGIS Server SOAP API Value 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));    


Converter. ValueObjectToCOMObject(object, ESRI.ArcGIS.Server.IServerContext) returns an ArcGIS Server ArcObjects API COM object. 

[C#]
ESRI.ArcGIS.Geometry.IPolyline com_polyline = (ESRI.ArcGIS.Geometry.IPolyline)
    ESRI.ArcGIS.ADF.ArcGISServer.Converter.ValueObjectToComObject(value_polyline, servercontext);    

Since the SOAP API represents a subset of the ArcObjects API, every Value object has a complimentary COM object. However, not every COM object has a complimentary Value object.  The following table lists some valid conversions between Value object and COM object types.

Value object type     ESRI.ArcGIS.ADF.ArcGISServer.*ArcObjects COM object type
 PointN ESRI.ArcGIS.Geometry.IPoint
 Line ESRI.ArcGIS.Geometry.ILine
 PolylineN ESRI.ArcGIS.Geometry.IPolyline
 PolygonN ESRI.ArcGIS.Geometry.IPolygon
 MapDescription ESRI.ArcGIS.Carto.IMapDescription
 GraphicsElement[] ESRI.ArcGIS.Carto.IGraphicElements
 Field ESRI.ArcGIS.Geodatabase.IField
 RecordSet ESRI.ArcGIS.Geodatabase.IRecordSet


Datasets 

Frequently when working with data sources, you need to manage and interact with tabular data.  In most cases, traversing tables of data requires using the data source specific API methods, properties and techniques.  To more effectively handle data source specific datasets and work with a common standardized ADO.NET data structure, the Web ADF provides a set of utility methods.   These methods convert data source specific tabular data to ADO.NET DataTables and Web ADF GraphicsLayers (extends DataTable).

To convert an ArcGIS Server ArcObjects ESRI.ArcGIS.Geodatabase.IRecordSet or ESRI.ArcGIS.ADF.ArcGISServer.RecordSet to an ADO.NET System.Data.DataTable, use the following static method in the ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer namespace.  The ArcObjects type IRecordSet will first need to be converted to a SOAP Value object RecordSet using the ComObjectToValueObject method discussed in the previous section.
  • ToDataTable(ESRI.ArcGIS.ADF.ArcGISServer.RecordSet)

If the ArcGIS Server RecordSet Value object has a column that contains Geometry Value objects, you can convert the RecordSet to a Web ADF feature graphics layer and display it in a map control.  Use the following static method to return a ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer:

  • ToFeatureGraphicsLayer(ESRI.ArcGIS.ADF.ArcGISServer.RecordSet recordSet)


The Web ADF Common API defines an IQueryFunctionality interface which, if implemented by a data source, provides a number of methods to query data layers exposed by the data source.  The data returned from a query is in the ADO.NET DataTable format.  However, it often contains Web ADF geometry that you would like to display as graphics in a map control.  Instead of creating the Web ADF graphics layer from scratch, the ESRI.ArcGIS.ADF.Web.Converter class contains following static method to create the graphics layer for you:
  • ToGraphicsLayer(System.Data.DataTable)


If all Web ADF geometry  in the DataTable is the same type, a ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer is returned.  If they are different types, an ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer is returned.  In either case, you can add the graphics layer to a Web ADF Graphics resource, if available.  The following example code illustrates how this may be accomplished: [C#]
System.Data.DataTable datatable = queryfunctionality.Query(null, layerids[layer_index], adf_spatialfilter); 
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer graphicslayer = Converter.ToGraphicsLayer(datatable, Color.Yellow, Color.Yellow); 
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsresource = null; 
foreach (IGISFunctionality gisfunctionality in gisfunctionalitycollection) { 
    if (gisfunctionality.Resource.Name == "Selection") 
    { 
        graphicsresource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
        graphicsresource.Graphics.Tables.Clear(); 
    } 
} 
graphicsresource.Graphics.Tables.Add(graphicslayer);

转载于:https://www.cnblogs.com/zany-hui/articles/1598301.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值