ArcGIS release GP services as well as front-end call (ArcGIS api for JS 4.12)

Foreword

Some time ago during the internship, received a demand for some of the geographic data needed to do spatial interpolation analysis, was like two solutions, one is to call some spatial interpolation to calculate the front-end database directly (such as Kriging.js, etc.), and the other One is released GP services with ArcGIS, then ArcGIS APi for JS calls. Because a large amount of data to be calculated, the final decision by way of GP services to achieve. To summarize some of the steps was achieved and problems encountered pit.

Published GP services

  • First established in ArcGIS Model Builder in a model, as shown, it is a direct call Kriging tool. Other parameters were: Mask layer as a mask to extract, obtained from the environment; Extend the analysis range is acquired from the environment; Zvalue the interpolation field is obtained from the parameters; input to the input layer, obtained from the parameters. P labeled set of model parameters, that is optional.
    When done, click Save and validate the model.

Service Modeling

  • Click Save model file, open the relevant input parameters and run. Because the service must first run a GP to post.

Running the model

  • After running the results are shown in FIG. Note: Classification GP service after calling the front display of the same color and layers in ArcGIS is the same. I would like to display a specific classification and color can directly attribute the results of the last run of the modified layer.
    Then, click to open the geoprocessing -> results window, right-just run the model in the current session, click Publish to services. The next step of publishing data services, like ArcGIS.

Results

  • Editing services. First analyze, then you can edit information about the prompts, error-free after release. Note: To execute mode "to see the results Map Service" can display the results in a layer on the front end of the election.

Edit Service

  • View and testing services in ArcGIS Server.

View Service

Call GP services

ArcGIS API for JavaScript 4.12 call GP service, put the code directly

        function doJob() {
            require([
                "esri/Map", "esri/views/MapView", "esri/layers/MapImageLayer", "esri/layers/FeatureLayer",
                "esri/layers/CSVLayer", "esri/tasks/Geoprocessor", "esri/widgets/Legend", "esri/request"
            ], function (Map, MapView, MapImageLayer, FeatureLayer, CSVLayer, Geoprocessor, Legend, request) {

                // 数据
                testLayer = new FeatureLayer({
                    url: "https://localhost:6443/arcgis/rest/services/test/data/MapServer/0"
                })

                // 边界掩膜数据
                maskLayer = new FeatureLayer({
                    url: 'https://localhost:6443/arcgis/rest/services/test/KrigingTestData/MapServer/2',
                    tranparent: 0.7
                })
                var KrigingGP = new Geoprocessor('https://localhost:6443/arcgis/rest/services/gp/Kriging/GPServer/Kriging')  //实例化和调用克里金插值服务
                // console.log('计算插值')

                pattern = $('#patterns option:selected').val()
                crop = $('#crops option:selected').val()
                el = $('#NP option:selected').val()


                var query = testLayer.createQuery()                  //要素服务中查询数据
                query.where = "crop = '"+ crop +"' AND pattern = '"+pattern +"'"
                testLayer.queryFeatures(query).then( re => {
                    console.log(JSON.stringify(re))
                    if (re.features.length == 0) {
                        alert('当前指标下无数据,请重新选取')
                    } else {
                        let params = {
                            Zvalue: el,
                            Input: re,
                            Extent: maskLayer,
                            Mask: maskLayer
                        }
                        KrigingGP.submitJob(params).then( result => {
                            if (result.jobStatus == 'job-failed') {
                                alert('计算插值失败')
                                // console.log(result)
                            } else if (result.jobStatus == 'job-succeeded') {
                                console.log('计算成功')
                                // console.log(result)
                                let resultLayer = KrigingGP.getResultMapImageLayer(result.jobId)   // 获取插值计算结果图层
                                // console.log(resultLayer)
                                resultLayer.opacity = 0.9
                                resultLayer.title = '插值结果'
                                map.layers.pop()
                                map.layers.add(resultLayer)      //结果图层添加到地图上显示
                            }
                        })
                    }
                })
            })
            }

Guess you like

Origin www.cnblogs.com/rendan/p/11574508.html