arcgis js(九)地理处理任务 缓冲区分析

待我称王封你为后i 2022-09-07 09:13 275阅读 0赞

1、基于上一节的讲解我们已经知道如何发布GP服务,arcgis js(九)地理处理任务0 发布GP服务_郝大大的博客-CSDN博客,接下来进入正题,后面会分节介绍如何进行调用和处理众多的地理任务,给从事本专业的高校学生或者对GIS感兴趣的开发者提供一个学习思路,满足大家对地理信息处理的迫切需求。

2、在查看了各种资料后发现esri在api提供了两种方式,一个是Geoprocessor,位于esri/tasks,另一个是geoprocessor,位于esri/rest,我们来看看它们的区别: Geoprocessor自从4.0版本后支持,但是自从4.20版本之后被舍弃掉了,geoprocessor自从4.19版本后支持,所以根据版本自行选择。

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hCX1Byb2dyYW1tZXI_size_16_color_FFFFFF_t_70

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hCX1Byb2dyYW1tZXI_size_16_color_FFFFFF_t_70 1

3、依然是基于天地图底图,我们分别介绍synchronous同步和asynchronous异步执行方法,显示速度和网速也有关系。同步的url是http://localhost:6080/arcgis/rest/services/buf/GPServer,在浏览器打开,可以看到执行方式,同时要注意Tasks:模型,在调用的时候一定要加上任务的名字,否则会失败,在代码中设置的url为:http://localhost:6080/arcgis/rest/services/buf/GPServer/模型

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hCX1Byb2dyYW1tZXI_size_16_color_FFFFFF_t_70 2

