GeometryService

require(["esri/tasks/GeometryService"], function(GeometryService) { /* code goes here */ });
Class: esri/tasks/GeometryService
Inheritance: GeometryService Task Accessor
Since: ArcGIS API for JavaScript 4.0

Represents a geometry service resource exposed by the ArcGIS REST API. It is used to perform various operations on geometries such as project, simplify, buffer, and relationships.

It is recommended that you create a geometry service for use within your applications. View the About the geometry service help topic in the Server Resource Center for details. Esri hosts a geometry service on sampleserver6.arcgisonline.com to support samples published in the Resource Center. However, we do not guarantee that the service will be available 24/7.

Many of the functions in GeometryService are available for use client-side using GeometryEngine. See GeometryEngine for more details.

See also:

Constructors

new GeometryService(properties)

Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryClass
String

The name of the class.

more details
more detailsAccessor
Object

The options to be used for data requests.

more details
more detailsTask
String

The ArcGIS Server REST service URL of a GeometryService.

more details
more detailsGeometryService

Property Details

declaredClassStringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

requestOptionsObject inherited

The options to be used for data requests. These options can also be controlled through the requestOptions method parameter.

The ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.

Method Overview

NameReturn TypeSummaryClass
Promise<Object>

Computes the area and length for the input polygons.

more details
more detailsGeometryService
Promise<Polygon>

The Auto Complete operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Polygon[]>

Creates buffer polygons at a specified distance around the given geometries.

more details
more detailsGeometryService
Promise<Geometry>

The convexHull operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Object>

The cut operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Geometry[]>

The densify operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Geometry>

The difference operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Number>

Measures the planar or geodesic distance between geometries.

more details
more detailsGeometryService
Promise

Converts an array of well-known strings into xy-coordinates based on the conversion type and spatial reference supplied by the user.

more details
more detailsGeometryService
Promise<Geometry[]>

Generalizes the input geometries using the Douglas-Peucker algorithm.

more details
more detailsGeometryService
Promise<Geometry[]>

The intersect operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Point>

Calculates an interior point for each polygon specified.

more details
more detailsGeometryService
Promise<Object>

Gets the lengths for a Geometry when the geometry type is Polyline.

more details
more detailsGeometryService
Promise<Geometry[]>

Constructs the offset of the input geometries.

more details
more detailsGeometryService
Promise<Geometry[]>

Projects a set of geometries to a new spatial reference.

more details
more detailsGeometryService
Promise<Polygon[]>

Computes the set of pairs of geometries from the input geometry arrays that belong to the specified relation.

more details
more detailsGeometryService
Promise<Geometry>

The reshape operation is performed on a geometry service resource.

more details
more detailsGeometryService
Promise<Geometry[]>

Alters the given geometries to make their definitions topologically legal with respect to their geometry type.

more details
more detailsGeometryService
Promise<String[]>

Converts an array of XY-coordinates into well-known strings based on the conversion type and spatial reference supplied by the user.

more details
more detailsGeometryService
Promise<Geometry[]>

Trims or extends the input polylines using the user specified guide polyline.

more details
more detailsGeometryService
Promise<Geometry>

The union operation is performed on a geometry service resource.

more details
more detailsGeometryService

Method Details

areasAndLengths(areasAndLengthsParameters, requestOptions){Promise<Object>}

Computes the area and length for the input polygons.

Parameters:
areasAndLengthsParameters AreasAndLengthsParameters

Specify the input polygons and optionally the linear and area units.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Object>When resolved, returns an object with the following specification:
{
  areas: <Number[]>,
  lengths: <Number[]>
}
Example:
geometryService.simplify([polygon]).then(function(simplifiedGeometries){
  var areasAndLengthParams = new AreasAndLengthsParameters({
    areaUnit: "square-kilometers",
    lengthUnit: "kilometers",
    polygons: [simplifiedGeometries]
  });
  geometryService.areasAndLengths(areasAndLengthParams).then(function(results){
    console.log("area: ", results.areas[0]);
    console.log("length: ", results.lengths[0]);
  });
});

autoComplete(polygons, polylines, requestOptions){Promise<Polygon>}

