Geometry service GetAreasAndLengths method

The GetAreasAndLengths method calculates area and perimeter for each polygon in the input array.

GetAreasAndLengths(SpatialReference SpatialReference, Polygon[] InPolygonArray, out double[] Lengths)

Parameter

Description

SpatialReference

The SpatialReference of the geometries in the InPolygonArray parameter. Cannot be null.

InPolygonArray

The array of Polygons on which area and boundary length will be calculated (on each Polygon). All geometries are assumed to be in the coordinate system defined by SpatialReference.

Lengths

A double[] containing the boundary length (perimeter) for each polygon in the input array. The variable is populated when the method is called.

Return Value

A double[] containing the area for each polygon in the input array, InPolygonArray.

Remarks

The area and perimeter 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" and the area would be calculated in units of "square degrees". Use the GetAreasAndLengthsGeodesic, the GetAreasAndLengthsPreserveShape, or the GetLengthsGeodesic method to compute areas and lengths for geometries 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;

 

// New PolygonN

Ring ring1 = new Ring();

ring1.PointArray = pnts1;

Ring[] rings = new Ring[] { ring1 }; class=codesample>PolygonN polygonn = new PolygonN();

polygonn.RingArray = rings;

PolygonN[] polygonArray = new PolygonN[] { polygonn };

 

double[] lengths = null;

double[] areas = geometryService.GetAreasAndLengths(inputSpatialReference, polygonArray, out lengths);

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

 

' New PolygonN

Dim ring1 As Ring = New Ring()

ring1.PointArray = pnts1

Dim rings() As Ring = New Ring() {ring1}

 

Dim polygonn As PolygonN = New PolygonN()

polygonn.RingArray = rings

Dim polygonArray() As PolygonN = New PolygonN() {polygonn}

 

Dim lengths() As Double = Nothing

Dim areas As Double() = geomeTryService.GetAreasAndLengths(inputSpatialReference, polygonArray, lengths)

Java

String serviceURL = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

GeometryServerBindingStub geometryService = new GeometryServerBindingStub(serviceURL);

 

//Test GetAreasAndLength

SpatialReference inputSpatialReference = geometryService.findSRByWKID(

      "EPSG", 54004, -1, true, true);

    

      //New PointN array

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[] points1 = new PointN[] { pnt1, pnt2, pnt3 };

 

//New PolylineN

Path path1 = new Path();

path1.setPointArray(points1);

 

Path[] paths1 = new Path[] { path1 };

 

PolylineN polylinen = new PolylineN();

polylinen.setPathArray(paths1);

 

//New PolygonN

Ring ring1 = new Ring();

ring1.setPointArray(points1);

 

Ring[] rings1 = new Ring[] { ring1 };

 

PolygonN polygonN1 = new PolygonN();

polygonN1.setRingArray(rings1);

 

PolygonN[] polygonArray1 = new PolygonN[] { polygonN1 };

 

//Get areas and length

Holder<double[]> lengthsArray = new Holder<double[]>();

Holder<double[]> areasArray = new Holder<double[]>();

 

geometryService.getAreasAndLengths(inputSpatialReference, polygonArray1,

      lengthsArray, areasArray);

 

//result

System.out.println(areasArray.value[0]);

System.out.println(lengthsArray.value[0]);

2/28/2020