Select to view content in your preferred language

Setting vehicle restrictions in UWP via TravelMode.AttributeParameterValues throws Exception Invalid attribute parameter attribute name

356
4
Jump to solution
03-19-2024 08:38 AM
DaveMorrow
New Contributor II

When setting vehicle restriction parameters via TravelMode.AttributeParameterValues, method RouteTask.CreateAsync throws an Exception with the following message.

Invalid attribute parameter attribute name "Height Restriction".
Invalid attribute parameter attribute name "Weight Restriction".
Invalid attribute parameter attribute name "Width Restriction".

I've been unable to find documentation for the values in the .Net or UWP section of the API reference, here:

Class AttributeParameterValue (arcgis.com)

However, there is explanation of these values in the REST services documentation here:

Direct request—ArcGIS REST APIs | ArcGIS Developers

Please advise if there is something incorrect in the code or parameters and how I can set vehicle restrictions to apply to SolveRouteAsync, specifically height, width and weight restrictions. And if there is a documentation page I can refer to.

Sample code:

RouteTask offlineRouteTask = await RouteTask.CreateAsync(Convert.ToString(dataPath), networkName);
RouteParameters routeParams = await offlineRouteTask.CreateDefaultParametersAsync();

List<Stop> routeStops = new List<Stop> { new Stop(fromPoint), new Stop(toPoint) };

routeParams.SetStops(routeStops);
routeParams.TravelMode.Type = "Driving";
routeParams.ReturnDirections = true;
routeParams.ReturnStops = true;
routeParams.DirectionsStyle = DirectionsStyle.Navigation;
routeParams.TravelMode.UTurnPolicy = UTurnPolicy.NotAllowed;


var attributes = routeParams.TravelMode.AttributeParameterValues;
attributes.Add(new AttributeParameterValue { AttributeName = "Height Restriction", ParameterName = "Vehicle Height (meters)", ParameterValue = 3.3 });
attributes.Add(new AttributeParameterValue { AttributeName = "Weight Restriction", ParameterName = "Vehicle Weight (kilograms)", ParameterValue = 12500 });
attributes.Add(new AttributeParameterValue { AttributeName = "Width Restriction", ParameterName = "Vehicle Width (meters)", ParameterValue = 2.5 });

Graphic routeGraphic = null;
try
{
RouteResult solvedRouted = await offlineRouteTask.SolveRouteAsync(routeParams);

}

catch (Exception ex)
{

// Log Exception

}

0 Kudos
1 Solution

Accepted Solutions
FrankK
by
New Contributor III


Using one of the attributes, "Height Restriction", as an example ...

Does your network data have a "Height Restriction"? This code is added a attribute parameter value to a network attribute called "Height Restriction", so if it does not exist you will get this error.

I assume you really just want to use the restriction with a specific parameter value. So you should update the network dataset by adding the restriction and setting up the parameters.

Then to set the parameter value you could use this code:

foreach (AttributeParameterValue attributeParameterValue in attributes) {
if (string.Equals(attributeParameterValue.AttributeName, "Height Restriction", StringComparison.OrdinalIgnoreCase)) {
if (string.Equals(attributeParameterValue.ParameterName, "Vehicle Height (meters)", StringComparison.OrdinalIgnoreCase)) {
attributeParameterValue.ParameterValue = 3.3;
}
}
}

 

We have some tutorial data at this url.  . The SanDiego.gdb data in `.\Network_Analyst_Pro_Tutorial\Network Analyst\Tutorial\CreateNetworkDataset\ExpectedOutput` has a "Height Restriction" you can use as an example.

View solution in original post

0 Kudos
4 Replies
FrankK
by
New Contributor III


Using one of the attributes, "Height Restriction", as an example ...

Does your network data have a "Height Restriction"? This code is added a attribute parameter value to a network attribute called "Height Restriction", so if it does not exist you will get this error.

I assume you really just want to use the restriction with a specific parameter value. So you should update the network dataset by adding the restriction and setting up the parameters.

Then to set the parameter value you could use this code:

foreach (AttributeParameterValue attributeParameterValue in attributes) {
if (string.Equals(attributeParameterValue.AttributeName, "Height Restriction", StringComparison.OrdinalIgnoreCase)) {
if (string.Equals(attributeParameterValue.ParameterName, "Vehicle Height (meters)", StringComparison.OrdinalIgnoreCase)) {
attributeParameterValue.ParameterValue = 3.3;
}
}
}

 

We have some tutorial data at this url.  . The SanDiego.gdb data in `.\Network_Analyst_Pro_Tutorial\Network Analyst\Tutorial\CreateNetworkDataset\ExpectedOutput` has a "Height Restriction" you can use as an example.

0 Kudos
DaveMorrow
New Contributor II

This makes sense. I believe our sample data doesn't include these attributes. And the API documentation doesn't explain that they will need to be added to the dataset and then updated where they exist in the collection.

I will try with the sample database.

Thank you.

0 Kudos
DaveMorrow
New Contributor II

Hi @FrankK 

The code provided no longer throws the Invalid Parameter exception so I think this will work with appropriate data.

I've downloaded the tutorial data but it's different to the structure I'm using. Apologies but I'm not an ArcGis Pro user so need some guidance. My sample has a .VTPK file for the map and .geodatabase file (and .tn folder) for the road network but I can't find this in the San Diego sample. What file do I target in the RouteTask.CreateAsync method?

Can I use the SanDiego sample without manipulating in ArcGisPro?

Your help would be appreciated.

Thanks

 

0 Kudos
FrankK
by
New Contributor III

The San Diego data is a file geodatabase, but the runtime requires a mobile geodatabase.  To create a mobile geodatabase from a file geodatabase you use the Geoprocessing Create Mobile Map Package tool.  To do this you would add the “NewSandiego_ND” from the file geodatabase to a map and then use the tool, entering the Output File.   Running the tool creates a .mmpk which is a zip file of the data, the map, plus some other metadata.

It sounds like for the original data you have just the .geodatabase file (and .tn folder), so to get to that you can unzip the .mmpk file.  The.geodatabase file (and .tn folder) will be in the “commondata” folder, so you can copy them from there.

Alternatively, to unzip the data, there is an Extract Package tool in Pro that can do the extraction\unzipping.

Tell me if that helps.

Frank

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/create-mobile-map-package.ht... 

https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/extract-package.htm 

 

0 Kudos