The Auto Complete operation is performed on a geometry service resource. The AutoComplete operation simplifies the process of constructing new polygons that are adjacent to other polygons. It constructs polygons that fill in the gaps between existing polygons and a set of polylines.

Parameters:
polygons Polygon[]

The array of polygons that will provide boundaries for new polygons.

polylines Polyline[]

An array of polylines that will provide the remaining boundaries for new polygons.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Polygon>When resolved, returns an array of Polygon geometries containing polygons with the gaps filled with a set of polylines.

buffer(bufferParameters, requestOptions){Promise<Polygon[]>}

Creates buffer polygons at a specified distance around the given geometries.

Parameters:
bufferParameters BufferParameters

Specifies the input geometries, buffer distances, and other options.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Polygon[]>Returns an array of Polygon geometries representing the buffered areas of the input.
See also:
Example:
var webMerPoint = webMercatorUtils.geographicToWebMercator(point);
params.distances = [560];
params.unit = "kilometers";
params.geodesic = true;
params.bufferSpatialReference = new SpatialReference({wkid: 3857});
params.outSpatialReference = view2d.spatialReference;
params.geometries  = [webMerPoint];

geometryService.buffer(params).then(function(results){
  bufferLayer.add(new Graphic({
     geometry: results[0]
  }));
});

convexHull(geometries, requestOptions){Promise<Geometry>}

The convexHull operation is performed on a geometry service resource. It returns the convex hull of the input geometry. The input geometry can be a point, multipoint, polyline or polygon. The hull is typically a polygon but can also be a polyline or point in degenerate cases.

Parameters:
geometries Geometry[]

The geometries whose convex hull is to be created.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry>When resolved, returns a Geometry representing the convex hull of the input.
See also:
Example:
var geoms = pointLayer.graphics.map(function(item, i){
  return webMercatorUtils.geographicToWebMercator(item.geometry);
});
geometryService.convexHull(geoms.toArray()).then(function(result){
  convexLayer.add(new Graphic({
    geometry: result
  }));
},function(error){
   console.log("error occured", error)
});

cut(geometries, cutter, requestOptions){Promise<Object>}

The cut operation is performed on a geometry service resource. This operation splits the input polyline or polygon where it crosses a cutting polyline.

Parameters:
geometries Geometry[]

The polylines or polygons to be cut.

cutter Polyline

The polyline that will be used to divide the target into pieces where it crosses the target.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Object>When resolved, returns an object with the following specification:
{
  cutIndexes: <Number[]>,
  geometries: <Geometry[]>
}
See also:

densify(densifyParameters, requestOptions){Promise<Geometry[]>}

The densify operation is performed on a geometry service resource. This operation densifies geometries by plotting points between existing vertices.

Parameters:
densifyParameters DensifyParameters

The DensifyParameters objects contains geometries, geodesic, lengthUnit, and maxSegmentLength properties.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of geometries defining the densified input features.
See also:
Example:
var params = new DensifyParameters();
params.geodesic = true;
params.lengthUnit = "meters";
params.maxSegmentLength = 30;
params.geometries = [polygon];
geometryService.densify(params).then(function(results){
  layer.add(new Graphic({
    geometry: results[0]
  }));
},function(error){
   console.log("error occured", error)
});

difference(geometries, geometry, requestOptions){Promise<Geometry>}

The difference operation is performed on a geometry service resource. This operation constructs the set-theoretic difference between an array of geometries and another geometry.

Parameters:
geometries Geometry[]

An array of points, multipoints, polylines or polygons.

geometry Geometry

A single geometry of any type, with a dimension equal to or greater than the items in geometries.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry>When resolved, returns an array of geometries defining the difference of the input features.
See also:

distance(params, requestOptions){Promise<Number>}

Measures the planar or geodesic distance between geometries.

Parameters:

Sets the input geometries to measure, distance units, and other parameters.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Number>When resolved, returns a number representing the distance between the input geometries.
See also:

fromGeoCoordinateString(params, requestOptions){Promise}

Converts an array of well-known strings into xy-coordinates based on the conversion type and spatial reference supplied by the user. Only available with ArcGIS Server 10.3 or above.

Parameters:
params Object

See the object specifications table below for the structure of the params object.

