예제 #1
0
 def loadSourceDatabaseScenarios(self):
     emmebank = Emmebank(self.FromEmmebankPath)
     
     options = []
     for scenario in emmebank.scenarios():
         text = "%s - %s" %(scenario.id, scenario.title)
         options.append('<option value="%s">%s</option>' %(scenario.id, text))
     
     emmebank.dispose()
     return "\n".join(options)
예제 #2
0
 def loadSourceDatabaseScenarios(self):
     emmebank = Emmebank(self.FromEmmebankPath)
     
     options = []
     for scenario in emmebank.scenarios():
         text = "%s - %s" %(scenario.id, scenario.title)
         options.append('<option value="%s">%s</option>' %(scenario.id, text))
     
     emmebank.dispose()
     return "\n".join(options)
예제 #3
0
 def _Execute(self):
     with _m.logbook_trace(name="{classname} v{version}".format(classname=(self.__class__.__name__), version=self.version),
                                  attributes=self._GetAtts()):           
         
         self.TRACKER.startProcess(5)
         with _m.logbook_trace("Loading scenarios and applying node filters"):
             #---Load the source network
             sourceBank = Emmebank(self.FromEmmebankPath)
             try:
                 sourceScenario = sourceBank.scenario(self.FromScenarioId)
                 if sourceScenario == None:
                     #Check, because the scenario could've been deleted in between the time
                     #that the list of scenarios was extracted, and the time that this tool
                     #is running
                     raise Exception("Scenario %s no longer exists" %self.FromScenarioId)
                 
                 with _util.tempExtraAttributeMANAGER(sourceScenario, 'NODE') as sourceTempAtt:
                     if self.FromZonesToIgnoreSelector:
                         self._ApplySelector(sourceScenario, sourceTempAtt, self.FromZonesToIgnoreSelector)
                     self.TRACKER.completeSubtask()
                     
                     sourceNetwork = sourceScenario.get_network()
                     self.TRACKER.completeSubtask()
             finally:
                 if self.FromEmmebankPath != _MODELLER.emmebank.path:
                     sourceBank.dispose()
             
             
             
             #---Load the target network
             with _util.tempExtraAttributeMANAGER(self.ToScenario, 'NODE') as targetTempAtt:
                 if self.ToNodesToIgnoreSelector:
                     self._ApplySelector(self.ToScenario, targetTempAtt, self.ToNodesToIgnoreSelector)
                 self.TRACKER.completeSubtask()
                 
                 targetNetwork = self.ToScenario.get_network()
                 self.TRACKER.completeSubtask()
         
         #---Determine the attributes to copy over
         attsToCopy = self._DetermineAttributesToCopy(sourceNetwork, targetNetwork)
         self.TRACKER.completeSubtask()
         self.TRACKER.completeTask()
         
         #---Get the source nodes to be copied
         zonesToCopy = [zone for zone in sourceNetwork.centroids() if zone[sourceTempAtt.id] == 0]          
         _m.logbook_write("Found %s zones to copy over." %len(zonesToCopy))
         
         #---Clear un-flagged zones from the target network
         if self.ClearTargetZonesFlag:
             with _m.logbook_trace("Clearing zones from target network"):
                 zonesToDelete = [zone.number for zone in targetNetwork.centroids()]
                 for id in zonesToDelete: targetNetwork.delete_node(id, cascade=True)
                 _m.logbook_write("%s zones deleted from target network" %len(zonesToDelete)) 
         
         #---Run the matching process
         if self.MatchOption == 1:
             message = "Copying zones using node coordinates"
             func = self._GetMatchByGeometryLambda(targetNetwork)
         elif self.MatchOption == 2:
             message = "Copying zones using node IDs"
             func = self._GetMatchByIdLambda(targetNetwork)
         else:
             raise KeyError("Unrecognized match option", self.MatchOption)
         with _m.logbook_trace(message):
             count, uncopiedConnectors = self._NewCopyZones(zonesToCopy, targetNetwork, targetTempAtt, attsToCopy, func)
             self._WriteLogbookReport(uncopiedConnectors)                
         
         _m.logbook_write("Copied over %s connectors from source scenario" %count)
         _m.logbook_write("%s connectors could not be copied" %len(uncopiedConnectors))
         
         #---Write  shapefile
         if len(uncopiedConnectors) > 0 and self.ShapefileReport:
             self._WriteShapefile(uncopiedConnectors)
             _m.logbook_write("Wrote shapefile to %s" %self.ShapefileReport)
         self.TRACKER.completeTask()
         
         #---Publish the network
         if self.PublishNetworkFlag:
             self.ToScenario.publish_network(targetNetwork, True)
             _MODELLER.desktop.refresh_needed(True)
         self.TRACKER.completeTask()
