Skip to content

Commit a8e53bf

Browse files
authored
Add error if no nodes selected by ShapeFile (#221)
1 parent e192242 commit a8e53bf

1 file changed

Lines changed: 64 additions & 64 deletions

File tree

TMGToolbox/src/input_output/export_subarea_tool.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ def __call__(
178178
self.normGap = normGap
179179
self.RunTitle = RunTitle[:25]
180180
self.PerformanceFlag = PerformanceFlag
181-
if str(xtmf_BackgroundTransit).lower() == "true":
182-
self.BackgroundTransit = True
183-
else:
184-
self.BackgroundTransit = False
181+
self.BackgroundTransit = str(xtmf_BackgroundTransit).lower() == "true"
185182
self.ShapeFileLocation = xtmf_shapeFileLocation
186183
self.ISubareaLinkSelection = xtmf_iSubareaLinkSelection
187184
self.JSubareaLinkSelection = xtmf_jSubareaLinkSelection
@@ -285,7 +282,6 @@ def get_attribute_name(at):
285282
self._tracker.completeTask()
286283
with _m.logbook_trace("Running Road Assignments."):
287284
# init assignment flag. if assignment done, then trip flag
288-
assignmentComplete = False
289285
for i in range(len(self.Demand_List)):
290286
# check to see if any time matrices defined to fix the times matrix for that class
291287
if self.TimesMatrixId[i] is not None:
@@ -302,65 +298,65 @@ def get_attribute_name(at):
302298
num_processors=self.NumberOfProcessors,
303299
)
304300
# if no assignment has been done, do an assignment
305-
if assignmentComplete is False:
306-
attributes = []
307-
for i in range(len(self.Demand_List)):
308-
attributes.append(None)
309-
SOLA_spec = self._RoadAssignmentUtil._getPrimarySOLASpec(
310-
self.Demand_List,
311-
peakHourMatrix,
312-
appliedTollFactor,
313-
self.Mode_List_Split,
314-
classVolumeAttributes,
315-
costAttribute,
316-
attributes,
317-
None,
318-
None,
319-
None,
320-
None,
321-
None,
322-
None,
323-
None,
324-
multiprocessing,
325-
self.Iterations,
326-
self.rGap,
327-
self.brGap,
328-
self.normGap,
329-
self.PerformanceFlag,
330-
self.TimesMatrixId,
331-
)
332-
333-
if self.CreateGateAttrib:
334-
self._CreateSubareaExtraAttribute(self.SubareaGateAttribute, "LINK")
335-
self._TagSubareaCentroids()
336-
337-
if self.CreateNodeFlagFromShapeFile:
338-
self._CreateSubareaExtraAttribute(self.SubareaNodeAttribute, "NODE")
339-
network = self.Scenario.get_network()
340-
subareaNodes = self._LoadShapeFIle(network)
341-
for node in subareaNodes:
342-
node[self.SubareaNodeAttribute] = 1
343-
self.Scenario.publish_network(network)
344-
d = _MODELLER.desktop.data_explorer()
345-
remove = None
346-
output_path = os.path.join(os.path.abspath(self.OutputFolder), "emmebank")
347-
for db in d.databases():
348-
db_path = os.path.abspath(db.path)
349-
if db_path == output_path:
350-
remove = db
351-
break
352-
if remove is not None:
353-
d.remove_database(remove)
354-
self._tracker.runTool(
355-
subareaAnalysisTool,
356-
subarea_nodes=self.SubareaNodeAttribute,
357-
subarea_folder=self.OutputFolder,
358-
traffic_assignment_spec=SOLA_spec,
359-
extract_transit=self.ExtractTransit,
360-
overwrite=True,
361-
gate_labels=self.SubareaGateAttribute,
362-
scenario=self.Scenario,
363-
)
301+
302+
attributes = []
303+
for i in range(len(self.Demand_List)):
304+
attributes.append(None)
305+
SOLA_spec = self._RoadAssignmentUtil._getPrimarySOLASpec(
306+
self.Demand_List,
307+
peakHourMatrix,
308+
appliedTollFactor,
309+
self.Mode_List_Split,
310+
classVolumeAttributes,
311+
costAttribute,
312+
attributes,
313+
None,
314+
None,
315+
None,
316+
None,
317+
None,
318+
None,
319+
None,
320+
multiprocessing,
321+
self.Iterations,
322+
self.rGap,
323+
self.brGap,
324+
self.normGap,
325+
self.PerformanceFlag,
326+
self.TimesMatrixId,
327+
)
328+
329+
if self.CreateGateAttrib:
330+
self._CreateSubareaExtraAttribute(self.SubareaGateAttribute, "LINK")
331+
self._TagSubareaCentroids()
332+
333+
if self.CreateNodeFlagFromShapeFile:
334+
self._CreateSubareaExtraAttribute(self.SubareaNodeAttribute, "NODE")
335+
network = self.Scenario.get_network()
336+
subareaNodes = self._LoadShapeFIle(network)
337+
for node in subareaNodes:
338+
node[self.SubareaNodeAttribute] = 1
339+
self.Scenario.publish_network(network)
340+
d = _MODELLER.desktop.data_explorer()
341+
remove = None
342+
output_path = os.path.join(os.path.abspath(self.OutputFolder), "emmebank")
343+
for db in d.databases():
344+
db_path = os.path.abspath(db.path)
345+
if db_path == output_path:
346+
remove = db
347+
break
348+
if remove is not None:
349+
d.remove_database(remove)
350+
self._tracker.runTool(
351+
subareaAnalysisTool,
352+
subarea_nodes=self.SubareaNodeAttribute,
353+
subarea_folder=self.OutputFolder,
354+
traffic_assignment_spec=SOLA_spec,
355+
extract_transit=self.ExtractTransit,
356+
overwrite=True,
357+
gate_labels=self.SubareaGateAttribute,
358+
scenario=self.Scenario,
359+
)
364360

365361
def _CreateSubareaExtraAttribute(self, attribID, attribType):
366362
if self.Scenario.extra_attribute(attribID) is None:
@@ -395,6 +391,10 @@ def _LoadShapeFIle(self, network):
395391
point = _geolib.nodeToShape(node)
396392
if border.contains(point):
397393
subareaNodes.append(node)
394+
# Make sure that we read in at least one node!
395+
if len(subareaNodes) == 0:
396+
raise Exception("No nodes were contained within the Shapefile's polygon to use for the subarea network!\r\n" + \
397+
"Make sure that the ShapeFile is in the same projection as the EMME project!")
398398
return subareaNodes
399399

400400
@_m.method(return_type=_m.TupleType)

0 commit comments

Comments
 (0)