Calculating freight cost in a network dataset cost attribute

99
5
Jump to solution
11-08-2022 07:52 AM
ConnieSu
New Contributor III

Hello! I have a network dataset with roads and railways (line features) and railway terminals (point feature). I want to calculate the freight cost based on the distance in kilometers. The freight cost is equal the distance multiplied by a constant, that depends on the transport mode.

I've added a freight cost attribute, firstly with an "others" unit and secondly with a "distance - kilometers" unit. I've tried the field script equal to [Shape]*constant and [Shape_Length]*constant, but in all tries I did not achieve the expected result, that would be the distance (in kilometers) multiplied by the constant.

2022-11-08 (8).png

2022-11-08 (9).png

Please, could somebody help me and tell me what I'm doing wrong?

Thanks and regards!  

0 Kudos
1 Solution

Accepted Solutions
MelindaMorang
Esri Regular Contributor

Can you give more details on what you mean by "I did not achieve the expected result"?  How was it different from what you expected?

In general, your approach seems correct.  You just want to scale the distance by some factor and report that as the freight cost.

My current suspicion is that the spatial reference of your data does not have units of Kilometers.  If it's in Meters or decimal degrees or something, the values returned by the Shape or Shape_Length fields will be in those units and not kilometers, so you'll get the wrong values.

You could precompute a field in your source feature classes that has the distance in Kilometers.  Or, you could use a function evaluator to combine your freight cost factors with your existing distance attribute that's already in Kilometers (for that case, where the Shape or Shape_Length fields are read directly, the network dataset does the unit conversion for you automatically).

MelindaMorang_0-1667934998609.png

 

View solution in original post

0 Kudos
5 Replies
MelindaMorang
Esri Regular Contributor

Can you give more details on what you mean by "I did not achieve the expected result"?  How was it different from what you expected?

In general, your approach seems correct.  You just want to scale the distance by some factor and report that as the freight cost.

My current suspicion is that the spatial reference of your data does not have units of Kilometers.  If it's in Meters or decimal degrees or something, the values returned by the Shape or Shape_Length fields will be in those units and not kilometers, so you'll get the wrong values.

You could precompute a field in your source feature classes that has the distance in Kilometers.  Or, you could use a function evaluator to combine your freight cost factors with your existing distance attribute that's already in Kilometers (for that case, where the Shape or Shape_Length fields are read directly, the network dataset does the unit conversion for you automatically).

MelindaMorang_0-1667934998609.png

 

0 Kudos
ConnieSu
New Contributor III

Hello Melinda! I have another problem, could you please help me? I've managed to calculate the freight cost using the following cost attribute:

2022-11-09 (4).png

I'm using a standalone Python script. I've included the command:

route.accumulateAttributeNames = (["Frete2"])

However, the field only appears at arcpy.nax.RouteOutputDataType.Routes, but does not appear at the arcpy.nax.RouteOutputDataType.RouteEdges.

Do you know why? I need this field in both tables, so I can use it in other calculations.

Thanks and regards!

0 Kudos
ConnieSu
New Contributor III

Hi! I don't know why, but the results of the freight cost attribute (in Distance units) are under the "Attr_Kilometers", "Cumul_Kilometers", etc. If I want the actual distance in kilometers, then I have to create another length cost attribute (also in Distance units), and its results appear in the fields "Attr_Length", "Cumul_Length", etc. So, problem solved! Thanks!

0 Kudos
MelindaMorang
Esri Regular Contributor

The output fields for routes and RouteEdges are documented here: https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/route-output-data-types.htm

Fields starting with "Attr_" are input fields and should not appear in the output tables at all, so your further comment confuses me a little.

Anyway, by default, the Route output always includes Minutes, Miles, and Kilometers, but any accumulated attributes will show up as Total_[AccumulateAttributeName]_[Units].  Yours should be something like Total_Frete2_Other.

This does not look right: route.accumulateAttributeNames = (["Frete2"]).  The parentheses are not necessary.  It should be route.accumulateAttributeNames = ["Frete2"].

0 Kudos
ConnieSu
New Contributor III

Hello Melinda! Thanks for your reply!

I compared both freight costs attributes' results with the length cost attribute's results, and the freight results were related to the shape length, and not with the kilometers (please refer to the picture below). 

I ran the route solver again following your advice and achieved the desired results. Thank you for your help!

2022-11-08 (10).png

0 Kudos