4、同步方法

  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  5. <title> Geoprocessing </title>
  6. <style>
  7. html,
  8. body,
  9. #viewDiv {
  10. padding: 0;
  11. margin: 0;
  12. height: 100%;
  13. width: 100%;
  14. }
  15. #paneDiv {
  16. position: absolute;
  17. top: 18px;
  18. right: 18px;
  19. padding: 12px;
  20. background-color: rgba(0, 0, 0, 0.5);
  21. color: white;
  22. width: 200px;
  23. }
  24. </style>
  25. <link rel="stylesheet" href="https://js.arcgis.com/4.20/esri/themes/light/main.css" />
  26. <script src="https://js.arcgis.com/4.20/"></script>
  27. <script>
  28. require([
  29. "esri/Map",
  30. "esri/views/MapView",
  31. "esri/layers/GraphicsLayer",
  32. "esri/Graphic",
  33. "esri/geometry/Point",
  34. "esri/rest/geoprocessor",
  35. "esri/rest/support/LinearUnit",
  36. "esri/rest/support/FeatureSet",
  37. "esri/layers/WebTileLayer",
  38. "esri/layers/support/TileInfo",
  39. "esri/geometry/SpatialReference",
  40. ], (
  41. Map,
  42. MapView,
  43. GraphicsLayer,
  44. Graphic,
  45. Point,
  46. geoprocessor,
  47. LinearUnit,
  48. FeatureSet,
  49. WebTileLayer,
  50. TileInfo,
  51. SpatialReference
  52. ) => {
  53. var tiandituBaseUrl = "http://{subDomain}.tianditu.com"; //天地图服务地址
  54. var token = ""; //天地图token,在官网申请
  55. var tileInfo = new TileInfo({
  56. "rows": 256,
  57. "cols": 256,
  58. "origin": {
  59. "x": -180,
  60. "y": 90
  61. },
  62. "spatialReference": {
  63. "wkid": 4490
  64. },
  65. "lods": [
  66. { "level": "1", "scale": 295829355.45, "resolution": 0.703125 },
  67. { "level": "2", "scale": 147914677.725, "resolution": 0.3515625 },
  68. { "level": "3", "scale": 73957338.8625, "resolution": 0.17578125 },
  69. { "level": "4", "scale": 36978669.43125, "resolution": 0.087890625 },
  70. { "level": "5", "scale": 18489334.715625, "resolution": 0.0439453125 },
  71. { "level": "6", "scale": 9244667.3578125, "resolution": 0.02197265625 },
  72. { "level": "7", "scale": 4622333.67890625, "resolution": 0.010986328125 },
  73. { "level": "8", "scale": 2311166.839453125, "resolution": 0.0054931640625 },
  74. { "level": "9", "scale": 1155583.4197265625, "resolution": 0.00274658203125 },
  75. { "level": "10", "scale": 577791.7098632812, "resolution": 0.001373291015625 },
  76. { "level": "11", "scale": 288895.8549316406, "resolution": 0.0006866455078125 },
  77. { "level": "12", "scale": 144447.9274658203, "resolution": 0.00034332275390625 },
  78. { "level": "13", "scale": 72223.96373291015, "resolution": 0.000171661376953125 },
  79. { "level": "14", "scale": 36111.98186645508, "resolution": 0.0000858306884765625 },
  80. { "level": "15", "scale": 18055.99093322754, "resolution": 0.00004291534423828125 },
  81. { "level": "16", "scale": 9027.99546661377, "resolution": 0.000021457672119140625 },
  82. { "level": "17", "scale": 4513.997733306885, "resolution": 0.000010728836059570312 },
  83. { "level": "18", "scale": 2256.9988666534423, "resolution": 0.000005364418029785156 },
  84. { "level": "19", "scale": 1128.4994333267211, "resolution": 0.000002682209014892578 }
  85. ]
  86. });
  87. //影像地图
  88. var tdtImageLayer = new WebTileLayer({
  89. urlTemplate: tiandituBaseUrl + "/DataServer?T=img_c&x={col}&y={row}&l={level}&tk=" + token,
  90. subDomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
  91. tileInfo: tileInfo,
  92. spatialReference: { wkid: 4490 },
  93. });
  94. //影像注记
  95. var tdtAnnoImageLayer = new WebTileLayer({
  96. urlTemplate: tiandituBaseUrl + "/DataServer?T=cia_c&x={col}&y={row}&l={level}&tk=" + token,
  97. subDomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
  98. tileInfo: tileInfo,
  99. spatialReference: { wkid: 4490 },
  100. });
  101. const gpUrl = "http://localhost:6080/arcgis/rest/services/buf/GPServer/模型";
  102. //定位到济南市中心
  103. var cityCenter = new Point(116.985, 36.671, new SpatialReference({ wkid: 4490 }));
  104. // 创建地图
  105. var map = new Map({
  106. basemap: {
  107. baseLayers: [tdtImageLayer, tdtAnnoImageLayer]
  108. },
  109. });
  110. //添加到view
  111. var view = new MapView({
  112. container: "viewDiv",
  113. map: map,
  114. center: cityCenter,
  115. zoom: 14,
  116. ui: {
  117. components: ["zoom", "compass"]
  118. }
  119. });
  120. //创建显示图层
  121. const graphicsLayer = new GraphicsLayer();
  122. map.add(graphicsLayer);
  123. //创建点符号样式
  124. const markerSymbol = {
  125. type: "simple-marker",
  126. color: [255, 0, 0],
  127. outline: {
  128. color: [255, 255, 255],
  129. width: 2
  130. }
  131. };
  132. //创建面符号样式
  133. const fillSymbol = {
  134. type: "simple-fill",
  135. color: [226, 119, 40, 0.75],
  136. outline: {
  137. color: [255, 255, 255],
  138. width: 1
  139. },
  140. };
  141. //输出参考
  142. const options = {
  143. outSpatialReference: {
  144. wkid: 4490
  145. }
  146. };
  147. //单击事件
  148. view.on("click", computeViewshed);
  149. function computeViewshed(event) {
  150. graphicsLayer.removeAll();
  151. const point = new Point({
  152. longitude: event.mapPoint.longitude,
  153. latitude: event.mapPoint.latitude
  154. });
  155. const inputGraphic = new Graphic({
  156. geometry: point,
  157. symbol: markerSymbol
  158. });
  159. graphicsLayer.add(inputGraphic);
  160. //设置输入数据集
  161. const inputGraphicContainer = [];
  162. inputGraphicContainer.push(inputGraphic);
  163. const featureSet = new FeatureSet();
  164. featureSet.features = inputGraphicContainer;
  165. //设置缓冲区距离
  166. const dis = new LinearUnit();
  167. dis.distance = 100;
  168. dis.units = "meters";
  169. const params = {
  170. input: featureSet,
  171. dis: dis
  172. };
  173. //执行gp task
  174. geoprocessor.execute(gpUrl, params, options).then(drawResultData);
  175. }
  176. //执行结果
  177. function drawResultData(result) {
  178. const resultFeatures = result.results[0].value.features;
  179. //显示缓冲区
  180. const graphic = resultFeatures.map((feature) => {
  181. feature.symbol = fillSymbol;
  182. return feature;
  183. });
  184. graphicsLayer.addMany(graphic);
  185. view.goTo({
  186. target: graphic,
  187. tilt: 0
  188. }).catch((error) => {
  189. if (error.name != "AbortError") {
  190. console.error(error);
  191. }
  192. });
  193. }
  194. });
  195. </script>
  196. </head>
  197. <body>
  198. <div id="viewDiv"></div>
  199. <div id="paneDiv" class="esri-widget">
  200. 在地图上单击执行 GP Task
  201. </div>
  202. </body>
  203. </html>

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hCX1Byb2dyYW1tZXI_size_16_color_FFFFFF_t_70 3

5、异步方法

打开链接http://localhost:6080/arcgis/rest/services/bufferpoint/GPServer可以看到执行类型是异步的:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hCX1Byb2dyYW1tZXI_size_16_color_FFFFFF_t_70 4

发表评论

表情:
评论列表 (有 0 条评论,275人围观)

还没有评论,来说两句吧...

相关阅读

    相关 arcgis js)天际线分析

    1、城市环境具有复杂的空间组成 - 既包含建筑物、树木、街道设施等实体结构的密集集合,也包含公园或公共城市广场等城市开放空间。使用天际线来更好的分析城市空间及其涵盖的空间区域,

    相关 arcgis js(八)地理查询

    1、地理查询主要是查询该图层的每个图斑的属性,分为基本查询和按距离查询,基本查询指的是如果鼠标选择的点在图斑上或内才有效,按距离查询指的是在给定距离内如果查询到了图斑就把该图斑

    相关 如何定义ArcGIS地理数据库方案

    我们知道,要素数据集和要素类是存储在数据库中的。地理数据库方案定义了存储在地理数据库中每个数据集和要素类的规则、关系和属性。简单来说,地理数据库中要创建哪些类型的要素类,创建哪