需求内容: 对某个arcgis server发布的服务进行缓冲区分析,并且下载缓冲区的结果要素图层
思路:
- 通过arcgis 服务的 find操作拿到所有的要素
- 对要素进行缓冲区分析
- 下载缓冲区分析的结果
项目使用的ags for javascript是3.14的。
1.获取arcgis 服务的所有的要素,可以使用 下面的两个类进行查找,接口返回的结果是要素的数组
"esri/tasks/FindTask",
"esri/tasks/FindParameters",
function findAllGeometry(layer){
if (layer.url){
var find = new FindTask(layer.url);
var parameter = new FindTaskParameter();
parameter.layerIds = [0];
parameter.searchText = 0;
parameter.returnGeometry = true
try{
find.execute(parameter,processResult)
}catch(e){
layer.msg("查找要素服务失败")
}
}
}
2. 进行缓冲区分析可以使用下面api的两个类进行分析(因为arcgis server自带的utilities/Geometry下面有buffer的服务工具)
"esri/tasks/GeometryService",
"esri/tasks/BufferParameters",
var _buffer = function (geometry, distance, callback, option) {
if (_geometryService == undefined) {
_geometryService = new GeometryService(_url);
}
if (distance == undefined)
distance = DEFAULT_BUFFER_DISTANCE;
on.once(_geometryService, 'buffer-complete', lang.hitch(this, callback));
on.once(_geometryService, 'error', one rrorHandler);
lang.mixin(_bufferOption, option);
var params = new BufferParameters();
params.geometries = lang.isArray(geometry) ? geometry : [geometry];
params.distances = lang.isArray(distance) ? distance : [distance];
params.unit = _bufferOption.unit;
params.unionResults = option.unionResults?option.unionResults:false;
params.bufferSpatialReference = _bufferOption.bufferSpatialReference;
params.outSpatialReference = _bufferOption.outSpatialReference;
_geometryService.buffer(params);
};
参数的unionResults如果为ture返回的结果只有一个要素,如果为false会返回和geometry数组一样的数组,geometry的类型是arcgis for javascript的类型。
3.进行下载需要将返回的geometry转化为geojson进行下载,调用接口进行下载
_expToShp: function (geo) {
var features = [];
var sr, wkt;
for (var i = 0; i < geo.length; i++) {
var geometry = geo[i].geometry;
var attr = geo[i].attributes;
var coordinates = [];
if (geometry) {
sr = geometry.spatialReference;
wkt = sr.wkid;
var rings = geometry.rings;
for (var j = 0; j < rings.length; j++) {
var ring = rings[j];
coordinates.push(ring);
}
}
var feature = {
"type": "Feature",
"geometry": {"type": geometry.type, "coordinates": coordinates},
"properties": attr
};
features.push(feature);
}
if (sr) {
wkt = sr.wkid;
}
var urlVar = {};
urlVar.geometry = JSON.stringify({"type": "FeatureCollection", "features": features});
urlVar.sr = wkt;
exportFile(urlVar, root + "/geometryService/export/shp");
}
标签:distance,geometry,javascript,arcgis,api,params,缓冲区,var From: https://www.cnblogs.com/1521681359qqcom/p/16709824.html