[Visual Basic .NET]Imports System Imports System.Collections.Generic Imports System.Text Imports System.Web.Services.Protocols Imports flintstone Namespace GSClient1 Friend Class Program Private Shared Function CreatePoint(ByVal x As Double, ByVal y As Double) As PointN Dim pP As PointN = New PointN() pP.X = x pP.Y = y Return pP End Function Private Shared Function CreateSquare() As PolygonN Dim pSquare As PolygonN = New PolygonN() Dim pRing As Ring = New Ring() ' points are in clockwise order and from/to point is duplicated pRing.PointArray = New PointN() {CreatePoint(0.0, 0.0), CreatePoint(0.0, 100.0), CreatePoint(100.0, 100.0), CreatePoint(100.0, 0.0), CreatePoint(0.0, 0.0)} pSquare.RingArray = New Ring() {pRing} Return pSquare End Function Shared Sub Main(ByVal args As String()) Dim pGS As Geometry_GeometryServer = New Geometry_GeometryServer() pGS.Url = "http://flintstone/arcgis/services/Geometry/GeometryServer" ' when specifying a URL for a web service programmatically in a .NET framework based app, ' omit the "?wsdl" from the string. ' create an instance of the "USA contiguous Lambert" projected coordinate system (WKID = 102004), ' WKID obtained from http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRProjCSType.htm, ' specify a vertical coordinate system WKID of -1 to indicate no VCS is desired, ' accept the default xy coordinate resolution and default xy cluster tolerance Dim pSR As SpatialReference = pGS.FindSRByWKID(Nothing, 102004, -1, True, True) ' create a unit object representing U.S. Survey feet (http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRUnitType.htm) Dim pU As Unit = pGS.FindUnitsByWKID(Nothing, 9003) ' Define a polygon (a square) and produce 3 concentric buffers for it. ' The Geometry Server WSDL (and other ArcGIS server WSDLs) expose geometry value types in two formats: N and B. For example, ' PolygonN and PolygonB. The N type is basically an array of arrays of points, and the B type is a binary-format stream ' version of a polygon that can be read and written by ArcObjects (the shapefile geometry format). The ESRI Web Applications Developer Framework (WebADF) ' includes functionality that makes it easier to work with these types (http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/adf_overview.htm). ' Details of the shapefile binary stream format can be found at http://support.esri.com/index.cfm?fa=knowledgebase.whitepapers.viewPaper&PID=21&MetaID=279. Dim pSquare As PolygonN = CreateSquare() Dim pBuffers As Geometry() Try pBuffers = pGS.Buffer(pSR, Nothing, Nothing, New Double() {10.0, 20.0, 30.0}, pU, False, New Geometry() {pSquare}) Catch serverException As SoapException System.Console.WriteLine(serverException.Message) End Try ' repeat the buffer operation, but with a custom unit equal to half a meter. ' In this case, there is no WKT or WKID defined for this unit, but WKID can't be <= 0 Dim pMyLU As LinearUnit = New LinearUnit() pMyLU.WKT = "UNIT[""JIM"", 0.5, AUTHORITY[""JIM"", 200000]]" Try pBuffers = pGS.Buffer(pSR, Nothing, Nothing, New Double() {10.0, 20.0, 30.0}, pMyLU, False, New Geometry() {pSquare}) Catch serverException As SoapException System.Console.WriteLine(serverException.Message) End Try ' Finally, cause the server to throw a SOAP exception by specifying angular units for a geometry defined in a planar cooordinate system ' WKID 9102 is degrees (http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRUnitType.htm) Dim pWrongUnit As Unit = pGS.FindUnitsByWKID(Nothing, 9102) Try pBuffers = pGS.Buffer(pSR, Nothing, Nothing, New Double() {10.0, 20.0, 30.0}, pWrongUnit, False, New Geometry() {pSquare}) Catch serverException As SoapException System.Console.WriteLine(serverException.Message) End Try End Sub End Class End Namespace
[C#]The following example uses a geometry server to buffer a geometry using both a predefined unit and a custom unit. The SOAP exception handling mechanism is also illustrated when trying to buffer a geometry, specified in a planar coordinate system, but using an angular unit.
To try out this code, create a new C# console project in Visual Studio 2005, right click on the “Web References” solution explorer item, and specify the URL of a WSDL document for an instance of the ArcGIS Server Geometry Server. The example below assumes that the server machine name is “flintstone”.
http://flintstone/arcgis/services/Geometry/GeometryServer?wsdl
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;namespace GSClient1
{
using flintstone;
class Program
{
static PointN CreatePoint(double x, double y)
{
PointN pP = new PointN();
pP.X = x;
pP.Y = y;
return pP;
}
static PolygonN CreateSquare()
{
PolygonN pSquare = new PolygonN();
Ring pRing = new Ring();
// points are in clockwise order and from/to point is duplicated
pRing.PointArray = new PointN[] {CreatePoint(0.0, 0.0), CreatePoint(0.0, 100.0), CreatePoint(100.0, 100.0), CreatePoint(100.0, 0.0), CreatePoint(0.0, 0.0)};
pSquare.RingArray = new Ring[] {pRing};
return pSquare;
}
static void Main(string[] args)
{
Geometry_GeometryServer pGS = new Geometry_GeometryServer();
pGS.Url = "http://flintstone/arcgis/services/Geometry/GeometryServer"; // when specifying a URL for a web service programmatically in a .NET framework based app,
// omit the "?wsdl" from the string.// create an instance of the "USA contiguous Lambert" projected coordinate system (WKID = 102004),
// WKID obtained from http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRProjCSType.htm,
// specify a vertical coordinate system WKID of -1 to indicate no VCS is desired,
// accept the default xy coordinate resolution and default xy cluster tolerance
SpatialReference pSR = pGS.FindSRByWKID(null, 102004, -1, true, true);
// create a unit object representing U.S. Survey feet (http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRUnitType.htm)
Unit pU = pGS.FindUnitsByWKID(null, 9003);
// Define a polygon (a square) and produce 3 concentric buffers for it.
//
// The Geometry Server WSDL (and other ArcGIS server WSDLs) expose geometry value types in two formats: N and B. For example,
// PolygonN and PolygonB. The N type is basically an array of arrays of points, and the B type is a binary-format stream
// version of a polygon that can be read and written by ArcObjects (the shapefile geometry format). The ESRI Web Applications Developer Framework (WebADF)
// includes functionality that makes it easier to work with these types (http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/adf_overview.htm).
// Details of the shapefile binary stream format can be found at http://support.esri.com/index.cfm?fa=knowledgebase.whitepapers.viewPaper&PID=21&MetaID=279.
PolygonN pSquare = CreateSquare();
Geometry [] pBuffers;
try
{
pBuffers = pGS.Buffer(pSR, null, null, new double[] {10.0, 20.0, 30.0}, pU, false, new Geometry[] {pSquare});
}
catch (SoapException serverException)
{
System.Console.WriteLine(serverException.Message);
}
// repeat the buffer operation, but with a custom unit equal to half a meter.
// In this case, there is no WKT or WKID defined for this unit, but WKID can't be <= 0
LinearUnit pMyLU = new LinearUnit();
pMyLU.WKT = "UNIT[\"JIM\", 0.5, AUTHORITY[\"JIM\", 200000]]";
try
{
pBuffers = pGS.Buffer(pSR, null, null, new double[] {10.0, 20.0, 30.0}, pMyLU, false, new Geometry[] {pSquare});
}
catch (SoapException serverException)
{
System.Console.WriteLine(serverException.Message);
}// Finally, cause the server to throw a SOAP exception by specifying angular units for a geometry defined in a planar cooordinate system
// WKID 9102 is degrees (http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeometry/esriSRUnitType.htm)
Unit pWrongUnit = pGS.FindUnitsByWKID(null, 9102);
try
{
pBuffers = pGS.Buffer(pSR, null, null, new double[] {10.0, 20.0, 30.0}, pWrongUnit, false, new Geometry[] {pSquare});
}
catch (SoapException serverException)
{
System.Console.WriteLine(serverException.Message);
}
}
}
}
[Visual Basic 6.0, C++]
No example is available for Visual Basic 6.0 or C++. To view a Visual Basic .NET or a C# example, click the Language Filter button
in the upper-left corner of the page.