Posts Tagged ‘driving directions’

Doing network analysis

This is post #3 in a three part series. It is meant to be read after Creating a Network Dataset.

Now that we’ve done all the hard work building our network dataset, it is time to have some fun putting it to work. Most presentations would cover this part first to lure you in. I might have done things backwards. If I haven’t scared you away yet, and you’ve brought along a working network dataset, let’s explore what Network Analyst can do with it.

I will give examples of the first three Network Analyst tools: Route, Service Area and Closest Facility. Each of these revolve around facility locations paired with the network dataset. The City of Portland GIS Catalog doesn’t have a Points of Interest or Buildings layer, so I used ESRI Streetmap USA data for the point locations.

Route Tool

The Route solver finds the best path between any number of stops. Let’s pretend we are tourists who want to see a bunch of sites downtown and need some help planning our day so we’ll spend the least amount of time driving. I opened up ArcMap and added my new network dataset and the ESRI Recreational Areas point layer. Zooming to the Portland area shows 12 sites on both sides of the Willamette River.

Check on the Network Analyst toolbar, and then select New Route from the drop down menu. Also, click the button right next to the drop down menu to show the Network Analyst Window. You’ll be using it a lot.

The window will have a list of Stops, Routes and Barriers, all empty for now. The first step is to populate your list of stops. You can create stops manually by activating the Create Network Location Tool and clicking on the screen while your pointer is in the flag with crosshairs shape. Or, you can load them from another layer. That’s what we’re going to do. Select the 12 sites that you see on screen. (This step is important because you don’t want to be working with all the recreational areas in the entire USA. I skipped it the first time and proceeded to crash my computer). Once you’ve selected your subset, right click on Stops and select Load Locations…

It’ll grab their name from a name field if one exists, and nicely number them for you. Now click the Solve button. It’s generated a topsy-turvey looking route, due in part I’m sure to all the one-way streets downtown.

If you click the driving directions button, you’ll see the route has 80 steps and takes about 14 minutes.

We can probably do better than this. There’s an obscure button that will allow you to change some of the parameters used to calculate your route. It’s hidden on the top right of the Network Analyst Window.

The Analysis Settings tab has a Reorder Stops to Find Optimal Route box that is checked off by default. This means that if you added the stops manually, it will visit them in the order you created them, which might make sense. But if you loaded them from a file like we did, it will visit them in the order of random numbers it assigned, which definitely doesn’t make sense. Check the Reorder Stops box on, and check off the two boxes under it: Preserve First and Last Stop.

Now, the software will have the freedom to plan an itinerary that maximizes efficiency. Let’s see what difference it makes. After you’ve pressed OK to dismiss the Route Properties box, press the Solve button again.

That’s much better! It now wants me to visit the Children’s Museum first instead of last. And it has rearranged the entire middle so it’s not a mess. This new route saves us 5 steps, 3 miles and 4 minutes.

Service Area Tool

Now let’s pretend we work for Woodland Park Hospital and we want to know the area around it than an ambulance can reach within 5 minutes. We would select New Service Area from the drop down menu, and then load that one hospital point into the Facilities list.

I personally like to go into the Service Area Properties box and change the Polygon Type to Detailed (under the Polygon Analysis tab) because, why wouldn’t you? It’s set to calculate for 5 minutes by default, but you can change this to anything by editing the value in the Default Breaks box (under the Analysis Settings tab). If you want to solve for multiple times, separate them by commas. Here’s how it looks if I solve for 1, 3, and 5 minutes with high detail:

By the way, if you want to change these colors you can edit the symbology just like you would any other layer in the table of contents. And, if you wanted to, you could turn off the OneWay restriction because ambulances don’t need to obey it.

Closest Facility Tool

For the final scenario we’ll pretend to be home owners in the southwest portion of the city. We are planning a family and would like to determine the closest school to our house. The first step to solve this problem is to select New Closest Facility from the Network Analyst drop down menu, then press the Create Network Location tool button, and click on the map at the location of the house.

The new location will automatically be added to the Facilities list, but you want it in the Incidents list. Either drag it down there, or make sure the Incidents list is highlighted before you use the Create Network Location tool. The point will be automatically named Graphic Pick 1. You can double click on its entry in the Incidents list to rename it.

I purposefully picked a location that seems equally close to three different schools. The tool will tell me which is actually the fastest to drive to, not the closest as the crow flies. I selected a bunch of schools around it (more than just those three, to be safe) and loaded them into the Facilities list. Then I pressed the Solve button. The result is that Markam School is the closest at 0.7 miles away.

The tool shows you the route to get there, too. You can open up the Directions Window to see driving directions as well.

These are pretty handy, aren’t they? I’m in the mood to plan a vacation now just so I can play with the Route Tool some more!

Tags: , ,

Creating a network dataset

