Ejemplo n.º 1
0
def delete_data(file):
    # FIXME if possible: still having file lock problems with Arc.
    if file is None:
        return
    try:
        if os.path.isfile(file):
            try:
                os.remove(file)
                gc.collect()
            except:
                try:
                    arcpy.delete_management(file)
                except:
                    pass
    except:
        pass
    return
Ejemplo n.º 2
0
def delete_data(file):
    # FIXME if possible: still having file lock problems with Arc.
    if file is None:
        return
    try:
        if os.path.isfile(file):
            try:
                os.remove(file)
                gc.collect()
            except:
                try:
                    arcpy.delete_management(file)
                except:
                    pass
    except:
        pass
    return
        except:
            pass

    del listOfDomains

    # ------------------------------------------------------------------------------- Remove existing layers from ArcMap
    layersToRemove = (landuseOut, soilsOut)

    x = 0
    for layer in layersToRemove:
        if arcpy.Exists(layer):
            if x == 0:
                AddMsgAndPrint("Removing layers from ArcMap...", 0)
                x += 1
            try:
                arcpy.delete_management(layer)
                AddMsgAndPrint("Removing " + layer + "...", 0)
            except:
                pass
    del x, layersToRemove

    # -------------------------------------------------------------------------- Delete Previous Data if present
    datasetsToRemove = (wsSoils, landuse, cluClip, wtshdDEMsmooth, slopeGrid,
                        slopeStats, watershedDissolve, cluClip, storageTemp,
                        subMask, subGrid, outletStats, outletBuffer)

    x = 0
    for dataset in datasetsToRemove:
        if arcpy.Exists(dataset):
            if x < 1:
                AddMsgAndPrint(
# ------------------------------ Permanent Datasets
projectAOI = os.sep + prjname + "_AOI"

# Feature Layers to Arcmap
aoiOut = "" + prjname + "_AOI"

# ----------------------------------------------------------------------------------------------- Create New AOI
    # if paths are not the same then assume AOI was manually digitized
    # or input is some from some other feature class/shapefile
if not arcpy.Describe(AOI).CatalogPath == projectAOI:       

        # delete the AOI feature class; new one will be created            
    if arcpy.exists(projectAOI):
            
        try:
            arcpy.delete_management(projectAOI)
            arcpy.CopyFeatures_management(AOI, projectAOI)
            AddMsgAndPrint("\nSuccessfully Recreated Area of Interest",1)
        except:
            print_exception()
            arcpy.OverWriteOutput = 1
            
    else:
        arcpy.CopyFeatures_management(AOI, projectAOI)
        AddMsgAndPrint("\nSuccessfully Created Area of Interest:" + str(os.path.basename(projectAOI)),1)

    # paths are the same therefore input IS projectAOI
else:
    AddMsgAndPrint("\nUsing existing \"" + str(projectName) + "_AOI\" feature class:",1)

if arcpy.Describe(projectAOI).ShapeType != "Polygon":