require(["esri/rest/geometryService"], (geometryService) => { /* code goes here */ });
import * as geometryService from "@arcgis/core/rest/geometryService.js";
esri/rest/geometryService
Represents geometry service resources 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 utilize geometry service functions 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
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Promise<Object> | Computes the area and length for the input polygons. | geometryService | |
The Auto Complete operation is performed on a geometry service resource. | geometryService | ||
Creates buffer polygons at a specified distance around the given geometries. | geometryService | ||
Promise<Geometry> | The convexHull operation is performed on a geometry service resource. | geometryService | |
Promise<Object> | The cut operation is performed on a geometry service resource. | geometryService | |
The densify operation is performed on a geometry service resource. | geometryService | ||
Promise<Geometry> | The difference operation is performed on a geometry service resource. | geometryService | |
Promise<Number> | Measures the planar or geodesic distance between geometries. | geometryService | |
Promise | Converts an array of well-known strings into xy-coordinates based on the conversion type and spatial reference supplied by the user. | geometryService | |
Generalizes the input geometries using the Douglas-Peucker algorithm. | geometryService | ||
The intersect operation is performed on a geometry service resource. | geometryService | ||
Calculates an interior point for each polygon specified. | geometryService | ||
Promise<Object> | Gets the lengths for a Geometry when the geometry type is Polyline | geometryService | |
Constructs the offset of the input geometries based on a planar distance. | geometryService | ||
Projects a set of geometries to a new spatial reference. | geometryService | ||
Computes the set of pairs of geometries from the input geometry arrays that belong to the specified relation. | geometryService | ||
Promise<Geometry> | The reshape operation is performed on a geometry service resource. | geometryService | |
Alters the given geometries to make their definitions topologically legal with respect to their geometry type. | geometryService | ||
Converts an array of XY-coordinates into well-known strings based on the conversion type and spatial reference supplied by the user. | geometryService | ||
Trims or extends the input polylines using the user specified guide polyline. | geometryService | ||
Promise<Geometry> | The union operation is performed on a geometry service resource. | geometryService |
Method Details
-
areasAndLengths
areasAndLengths(url, areasAndLengthsParameters, requestOptions){Promise<Object>}
-
Computes the area and length for the input polygons.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
areasAndLengthsParameters AreasAndLengthsParametersSpecify the input polygons and optionally the linear and area units.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Object> When resolved, returns an object with the following specification: { areas: <Number[]>, lengths: <Number[]> }
Examplesimplify(url, { polygons: [polygon] }).then(function(simplifiedGeometries){ const areasAndLengthParams = new AreasAndLengthsParameters({ areaUnit: "square-kilometers", lengthUnit: "kilometers", polygons: simplifiedGeometries }); areasAndLengths(url, areasAndLengthParams).then(function(results){ console.log("area: ", results.areas[0]); console.log("length: ", results.lengths[0]); }); });
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
The array of polygons that will provide boundaries for new polygons.
An array of polylines that will provide the remaining boundaries for new polygons.
requestOptions ObjectoptionalAdditional options to be used for the data request.
Returns
-
Creates buffer polygons at a specified distance around the given geometries.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
bufferParameters BufferParametersSpecifies the input geometries, buffer distances, and other options.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsExampleconst webMerPoint = webMercatorUtils.geographicToWebMercator(point); const params = new BufferParameters({ distances: [560], unit: "kilometers", geodesic: true, bufferSpatialReference: new SpatialReference({wkid: 3857}), outSpatialReference: view.spatialReference, geometries: [webMerPoint] }); buffer(url, params).then(function(results){ bufferLayer.add(new Graphic({ geometry: results[0] })); });
-
convexHull
convexHull(url, 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
The geometries whose convex hull is to be created.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsExampleconst geoms = pointLayer.graphics.map(function(item, i){ return webMercatorUtils.geographicToWebMercator(item.geometry); }); convexHull(url, { geometries: geoms.toArray() }).then(function(result){ convexLayer.add(new Graphic({ geometry: result })); },function(error){ console.log("error occurred", error) });
-
cut
cut(url, 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
The polylines or polygons to be cut.
cutter PolylineThe polyline that will be used to divide the target into pieces where it crosses the target.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Object> When resolved, returns an object with the following specification: { cutIndexes: <Number[]>, geometries: <Geometry[]> }
-
The densify operation is performed on a geometry service resource. This operation densifies geometries by plotting points between existing vertices.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
densifyParameters DensifyParametersThe DensifyParameters objects contains
geometries
,geodesic
,lengthUnit
, andmaxSegmentLength
properties.requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of geometries defining the densified input features. Exampleconst params = new DensifyParameters({ geodesic: true, lengthUnit: "meters", maxSegmentLength: 30, geometries: [polygon] }); densify(url, params).then(function(results){ layer.add(new Graphic({ geometry: results[0] })); }.catch(function(error){ console.log("error occurred", error) });
-
difference
difference(url, 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
An array of points, multipoints, polylines or polygons.
geometry GeometryA single geometry of any type, with a dimension equal to or greater than the items in geometries.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry> When resolved, returns an array of geometries defining the difference of the input features.
-
distance
distance(url, distanceParameters, requestOptions){Promise<Number>}
-
Measures the planar or geodesic distance between geometries.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
distanceParameters DistanceParametersSets the input geometries to measure, distance units, and other parameters.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Number> When resolved, returns a number representing the distance between the input geometries.
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
params ObjectSee the object specifications table below for the structure of the
params
object.SpecificationAn 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 StringoptionalDefault Value: mrgsThe conversion type of the input strings.
Possible Values:"mrgs"|"usng"|"utm"|"geo-ref"|"gars"|"dms"|"ddm"|"dd"
conversionMode StringoptionalConversion options for mrgs, utm and gars conversion types. See the ArcGIS REST API documentation for possible values and their descriptions.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise When resolved, returns an array of XY-coordinate pairs. Exampleparams = { conversionType: "geo-ref", sr: "4326", strings: ["ZGQA5999999900000000","EJCE3864000012728040","NKBH1196052000273924" ] }; fromGeoCoordinateString(url, params).then(function(results){ console.log("results", results); }, function(error){ console.log(error); });
-
Generalizes the input geometries using the Douglas-Peucker algorithm.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
generalizeParameters GeneralizeParametersAn array of geometries to generalize and a maximum deviation. Optionally set the deviation units.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of geometries defining the generalized geometries of the input.
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
An array of points, multipoints, polylines, or polygons.
intersector GeometryA single geometry of any type, of dimension equal to or greater than the dimension of the items in
geometries
.requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of geometries defining the intersection of the input features.
-
Calculates an interior point for each polygon specified. These interior points can be used by clients for labeling the polygons.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
The polygon graphics to process.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsExampleif (geometries[0].rings.length > 0) { labelPoints(url, { geometries: geometries }).then(function(labelPoints) { const graphics = labelPoints.map(function(labelPoint, i){ const 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" } }; const labelPointGraphic = new Graphic({ geometry: labelPoint, symbol: textSymbol }); return labelPointGraphic; }); // add the labels to the map view.graphics.addMany(graphics); }); }
-
lengths
lengths(url, lengthsParameters, requestOptions){Promise<Object>}
-
Parametersurl String
The ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
lengthsParameters LengthsParametersSpecify the polylines and optionally the length unit and the geodesic length option.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description 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[]> }
-
Constructs the offset of the input geometries based on a planar distance. 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
offsetParameters OffsetParametersSet the geometries to offset, distance, and units.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of geometries offset at the specified distance from the input.
-
Projects a set of geometries to a new spatial reference.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
projectParameters ProjectParametersThe input projection parameters.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of projected geometries. Examplerequire([ "esri/rest/geometryService", "esri/rest/support/ProjectParameters" ], function(geometryService, ProjectParameters) { const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; const params = new ProjectParameters({ geometries: [point], outSpatialReference: outSpatialReference, transformation: transformation }); geometryService.project(url, params).then(function(response){ console.log("results: ", response); }); });
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
relationParameters RelationParametersThe set of parameters required to perform the comparison.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsExamplerequire([ "esri/rest/geometryService", "esri/rest/support/RelationParameters" ], function(geometryService, RelationParameters) { const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; const params = new RelationParameters({ geometries1: geometries[0], geometries2: geometries[1], relation: "within" }); geometryService.relation(url, params).then(function(response){ console.log("results: ", response); }); });
-
reshape
reshape(url, geometry, 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
geometry GeometryThe Polyline or Polygon to be reshaped.
reshaper PolylineThe single-part polyline that performs the reshaping.
requestOptions ObjectoptionalAdditional options to be used for the data request.
Returns
-
Alters the given geometries to make their definitions topologically legal with respect to their geometry type.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
The geometries to simplify.
requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Geometry[]> When resolved, returns an array of the simplified geometries. ExamplegeometryService.simplify(url, [polygonGraphic.geometry]).then( ... );
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
params ObjectSee the object specifications table below for the structure of the
params
object.SpecificationThe spatial reference (or WKID of the spatial reference) of the XY-coordinates to be converted.
An array of XY-coordinates (in JSON format) to be converted.
conversionType StringThe conversion type of the input strings.
Possible Values:"mgrs"|"usng"|"utm"|"geo-ref"|"gars"|"dms"|"ddm"|"dd"
conversionMode StringoptionalConversion options for mgrs and utm conversion types. See the ArcGIS REST API documentation for valid conversion modes and their descriptions.
numOfDigits NumberoptionalThe 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 BooleanoptionalDefault Value: trueIf
true
, then numeric portions of the string are rounded to the nearest whole magnitude as specified bynumOfDigits
. Otherwise, numeric portions of the string are truncated. The rounding parameter applies only to conversion typesmgrs
,usng
andgeo-ref
.addSpaces BooleanoptionalIf
true
, then spaces are added between components of the string. TheaddSpaces
parameter applies only to conversion typesmgrs
,usng
andutm
. The default value formgrs
isfalse
, while the default value for bothusng
andutm
istrue
.requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsExamplerequire([ "esri/rest/geometryService" ], function(geometryService) { const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; const params = { sr: "4326", coordinates: [ [180,0] , [-117,34] , [0,52] ], conversionType: "mgrs", conversionMode: "mgrsNewWith180InZone01", numOfDigits: 8 }; geometryService.toGeoCoordinateString(url, 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" }); });
-
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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
trimExtendParameters TrimExtendParametersInput parameters for the
trimExtend
operation.requestOptions ObjectoptionalAdditional options to be used for the data request.
ReturnsType Description Promise<Polyline[]> When resolved, returns an array of the trimmed or extended geometries.
-
union
union(url, 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.
Parametersurl StringThe ArcGIS Server REST service URL of a GeometryService. Esri hosts a geometry service on sampleserver6.arcgisonline.com for development and testing purposes.
An array of the geometries to be unioned.
requestOptions ObjectoptionalAdditional options to be used for the data request.
Returns