The main function of service area analysis is to determine the areas that can be reached within a certain period of time. For example, from a certain point, we want to know the scope of the areas that can be reached within 30 minutes, then we can use the service area analysis. The following is the final implementation of this article:
The following describes the specific implementation process.
Service area analysis is the last part of web-based network analysis. We have explained how to create network datasets, publish network analysis services, and query the latest paths and facilities, let's talk about the service area analysis in the last part today.
If you have completed the analysis of the shortest path and the latest facilities, the analysis of the service area must be a piece of cake. There is nothing new here. The implementation process is still similar to the previous path analysis and facility point analysis. The difference is that the parameters are different. At the same time, we also need to publish a service area analysis layer.
Suppose we have already built the Network Analysis Service (the process of releasing the Network Analysis Service is described in detail in the previous blog post, and we will not describe it here). Open the address of our Network Analysis Service, the address format is the same as before. For example, the address of this article is:
Http: // qzj-PC/ArcGIS/rest/services/networkanaysismap/naserver/servicearea
Previously, the parameters of the service area are different from those of other analyses. What about the parameters of the service area?
In ArcGIS Silverlight, routeserviceareaparameters is used as the parameter in recent facility analysis. The important attributes of routeserviceareaparameters are as follows:
Parameter Name |
Parameter description |
Facilities |
Indicates the Facility point, that is, the starting point |
Defaultbreaks |
Indicates the default interrupt value, which is a string. Use commas to separate the values. For example, "10, 20, 30" (if the time is Min) indicates the area that can be reached within 10 minutes, 20 minutes, and 30 minutes. |
Excludesourcesfrompolygons |
String names separated by commas (,), indicating the source element class to be excluded |
Trimpolygondistance |
It indicates the tolerance distance of the TRIM polygon. |
Trimpolygondistanceunits |
It indicates the units of tolerance distance of the TRIM polygon. |
Splitpolygonsatbreaks |
Splits the polygon from the center Break (different region levels) to obtain the area polygon that arrive at different times. |
Splitlineatbreaks |
Indicates the split line from the center (different regions. |
Overlaplines |
Indicates whether the lines generated by multiple facility points are overwritten. |
Overlappolygons |
Indicates whether the polygon generated by multiple facility points overwrites each other. |
Returnfacilities |
Indicates whether to return to the Facility point |
Mergesimilarpolygonranges |
Indicates whether to combine the polygon range of the approximate interrupt value (level ). |
Outputpolygons |
Indicates the polygon type generated. It is specified by the network layer by default. |
Traveldirection |
Indicates the path direction. For example, the start point is the facility or the end point. |
These are some important attributes of the routeserviceareaparameters parameter. Let's take a look at the code declaration:
Routeserviceareaparameters serviceareaparameter = new routeserviceareaparameters () {// obtain the facility, that is, the starting point is facilities = stopsgraphicslayer. graphics, // set the terminal value, breakstring is the declared string variable defaultbreaks = breakstring, // sets the tolerance trimpolygondistance = 10000, // whether to return the Facility point (starting point) returnfacilities = true, splitpolygonsatbreaks = true, splitlineatbreaks = false, overlaplines = false, overlappolygons = true, mergesimilarpolygonranges = true, outspatialreference = mymap. spatialreference ,};
The preceding Sample Code declares a routeserviceareaparameters variable. Breakstring is the value of the text box, in which the time unit is hour and minute. Therefore, you need to determine whether the selected time unit is hour or minute (the default setting is the same as that of the network analysis layer, this article is hour ).
Therefore, a corresponding conversion is required. For example, if the user input is 30 minutes, it needs to be converted to 0.5 hours. Therefore, we define a breakstring. The sample code is as follows:
string breakString = ""; if (TimeUnitcomboBox.SelectedIndex == 0) { breakString = ServiceAreaBreakTextBox.Text; } else if(TimeUnitcomboBox.SelectedIndex==1) { string[] TimeString = ServiceAreaBreakTextBox.Text.Split(','); for (int i = 0; i < TimeString.Length-1;i++ ) { breakString += (Convert.ToDouble(TimeString[i]) / 60).ToString(); breakString += ","; } breakString += (Convert.ToDouble(TimeString[TimeString.Length - 1]) / 60).ToString(); }
After defining the parameters, we can start querying the Network Analysis Service. Of course, first we need to define a routetask, and the corresponding functions of the event of successful and failed queries. This is the same as the latest facility analysis and path analysis:
Define routetask and point the URL to the network analysis layer of the service area:
Routetask serviceareatask = new routetask ("http: // qzj-PC/ArcGIS/rest/services/networkanaysismap/naserver/servicearea"); // service area task
Register the Event Response Function:
ServiceAreaTask.SolveServiceAreaCompleted += new EventHandler<RouteEventArgs>(ServiceAreaTask_SolveServiceAreaCompleted);ServiceAreaTask.Failed += new EventHandler<TaskFailedEventArgs>(Task_Failed);
Private void serviceareatask_solveserviceareacompleted (Object sender, routeeventargs e) {} private void task_failed (Object sender, taskfailedeventargs e) {MessageBox. show ("failed to solve" + E. error. tostring ());}
The basic preparation is complete. You can use the routetask to query the service area.
if (ServiceAreaTask.IsBusy) ServiceAreaTask.CancelAsync(); ServiceAreaTask.SolveServiceAreaAsync(serviceAreaParameter);
At this point, you should also think that the next step is to obtain the query results. If you are careful, you will find that this is basically the same as other analysis implementation processes.
What is the result of service area analysis?
We know that the service area is a plane, and the result is definitely a plane element. But the difference is that the service area analysis result is no longer routeresult. The service area elements can be obtained directly through the serviceareapolympus attribute of event parameter E. Let's take a look at the process of getting results through code implementation:
Private void serviceareatask_solveserviceareacompleted (Object sender, routeeventargs e) {int I = 1; foreach (Graphic g in E. serviceareapolympus gons) {// here, the input interrupt value is generally three, so the result has three surface elements, indicating the region switch (I) that can be achieved at different times) {Case 1: G. symbol = layoutroot. resources ["myservicearea1"] As simplefillsymbol; break; Case 2: G. symbol = layoutroot. resources ["myservicearea2"] As simplefillsymbol; break; Case 3: G. symbol = layoutroot. resources ["myservicearea3"] As simplefillsymbol; break;} I ++; servicearealayer. graphics. add (g );}}
Here, myservicearea1, myservicearea2, and myservicearea3 are the surface element resource styles defined in XAML. Refer to the sample code:
<esri:SimpleFillSymbol x:Name="MyServiceArea1" Fill="Red" BorderBrush="Yellow" BorderThickness="3"/> <esri:SimpleFillSymbol x:Name="MyServiceArea2" Fill="Yellow" BorderBrush="Green" BorderThickness="3"/> <esri:SimpleFillSymbol x:Name="MyServiceArea3" Fill="Green" BorderBrush="Blue" BorderThickness="3"/>
At this point, all the work is over. If everything goes well, you will also get the photo that was given at the beginning of this article.
All the web-side network analysis functions are over. You are welcome to exchange ideas!
Source programs of the Network Analysis Series and network analysis data:
Download network analysis data
Download network analysis source program
(All Rights Reserved. For details, refer to the source)