This is post #2 in a three part series. It is meant to be read after Preparing your Data to Become a Network Dataset.

A network dataset can be created from a shapefile or a feature class. If you are creating one from a feature class, it needs to be in its own feature dataset. Make sure you have the Network Analyst extension checked on, then right click on your streetline shapefile or the feature dataset that holds your streetline feature class, and choose “New… Network Dataset”.

After you give it a name, you will have the option the set Connectivity. Select the connectivity policy that you decided on before.

If you have designated z-levels the way I described, the next screen you encounter will automatically have these elevation settings. Keep them.

I haven’t tackled turn modeling yet, so select “No” on the next screen unless you’ve figured that out. (In which case, do you want to do a guest post?) :)

Now you are at the Attributes screen. If you’ve designated one-way streets the way I described, they will already be set up as a Oneway Restriction attribute. In addition, you’ll have a RoadClass Descriptor Attribute. Network Analyst uses this attribute to make the wording for turn-by-directions read correctly. There are 5 categories:

1 Local Street
2 Highway
3 Ramp
4 Ferry
5 Roundabout

It is automatically configured to try to inspect your attribute table and pull out these categories, but there’s no guarantee it’s going to work right. You should look at the code to check. Select it and click on the Evaluators button. Then select the first one in the list and click on the Evaluator Properties button.

Here’s what appears in my Pre-Logic VB Script Code box:

rc = 1 'Local road
Select Case UCase([CFCC])
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19"
rc = 2 'Highway
Case "A60", "A63"
rc = 3 'Ramp
Case "A65", "A66", "A68", "A69"
rc = 4 'Ferry
Case "A62"
rc = 5 'Roundabout
End Select

It is picking attributes out of my Census Feature Class Code (CFCC) column. But is it not classifying them in the same way my metadata says they should be. I have some evidence my metadata is out of date, so maybe the code knows better, but I can’t be sure. So, I replaced the code with this, which I am sure about:

If [FTYPE] = "FWY" Or [FTYPE] = "HWY" Then
rc = 2 'Highway
ElseIf [FTYPE] = "RAMP" Then
rc = 3 'Ramp
Else
rc = 1 'Local road
End If

I didn’t have anything that was obviously ferries or roundabouts. Make sure rc, or whatever variable you use, is in the “Value =” box below the code window. Make the same changes for the To-From direction as well.

Now it is time to create your Cost Attributes. Press the Add… button and create a Distance Attribute. Make sure the Usage Type is Cost and that you set the units and data type to match your length field. Uncheck the Use by Default box unless you don’t have information to create a Time attribute.

It will have a yellow exclamation point beside it until you press the Evaluators button and define how it should be calculated. Set the Type to Field and the Value to your length field for both directions.

Follow the same procedure to create a Time attribute, except this time set the units to Minutes and keep Use by Default checked on. When you get to the Evaluators screen, set the Type to Field and then click the Evaluator Properties button so you can enter an expression (unless there is already a time field in your attribute table). I used the expression ( [LENGTH] / [Speed] ) * 60 in the “Value =” box. This works if you have a field for length in miles, speed in miles per hour, and want time in minutes. Adjust accordingly.

Next create a Hierarchy attribute (Usage Type: Hierarchy). You will probably want to leave the Use by Default box checked, but I will leave that up to you. (These default settings can still be changed when you run scenarios later). If you created a new field for it, then calculate it using that. Otherwise you’ll have to code a classification expression like I did for the RoadClass attribute… only this time with categories 1-3.

Finally, if you thought of any potential restrictions to travel earlier, create Restriction attributes for them now. Create a different attribute for each type of Restriction. I set one: “Private”, for private roads and driveways, so I could avoid them if need be (like if I was driving a commercial vehicle). I didn’t use it by default because most of the time this won’t be an issue. Restriction attributes are based on a Boolean value (True or False) so my classification expression looks a little different:

Here’s my list of attributes in the end:

If you’ve done everything right thus far, you’ll have the option to configure driving directions. (It didn’t let me the first time around, I think because I didn’t create a Distance attribute). These are cool and you definitely want them! Click the Directions… button to see/change the settings. It’s pretty smart and gets everything right for me automatically. You can click anywhere to bring up drop-down menus and change things.

I didn’t have anything in my attribute table that helps with labeling highway shields (like route numbers). But I do have a field that says which city/county each road segment is in. So I pointed to that as the boundary field on the Boundary tab. Now, the driving directions will tell me if I cross over from one jurisdiction to another.

You’ll get a summary at the end, and then it’s time to click FINISH! Go ahead and Build when it prompts you. Then, add your new network dataset to ArcMap because it is time to play.

Stay tuned for installment #3: Doing network analysis

Tags: , , ,

Bad Behavior has blocked 62 access attempts in the last 7 days.