def runTool(inGTFSdir, SQLDbase):
    try:

        BBB_SharedFunctions.CheckArcVersion(min_version_pro="1.2")

        #----- SQLize the GTFS data-----
        arcpy.AddMessage("SQLizing the GTFS data...")
        arcpy.AddMessage("(This will take a while for large datasets.)")

        # GTFS files
        if not SQLDbase.lower().endswith(".sql"):
            SQLDbase = SQLDbase + ".sql"

        # Fix up list of GTFS datasets
        inGTFSdirList = inGTFSdir.split(";")
        # Remove single quotes ArcGIS puts in if there are spaces in the filename.
        for d in inGTFSdirList:
            if d[0] == "'" and d[-1] == "'":
                loc = inGTFSdirList.index(d)
                inGTFSdirList[loc] = d[1:-1]

        # The main SQLizing work is done in the sqlize_csv module
        # written by Luitien Pan.
        # Connect to or create the SQL file.
        sqlize_csv.connect(SQLDbase)
        # Create tables.
        for tblname in sqlize_csv.sql_schema:
            sqlize_csv.create_table(tblname)
        # SQLize all the GTFS files, for each separate GTFS dataset.
        for gtfs_dir in inGTFSdirList:
            # handle_agency checks for blank values in arrival_time and departure_time
            sqlize_csv.handle_agency(gtfs_dir)

        # Create indices to make queries faster.
        sqlize_csv.create_indices()

        # Check for non-overlapping date ranges to prevent double-counting.
        overlapwarning = sqlize_csv.check_nonoverlapping_dateranges()
        if overlapwarning:
            arcpy.AddWarning(overlapwarning)

        arcpy.AddMessage("Successfully created SQL database of GTFS data:")
        arcpy.AddMessage("- " + SQLDbase)

    except BBB_SharedFunctions.CustomError:
        arcpy.AddMessage("Failed to create SQL database of GTFS data.")
        pass

    except:
        arcpy.AddMessage("Failed to create SQL database of GTFS data.")
        raise
예제 #2
0
def runTool(inGTFSdir, SQLDbase):
    try:

        BBB_SharedFunctions.CheckArcVersion(min_version_pro="1.2")

        #----- SQLize the GTFS data-----
        arcpy.AddMessage("SQLizing the GTFS data...")
        arcpy.AddMessage("(This will take a while for large datasets.)")

        # GTFS files
        if not SQLDbase.lower().endswith(".sql"):
            SQLDbase = SQLDbase + ".sql"

        # Fix up list of GTFS datasets
        inGTFSdirList = inGTFSdir.split(";")
        # Remove single quotes ArcGIS puts in if there are spaces in the filename.
        for d in inGTFSdirList:
            if d[0] == "'" and d[-1] == "'":
                loc = inGTFSdirList.index(d)
                inGTFSdirList[loc] = d[1:-1]

        # The main SQLizing work is done in the sqlize_csv module
        # written by Luitien Pan.
        # Connect to or create the SQL file.
        sqlize_csv.connect(SQLDbase)
        # Create tables.
        for tblname in sqlize_csv.sql_schema:
            sqlize_csv.create_table(tblname)
        # SQLize all the GTFS files, for each separate GTFS dataset.
        for gtfs_dir in inGTFSdirList:
            # handle_agency checks for blank values in arrival_time and departure_time
            sqlize_csv.handle_agency(gtfs_dir)

        # Create indices to make queries faster.
        sqlize_csv.create_indices()

        # Check for non-overlapping date ranges to prevent double-counting.
        overlapwarning = sqlize_csv.check_nonoverlapping_dateranges()
        if overlapwarning:
            arcpy.AddWarning(overlapwarning)

        arcpy.AddMessage("Successfully created SQL database of GTFS data:")
        arcpy.AddMessage("- " + SQLDbase)

    except BBB_SharedFunctions.CustomError:
        arcpy.AddMessage("Failed to create SQL database of GTFS data.")
        pass

    except:
        arcpy.AddMessage("Failed to create SQL database of GTFS data.")
        raise
    for tblname in sqlize_csv.sql_schema:
        sqlize_csv.create_table(tblname)
    # SQLize all the GTFS files, for each separate GTFS dataset.
    for gtfs_dir in inGTFSdirList:
        # Run sqlize for each GTFS dataset. Check for returned errors
        GTFSErrors = sqlize_csv.handle_agency(gtfs_dir)
        if GTFSErrors:
            for error in GTFSErrors:
                arcpy.AddError(error)
            raise CustomError

    # Create indices to make queries faster.
    sqlize_csv.create_indices()

    # Check for non-overlapping date ranges to prevent double-counting.
    overlapwarning = sqlize_csv.check_nonoverlapping_dateranges()
    if overlapwarning:
        arcpy.AddWarning(overlapwarning)

# ----- Connect to SQL locally for further queries and entries -----

# Connect to the SQL database
    conn = sqlite3.connect(SQLDbase)
    c = conn.cursor()

    # ----- Make dictionary of route types -----

    # Find all routes and associated info.
    RouteDict = {}
    routesfetch = '''
        SELECT route_id, route_type
예제 #4
0
    # Create tables.
    for tblname in sqlize_csv.sql_schema:
        sqlize_csv.create_table(tblname)
    # SQLize all the GTFS files, for each separate GTFS dataset.
    for gtfs_dir in inGTFSdirList:
        # handle_agency checks for blank values in arrival_time and departure_time
        GTFSErrors = sqlize_csv.handle_agency(gtfs_dir)
        if GTFSErrors:
            for error in GTFSErrors:
                arcpy.AddError(error)
            raise CustomError

    # Create indices to make queries faster.
    sqlize_csv.create_indices()

    # Check for non-overlapping date ranges to prevent double-counting.
    overlapwarning = sqlize_csv.check_nonoverlapping_dateranges()
    if overlapwarning:
        arcpy.AddWarning(overlapwarning)

    arcpy.AddMessage("Successfully created SQL database of GTFS data:")
    arcpy.AddMessage("- " + SQLDbase)

except CustomError:
    arcpy.AddMessage("Failed to create SQL database of GTFS data.")
    pass

except:
    arcpy.AddMessage("Failed to create SQL database of GTFS data.")
    raise