Local (DCOM) connections are only supported for ArcGIS Server versions prior to 10.1.
About the geometry service
A geometry service contains utility methods that provide access to sophisticated and frequently used geometric operations. An ArcGIS for Server instance can only expose one geometry service with the static name "Geometry." Geometry input and output, where required, is always packaged as an array.
Use a geometry service to do the following:
- Buffer, densify, project, relate, and simplify geometry
- Calculate areas, lengths, and label points for geometry
- Edit and construct geometries (splitting polygons, constructing offset polylines, and so on)
- Return well known IDs and text strings for spatial references and units
Refer to series of code snippets below demonstrating usage of some of the functions exposed by GeometryService.
// BUFFER
private static void GeometryServer_Buffer()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = - 120;
point1.Y = 45;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = - 110;
point2.Y = 40;
ESRI.ArcGIS.Geometry.IGeometryArray pInputGeomArray =
serverContext.CreateObject("esriGeometry.GeometryArray")as
IGeometryArray;
pInputGeomArray.Add(point1);
pInputGeomArray.Add(point2);
//Set the distance for buffer
IDoubleArray pDistanceArray = serverContext.CreateObject(
"esriSystem.DoubleArray")as IDoubleArray;
pDistanceArray.Add(200);
pDistanceArray.Add(400);
bool unionResults = false;
ISpatialReferenceFactory2 pSRF = serverContext.CreateObject(
"esriGeometry.SpatialReferenceEnvironment")as ISpatialReferenceFactory2;
ISpatialReference inputSpatialReference =
pSRF.CreateGeographicCoordinateSystem(4326);
ISpatialReference bufferSpatialReference =
pSRF.CreateProjectedCoordinateSystem(102004);
ISpatialReference outputSpatialReference = inputSpatialReference;
//Get the units as US survey Mile
IUnit pUnit = geometryServer.FindUnitsByWKID(null, 9035)as IUnit;
ESRI.ArcGIS.Geometry.IGeometryArray pGeomArrayRes = geometryServer.Buffer
(inputSpatialReference, bufferSpatialReference, outputSpatialReference,
pDistanceArray, pUnit, unionResults, pInputGeomArray);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//DENSIFY
private static void GeometryServer_Densify()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = 500000;
point1.Y = 500000;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = 600000;
point2.Y = 500000;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = 700000;
point3.Y = 500000;
IPointCollection pPointColl = serverContext.CreateObject("esriGeometry.Path")
as IPointCollection;
object _missing = Type.Missing;
pPointColl.AddPoint(point1, ref _missing, ref _missing);
pPointColl.AddPoint(point2, ref _missing, ref _missing);
pPointColl.AddPoint(point3, ref _missing, ref _missing);
IPath inputPath = (IPath)pPointColl;
IGeometryCollection inputPolyline = serverContext.CreateObject(
"esriGeometry.Polyline")as IGeometryCollection;
inputPolyline.AddGeometry(inputPath, ref _missing, ref _missing);
ESRI.ArcGIS.Geometry.IGeometryArray pInputGeomArray =
serverContext.CreateObject("esriGeometry.GeometryArray")as
IGeometryArray;
pInputGeomArray.Add(inputPolyline as IGeometry);
ISpatialReferenceFactory2 pSRF = serverContext.CreateObject(
"esriGeometry.SpatialReferenceEnvironment")as ISpatialReferenceFactory2;
//World Mercator
ISpatialReference inputSpatialReference = serverContext.CreateObject(
"esriGeometry.ProjectedCoordinateSystem")as ISpatialReference;
inputSpatialReference = pSRF.CreateProjectedCoordinateSystem(54004);
double maxSegmentLength = 10000;
bool useDeviationDensification = false;
double densificationParam = 0;
ESRI.ArcGIS.Geometry.IGeometryArray pGeomArrayRes = geometryServer.Densify
(inputSpatialReference, pInputGeomArray, maxSegmentLength,
useDeviationDensification, densificationParam);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//GETAREASANDLENGTH
private static void GeometryServer_GetAreasAndLengths()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
object _missing = Type.Missing;
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = 100000;
point1.Y = 300000;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = 100000;
point2.Y = 350000;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = 900000;
point3.Y = 350000;
//New point collection for path
IPointCollection pPointColl = serverContext.CreateObject("esriGeometry.Path")
as IPointCollection;
pPointColl.AddPoint(point1, ref _missing, ref _missing);
pPointColl.AddPoint(point2, ref _missing, ref _missing);
pPointColl.AddPoint(point3, ref _missing, ref _missing);
//New Polyline
IPath inputPath = (IPath)pPointColl;
IGeometryCollection inputPolyline = serverContext.CreateObject(
"esriGeometry.Polyline")as IGeometryCollection;
inputPolyline.AddGeometry(inputPath, ref _missing, ref _missing);
//point collection for Rings
IPointCollection pRingsPoints = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRingsPoints.AddPoint(point1, ref _missing, ref _missing);
pRingsPoints.AddPoint(point2, ref _missing, ref _missing);
pRingsPoints.AddPoint(point3, ref _missing, ref _missing);
IRing inputRing = (IRing)pRingsPoints;
//New Polygon
IGeometryCollection inputPolygon = serverContext.CreateObject(
"esriGeometry.Polygon")as IGeometryCollection;
inputPolygon.AddGeometry(inputRing, ref _missing, ref _missing);
ESRI.ArcGIS.Geometry.IPolygonArray polygonArray = serverContext.CreateObject
("esriGeometry.PolygonArray")as IPolygonArray;
polygonArray.Add(inputPolygon as IPolygon);
ISpatialReference inputSpatialReference = geometryServer.FindSRByWKID("EPSG",
54004, - 1, true, true);
IDoubleArray lengths = null;
IDoubleArray areas = null;
geometryServer.GetAreasAndLengths(inputSpatialReference, polygonArray, out
areas, out lengths);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//GETLABELPOINTS
private static void GeometryServer_GetLabelPoints()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
object _missing = Type.Missing;
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = 10.0;
point1.Y = 30.0;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = 10.0;
point2.Y = 40.0;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = 20.0;
point3.Y = 40.0;
IPoint point4 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point4.X = 20.0;
point4.Y = 30.0;
IPoint point5 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point5.X = 10.0;
point5.Y = 30.0;
//point collection for Rings
IPointCollection pRingsPoints = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRingsPoints.AddPoint(point1, ref _missing, ref _missing);
pRingsPoints.AddPoint(point2, ref _missing, ref _missing);
pRingsPoints.AddPoint(point3, ref _missing, ref _missing);
pRingsPoints.AddPoint(point4, ref _missing, ref _missing);
pRingsPoints.AddPoint(point5, ref _missing, ref _missing);
IRing inputRing = (IRing)pRingsPoints;
//New Polygon
IGeometryCollection inputPolygon = serverContext.CreateObject(
"esriGeometry.Polygon")as IGeometryCollection;
inputPolygon.AddGeometry(inputRing, ref _missing, ref _missing);
ESRI.ArcGIS.Geometry.IPolygonArray polygonArray = serverContext.CreateObject
("esriGeometry.PolygonArray")as IPolygonArray;
polygonArray.Add(inputPolygon as IPolygon);
// GCS-NAD83
ISpatialReference inputSpatialReference = geometryServer.FindSRByWKID("EPSG",
4269, - 1, true, true);
IPointArray labelPoints = geometryServer.GetLabelPoints
(inputSpatialReference, polygonArray);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//PROJECT
private static void GeometryServer_Project()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
object _missing = Type.Missing;
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
ISpatialReference inputSpatialReference = geometryServer.FindSRByWKID("EPSG",
4326, - 1, true, true);
// USA_Contiguous_Lambert_Conformal_Conic
ISpatialReference outputSpatialReference = geometryServer.FindSRByWKID(
"EPSG", 102004, - 1, true, true);
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = - 120;
point1.Y = 50;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = - 110;
point2.Y = 40;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = - 130;
point3.Y = 40;
//New point collection for path
IPointCollection pPointColl = serverContext.CreateObject("esriGeometry.Path")
as IPointCollection;
pPointColl.AddPoint(point1, ref _missing, ref _missing);
pPointColl.AddPoint(point2, ref _missing, ref _missing);
pPointColl.AddPoint(point3, ref _missing, ref _missing);
//New Polyline
IPath inputPath = (IPath)pPointColl;
IGeometryCollection inputPolyline = serverContext.CreateObject(
"esriGeometry.Polyline")as IGeometryCollection;
inputPolyline.AddGeometry(inputPath, ref _missing, ref _missing);
//point collection for Rings
IPointCollection pRingsPoints = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRingsPoints.AddPoint(point1, ref _missing, ref _missing);
pRingsPoints.AddPoint(point2, ref _missing, ref _missing);
pRingsPoints.AddPoint(point3, ref _missing, ref _missing);
IRing inputRing = (IRing)pRingsPoints;
//New Polygon
IGeometryCollection inputPolygon = serverContext.CreateObject(
"esriGeometry.Polygon")as IGeometryCollection;
inputPolygon.AddGeometry(inputRing, ref _missing, ref _missing);
IGeometryArray inputGeometry = serverContext.CreateObject(
"esriGeometry.GeometryArray")as IGeometryArray;
inputGeometry.Add(point1);
inputGeometry.Add(inputPolyline as IPolyline);
inputGeometry.Add(inputPolygon as IPolygon);
ISpatialReferenceFactory2 pSRF = serverContext.CreateObject(
"esriGeometry.SpatialReferenceEnvironment")as ISpatialReferenceFactory2;
//esriSRGeoTransformation_NAD1983_To_WGS1984_1
IGeoTransformation transformation = (IGeoTransformation)
pSRF.CreateGeoTransformation(1188);
IEnvelope extent = null;
IGeometryArray poutGeomArray = geometryServer.Project(inputSpatialReference,
outputSpatialReference, esriTransformDirection.esriTransformForward,
transformation, extent, inputGeometry);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//RELATION
private static void GeometryServer_Relation()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
object _missing = Type.Missing;
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
ISpatialReference inputSpatialReference = geometryServer.FindSRByWKID("EPSG",
4326, - 1, true, true);
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = 10;
point1.Y = 30;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = 10;
point2.Y = 45;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = 25;
point3.Y = 45;
IPoint point4 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point4.X = 25;
point4.Y = 30;
IPoint point5 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point5.X = 10;
point5.Y = 30;
//point collection for Rings
IPointCollection pRingsPoints = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRingsPoints.AddPoint(point1, ref _missing, ref _missing);
pRingsPoints.AddPoint(point2, ref _missing, ref _missing);
pRingsPoints.AddPoint(point3, ref _missing, ref _missing);
pRingsPoints.AddPoint(point4, ref _missing, ref _missing);
pRingsPoints.AddPoint(point5, ref _missing, ref _missing);
IRing inputRing = (IRing)pRingsPoints;
//New Polygon
IGeometryCollection inputPolygon = serverContext.CreateObject(
"esriGeometry.Polygon")as IGeometryCollection;
inputPolygon.AddGeometry(inputRing, ref _missing, ref _missing);
IGeometryArray inputGeometry = serverContext.CreateObject(
"esriGeometry.GeometryArray")as IGeometryArray;
inputGeometry.Add(inputPolygon as IPolygon);
//Second collection of points with relation to prev polygon
IPoint point1a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1a.X = 20;
point1a.Y = 40;
IPoint point2a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2a.X = 10;
point2a.Y = 30;
IPoint point3a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3a.X = 50;
point3a.Y = 50;
IGeometryArray pRelatedGeomArray = serverContext.CreateObject(
"esriGeometry.GeometryArray")as IGeometryArray;
pRelatedGeomArray.Add(point1a); //inside polygom
pRelatedGeomArray.Add(point2a); //Edge of polygon
pRelatedGeomArray.Add(point3a); //outside polygon
IRelationResultArray pResultArray = geometryServer.Relation
(inputSpatialReference, inputGeometry, pRelatedGeomArray,
esriSpatialRelationEnum.esriSpatialRelationRelation, "G2 INTERSECT G1");
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
//SIMPLIFY
private static void GeometryServer_Simplyfy()
{
IServerContext serverContext = null;
try
{
GISServerConnection serverConnection = new GISServerConnection();
serverConnection.Connect("LocalHost");
IServerObjectManager serverManager = serverConnection.ServerObjectManager;
//Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry",
"GeometryServer");
object _missing = Type.Missing;
// Get the geometry Server Object
ESRI.ArcGIS.Geometry.IGeometryServer geometryServer =
serverContext.ServerObject as ESRI.ArcGIS.Geometry.IGeometryServer;
ISpatialReference inputSpatialReference = geometryServer.FindSRByWKID("EPSG",
4326, - 1, true, true);
IGeometryCollection inputPolygon = serverContext.CreateObject(
"esriGeometry.Polygon")as IGeometryCollection;
//Points for Ring 1
IPoint point1 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1.X = 10;
point1.Y = 30;
IPoint point2 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2.X = 10;
point2.Y = 45;
IPoint point3 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3.X = 25;
point3.Y = 45;
IPoint point4 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point4.X = 25;
point4.Y = 30;
IPoint point5 = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point5.X = 10;
point5.Y = 30;
//Add points to pointcollection to form Ring1
IPointCollection pRing1Points = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRing1Points.AddPoint(point1, ref _missing, ref _missing);
pRing1Points.AddPoint(point2, ref _missing, ref _missing);
pRing1Points.AddPoint(point3, ref _missing, ref _missing);
pRing1Points.AddPoint(point4, ref _missing, ref _missing);
pRing1Points.AddPoint(point5, ref _missing, ref _missing);
IRing inputRing1 = (IRing)pRing1Points;
//Add the Ist ring to geomCollection
inputPolygon.AddGeometry(inputRing1, ref _missing, ref _missing);
//Points for IInd Ring
IPoint point1a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point1a.X = 15;
point1a.Y = 35;
IPoint point2a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point2a.X = 15;
point2a.Y = 50;
IPoint point3a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point3a.X = 30;
point3a.Y = 50;
IPoint point4a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point4a.X = 30;
point4a.Y = 35;
IPoint point5a = serverContext.CreateObject("esriGeometry.Point")as IPoint;
point5a.X = 15;
point5a.Y = 35;
//Add points to pointcollection to form IInd Ring
IPointCollection pRing2Points = serverContext.CreateObject(
"esriGeometry.Ring")as IPointCollection;
pRing2Points.AddPoint(point1a, ref _missing, ref _missing);
pRing2Points.AddPoint(point2a, ref _missing, ref _missing);
pRing2Points.AddPoint(point3a, ref _missing, ref _missing);
pRing2Points.AddPoint(point4a, ref _missing, ref _missing);
pRing2Points.AddPoint(point5a, ref _missing, ref _missing);
IRing inputRing2 = (IRing)pRing1Points;
//Add the IInd ring to geomCollection
inputPolygon.AddGeometry(inputRing2, ref _missing, ref _missing);
IGeometryArray inputGeometry = serverContext.CreateObject(
"esriGeometry.GeometryArray")as IGeometryArray;
inputGeometry.Add(inputPolygon as IPolygon);
IGeometryArray pResulGeomArray = geometryServer.Simplify
(inputSpatialReference, inputGeometry);
}
catch (Exception ex)
{
if (serverContext != null)
serverContext.ReleaseContext();
System.Diagnostics.Debug.WriteLine(ex.Message);
}
finally
{
serverContext.ReleaseContext();
}
}
[VB.NET]
'*****BUFFER
Private Shared Sub GeometryServer_Buffer()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = -120
point1.Y = 45
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = -110
point2.Y = 40
Dim pInputGeomArray As ESRI.ArcGIS.Geometry.IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
pInputGeomArray.Add(point1)
pInputGeomArray.Add(point2)
'Set the distance for buffer
Dim pDistanceArray As IDoubleArray = TryCast(serverContext.CreateObject("esriSystem.DoubleArray"), IDoubleArray)
pDistanceArray.Add(200)
pDistanceArray.Add(400)
Dim unionResults As Boolean = False
Dim pSRF As ISpatialReferenceFactory2 = TryCast(serverContext.CreateObject("esriGeometry.SpatialReferenceEnvironment"), ISpatialReferenceFactory2)
Dim inputSpatialReference As ISpatialReference = pSRF.CreateGeographicCoordinateSystem(4326)
Dim bufferSpatialReference As ISpatialReference = pSRF.CreateProjectedCoordinateSystem(102004)
Dim outputSpatialReference As ISpatialReference = inputSpatialReference
'Get the units as US survey Mile
Dim pUnit As IUnit = TryCast(geometryServer.FindUnitsByWKID(Nothing, 9035), IUnit)
Dim pGeomArrayRes As ESRI.ArcGIS.Geometry.IGeometryArray = geometryServer.Buffer(inputSpatialReference, bufferSpatialReference, outputSpatialReference, pDistanceArray, pUnit, unionResults, pInputGeomArray)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****DENSIFY
Private Shared Sub GeometryServer_Densify()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = 500000
point1.Y = 500000
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = 600000
point2.Y = 500000
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = 700000
point3.Y = 500000
Dim pPointColl As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Path"), IPointCollection)
Dim _missing As Object = Type.Missing
pPointColl.AddPoint(point1, _missing, _missing)
pPointColl.AddPoint(point2, _missing, _missing)
pPointColl.AddPoint(point3, _missing, _missing)
Dim inputPath As IPath = CType(pPointColl, IPath)
Dim inputPolyline As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polyline"), IGeometryCollection)
inputPolyline.AddGeometry(inputPath, _missing, _missing)
Dim pInputGeomArray As ESRI.ArcGIS.Geometry.IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
pInputGeomArray.Add(TryCast(inputPolyline, IGeometry))
Dim pSRF As ISpatialReferenceFactory2 = TryCast(serverContext.CreateObject("esriGeometry.SpatialReferenceEnvironment"), ISpatialReferenceFactory2)
'World Mercator
Dim inputSpatialReference As ISpatialReference = TryCast(serverContext.CreateObject("esriGeometry.ProjectedCoordinateSystem"), ISpatialReference)
inputSpatialReference = pSRF.CreateProjectedCoordinateSystem(54004)
Dim maxSegmentLength As Double = 10000
Dim useDeviationDensification As Boolean = False
Dim densificationParam As Double = 0
Dim pGeomArrayRes As ESRI.ArcGIS.Geometry.IGeometryArray = geometryServer.Densify(inputSpatialReference, pInputGeomArray, maxSegmentLength, useDeviationDensification, densificationParam)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****GETAREASANDLENGTH
Private Shared Sub GeometryServer_GetAreasAndLengths()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
Dim _missing As Object = Type.Missing
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = 100000
point1.Y = 300000
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = 100000
point2.Y = 350000
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = 900000
point3.Y = 350000
'New point collection for path
Dim pPointColl As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Path"), IPointCollection)
pPointColl.AddPoint(point1, _missing, _missing)
pPointColl.AddPoint(point2, _missing, _missing)
pPointColl.AddPoint(point3, _missing, _missing)
'New Polyline
Dim inputPath As IPath = CType(pPointColl, IPath)
Dim inputPolyline As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polyline"), IGeometryCollection)
inputPolyline.AddGeometry(inputPath, _missing, _missing)
'point collection for Rings
Dim pRingsPoints As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRingsPoints.AddPoint(point1, _missing, _missing)
pRingsPoints.AddPoint(point2, _missing, _missing)
pRingsPoints.AddPoint(point3, _missing, _missing)
Dim inputRing As IRing = CType(pRingsPoints, IRing)
'New Polygon
Dim inputPolygon As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polygon"), IGeometryCollection)
inputPolygon.AddGeometry(inputRing, _missing, _missing)
Dim polygonArray As ESRI.ArcGIS.Geometry.IPolygonArray = TryCast(serverContext.CreateObject("esriGeometry.PolygonArray"), IPolygonArray)
polygonArray.Add(TryCast(inputPolygon, IPolygon))
Dim inputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 54004, -1, True, True)
Dim lengths As IDoubleArray = Nothing
Dim areas As IDoubleArray = Nothing
geometryServer.GetAreasAndLengths(inputSpatialReference, polygonArray, areas, lengths)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****GETLABELPOINTS
Private Shared Sub GeometryServer_GetLabelPoints()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
Dim _missing As Object = Type.Missing
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = 10.0
point1.Y = 30.0
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = 10.0
point2.Y = 40.0
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = 20.0
point3.Y = 40.0
Dim point4 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point4.X = 20.0
point4.Y = 30.0
Dim point5 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point5.X = 10.0
point5.Y = 30.0
'point collection for Rings
Dim pRingsPoints As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRingsPoints.AddPoint(point1, _missing, _missing)
pRingsPoints.AddPoint(point2, _missing, _missing)
pRingsPoints.AddPoint(point3, _missing, _missing)
pRingsPoints.AddPoint(point4, _missing, _missing)
pRingsPoints.AddPoint(point5, _missing, _missing)
Dim inputRing As IRing = CType(pRingsPoints, IRing)
'New Polygon
Dim inputPolygon As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polygon"), IGeometryCollection)
inputPolygon.AddGeometry(inputRing, _missing, _missing)
Dim polygonArray As ESRI.ArcGIS.Geometry.IPolygonArray = TryCast(serverContext.CreateObject("esriGeometry.PolygonArray"), IPolygonArray)
polygonArray.Add(TryCast(inputPolygon, IPolygon))
' GCS-NAD83
Dim inputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 4269, -1, True, True)
Dim labelPoints As IPointArray = geometryServer.GetLabelPoints(inputSpatialReference, polygonArray)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****PROJECT
Private Shared Sub GeometryServer_Project()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
Dim _missing As Object = Type.Missing
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim inputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 4326, -1, True, True)
' USA_Contiguous_Lambert_Conformal_Conic
Dim outputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 102004, -1, True, True)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = -120
point1.Y = 50
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = -110
point2.Y = 40
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = -130
point3.Y = 40
'New point collection for path
Dim pPointColl As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Path"), IPointCollection)
pPointColl.AddPoint(point1, _missing, _missing)
pPointColl.AddPoint(point2, _missing, _missing)
pPointColl.AddPoint(point3, _missing, _missing)
'New Polyline
Dim inputPath As IPath = CType(pPointColl, IPath)
Dim inputPolyline As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polyline"), IGeometryCollection)
inputPolyline.AddGeometry(inputPath, _missing, _missing)
'point collection for Rings
Dim pRingsPoints As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRingsPoints.AddPoint(point1, _missing, _missing)
pRingsPoints.AddPoint(point2, _missing, _missing)
pRingsPoints.AddPoint(point3, _missing, _missing)
Dim inputRing As IRing = CType(pRingsPoints, IRing)
'New Polygon
Dim inputPolygon As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polygon"), IGeometryCollection)
inputPolygon.AddGeometry(inputRing, _missing, _missing)
Dim inputGeometry As IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
inputGeometry.Add(point1)
inputGeometry.Add(TryCast(inputPolyline, IPolyline))
inputGeometry.Add(TryCast(inputPolygon, IPolygon))
Dim pSRF As ISpatialReferenceFactory2 = TryCast(serverContext.CreateObject("esriGeometry.SpatialReferenceEnvironment"), ISpatialReferenceFactory2)
'esriSRGeoTransformation_NAD1983_To_WGS1984_1
Dim transformation As IGeoTransformation = CType(pSRF.CreateGeoTransformation(1188), IGeoTransformation)
Dim extent As IEnvelope = Nothing
Dim poutGeomArray As IGeometryArray = geometryServer.Project(inputSpatialReference, outputSpatialReference, esriTransformDirection.esriTransformForward, transformation, extent, inputGeometry)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****RELATION
Private Shared Sub GeometryServer_Relation()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
Dim _missing As Object = Type.Missing
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim inputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 4326, -1, True, True)
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = 10
point1.Y = 30
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = 10
point2.Y = 45
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = 25
point3.Y = 45
Dim point4 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point4.X = 25
point4.Y = 30
Dim point5 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point5.X = 10
point5.Y = 30
'point collection for Rings
Dim pRingsPoints As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRingsPoints.AddPoint(point1, _missing, _missing)
pRingsPoints.AddPoint(point2, _missing, _missing)
pRingsPoints.AddPoint(point3, _missing, _missing)
pRingsPoints.AddPoint(point4, _missing, _missing)
pRingsPoints.AddPoint(point5, _missing, _missing)
Dim inputRing As IRing = CType(pRingsPoints, IRing)
'New Polygon
Dim inputPolygon As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polygon"), IGeometryCollection)
inputPolygon.AddGeometry(inputRing, _missing, _missing)
Dim inputGeometry As IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
inputGeometry.Add(TryCast(inputPolygon, IPolygon))
'Second collection of points with relation to prev polygon
Dim point1a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1a.X = 20
point1a.Y = 40
Dim point2a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2a.X = 10
point2a.Y = 30
Dim point3a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3a.X = 50
point3a.Y = 50
Dim pRelatedGeomArray As IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
pRelatedGeomArray.Add(point1a) 'inside polygom
pRelatedGeomArray.Add(point2a) 'Edge of polygon
pRelatedGeomArray.Add(point3a) 'outside polygon
Dim pResultArray As IRelationResultArray = geometryServer.Relation(inputSpatialReference, inputGeometry, pRelatedGeomArray, esriSpatialRelationEnum.esriSpatialRelationRelation, "G2 INTERSECT G1")
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub
'*****SIMPLIFY
Private Shared Sub GeometryServer_Simplyfy()
Dim serverContext As IServerContext = Nothing
Try
Dim serverConnection As New GISServerConnection()
serverConnection.Connect("LocalHost")
Dim serverManager As IServerObjectManager = serverConnection.ServerObjectManager
'Get GeometryServer Context
serverContext = serverManager.CreateServerContext("Geometry", "GeometryServer")
Dim _missing As Object = Type.Missing
' Get the geometry Server Object
Dim geometryServer As ESRI.ArcGIS.Geometry.IGeometryServer = TryCast(serverContext.ServerObject, ESRI.ArcGIS.Geometry.IGeometryServer)
Dim inputSpatialReference As ISpatialReference = geometryServer.FindSRByWKID("EPSG", 4326, -1, True, True)
Dim inputPolygon As IGeometryCollection = TryCast(serverContext.CreateObject("esriGeometry.Polygon"), IGeometryCollection)
'Points for Ring 1
Dim point1 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1.X = 10
point1.Y = 30
Dim point2 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2.X = 10
point2.Y = 45
Dim point3 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3.X = 25
point3.Y = 45
Dim point4 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point4.X = 25
point4.Y = 30
Dim point5 As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point5.X = 10
point5.Y = 30
'Add points to pointcollection to form Ring1
Dim pRing1Points As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRing1Points.AddPoint(point1, _missing, _missing)
pRing1Points.AddPoint(point2, _missing, _missing)
pRing1Points.AddPoint(point3, _missing, _missing)
pRing1Points.AddPoint(point4, _missing, _missing)
pRing1Points.AddPoint(point5, _missing, _missing)
Dim inputRing1 As IRing = CType(pRing1Points, IRing)
'Add the Ist ring to geomCollection
inputPolygon.AddGeometry(inputRing1, _missing, _missing)
'Points for IInd Ring
Dim point1a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point1a.X = 15
point1a.Y = 35
Dim point2a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point2a.X = 15
point2a.Y = 50
Dim point3a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point3a.X = 30
point3a.Y = 50
Dim point4a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point4a.X = 30
point4a.Y = 35
Dim point5a As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
point5a.X = 15
point5a.Y = 35
'Add points to pointcollection to form IInd Ring
Dim pRing2Points As IPointCollection = TryCast(serverContext.CreateObject("esriGeometry.Ring"), IPointCollection)
pRing2Points.AddPoint(point1a, _missing, _missing)
pRing2Points.AddPoint(point2a, _missing, _missing)
pRing2Points.AddPoint(point3a, _missing, _missing)
pRing2Points.AddPoint(point4a, _missing, _missing)
pRing2Points.AddPoint(point5a, _missing, _missing)
Dim inputRing2 As IRing = CType(pRing1Points, IRing)
'Add the IInd ring to geomCollection
inputPolygon.AddGeometry(inputRing2, _missing, _missing)
Dim inputGeometry As IGeometryArray = TryCast(serverContext.CreateObject("esriGeometry.GeometryArray"), IGeometryArray)
inputGeometry.Add(TryCast(inputPolygon, IPolygon))
Dim pResulGeomArray As IGeometryArray = geometryServer.Simplify(inputSpatialReference, inputGeometry)
Catch ex As Exception
If serverContext IsNot Nothing Then
serverContext.ReleaseContext()
End If
System.Diagnostics.Debug.WriteLine(ex.Message)
Finally
serverContext.ReleaseContext()
End Try
End Sub