projectType = cceNo.split('-')[1]

#Find corresponding combo number
if "-AS-" in cceNo:
    cceNo = cceNo.replace("-AS-", "-ASlRS-")
if "-AA-" in cceNo:
    cceNo = cceNo.replace("-AA-", "-AAlRA-")

scratch_folder = scratch_folder.replace('Templates', 'scratch')

today = datetime.datetime.now()
ts = today.strftime('%y%m%d_%H%M%S')
#Create Scratch GDB
scratchGDB = "CC_" + cceNo + "_" + userInit + "_" + ts + ".gdb"
arcpy.CreateFileGDB_management(scratch_folder, scratchGDB)
scratch = scratch_folder + "\\" + scratchGDB

descSDE = arcpy.Describe(SDE)
sdeName = descSDE.baseName[:-3]
print sdeName

sdePath = os.path.dirname(os.path.dirname(target))

descTarget = arcpy.Describe(target)
targetName = descTarget.name[:-17]
print targetName

where = "strCCEProjectNumber = '" + cceNo + "' AND(OmitYN IS NULL OR OmitYN = 'No')"
sql = "\"strCCEProjectNumber\"" + " = '" + cceNo + "'"
print where
Example #2
0
# ChompOverlaps.py
# Removes overlaps by letting the first polygon chomp its overlapping area out of the second.

import arcpy, os
arcpy.env.overwriteOutput = True
inpoly = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
outfolder = arcpy.GetParameterAsText(2)
try:
    arcpy.CreateFileGDB_management(outfolder, "ChompOverlaps")
except:
    pass
