04_interpolationAnalystService_IDW_geometry.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_interpolationAnalystByGeo"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" style="width: 100%;height:100%"></div>
  14. <script type="text/javascript">
  15. var map, options, interpolationAnalystService, interpolationAnalystParameters, interpolationAnalystResult, points,
  16. themeService, themeGridRange, themeParameters,
  17. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-temperature/rest/maps/全国温度变化图",
  18. serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
  19. var mapService = new ol.supermap.MapService(baseUrl);
  20. var extent = [-2640403.63, 1873792.1, 3247669.39, 5921501.4];
  21. var projection = new ol.proj.Projection({
  22. code:'',
  23. extent: extent,
  24. units: 'm'
  25. });
  26. mapService.getMapInfo(function (serviceResult) {
  27. var mapJSONObj = serviceResult.result;
  28. map = new ol.Map({
  29. target: 'map',
  30. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  31. .extend([new ol.supermap.control.Logo()]),
  32. view: new ol.View({
  33. center: [531762, 3580330],
  34. zoom: 1,
  35. projection: projection,
  36. multiWorld: true
  37. })
  38. });
  39. options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  40. options.layersID = "[0,1,2]";
  41. var layer = new ol.layer.Tile({
  42. source: new ol.source.TileSuperMapRest(options)
  43. });
  44. map.addLayer(layer);
  45. interpolationAnalystProcess();
  46. });
  47. function interpolationAnalystProcess() {
  48. //通过SQL查询的方法获取用于插值分析的geometry
  49. var queryBySQLParams, queryBySQLService;
  50. queryBySQLService = new ol.supermap.QueryService(baseUrl);
  51. queryBySQLParams = new SuperMap.QueryBySQLParameters({
  52. queryParams: [
  53. new SuperMap.FilterParameter({
  54. name: "SamplesP@Interpolation",
  55. attributeFilter: "SMID>0"
  56. })
  57. ]
  58. });
  59. queryBySQLService.queryBySQL(queryBySQLParams, function (serviceResult) {
  60. var result = serviceResult.result;
  61. var z;
  62. var zMin = parseFloat(-5), zMax = parseFloat(28);
  63. points = [];
  64. if (result) {
  65. for (var i = 0; i < result.recordsets[0].features.features.length; i++) {
  66. gp = result.recordsets[0].features.features[i].geometry;
  67. var point = new ol.geom.Point([gp.coordinates[0], gp.coordinates[1]]);
  68. //每个插值点在插值过程中的权重值
  69. z = Math.random() * (zMax - zMin) + zMin;
  70. point.tag = z;
  71. points.push(point);
  72. }
  73. }
  74. //创建离散点插值分析服务实例
  75. interpolationAnalystService = new ol.supermap.SpatialAnalystService(serviceUrl);
  76. //创建离散点插值分析参数实例
  77. interpolationAnalystParameters = new SuperMap.InterpolationIDWAnalystParameters({
  78. // 插值分析类型,geometry类型表示对离散点插值分析,默认为“dataset”
  79. InterpolationAnalystType: "geometry",
  80. // 插值分析结果数据集的名称
  81. outputDatasetName: "IDWcretePoints_result",
  82. // 插值分析结果数据源的名称
  83. outputDatasourceName: "Interpolation",
  84. // 结果栅格数据集存储的像素格式
  85. pixelFormat: SuperMap.PixelFormat.BIT16,
  86. // 用于做插值分析的离散点集合
  87. inputPoints: points,
  88. // 属性过滤条件
  89. // filterQueryParameter: {
  90. // attributeFilter: ""
  91. // },
  92. // 采取定长查找参与运算点的方式
  93. searchMode: "KDTREE_FIXED_RADIUS",
  94. // 查找半径,与点数据单位相同
  95. searchRadius: 200,
  96. resolution: 9000,
  97. bounds: [-2640403.63, 1873792.1, 3247669.39, 5921501.4]
  98. });
  99. interpolationAnalystService.interpolationAnalysis(interpolationAnalystParameters, function (serviceResult) {
  100. interpolationAnalystResult = serviceResult.result;
  101. //用栅格专题图展示分析结果
  102. showAnalysisResult_ThemeGridRange();
  103. });
  104. });
  105. //构造栅格专题图
  106. function showAnalysisResult_ThemeGridRange() {
  107. //创建专题图服务实例
  108. themeService = new ol.supermap.ThemeService(baseUrl);
  109. var color1 = new SuperMap.ServerColor(170, 240, 233),
  110. color2 = new SuperMap.ServerColor(176, 244, 188),
  111. color3 = new SuperMap.ServerColor(218, 251, 178),
  112. color4 = new SuperMap.ServerColor(220, 236, 145),
  113. color5 = new SuperMap.ServerColor(96, 198, 66),
  114. color6 = new SuperMap.ServerColor(20, 142, 53),
  115. color7 = new SuperMap.ServerColor(85, 144, 55),
  116. color8 = new SuperMap.ServerColor(171, 168, 38),
  117. color9 = new SuperMap.ServerColor(235, 165, 9),
  118. color10 = new SuperMap.ServerColor(203, 89, 2),
  119. color11 = new SuperMap.ServerColor(157, 25, 1),
  120. color12 = new SuperMap.ServerColor(118, 15, 3),
  121. color13 = new SuperMap.ServerColor(112, 32, 7),
  122. color14 = new SuperMap.ServerColor(106, 45, 12),
  123. color15 = new SuperMap.ServerColor(129, 80, 50),
  124. color16 = new SuperMap.ServerColor(160, 154, 146),
  125. color17 = new SuperMap.ServerColor(107, 47, 14),
  126. color18 = new SuperMap.ServerColor(125, 75, 44),
  127. color19 = new SuperMap.ServerColor(146, 110, 88),
  128. color20 = new SuperMap.ServerColor(166, 153, 146);
  129. var themeGridRangeItem1 = new SuperMap.ThemeGridRangeItem({
  130. start: -5,
  131. end: -3.4,
  132. color: color1
  133. }),
  134. themeGridRangeItem2 = new SuperMap.ThemeGridRangeItem({
  135. start: -3.4,
  136. end: -1.8,
  137. color: color2
  138. }),
  139. themeGridRangeItem3 = new SuperMap.ThemeGridRangeItem({
  140. start: -1.8,
  141. end: -0.2,
  142. color: color3
  143. }),
  144. themeGridRangeItem4 = new SuperMap.ThemeGridRangeItem({
  145. start: -0.2,
  146. end: 1.4,
  147. color: color4
  148. }),
  149. themeGridRangeItem5 = new SuperMap.ThemeGridRangeItem({
  150. start: 1.4,
  151. end: 3,
  152. color: color5
  153. }),
  154. themeGridRangeItem6 = new SuperMap.ThemeGridRangeItem({
  155. start: 3,
  156. end: 4.6,
  157. color: color6
  158. }),
  159. themeGridRangeItem7 = new SuperMap.ThemeGridRangeItem({
  160. start: 4.6,
  161. end: 6.2,
  162. color: color7
  163. }),
  164. themeGridRangeItem8 = new SuperMap.ThemeGridRangeItem({
  165. start: 6.2,
  166. end: 7.8,
  167. color: color8
  168. }),
  169. themeGridRangeItem9 = new SuperMap.ThemeGridRangeItem({
  170. start: 7.8,
  171. end: 9.4,
  172. color: color9
  173. }),
  174. themeGridRangeItem10 = new SuperMap.ThemeGridRangeItem({
  175. start: 9.4,
  176. end: 11,
  177. color: color10
  178. }),
  179. themeGridRangeItem11 = new SuperMap.ThemeGridRangeItem({
  180. start: 11,
  181. end: 12.6,
  182. color: color11
  183. }),
  184. themeGridRangeItem12 = new SuperMap.ThemeGridRangeItem({
  185. start: 12.6,
  186. end: 14.2,
  187. color: color12
  188. }),
  189. themeGridRangeItem13 = new SuperMap.ThemeGridRangeItem({
  190. start: 14.2,
  191. end: 15.8,
  192. color: color13
  193. }),
  194. themeGridRangeItem14 = new SuperMap.ThemeGridRangeItem({
  195. start: 15.8,
  196. end: 17.4,
  197. color: color14
  198. }),
  199. themeGridRangeItem15 = new SuperMap.ThemeGridRangeItem({
  200. start: 17.4,
  201. end: 19,
  202. color: color15
  203. }),
  204. themeGridRangeItem16 = new SuperMap.ThemeGridRangeItem({
  205. start: 19,
  206. end: 20.6,
  207. color: color16
  208. }),
  209. themeGridRangeItem17 = new SuperMap.ThemeGridRangeItem({
  210. start: 20.6,
  211. end: 22.2,
  212. color: color17
  213. }),
  214. themeGridRangeItem18 = new SuperMap.ThemeGridRangeItem({
  215. start: 22.2,
  216. end: 23.8,
  217. color: color18
  218. }),
  219. themeGridRangeItem19 = new SuperMap.ThemeGridRangeItem({
  220. start: 23.8,
  221. end: 25.4,
  222. color: color19
  223. }),
  224. themeGridRangeItem20 = new SuperMap.ThemeGridRangeItem({
  225. start: 25.4,
  226. end: 27,
  227. color: color20
  228. });
  229. themeGridRange = new SuperMap.ThemeGridRange({
  230. reverseColor: false,
  231. rangeMode: SuperMap.RangeMode.EQUALINTERVAL,
  232. //栅格分段专题图子项数组
  233. items: [themeGridRangeItem1, themeGridRangeItem2,
  234. themeGridRangeItem3, themeGridRangeItem4,
  235. themeGridRangeItem5, themeGridRangeItem6,
  236. themeGridRangeItem7, themeGridRangeItem8,
  237. themeGridRangeItem9, themeGridRangeItem10,
  238. themeGridRangeItem11, themeGridRangeItem12,
  239. themeGridRangeItem13, themeGridRangeItem14,
  240. themeGridRangeItem15, themeGridRangeItem16,
  241. themeGridRangeItem17, themeGridRangeItem18,
  242. themeGridRangeItem19, themeGridRangeItem20
  243. ]
  244. });
  245. themeParameters = new SuperMap.ThemeParameters({
  246. //制作专题图的数据集
  247. datasetNames: [interpolationAnalystResult.dataset.split('@')[0]],
  248. dataSourceNames: ["Interpolation"],
  249. joinItems: null,
  250. themes: [themeGridRange]
  251. });
  252. themeService.getThemeInfo(themeParameters, function (serviceResult) {
  253. var result = serviceResult.result;
  254. if (result && result.newResourceID) {
  255. var themeLayer = new ol.layer.Tile({
  256. source: new ol.source.TileSuperMapRest({
  257. url: baseUrl,
  258. noWrap: true,
  259. cacheEnabled: false,
  260. transparent: true,
  261. layersID: result.newResourceID,
  262. tileGrid: new ol.tilegrid.TileGrid({
  263. extent: extent,
  264. resolutions: options.tileGrid.getResolutions()
  265. }),
  266. })
  267. });
  268. map.addLayer(themeLayer);
  269. }
  270. });
  271. }
  272. }
  273. </script>
  274. </body>
  275. </html>