ArcGIS Flex (9.3) + GP service for Shortest Path Analysis (1)-reprinted

Source: Internet
Author: User
(10:00:57)

Reprinted
Tags:

Arcgisflexgp service geoprocessing

     Recently, I used the ArcGIS GP service to make several demos. In order not to lose my practical experience, I decided to write down the process !!!

 

(1) Shortest Path Analysis


 For the above, I would like to thank the author (because the English language is directly Chinese, it may be a bit lacking in ehinese). The following describes the entire model creation and program implementation process:

(1) data preparation

  The Network dataset must be used here. I generate it from shapefile and operate it in arccatalog. First, create an empty folder named testrouting and create the scrach and tooldata subfolders, scrach is used to store the script results generated by the model. tooldata is full of the original data of the model, and a toolbox called testrouting is created, as shown in the following figure:

  Put our experiment data in the tooldata folder and create a network dataset. Of course, this experiment data is not a simple road data, including some fields necessary for the network dataset (zbcov. SHP), right-click, and select new network dataset...
   Some Basic settings are default, but you must note that in the following window, you need to make the following settings for elevation data, and field should select the corresponding field in your data.

 One way to next, generate the following two data, zbcov_nd and zbcov_nd_junctions.

(2) Model Creation
 Open zbcov_nd In ArcMap and add the newly created testrouting to arctoolbox. Right-click testrouting and name it shortestroute as a new model, follow the PIC below to create the shortest path analysis model.

    
 You need to pay attention to creating models. It is certainly not impossible to directly use ArcGIS examples. However, it is also a pleasure to make models and helps you understand some algorithm processes of ArcGIS, as I encountered many problems in this process, I plan to write down the process step by step. First, add the network extension module, tools-> extension, and select the network analyst check box.

 A. Open the network analyst tools toolbox, select analysisi-> make route layer, and drag it into the model window. Of course, if you cannot find this tool, you don't have to worry about it. Simply search for it in search. Double-click the Make route layer tool. In the input Analysis Network, select the layer zbcov_nd we added In ArcMap. You can select the default option for all other options. In the model, the input item turns blue, the tool turns yellow, and the output is green.


 B. Find the Add locations tool and drag it into the model window. Right-click the tool and choose make variable-> from parameter-> input locations.

C. right-click the input item "input locations" and choose Properties ..., set the following parameters for this data item. The data type is feature set, and the symbology from option is zbcov_nd_junctions.shp. In fact, this is to determine the style and contain fields when you enter the feature, you can select the style saved in ArcGIS. To facilitate the selection of a point data layer, it indicates that the style varies with the selected data layer, the added vertex data is the same as the zbcov_nd_junctions field.
 D. double-click the Add locations tool. Input network analysis layer selects the previously generated route layer. The sub layer is stops, indicating that we want to add the Shortest Path site to the route layer. In addition, there are barriers, indicates the obstacle. Input locaations is the layer added in the previous step, and field matching is performed in field mappings, because we have selected zbcov_nd_junctions as the symbol layer of input locations, so there are only two fields FID, and zelev, therefore, we only select the FID field in name. You can select the default value for other fields.


F. Drag another add locations tool in the model window. The steps are similar to the steps for adding sites. This is the process of adding obstacles to path analysis. To distinguish between sites, change the name of the sub-model for which obstacles are added to addBarriers. The input item changes to input barriers. The other input item is the previously generated result layer route (2 ). Set sub layer in add barriers to select barriers. Fields mapping still only sets name to FID. As follows.


G. Drag the solve tool in the model window, double-click it, and clickIn Network Analysis layer, select the network analyst layer generated in the previous step, as shown in.

