ArcGIS Server发布GP服务-等值线

来源:互联网 发布:edu域名申请 编辑:程序博客网 时间:2024/06/03 23:39

本文首先建设了两个制作等值线的Model Builder,并发布为GP服务,随后用js api调用服务并在前端绘制等值线;

1.1 Model Builder 1


说明:此模型在ArcGIS 10.0 中建立,天气数据为注:右键IDW-获取变量-从参数-输入点要素,右键椭圆-设为模型参数);将参数设为变量后可以传值。
1.2 发布Model Builder 1
ArcGIS 10.0 发布ModelBuilder需将其先拖入到mxd中,然后发布mxd顺带发布了GP工具,直接发布GP貌似不能用;
2.1 Model Builder 2

说明:此模型在ArcGIS10.2版本中建立,10.2版本以上提供JSON转要素工具,然后再进行IDW,再进行Contour;
2.2 发布Model Builder2
点击ArcMap中Geoprocessing(地理处理)-->Results(结果)-->共享 进行模型的发布;这里与10.0版本是有区别的;
3 调用GP服务
<!DOCTYPE html> <html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title>test GP</title>    <link rel="Stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/dojo/dijit/themes/claro/claro.css" />    <link rel="stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css" />    <script type="text/javascript"> var djConfig = { parseOnLoad: true, url: "localhost" };</script>    <script type="text/javascript" src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>    <style type="text/css">      html,body,#map{ height: 100%; width: 100%; margin: 0; padding: 0; }    </style>    <script type="text/javascript">dojo.require("dijit.layout.BorderContainer");        dojo.require("dijit.layout.ContentPane");        dojo.require("esri.map");        dojo.require("esri.toolbars.draw");        dojo.require("esri.tasks.gp");        var map, gp;var resultLayer;        var resultUrl;var jobId;      function init() {    map = new esri.Map("map");            basemap = new esri.layers.ArcGISDynamicMapServiceLayer("http://localhost/ArcGIS/rest/services/weather/MapServer");            map.addLayer(basemap);            var button = dojo.byId("Submit");            dojo.connect(button, 'onclick', doSubmit);}function doSubmit() {                var gpUrl = "http://localhost/ArcGIS/rest/services/weather/GPServer/weather_dzx";    gp = new esri.tasks.Geoprocessor(gpUrl);            var parms = {Contour_Interval:1,zvalue:"WEAVALUE",Input:'字符串'            };
   //esriConfig.defaults.io.proxyUrl = "proxy.ashx";     //esriConfig.defaults.io.alwaysUseProxy = false;             gp.submitJob(parms,jobResult);//异步方式    //gp.execute(parms,jobResult);//同步方式        }        function jobResult(result) {jobId = result.jobId;var status = result.jobStatus;if(status === esri.tasks.JobInfo.STATUS_SUCCEEDED) {//成功之后,将其中的结果取出来,当然这也是参数名字//在模型中,想要取出中间结果,需要设置为模型参数gp.getResultData(jobId,"Contour_Output", addResults);}        }function addResults(results) {console.log(results);var features = results.value.features;for(var f = 0, fl = features.length; f < fl; f++) {var feature = features[f];var symbol =new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([160, 32,240]), 1);feature.setSymbol(symbol);map.graphics.add(feature);}}         dojo.addOnLoad(init);     </script>  </head>  <body class="claro">    <div id="info">       <button id="Submit" style="border:2px solid pink;">Submit</button>     </div>     <div id="map" ></div>  </body></html>
注意:
1)上述代码中标红的字符串为GeoJSON格式的数据,格式如下图:

2)"注意1"中的GeoJSON字符串如果数据过长,会受到"get请求对数据长度有要求"的限制,一般会出现"esri.config.defaults.io.proxyUrl尚未进行设置;get方式参数超过2048个"提示错误
解决方式:
需要一个proxy page做代理,通过代理使用post方式做查询,这样我们就不会受限于字符总数的限制了,如代码中红色注释部分,具体可参见文章:
http://blog.csdn.net/wpz0713/article/details/50245041
http://blog.csdn.net/cc752/article/details/60956362
http://blog.csdn.net/esrichinacd/article/details/42234837
大致步骤:下载resource-proxy-->1.0-修改proxy.config-->在代码中添加配置
此问题只会出现在10.0版本的GP服务中,因为10.0传的是字符串;10.2版本中的GP服务传的存储字符串文件的路径即可,不会超过字符总数限制;