Geometry service GetLengths method
The GetLengths method calculates the length of each input polyline.
GetLengths(SpatialReference SpatialReference, Polyline[] InPolylineArray)
Parameter |
Description |
---|---|
SpatialReference |
The SpatialReference of the geometries in InPolygonArray. Cannot be null. |
InPolylineArray |
The array of polylines on which the length will be calculated. All geometries are assumed to be in the coordinate system defined by SpatialReference. |
Return Value
A double[] containing the length of each polyline in the input array.
Remarks
The length values are computed in the units of the input spatial reference. It is not recommended that this method be used on geometries having latitude-longitude coordinates, since the length would then be calculated in units of "degrees". You can use the GetLengthsGeodesic method to compute accurate lengths for polylines with latitude-longitude coordinates.
Examples
C#
Geometry_GeometryServer geometryService = new Geometry_GeometryServer();
geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";
SpatialReference inputSpatialReference = geometryService.FindSRByWKID("EPSG", 54004, -1, true, true);
// New PointN array
PointN pnt1 = new PointN();
pnt1.X = 100000;
pnt1.Y = 300000;
PointN pnt2 = new PointN();
pnt2.X = 100000;
pnt2.Y = 350000;
PointN pnt3 = new PointN();
pnt3.X = 900000;
pnt3.Y = 350000;
PointN[] pnts1 = new PointN[] { pnt1, pnt2, pnt3 };
// New PolylineN
Path path1 = new Path();
path1.PointArray = pnts1;
Path[] paths = new Path[] { path1 };
PolylineN polylinen = new PolylineN();
polylinen.PathArray = paths;
PolylineN[] polylineArray = new PolylineN[] { polylinen };
double[] lengths = geometryService.GetLengths(inputSpatialReference, polylineArray);
VB.NET
Dim geomeTryService As Geometry_GeometryServer = New Geometry_GeometryServer()
geomeTryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer"
Dim inputSpatialReference As SpatialReference = geomeTryService.FindSRByWKID("EPSG", 54004, -1, True, True)
' New PointN array
Dim pnt1 As PointN = New PointN()
pnt1.X = 100000
pnt1.Y = 300000
Dim pnt2 As PointN = New PointN()
pnt2.X = 100000
pnt2.Y = 350000
Dim pnt3 As PointN = New PointN()
pnt3.X = 900000
pnt3.Y = 350000
Dim pnts1() As PointN = New PointN() {pnt1, pnt2, pnt3}
' New PolylineN
Dim path1 As Path = New Path()
path1.PointArray = pnts1
Dim paths() As Path = New Path() {path1}
Dim polylinen As PolylineN = New PolylineN()
polylinen.PathArray = paths
Dim polylineArray() As PolylineN = New PolylineN() {polylinen}
Dim lengths() As Double = geomeTryService.GetLengths(inputSpatialReference, polylineArray)
Java
String serviceURL = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";
GeometryServerBindingStub geometryService = new GeometryServerBindingStub(serviceURL);
//Test GetLengths
SpatialReference inputSpatialReference3 = geometryService.findSRByWKID(
"EPSG", 54004, -1, true, true);
//Create some points for a polyline
PointN pnt1 = new PointN();
pnt1.setX(100000);
pnt1.setY(300000);
PointN pnt2 = new PointN();
pnt2.setX(100000);
pnt2.setY(350000);
PointN pnt3 = new PointN();
pnt3.setX(900000);
pnt3.setY(350000);
PointN[] points3 = new PointN[] { pnt1, pnt2, pnt3 };
//New PolylineN
Path path3 = new Path();
path3.setPointArray(points3);
Path[] paths3 = new Path[] { path3 };
PolylineN polylineN3 = new PolylineN();
polylineN3.setPathArray(paths3);
PolylineN[] polylineArray3 = new PolylineN[] { polylineN3 };
//Get the length of the polyline
double[] lengths3 = geometryService.getLengths(inputSpatialReference3, polylineArray3);
for (double length : lengths3){
System.out.println("Length: " + length);
}