Specification:
strings String[]

An array of formatted strings as specified by conversionType. Example: ["01N AA 66021 00000" , "11S NT 00000 62155" , "31U BT 94071 65288"]

The spatial reference or well-known ID to convert the input string coordinates to.

conversionType String

The converstion type of the input strings. The default value is mrgs.

Possible Values: mrgs | usng | utm | geo-ref | gars | dms | ddm | dd

conversionMode String
optional

Conversion options for mrgs, utm and gars conversion types. See the ArcGIS REST API documentation for valid values and their descriptions.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
PromiseWhen resolved, returns an array of XY-coordinate pairs.
Example:
params = {
  conversionType: "geo-ref",
  sr: "4326",
  strings: ["ZGQA5999999900000000","EJCE3864000012728040","NKBH1196052000273924" ]
};

geometryService.fromGeoCoordinateString(params).then(function(results){
  console.log("results", results);
}, function(error){
    console.log(error);
});

generalize(params, requestOptions){Promise<Geometry[]>}

Generalizes the input geometries using the Douglas-Peucker algorithm.

Parameters:

An array of geometries to generalize and a maximum deviation. Optionally set the deviation units.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of geometries defining the generalized geometries of the input.
See also:

intersect(geometries, intersector, requestOptions){Promise<Geometry[]>}

The intersect operation is performed on a geometry service resource. This operation constructs the set-theoretic intersection between an array of geometries and another geometry.

Parameters:
geometries Geometry[]

An array of points, multipoints, polylines, or polygons.

intersector Geometry

A single geometry of any type, of dimension equal to or greater than the dimension of the items in geometries.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of geometries defining the intersection of the input features.
See also:

labelPoints(polygons, requestOptions){Promise<Point>}

Calculates an interior point for each polygon specified. These interior points can be used by clients for labeling the polygons.

Parameters:
polygons Polygon[]

The polygon graphics to process.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Point>When resolved, returns an array of Point geometries defining the interior points of the input polygons that may be used for labeling.
Example:
if (geometries[0].rings.length > 0) {
 geometryService.labelPoints(geometries).then(function(labelPoints) {
  var graphics = labelPoints.map(function(labelPoint, i){
      var textSymbol = {
        type: "text",  // autocasts as new TextSymbol()
        color: "white",
        haloColor: "black",
        haloSize: "1px",
        text: "X: " + number.format(labelPoint.x) + ", Y: " + number.format(labelPoint.y),
        xoffset: 3,
        yoffset: 3,
        font: {  // autocast as new Font()
          size: 12,
          family: "sans-serif",
          weight: "bolder"
        }
      };
    var labelPointGraphic = new Graphic({
      geometry: labelPoint,
      symbol: textSymbol
    });
    return labelPointGraphic;
  });

  // add the labels to the map
  view.graphics.addMany(graphics);
 });
}

lengths(params, requestOptions){Promise<Object>}

Gets the lengths for a Geometry when the geometry type is Polyline

Parameters:

Specify the polylines and optionally the length unit and the geodesic length option.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Object>When resolved, returns an object containing a lengths property, which is an array of numbers, each representing the length of an input line. See object specification below:
{
  lengths: <Number[]>
}

offset(params, requestOptions){Promise<Geometry[]>}

Constructs the offset of the input geometries. If the offsetDistance is positive the constructed offset will be on the right side of the geometry. Left side offsets are constructed with negative values.

Parameters:

Set the geometries to offset, distance, and units.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of geometries offset at the specified distance from the input.
See also:

project(params, requestOptions){Promise<Geometry[]>}

Projects a set of geometries to a new spatial reference.

Parameters:

The input projection parameters.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of projected geometries.
Example:
var geomSer = new GeometryService( ... );
var params = new ProjectParameters();
params.geometries = [point];
params.outSpatialReference = outSpatialReference;
params.transformation = transformation;
geomSer.project(params).then( ... );

relation(params, requestOptions){Promise<Polygon[]>}

Computes the set of pairs of geometries from the input geometry arrays that belong to the specified relation. Both arrays are assumed to be in the same spatial reference. The relations are evaluated in 2D. Z-coordinates are not used. Geometry types cannot be mixed within an array.