예제 #4
0
    def _Execute(self):
        with _m.logbook_trace(name="{classname} v{version}".format(
                classname=(self.__class__.__name__), version=self.version),
                              attributes=self._GetAtts()):

            self.TRACKER.startProcess(5)
            with _m.logbook_trace(
                    "Loading scenarios and applying node filters"):
                #---Load the source network
                sourceBank = Emmebank(self.FromEmmebankPath)
                try:
                    sourceScenario = sourceBank.scenario(self.FromScenarioId)
                    if sourceScenario is None:
                        #Check, because the scenario could've been deleted in between the time
                        #that the list of scenarios was extracted, and the time that this tool
                        #is running
                        raise Exception("Scenario %s no longer exists" %
                                        self.FromScenarioId)

                    with _util.tempExtraAttributeMANAGER(
                            sourceScenario, 'NODE') as sourceTempAtt:
                        if self.FromZonesToIgnoreSelector:
                            self._ApplySelector(sourceScenario, sourceTempAtt,
                                                self.FromZonesToIgnoreSelector)
                        self.TRACKER.completeSubtask()

                        sourceNetwork = sourceScenario.get_network()
                        self.TRACKER.completeSubtask()
                finally:
                    if self.FromEmmebankPath != _MODELLER.emmebank.path:
                        sourceBank.dispose()

                #---Load the target network
                with _util.tempExtraAttributeMANAGER(self.ToScenario,
                                                     'NODE') as targetTempAtt:
                    if self.ToNodesToIgnoreSelector:
                        self._ApplySelector(self.ToScenario, targetTempAtt,
                                            self.ToNodesToIgnoreSelector)
                    self.TRACKER.completeSubtask()

                    targetNetwork = self.ToScenario.get_network()
                    self.TRACKER.completeSubtask()

            #---Determine the attributes to copy over
            attsToCopy = self._DetermineAttributesToCopy(
                sourceNetwork, targetNetwork)
            self.TRACKER.completeSubtask()
            self.TRACKER.completeTask()

            #---Get the source nodes to be copied
            zonesToCopy = [
                zone for zone in sourceNetwork.centroids()
                if zone[sourceTempAtt.id] == 0
            ]
            _m.logbook_write("Found %s zones to copy over." % len(zonesToCopy))

            #---Clear un-flagged zones from the target network
            if self.ClearTargetZonesFlag:
                with _m.logbook_trace("Clearing zones from target network"):
                    zonesToDelete = [
                        zone.number for zone in targetNetwork.centroids()
                    ]
                    for id in zonesToDelete:
                        targetNetwork.delete_node(id, cascade=True)
                    _m.logbook_write("%s zones deleted from target network" %
                                     len(zonesToDelete))

            #---Run the matching process
            if self.MatchOption == 1:
                message = "Copying zones using node coordinates"
                func = self._GetMatchByGeometryLambda(targetNetwork)
            elif self.MatchOption == 2:
                message = "Copying zones using node IDs"
                func = self._GetMatchByIdLambda(targetNetwork)
            else:
                raise KeyError("Unrecognized match option", self.MatchOption)
            with _m.logbook_trace(message):
                count, uncopiedConnectors = self._NewCopyZones(
                    zonesToCopy, targetNetwork, targetTempAtt, attsToCopy,
                    func)
                self._WriteLogbookReport(uncopiedConnectors)

            _m.logbook_write("Copied over %s connectors from source scenario" %
                             count)
            _m.logbook_write("%s connectors could not be copied" %
                             len(uncopiedConnectors))

            #---Write  shapefile
            if len(uncopiedConnectors) > 0 and self.ShapefileReport:
                self._WriteShapefile(uncopiedConnectors)
                _m.logbook_write("Wrote shapefile to %s" %
                                 self.ShapefileReport)
            self.TRACKER.completeTask()

            #---Publish the network
            if self.PublishNetworkFlag:
                self.ToScenario.publish_network(targetNetwork, True)
                _MODELLER.desktop.refresh_needed(True)
            self.TRACKER.completeTask()