Esempio n. 1
0
def setScript(args):
    script_name = args.script_name

    if not script_name:
        msg = '-s argument is required. Set -s argument to use script. (e.g. [-s st02-045] or [-s script/struts/st02-045.py])'
        sys.exit(logger.error(msg))

    if script_name.endswith('.py'):
        if paths.SCRIPT_PATH in script_name:
            script_path = os.path.join(paths.SCRIPT_PATH, script_name)
            checkFile(script_path)
            conf.SCRIPT_NAME = script_path
        else:
            checkFile(script_name)
            conf.SCRIPT_NAME = script_name
    else:
        if not os.path.splitext(script_name)[-1]:
            script_path = os.path.join(paths.SCRIPT_PATH, script_name + '.py')
            checkFile(script_path)
            conf.SCRIPT_NAME = script_path
        else:
            checkFile(script_name)
            conf.SCRIPT_NAME = script_name

    msg = 'Use script: %s' % conf.SCRIPT_NAME  # os.path.split(conf.SCRIPT_NAME)[-1].rstrip('.py')
    logger.success(msg)
Esempio n. 2
0
 def loadNetwork(self, network, cost=None, cutoff=None, numToFind=None, searchDist=None, cutoffFld=None, numToFindFld=None, mappings=[]):
   common.progress('creating routing layer')
   if not numToFind:
     numToFind = common.count(self.places)
   self.naLayer = self.makeNALayer(common.checkFile(network), self.NA_LAY, cost, cutoff, numToFind)
   self.cost = cost
   self.placeMapper.addSilentField(cost, float)
   common.progress('calculating places\' network locations')
   self.calculateLocations(network, self.places, searchDist)
   common.progress('loading places to network')
   # create mappings
   toMappingList = common.NET_FIELDS + [(self.NAME_MAP, self.placesIDField, None)]
   for item in mappings:
     toMappingList.append(item + [None])
   fromMappingList = toMappingList[:]
   if cutoffFld:
     fromMappingList.append((self.CUTOFF_PREFIX + cost, cutoffFld, None))
   if numToFindFld:
     fromMappingList.append((self.NUM_TO_FIND_HEADER, numToFindFld, None))
   # load locations
   arcpy.AddLocations_na(self.NA_LAY, self.OD_SUBLAYERS[0], self.places, self.networkMappings(fromMappingList), '', append='clear')
   arcpy.AddLocations_na(self.NA_LAY, self.OD_SUBLAYERS[1], self.places, self.networkMappings(toMappingList), '', append='clear')
   self.routeSublayer = common.sublayer(self.naLayer, self.OUTPUT_SUBLAYER)
   self.linkMapper = conversion.LinkFieldMapper(self.routeSublayer)
   try:
     self.linkMapper.addMapField(self.OUT_COST_PREFIX + cost, cost)
   except conversion.FieldError:
     raise conversion.FieldError, 'cost attribute %s not found in network dataset' % cost
Esempio n. 3
0
 def __init__(self, zones, zoneIDFld, method, location, **kwargs):
   zones = common.toFeatureClass(common.checkFile(zones))
   if not location:
     location = common.location(zones)
   Converter.__init__(self, location, **kwargs)
   self.zones = zones
   self.zoneMapper = ODFieldMapper(self.zones)
   self.zoneMapper.addIDField(zoneIDFld, [common.NEIGH_FROM_FLD, common.NEIGH_TO_FLD], transfer=True)
   self.method = method
   self.tmpTable = self.tablePath(self.TABLE_FILE_NAME)
   self.swmFile = self.folderPath(self.SWM_FILE_NAME)
   common.overwrite(True)
Esempio n. 4
0
 def loadNetwork(self, network, cost, searchDist, mappings=[]):
   common.progress('calculating places\' network locations')
   network = common.checkFile(network)
   self.calculateLocations(network, self.places, searchDist)
   self.mappings = self.networkMappings(common.NET_FIELDS + mappings)
   if self.speedup:
     self.performSpeedup(network, cost)
   common.progress('preparing routing layer')
   self.naLayer = self.makeRouteLayer(network, self.ROUTE_LAY, cost)
   self.routeSublayer = common.sublayer(self.naLayer, 'Routes')
   # common.debug(common.fieldList(self.routeSublayer))
   self.cost = cost
   self.placeMapper.addSilentField(self.cost, float)
Esempio n. 5
0
 def loadNetwork(self, network, cost=None, searchDist=None, breaks=[1]):
   common.progress('creating routing layer')
   # if not numToFind:
     # numToFind = common.count(self.places)
   self.naLayer = self.makeNALayer(common.checkFile(network), self.NA_LAY, cost, breaks)
   common.progress('calculating places\' network locations')
   self.calculateLocations(network, self.places, searchDist)
   common.progress('loading places to network')
   # create mappings
   toMappingList = common.NET_FIELDS + [(self.NAME_MAP, self.placesIDField, None)]
   for item in mappings:
     toMappingList.append(item + [None])
   # fromMappingList = toMappingList[:]
   # if cutoffFld:
     # fromMappingList.append((self.CUTOFF_PREFIX + cost, cutoffFld, None))
   # if numToFindFld:
     # fromMappingList.append((self.NUM_TO_FIND_HEADER, numToFindFld, None))
   # load locations
   arcpy.AddLocations_na(self.NA_LAY, self.OD_SUBLAYER, self.places, self.networkMappings(toMappingList), '', append='clear')
   self.outputSublayer = common.sublayer(self.naLayer, self.OUTPUT_SUBLAYER)
Esempio n. 6
0
 def __init__(self, polygons, inside=False, idFld=None, mapping=None, **kwargs):
   Converter.__init__(self, **kwargs)
   self.polygons = common.checkFile(polygons)
   self.inside = inside
Esempio n. 7
0
 def __init__(self, location=None, **kwargs):
   common.progress('initializing paths')
   if location:
     self.location = common.checkFile(location)
Esempio n. 8
0
 def _file_target(target):
     checkFile(filename_target)
     targets.file_target = target
     targets.handle_mode = targets.FILE_MODE
Esempio n. 9
0
 def __init__(self, table, odIDFields, places, placeIDField, location, **kwargs):
   PlaceLinker.__init__(self, location, places, placeIDField, **kwargs)
   self.table = common.checkFile(table)
   self.linkMapper = conversion.LinkFieldMapper(self.table)
   self.placeMapper.setJoinIDFields(odIDFields)
Esempio n. 10
0
 def __init__(self, table, odIDFields, places, placeIDField, **kwargs):
   PlaceLinker.__init__(self, common.location(table), places, placeIDField, **kwargs)
   self.table = common.checkFile(table)
   self.placeMapper.setJoinIDFields(odIDFields)
Esempio n. 11
0
 def __init__(self, location, places, placesIDField, **kwargs):
   conversion.Converter.__init__(self, location, **kwargs)
   self.places = common.checkFile(places)
   self.placesIDField = placesIDField
   self.placeMapper = self.MAPPER_CLASS(self.places)
   self.placeMapper.addIDField(placesIDField)