Parameters:

The set of parameters required to perform the comparison.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Polygon[]>When resolved, returns an array of Polygon geometries that meet the relation.
See also:
Example:
var geometryService = new GeometryService( ... );

var relationParams = new RelationParameters();
relationParams.geometries1 = geometries[0];
relationParams.geometries2 = geometries[1];
relationParams.relation = "within";

geometryService.relation(relationParams).then( ... );

reshape(targetGeometry, reshaper, requestOptions){Promise<Geometry>}

The reshape operation is performed on a geometry service resource. It reshapes a Polyline or a part of a Polygon using a reshaping line.

Parameters:
targetGeometry Geometry

The Polyline or Polygon to be reshaped.

reshaper Geometry

The single-part polyline that performs the reshaping.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry>When resolved, returns the Geometry defining the reshaped input feature.

simplify(geometries, requestOptions){Promise<Geometry[]>}

Alters the given geometries to make their definitions topologically legal with respect to their geometry type.

Parameters:
geometries Geometry[]

The geometries to simplify.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of the simplified geometries.
See also:
Example:
geometryService.simplify([polygonGraphic.geometry]).then( ... );

toGeoCoordinateString(params, requestOptions){Promise<String[]>}

Converts an array of XY-coordinates into well-known strings based on the conversion type and spatial reference supplied by the user. Only available with ArcGIS Server 10.3 or above.

Parameters:
params Object

See the object specifications table below for the structure of the params object.

Specification:

The spatial reference (or WKID of the spatial reference) of the XY-coordinates to be converted.

coordinates Number[][]

An array of XY-coordinates (in JSON format) to be converted.

conversionType String

The conversion type of the input strings.

Possible values: mgrs | usng | utm | geo-ref | gars | dms | ddm | dd

conversionMode String
optional

Conversion options for mgrs and utm conversion types. See the ArcGIS REST API documentation for valid conversion modes and their descriptions.

numOfDigits Number
optional

The number of digits to output for each of the numerical portions in the string. The default value depends of conversionType. See the ArcGIS REST API documentation for default values.

rounding Boolean
optional

If true, then numeric portions of the string are rounded to the nearest whole magnitude as specified by numOfDigits. Otherwise, numeric portions of the string are truncated. The rounding parameter applies only to conversion types mgrs, usng and geo-ref. The default value is true.

addSpaces Boolean
optional

If true, then spaces are added between components of the string. The addSpaces parameter applies only to conversion types mgrs, usng and utm. The default value for mgrs is false , while the default value for both usng and utm is true.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< String[]>When resolved, returns an array of well-known strings.
Example:
var geomSer = new GeometryService( ... );
var params = {};
params.sr = "4326";
params.coordinates = [ [180,0] , [-117,34] , [0,52] ];
params.conversionType = "mgrs";
params.conversionMode = "mgrsNewWith180InZone01";
params.numOfDigits = 8;

geomSer.toGeoCoordinateString(params).then(function(response){
  // When resolved, these strings are stored in response object
  // response.strings[0] = "01N AA 66021443 00000000"
  // response.strings[1] = "11S NT 00000000 62155978"
  // response.strings[2] = "31U BT 94071081 65288255"
});

trimExtend(params, requestOptions){Promise<Geometry[]>}

Trims or extends the input polylines using the user specified guide polyline. When trimming features, the portion to the left of the cutting line is preserved in the output and the rest is discarded. If the input polyline is not cut or extended then an empty polyline is added to the output array.

Parameters:

Input parameters for the trimExtend operation.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry[]>When resolved, returns an array of the trimmed or extended geometries.

union(geometries, requestOptions){Promise<Geometry>}

The union operation is performed on a geometry service resource. This operation constructs the set-theoretic union of the geometries in the input array. All inputs must be of the same type.

Parameters:
geometries Geometry[]

An array of the geometries to be unioned.

requestOptions Object
optional

Additional options to be used for the data request (will override requestOptions defined during construction).

Returns:
TypeDescription
Promise< Geometry>When resolved, returns a Geometry representing the union of the input features.
See also:

API Reference search results

NameTypeModule

There were no match results from your search criteria.