scratch = os.path.join(outfolder, "ChompOverlaps.gdb")
arcpy.CopyFeatures_management(inpoly, os.path.join(scratch, "inpoly"))
scratchpoly = os.path.join(scratch, "inpoly")
mem = "in_memory"
arcpy.env.workspace = mem
arcpy.Split_analysis(inpoly, inpoly, field, mem, '1')
fcs = []
for root, dirs, files in arcpy.da.Walk(mem):
    for file in files:
        fcs.append(os.path.join(root, file)

for fc in fcs:
    arcpy.Erase_analysis(scratchpoly, fc, os.path.join(scratch, "outpoly"))
        
Example #3
0
def Guidos_Prep(city, inDir, workFld):
    import traceback, time, arcpy, os
    from arcpy import env
    arcpy.CheckOutExtension('Spatial')

    #-------- DIRECTORY SETUP ------------------------------------------------
    """ Working Directory """
    try:
        arcpy.CreateFileGDB_management(str(workFld), str(city) + '_GUIDOS.gdb')
    except:
        print 'GUIDOS GDB already exists'
    workDir = str(workFld) + '/' + city + '_GUIDOS.gdb'
    arcpy.env.workspace = workDir
    """ Report File Directory """
    reportfileDir = str(workFld) + '/Logs'
    """ Frequent Directory """
    freqDir = str(workFld) + '/' + city + '_Freq.gdb'
    """ Final Geodatabase """
    finalDir = str(workFld) + '/' + city + '_Final.gdb'
    """ Projection File Directory """
    prjDir = str(inDir) + '/Prj'
    prjfile = prjDir + '/USA Contiguous Albers Equal Area Conic USGS.prj'
    """ Split Raster Directory """
    if os.path.isdir(str(workFld) + '/' + city + '_Split') == True:
        pass
    else:
        os.makedirs(str(workFld) + '/' + city + '_Split')
    splitDir = str(workFld) + '/' + city + '_Split'
    """ Set Workspace Environments """
    arcpy.env.workspace = workDir
    arcpy.env.scratch = str(inDir) + '/Scratch.gdb'
    arcpy.env.overwriteOutput = True

    #-----------------------------------------------------------------------------
    # BEGIN ANALYSIS
    #-----------------------------------------------------------------------------
    try:
        #-------- LOGFILE CREATION ---------------------------------------------
        """ Create report file for each metric """
        tmpName = city + '_Conn_' + time.strftime('%Y%m%d_%H-%M')
        reportfileName = reportfileDir + '/' + tmpName + '.txt'
        reportFile = open(reportfileName, 'w')
        """ Write out first line of report file """
        print 'Connectivity Data Prep Start Time: ' + time.asctime()
        reportFile.write(
            "Begin with EnviroAtlas 1-meter Land Cover for the EnviroAtlas community--"
            + time.strftime('%Y%m%d--%H%M%S') + '--\n')

        #-------- PROCESSING LAYERS ----------------------------------------------
        """ Set Environments """
        arcpy.env.extent = freqDir + '/LC'
        arcpy.env.snapRaster = freqDir + '/LC'
        """ -------- Reclassify LC into Forest Foreground, All Else Background ----- """
        outReclass2 = arcpy.sa.Reclassify(
            freqDir + '/LC', 'Value',
            arcpy.sa.RemapValue([[0, 0], [10, 1], [20, 1], [21, 1], [22, 1],
                                 [30, 1], [40, 2], [52, 1], [52, 1], [70, 1],
                                 [80, 1], [82, 1], [91, 2], [92, 1],
                                 ["NODATA", 0]]))
        outReclass2.save('FWW_WB')
        reportFile.write(
            "Reclassify the land cover into Foreground (REPLACE-GUID), and Background (All Else = 1). --"
            + time.strftime('%Y%m%d--%H%M%S') + '--\n')
        """-------- Split the Raster As Needs, Process Each Piece ----------------- """
        """ Check if the raster should be split """
        columns = arcpy.GetRasterProperties_management(
            'FWW_WB', 'COLUMNCOUNT').getOutput(0)
        xsplit = int(float(columns) / 8000) + 1
        rows = arcpy.GetRasterProperties_management('FWW_WB',
                                                    'ROWCOUNT').getOutput(0)
        ysplit = int(float(rows) / 8000) + 1
        """ Delete the raster, if necessary """
        xy = (xsplit * ysplit)
        for rast in range(xy):
            try:
                arcpy.Delete_management(splitDir + '/FWW_WB_' + str(rast) +
                                        '.tif')
            except:
                pass
        try:
            arcpy.Delete_management(splitDir + '/fww_wb')
        except:
            pass
        try:
            arcpy.Delete_management(splitDir + '/fww_wb.tif')
        except:
            pass
        """-------- If no split, run the analysis --------------------------------- """
        if xsplit * ysplit == 1:
            print 'FWW_' + raster + ' is small enough as is.'
            arcpy.CopyRaster_management('FWW_WB', splitDir + '/FWW_WB.tif', '',
                                        '', 0, '', '', '8_BIT_UNSIGNED', '',
                                        '')
            reportFile.write("Convert Raster into Tiff.--" +
                             time.strftime('%Y%m%d--%H%M%S') + '--\n')
            """-------- If split, run the analysis on each piece and recombine --------- """
        else:
            arcpy.CopyRaster_management('FWW_WB', splitDir + '/FWW_WB.tif', '',
                                        '', 0, '', '', '8_BIT_UNSIGNED', '',
                                        '')
            arcpy.SplitRaster_management(splitDir + '/FWW_WB.tif', splitDir,
                                         'FWW_WB_', 'NUMBER_OF_TILES', 'TIFF',
                                         '',
                                         str(xsplit) + ' ' + str(ysplit), '',
                                         '1000', 'PIXELS')
            reportFile.write(
                "Split the reclassified land cover into pieces of 10,000 x 10,000 pixels or fewer with a 1,000 pixel overlap. Convert to Tiff.--"
                + time.strftime('%Y%m%d--%H%M%S') + '--\n')

        print 'Connectivity Data Prep End Time: ' + time.asctime() + '\n'
        print 'Be sure to run the BatchStripedTile Model in ArcMap before GUIDOS.py runs.\n'

        #-------- COMPELETE LOGFILES ---------------------------------------------
        reportFile.close()

#-----------------------------------------------------------------------------
# END ANALYSIS
#-----------------------------------------------------------------------------
    except:
        """ This part of the script executes if anything went wrong in the main script above """
        #-------- PRINT ERRORS ---------------------------------------------------
        print "\nSomething went wrong.\n\n"
        print "Python Traceback Message below:"
        print traceback.format_exc()
        print "\nArcMap Error Messages below:"
        print arcpy.GetMessages(2)
        print "\nArcMap Warning Messages below:"
        print arcpy.GetMessages(1)

        #-------- COMPLETE LOGFILE ------------------------------------------------
        reportFile.write("\nSomething went wrong.\n\n")
        reportFile.write("Pyton Traceback Message below:")
        reportFile.write(traceback.format_exc())
        reportFile.write("\nArcMap Error Messages below:")
        reportFile.write(arcpy.GetMessages(2))
        reportFile.write("\nArcMap Warning Messages below:")
        reportFile.write(arcpy.GetMessages(1))

        reportFile.write("\n\nEnded at " + time.asctime() + '\n')
        reportFile.write("\n---End of Log File---\n")

        if reportFile:
            reportFile.close()
Example #4
0
arcpy.CheckOutExtension("Network")

# --------------------------------------------------------------------------------

# Set local variables
out_folder_path = "C:\Users\810000689\The University of the West Indies\DataGroup - repo_data\data_p145\version01\1-input\GIS Data"
out_name = "SES_BSS_ED.gdb"

datapath = "C:\Users\810000689\Documents\ArcGIS\Default.gdb"

#Features 
inFeatures = ["ED_SES", "parish1"]
outlocation = 'C:\Users\810000689\The University of the West Indies\DataGroup - repo_data\data_p145\version01\1-input\GIS Data\SES_BSS_ED.gdb'

# Create File Geodatabase
arcpy.CreateFileGDB_management(out_folder_path, out_name)

# Importing Features to File Geodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outlocation)

#Creating Layer for Health of the Nation sampled EDs
HoTN_query = arcpy.SelectLayerByAttribute_management("ED_SES", "NEW_SELECTION", 'ENUM_NO1 in (2, 12, 25, 37, 51, 63, 74, 86, 101, 111, 120, 132, 149, 159, 172, 193, 206, 217, 229, 244, 258, 270, 282, 298, 310, 322, 334, 340, 354, 368, 381, 395, 405, 431, 445, 459, 472, 485, 500, 509, 520, 533, 546, 562, 579)')
arcpy.MakeFeatureLayer_management("ED_SES", "HoTN_ED", HoTN_query)
arcpy.CopyFeatures_management(HoTN_query)

#Creating Layer for ECHORN sampled EDs
ECHORN_query = arcpy.SelectLayerByAttribute_management("ED_SES", "NEW_SELECTION", 'ENUM_NO1 in (15, 32, 49, 98, 118, 133, 155, 166, 181, 196, 211, 224, 241, 257, 273, 290, 309, 324, 346, 363, 379, 396, 408, 422, 436, 455, 469, 486, 504, 517, 536, 556, 581)')
arcpy.MakeFeatureLayer_management("ED_SES", "ECHORN_ED", ECHORN_query)
arcpy.CopyFeatures_management(ECHORN_query)

# Import SES Excel Data to geodatabase
quads = r"M:\reg0\reg0data\layerfiles\quad24.lyr"
arcpy.MakeFeatureLayer_management(quads, "quads")
arcpy.SelectLayerByLocation_management("quads", "intersect", clip, 0,
                                       "NEW_SELECTION")

R1 = 1
R2 = 10
R3 = 100
maxRad = max(R1, R2, R3)

outGDB1 = os.path.join(
    ADK, "ADKR1.gdb"
)  #arcpy.GetParameterAsText(6) # Geodatabase to hold final products for neighborhood 1
if not os.path.exists(outGDB1):
    arcpy.CreateFileGDB_management(ADK, "ADKR1.gdb")

outGDB2 = os.path.join(
    ADK, "ADKR10.gdb"
)  #arcpy.GetParameterAsText(7) # Geodatabase to hold final products for neighborhood 2
if not os.path.exists(outGDB2):
    arcpy.CreateFileGDB_management(ADK, "ADKR10.gdb")

outGDB3 = os.path.join(
    ADK, "ADKR100.gdb"
)  #arcpy.GetParameterAsText(8) # Geodatabase to hold final products for neighborhood 3
if not os.path.exists(outGDB3):
    arcpy.CreateFileGDB_management(ADK, "ADKR100.gdb")

inFld = "PREFIX"
ProcUnits = arcpy.da.SearchCursor("quads", [inFld])