ArcObjects Library Reference  

PolylineGeometry

About the Creating a toolbar of globe tools Sample

[C#]

PolylineGeometry.cs

using ESRI.ArcGIS.Geometry;
using System;

namespace GlobeGraphicsToolbar
{
    public class PolylineGeometry
    {
        private IGeometry _geometry;

        public PolylineGeometry(ISpatialReference spatialReference)
        {
            _geometry = GetGeometry(spatialReference);
        }

        public PolylineGeometry(IGeometry baseGeometry)
        {
            _geometry = GetGeometry(baseGeometry);
        }

        private IGeometry GetGeometry(ISpatialReference spatialReference)
        {
            IGeometry geometry;

            IPolyline polyline = new PolylineClass();

            polyline.SpatialReference = spatialReference;

            geometry = polyline as IGeometry;

            MakeZAware(geometry);

            return geometry;
        }

        private IGeometry GetGeometry(IGeometry baseGeometry)
        {
            IGeometry geometry;

            IPolyline polyline = new PolylineClass();

            polyline.SpatialReference = baseGeometry.SpatialReference;

            geometry = polyline as IGeometry;
            
            IPointCollection targetPointCollection = geometry as IPointCollection;

            IPointCollection basePointCollection = baseGeometry as IPointCollection;

            object missing = Type.Missing;

            for (int i = 0; i < basePointCollection.PointCount; i++)
            {
                targetPointCollection.AddPoint(basePointCollection.get_Point(i), ref missing, ref missing);
            }

            MakeZAware(geometry);

            return geometry;
        }

        private void MakeZAware(IGeometry geometry)
        {
            IZAware zAware = geometry as IZAware;
            zAware.ZAware = true;
        }

        public void AddPoint(IPoint point)
        {
            IPointCollection pointCollection = _geometry as IPointCollection;

            object missing = Type.Missing;

            pointCollection.AddPoint(point, ref missing, ref missing);
        }

        public IGeometry Geometry
        {
            get
            {
                return _geometry;
            }
        }

        public int PointCount
        {
            get
            {
                int pointCount;

                IPointCollection pointCollection = _geometry as IPointCollection;

                pointCount = pointCollection.PointCount;

                return pointCount;
            }
        }
    }
}
[Visual Basic .NET]

PolylineGeometry.vb

Imports Microsoft.VisualBasic
Imports ESRI.ArcGIS.Geometry
Imports System

Namespace GlobeGraphicsToolbar
	Public Class PolylineGeometry
		Private _geometry As IGeometry

		Public Sub New(ByVal spatialReference As ISpatialReference)
			_geometry = GetGeometry(spatialReference)
		End Sub

		Public Sub New(ByVal baseGeometry As IGeometry)
			_geometry = GetGeometry(baseGeometry)
		End Sub

		Private Function GetGeometry(ByVal spatialReference As ISpatialReference) As IGeometry
			Dim geometry As IGeometry

			Dim polyline As IPolyline = New PolylineClass()

			polyline.SpatialReference = spatialReference

			geometry = TryCast(polyline, IGeometry)

			MakeZAware(geometry)

			Return geometry
		End Function

		Private Function GetGeometry(ByVal baseGeometry As IGeometry) As IGeometry
			Dim geometry As IGeometry

			Dim polyline As IPolyline = New PolylineClass()

			polyline.SpatialReference = baseGeometry.SpatialReference

			geometry = TryCast(polyline, IGeometry)

			Dim targetPointCollection As IPointCollection = TryCast(geometry, IPointCollection)

			Dim basePointCollection As IPointCollection = TryCast(baseGeometry, IPointCollection)

			Dim missing As Object = Type.Missing

			For i As Integer = 0 To basePointCollection.PointCount - 1
				targetPointCollection.AddPoint(basePointCollection.Point(i), missing, missing)
			Next i

			MakeZAware(geometry)

			Return geometry
		End Function

		Private Sub MakeZAware(ByVal geometry As IGeometry)
			Dim zAware As IZAware = TryCast(geometry, IZAware)
			zAware.ZAware = True
		End Sub

		Public Sub AddPoint(ByVal point As IPoint)
			Dim pointCollection As IPointCollection = TryCast(_geometry, IPointCollection)

			Dim missing As Object = Type.Missing

			pointCollection.AddPoint(point, missing, missing)
		End Sub

		Public ReadOnly Property Geometry() As IGeometry
			Get
				Return _geometry
			End Get
		End Property

		Public ReadOnly Property PointCount() As Integer
			Get
                Dim numPoints As Integer

                Dim pointCollection As IPointCollection = TryCast(_geometry, IPointCollection)

                numPoints = pointCollection.PointCount

                Return numPoints
            End Get
		End Property
	End Class
End Namespace