Barrier "" in "Line Barriers" has no associated network location information.

802
1
09-13-2019 05:12 AM
sotokan80_
New Contributor III

I am using ArcGis 10.4.1 and network analyst extension. I am facing an issue when loading barrier lines using arcpy. It appears that the network elements that have restrictions in network dataset attributes have no network location information.

If i load the line barriers using ArcMap and a New Route layer everything works ok, if i click "Use Geometry" in Location Position frame, whilst if i use the arcpy created layer if i click  "Use Geometry" in Location Position frame and if i add a new line barrier that is crossing an network element that has restriction i get error: Barrier "whatever" in "Line Barriers" has no associated network location information. If the line barrier doesnt cross elements with restrictions i get no error.

Obviously the arcpy created layer has a miconfiguration. Part of the code that i use:

## Create a new Route layer


outRouteResultObject = arcpy.na.MakeRouteLayer(inNetworkDataset, outNALayerName, impedanceAttribute, "FIND_BEST_ORDER", ""+EndPoint+"", "", ["Minutes", "Length"], "ALLOW_DEAD_ENDS_AND_INTERSECTIONS_ONLY", RoadRules, "USE_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES","")


##Get the layer object from the result object. The route layer can now be referenced using the layer object.


outNALayer = outRouteResultObject.getOutput(0)

##Get the names of all the sublayers within the route layer.


subLayerNames = arcpy.na.GetNAClassNames(outNALayer)

##Store the layer names that we will use later


stopsLayerName = subLayerNames["Stops"]
routesLayerName = subLayerNames["Routes"]


##set up field mapping. Map the "Group_ID" field from the input data to the RouteName property in the Stops sublayer


fieldMappingsStore = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
fieldMappingsStore["RouteName"].mappedFieldName = "Group_ID"
fieldMappingsStops = arcpy.na.NAClassFieldMappings(outNALayer, stopsLayerName)
fieldMappingsStops["RouteName"].mappedFieldName = "Group_ID"
fieldMappingsStops["Attr_Minutes"].defaultValue = 2


##Add locations as Stops.


arcpy.na.AddLocations(outNALayer, stopsLayerName, inDepots, fieldMappingsStore, "300 meters", "OBJECTID", [["networkDataset_ND", "MIDDLE"], ["networkDataset_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "", "", "")
arcpy.na.AddLocations(outNALayer, stopsLayerName, inOrders, fieldMappingsStops, "300 meters", "OBJECTID", [["networkDataset_ND", "SHAPE"], ["networkDataset_ND_Junctions", "NONE"]], "MATCH_TO_CLOSEST", "APPEND", "SNAP", "1", "EXCLUDE", searchQuery)

#Figure out the layer's impedance attribute


solver_props = arcpy.na.GetSolverProperties(outNALayer)
impedance = solver_props.impedance
pointBarriersLayerName = subLayerNames["PolylineBarriers"]# {u'Barriers': u'Point Barriers', u'Routes': u'Routes', u'PolylineBarriers': u'Line Barriers', u'Stops': u'Stops', u'PolygonBarriers': u'Polygon Barriers'} etc
fieldMappingsBR = arcpy.na.NAClassFieldMappings(outNALayer, pointBarriersLayerName)
fieldMappingsBR["BarrierType"].defaultValue = 0 #if it is restriction otherwise 1
fieldMappingsBR["Attr_" + impedance].defaultValue = 1.4

#Load restrictions features


arcpy.na.AddLocations(outNALayer, pointBarriersLayerName, Barriers_shp, fieldMappingsBR)

Can you spot the mistake

0 Kudos
1 Reply
sotokan80_
New Contributor III

i figured out my mistake i had a searchQuery parameter for the stops to exclude locate on highways that was doing the same for line barriers. I changed

#Load restrictions features


arcpy.na.AddLocations(outNALayer, pointBarriersLayerName, Barriers_shp, fieldMappingsBR)

with 

arcpy.na.AddLocations(outNALayer, pointBarriersLayerName, Barriers_shp, fieldMappingsBR, "#", "", [["networkDataset_ND", "SHAPE"], ["networkDataset_ND_Junctions", "NONE"]], "", "APPEND", "#", "#", "#", [["RoadNetwork", '"Access" <> -2'],["networkDataset_ND_Junctions", ""]])

i tried with 

arcpy.na.AddLocations(outNALayer, pointBarriersLayerName, Barriers_shp, fieldMappingsBR, "#", "", [["networkDataset_ND", "SHAPE"], ["networkDataset_ND_Junctions", "NONE"]], "", "APPEND", "#", "#", "#", "#")

but it didnt work. Any ideas why?

0 Kudos