コード例 #1
0
def setup_wrkspace(gisdbase, ccr_grassrc, geo_file):
    """Setup GRASS workspace and modify windows path for GRASS GDAL"""
    lm_util.gprint("Creating GRASS workspace")
    gisbase = cc_env.gisbase
    location = "gcwd"
    mapset = "PERMANENT"

    os.environ['GISRC'] = ccr_grassrc
    os.environ['LD_LIBRARY_PATH'] = os.path.join(gisbase, "lib")
    os.environ['GRASS_SH'] = os.path.join(gisbase, "msys", "bin", "sh.exe")

    try:
        grass.create_location(gisdbase, location, filename=geo_file)
    except:
        cc_util.gdal_fail_check()
        arcpy.AddWarning("GRASS ERROR. Try rebooting and restarting ArcGIS.")
        arcpy.AddWarning("If that doesn't work you can try using ")
        arcpy.AddWarning("the 'CC Run Script.py' python script in the ")
        arcpy.AddWarning("demo directory where the Linkage Mapper toolbox")
        arcpy.AddWarning("is installed instead of ArcGIS to call the tool")
        arcpy.AddWarning("(see user guide).")
        raise Exception("GRASS ERROR: Cannot create workspace.")
    gsetup.init(gisbase, gisdbase, location, mapset)
    run_grass_cmd("g.gisenv", set="OVERWRITE=1")
    os.environ['GRASS_VERBOSE'] = "0"  # Only errors and warnings are printed
コード例 #2
0
def setup_wrkspace(gisdbase, ccr_grassrc, geo_file):
    """Setup GRASS workspace and modify windows path for GRASS GDAL"""
    lm_util.gprint("Creating GRASS workspace")
    gisbase = cc_env.gisbase
    location = "gcwd"
    mapset = "PERMANENT"

    os.environ['GISRC'] = ccr_grassrc
    os.environ['LD_LIBRARY_PATH'] = os.path.join(gisbase, "lib")
    os.environ['GRASS_SH'] = os.path.join(gisbase, "msys", "bin", "sh.exe")

    try:
        grass.create_location(gisdbase, location, filename=geo_file)
    except:
        cc_util.gdal_fail_check()
        arcpy.AddWarning("GRASS ERROR. Try rebooting and restarting ArcGIS.")
        arcpy.AddWarning("If that doesn't work you can try using ")
        arcpy.AddWarning("the 'CC Run Script.py' python script in the ")
        arcpy.AddWarning("demo directory where the Linkage Mapper toolbox")
        arcpy.AddWarning("is installed instead of ArcGIS to call the tool")
        arcpy.AddWarning("(see user guide).")
        raise Exception("GRASS ERROR: Cannot create workspace.")
    gsetup.init(gisbase, gisdbase, location, mapset)
    run_grass_cmd("g.gisenv", set="OVERWRITE=1")
    os.environ['GRASS_VERBOSE'] = "0"  # Only errors and warnings are printed
コード例 #3
0
ファイル: cc_main.py プロジェクト: bmcrae/tutorials
def main(argv=None):
    """Main function for Climate Linkage Mapper tool"""

    start_time = datetime.now()
    print "Start time: %s" % start_time.strftime(TFORMAT)

    if argv is None:
        argv = sys.argv
    try:
        cc_env.configure(argv)
        cc_util.check_cc_project_dir()

        grass_dir_setup()
        cc_util.gdal_fail_check()  # Make sure no dll conflict

        check_out_sa_license()
        arc_wksp_setup()
        config_lm()
        log_setup()

        run_analysis()

    except arcpy.ExecuteError:
        msg = arcpy.GetMessages(2)
        arcpy.AddError(arcpy.GetMessages(2))
        lm_util.write_log(msg)
        exc_traceback = sys.exc_info()[2]
        lm_util.gprint("Traceback (most recent call last):\n" +
                       "".join(traceback.format_tb(exc_traceback)[:-1]))

    except Exception:
        exc_value, exc_traceback = sys.exc_info()[1:]
        arcpy.AddError(exc_value)
        lm_util.gprint("Traceback (most recent call last):\n" +
                       "".join(traceback.format_tb(exc_traceback)))
    finally:
        delete_proj_files()
        arcpy.CheckInExtension("Spatial")
        print_runtime(start_time)
コード例 #4
0
ファイル: cc_main.py プロジェクト: zenwalk/linkage-mapper
def main(argv=None):
    """Main function for Climate Linkage Mapper tool"""

    start_time = datetime.now()
    print "Start time: %s" % start_time.strftime(TFORMAT)

    if argv is None:
        argv = sys.argv
    try:
        cc_env.configure(argv)
        cc_util.check_cc_project_dir()

        grass_dir_setup()
        cc_util.gdal_fail_check()  # Make sure no dll conflict

        check_out_sa_license()
        arc_wksp_setup()
        config_lm()
        log_setup()

        run_analysis()

    except arcpy.ExecuteError:
        msg = arcpy.GetMessages(2)
        arcpy.AddError(arcpy.GetMessages(2))
        lm_util.write_log(msg)
        exc_traceback = sys.exc_info()[2]
        lm_util.gprint("Traceback (most recent call last):\n" +
                       "".join(traceback.format_tb(exc_traceback)[:-1]))

    except Exception:
        exc_value, exc_traceback = sys.exc_info()[1:]
        arcpy.AddError(exc_value)
        lm_util.gprint("Traceback (most recent call last):\n" +
                       "".join(traceback.format_tb(exc_traceback)))
    finally:
        delete_proj_files()
        arcpy.CheckInExtension("Spatial")
        print_runtime(start_time)