H. the generated results are processed in two ways. One is to directly display the Path results as an additional layer, the other is to generate the path description XML, and drag the Select data tool and the directions ctions tool into the model window, the Select data tool is directly connected to the route (3) generated in the previous step. Double-click the Select data tool and select routes for the Child Data Element (optional), which indicates that the output result layer is a path, double-click directions ctions, select XML for output file type, and select the generated XML Path for output directions file, which is the scratch folder we first generated.

  Of course, there is another way to set the generated XML file path. In the ArcMap window, select Tools> Options> geoprocessing, and make the following settings: overwrite... indicates that each new XML file will overwrite the previous results; log... indicates that there is a warning for overwriting.

  In environments, select scratch workspace as the initial scrach folder.

   In this case, you can directly set the XML generation path of the direnctions tool in the model window as follows.


   Generally, we select the second path setting method to facilitate unified management of multiple generated files.

I. when we started to build a model, we thought this would be done. In fact, we neglected a very easy but important link, that is, to determine the input and output items of the model. If we do not do this step, the model is empty. This model has two input items: Input locations (set site), input barriers (set obstacle), two output items: shortestroute and route_dires.s.xml. zbcov_nd is actually an input item, however, because we have already set the model when creating it, it is not used as user input. The setting method is as follows. Right-click the setting item and select model parameter.

      The final model is as follows:

(3) Test Model

   Save the generated model and double-click the model in the toolbox. The model box is displayed. Click on the ArcMap layer and enter two sites and one obstacle. After running, the result is displayed as a layer.

 (4) Publish the GP Service

   Drag the shortestroute model you just created into layers In ArcMap as the first layer, zbcov_nd as the analysis layer, and save it as a mxd (testroutingservice. mxd ). At the same time, the original zbcov. SHP data is separately stored as an mxd (testroutingbasemap. mxd) as the basemap for path analysis. If there is other data, it can be added. This is not the focus. In arccatalog, you can see the following file structure.

  Testroutingbasemap is directly published as a mapservice, which is not described in detail; testroutingservice is published as a geoprocessingservice, the specific steps are as follows:

 A. Add ArcGIS Server, add GIS service, select geoprocessing service for type, and name the service. Next step...

   

B. Select the synchronous execution method, select the method for publishing a map, select layers in the data frame, and select the show messages check box. As for the difference between synchronous and asynchronous, the former is synchronous execution, which is used for less complex GP services and is more efficient. The latter is asynchronous execution and will not be repeated. Next step... Select the default settings.

(5) Test the GP Service

    Open an empty ArcMap and drag the just-released basemap from the catalog into layers. Load the newly released geoprocessing service in the arctoolbox. Then, we can see that the model icon is changed to a small ax.

   Double-click the model, enter the parameters, and run

   If the released model is correct, the following results are displayed.

 

  (6) Call the model in flex.

     The base map service URL is "http: // localhost/ArcGIS/rest/services/testroutingbm/mapserver ";

    The URL of the GP service is "http: // localhost/ArcGIS/rest/services/drivetime/gpserver/shortestroute2 ".

    Because it is released on your own machine, it is all localhost...

    For more information about the code, see examples.

  The key to calling GP is the following statement:

 VaR Params: Object = {
                   "Input_locations": featureset,
                   "Input_barriers": featureset2
                   };
                   // The onresult method is successfully called for analysis, and the onfault method is called if the analysis fails.
                   Gp.exe cute (Params, new asyncresponder (onresult, onfault ));
 Here, input_locations and input_barriers are two input items of the model. You can see the detailed description directly through the URL of the GP service, as shown below: The detailed description of input_barriers.

 Gp.exe cute: The execution result is passed in onresult through asyncresponder. If an error occurs, it is executed through onfault.

 (7) Chinese input path

  The description of the output path is in English by default, which is depressing. Therefore, we recommend that you define the path in Chinese. Find % ArcGIS installation path % \ networkanalyst \ directions. my options are c: \ Program Files \ ArcGIS \ networkanalyst \ directions ctions. the English description of the LNG file is changed to Chinese. Although it is complicated and trivial, it is a process (it is best to back up the previous directions. LNG ). To save as pay attention to selecting the encoding method for the UTF-8.

At the top, change to the following

[General]
Encoding = UTF-8
Default = zh_cn

  Run the program again and you will find that all the path descriptions in the directions table are in Chinese.

 

   Finally, I wrote the first article, and the next article will be the latest facility query ...... If you have time to write it again, paste it first.

Share

1

Top

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.