This document is archived and information here might be outdated.  Recommended version.

Working with GeometryEnvironment (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with geometry > Working with GeometryEnvironment

Working with GeometryEnvironment

About working with GeometryEnvironment

GeometryEnvironment provides a way of creating geometries from different inputs and setting or getting global variables for controlling the behavior of geometry methods. It also provides Java and .NET friendly versions of methods originally defined on other geometry objects (see the IGeometryBridge and IGeometryBridge2 interfaces).
The GeometryEnvironment object is a singleton object (see Interacting with singleton objects), so calling new several times does not create a new object each time. Instead, it returns a reference to the existing GeometryEnvironment object.

Using GeometryEnvironment and SpatialReferenceEnvironment

The following code example uses the IGeometryBridge2 interface on the GeometryEnvironment singleton object to define a polyline from an array of WKSPoint structures. It also uses the SpatialReferenceEnvironment singleton object to create a predefined projected coordinate system. Some of the concepts discussed in the previous introduction are used here.
public IPolyline TestGeometryEnvironment()
    ISpatialReferenceFactory spatialReferenceFactory=new

    //Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
    ISpatialReferenceResolution spatialReferenceResolution =
        esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N)as ISpatialReferenceResolution;
    ISpatialReferenceTolerance spatialReferenceTolerance =
        spatialReferenceResolution as ISpatialReferenceTolerance;
    ISpatialReference spatialReference=spatialReferenceResolution as

    //Create an array of WKSPoint structures starting in the middle of the x,y domain of the 
    //projected coordinate system.

    double xMin;
    double xMax;
    double yMin;
    double yMax;
    spatialReference.GetDomain(out xMin, out xMax, out yMin, out yMax);

    double xFactor=(xMin + xMax) * 0.5;
    double yFactor=(yMin + yMax) * 0.5;

    WKSPoint[] wksPoints=new WKSPoint[10];
    for (int i=0; i < wksPoints.Length; i++)
        wksPoints[i].X=xFactor + i;
        wksPoints[i].Y=yFactor + i;

    IPointCollection4 pointCollection=new PolylineClass();

    IGeometryBridge2 geometryBridge=new GeometryEnvironmentClass();
    geometryBridge.AddWKSPoints(pointCollection, ref wksPoints);

    IPolyline polyline=pointCollection as IPolyline;

    return polyline;
Public Function TestGeometryEnvironment() As IPolyline
    Dim spatialReferenceFactory As ISpatialReferenceFactory=New SpatialReferenceEnvironmentClass()
    'Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
    Dim spatialReferenceResolution As ISpatialReferenceResolution=spatialReferenceFactory.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1983UTM_11N)
    Dim spatialReferenceTolerance As ISpatialReferenceTolerance=CType(spatialReferenceResolution, ISpatialReferenceTolerance)
    Dim spatialReference As ISpatialReference=CType(spatialReferenceResolution, ISpatialReference)
    'Create an array of WKSPoint structures starting in the middle of the x,y domain of the
    'projected coordinate system.
    Dim xMin As Double
    Dim xMax As Double
    Dim yMin As Double
    Dim yMax As Double
    spatialReference.GetDomain(xMin, xMax, yMin, yMax)
    Dim xFactor As Double=(xMin + xMax) * 0.5
    Dim yFactor As Double=(yMin + yMax) * 0.5
    Dim wksPoints(9) As WKSPoint
    For i As Integer=0 To wksPoints.Length - 1 Step 1
        wksPoints(i).X=xFactor + i
        wksPoints(i).Y=yFactor + i
    Next i
    Dim pointCollection As IPointCollection4=New PolylineClass()
    Dim geometryBridge As IGeometryBridge2=New GeometryEnvironmentClass()
    geometryBridge.AddWKSPoints(pointCollection, wksPoints)
    Dim polyline As IPolyline=CType(pointCollection, IPolyline)
    Return polyline
End Function

To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine