Exemplo n.º 1
0
    def merge_any_tmo_coverage_export(self):

        fc_list_p1 = get_path.pathFinder(env=self.in_gdb_path).get_file_path_with_wildcard_from_gdb(wildcard="*_dissolved")


        output = os.path.join(self.out_gdb, "June_2020_F477_65_T_Mobile_merged_dissolved_dissolved")
        if not arcpy.Exists(output):
            arcpy.Merge_management(inputs=fc_list_p1, output="in_memory/temp_merge")

            arcpy.PairwiseDissolve_analysis(in_features="in_memory/temp_merge", out_feature_class=output,dissolve_field=["pid", 'pname'])
            print(arcpy.GetMessages(0))
Exemplo n.º 2
0
    def diss_vrz_coverage_by_state(self, dissolve_list ="", postfix = '_dissolved'):

        state_list = get_path.pathFinder.make_fips_list()
        for state in state_list:

            fc_list = get_path.pathFinder(env=self.in_gdb_path).get_file_path_with_wildcard_from_gdb(wildcard="*_{}".format(state))
            if len(fc_list) !=0:

                for fc in fc_list:
                    print(fc)

                    output = os.path.join(self.out_gdb, os.path.basename(fc) + postfix)
                    if not arcpy.Exists(output):
                        arcpy.PairwiseDissolve_analysis(in_features=fc, out_feature_class=output,
                                                        dissolve_field=dissolve_list)
                        print(arcpy.GetMessages(0))
Exemplo n.º 3
0
    def dissolve_fc(self, dissolve_list, wildcard=None):

        if wildcard is None:
            fc_list = get_path.pathFinder(env=self.in_gdb_path).get_path_for_all_feature_from_gdb()
        else:
            fc_list = get_path.pathFinder(env=self.in_gdb_path).get_file_path_with_wildcard_from_gdb(wildcard=wildcard)

        for fc in fc_list:
            print(fc)

            if os.path.basename(fc) == "June_2020_F477_70_Verizon_Wireless_merged_p1":
                pass
            elif os.path.basename(fc) == "June_2020_F477_70_Verizon_Wireless_merged_p2":
                pass
            elif os.path.basename(fc) == "June_2020_F477_70_Verizon_Wireless_merged__p1_p2_by_tech_dissolved":
                pass
            else:

                output = os.path.join(self.out_gdb, os.path.basename(fc) + '_dissolved')
                print(output)
                if not arcpy.Exists(output):
                    arcpy.PairwiseDissolve_analysis(in_features=fc, out_feature_class=output, dissolve_field=dissolve_list)
                    print(output)
Exemplo n.º 4
0
                arcpy.AddMessage("There were no records found in " +
                                 forestGDBDict.get(forest) + " for " + tes)

            if count > 0:
                arcpy.AddMessage("Copying selected records to " + forest +
                                 "  Geodatabase ......")
                arcpy.CopyFeatures_management("lyr", final_wo_space)
                forestFCList.append(final_wo_space)

        mergeFeatureClass = tes_folder + forest + "\\" + "FireRetardantEIS_merge"
        arcpy.AddMessage("Merging Feature Classes")
        arcpy.AddMessage(
            "If there are no files to merge this will error until a workaround is produced!"
        )
        arcpy.Merge_management(forestFCList, mergeFeatureClass)

        arcpy.AddMessage("Dissolving Features")

        dissolveFeatureClass = tes_folder + forest + "\\" + "FireRetardantEIS_Dissolve"

        if sys.version_info[0] < 3:
            arcpy.Dissolve_management(mergeFeatureClass, dissolveFeatureClass,
                                      "UnitID")
        else:
            arcpy.PairwiseDissolve_analysis(mergeFeatureClass,
                                            dissolveFeatureClass, "UnitID")

except arcpy.ExecuteError:
    arcpy.AddError(arcpy.GetMessages(2))
except Exception as e:
    arcpy.AddMessage(e)
Exemplo n.º 5
0
def unitid_dissolve(filename):
    arcpy.AddMessage(" ____________________________________________________________________")

    arcpy.AddMessage("Updating UnitID field from intersection")

    cur = arcpy.UpdateCursor(filename)

    field = "UnitID_FS"
    fieldrank = "GRANK_FIRE"
    fieldforest = "FORESTNAME"
    fieldother = "Type"
    fieldspecies = "SNAME_FIRE"
    plant0512num = 0
    ranaboyliinum = 0
    cohosalmnum = 0
    ranamuscosanum = 0
    unprotforestnum = 0

    csvfile = in_workspace + "\\csv_tables\AllMerge_SummaryTable.csv"

    if layerType == "CNDDB":
        arcpy.AddMessage("csv File: " + csvfile)
        arcpy.AddMessage("NOTE: Code will operate differently for csv in Pro vs 10.x!!!!!")
        arcpy.AddMessage("Version of Python: " + sys.version)

    if sys.version_info[0] < 3:
        # uncomment when using arcgis 10.3
        with open(csvfile, 'rb') as f:
            reader = csv.reader(f)
            selectionList = list(reader)
    else:
        # use when using arcgis pro
        with open(csvfile) as f:
            reader = csv.reader(f)
            selectionList = list(reader)

    # populating UnitID field with UnitID_FS field
    for row in cur:
        speciesname = row.getValue(fieldspecies)
        forestname = row.getValue(fieldforest)
        row.UnitID = row.getValue(field)
        cur.updateRow(row)
        if layerType == "Wildlife_Observations":
            if speciesname == "Oncorhynchus kisutch" \
                    and str(row.getValue(field)) == "0516":
                cur.deleteRow(row)
                cohosalmnum += 1
                arcpy.AddMessage(
                    "Deleting row for Oncorhynchus kisutch because forest not protected, found in " + forestname)
        elif layerType == "Critical_Habitat_Polygons":
            if speciesname == "Rana muscosa" \
                    and str(row.getValue(field)) != "0501" \
                    and str(row.getValue(field)) != "0512" \
                    and str(row.getValue(field)) != "0502" \
                    and str(row.getValue(field)) != "0507":
                cur.deleteRow(row)
                ranamuscosanum += 1
                arcpy.AddMessage(
                    "Deleting row for Rana muscosa because not Southern forest species, found in " + forestname)
        # Used for filtering out records in CNDDB
        elif layerType == "CNDDB":
            # Used for deleting all the plant records in San Bernardino for CNDDB
            if str(row.getValue(field)) == "0512" \
                    and row.getValue(fieldrank) != "Sensitive" \
                    and row.getValue(fieldother) == "PLANT":
                cur.deleteRow(row)
                plant0512num += 1
                arcpy.AddMessage("deleted a row for 0512 Plant: " + speciesname)
            # Used for deleting all the Rana boylii not in the following three forests
            elif str(row.getValue(field)) != "0507" \
                    and str(row.getValue(field)) != "0513" \
                    and str(row.getValue(field)) != "0515" \
                    and speciesname == "Rana boylii":
                cur.deleteRow(row)
                ranaboyliinum += 1
                arcpy.AddMessage("deleted a row for Rana boylii in forest: " + forestname)
            # elif (str(row.getValue(field)) == "0508" \
            #         or str(row.getValue(field)) == "0514" \
            #         or str(row.getValue(field)) == "0510" \
            #         or str(row.getValue(field)) == "0505") \
            #         and speciesname == "Rana muscosa":
            #     cur.deleteRow(row)
            #     arcpy.AddMessage("deleted a row for Rana muscosa in forest: " + forestname)
            else:
                # Used for deleting all the species selected not in a particular forest
                for item in selectionList:
                    if item[0].startswith(speciesname) \
                            and speciesname != "Rana boylii" \
                            and speciesname != "Rana muscosa":
                        if item[3] == "":
                            break
                        elif item[3] != forestname.upper():
                            cur.deleteRow(row)
                            unprotforestnum += 1
                            arcpy.AddMessage("deleted row for " + speciesname +
                                             " because found in " + forestname)

    del cur

    # running export to gdb just for datasets that required additional filtering others were ran prior to this function
    if layerType == "CNDDB":
        arcpy.AddMessage("Total records deleted because they were Plants from San Bernardino : "
                         + str(plant0512num))
        arcpy.AddMessage("Total records deleted because they were Rana boylii not in target forests : "
                         + str(ranaboyliinum))
        arcpy.AddMessage("Total records deleted because they were species found in unprotected forests : "
                         + str(unprotforestnum))
        copy_to_gdb("Interim", filename)
    elif layerType == "Wildlife_Observations":
        arcpy.AddMessage("Total records deleted because they were Oncorhynchus kisutch in STF : "
                         + str(cohosalmnum))
        copy_to_gdb("Interim", filename)
    elif layerType == "Critical_Habitat_Polygons":
        arcpy.AddMessage("Total records deleted because they were Rana muscosa not in southern forests : "
                         + str(ranamuscosanum))
        copy_to_gdb("Interim", filename)

    arcpy.AddMessage("Repairing Geometry ......")
    arcpy.RepairGeometry_management(filename)

    arcpy.AddMessage("Dissolving Features")

    dissolveFeatureClass = filename + "_dissolved"

    dissolvefields = ["UnitID", "GRANK_FIRE", "SNAME_FIRE", "CNAME_FIRE", "SOURCEFIRE",
                      "BUFFT_FIRE", "BUFFM_FIRE", "CMNT_FIRE", "INST_FIRE"]

    if layerType != "Critical_Habitat_Lines" and layerType != "Critical_Habitat_Polygons" and layerType != "NOAA_ESU":
        dissolvefields.append("BUFF_DIST")

    if sys.version_info[0] < 3:
        arcpy.Dissolve_management(filename, dissolveFeatureClass, dissolvefields, "", "SINGLE_PART")
    else:
        arcpy.PairwiseDissolve_analysis(intersectFeatureClass, dissolveFeatureClass, dissolvefields)

    arcpy.AddMessage("Repairing Dissolved Geometry ......")
    arcpy.RepairGeometry_management(filename)
    arcpy.AddMessage("Dissolve and Repair complete")
    arcpy.AddMessage(" ____________________________________________________________________")

    return dissolveFeatureClass
Exemplo n.º 6
0
import arcpy

arcpy.env.overwriteOutput = True

inFC = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(1)
out_xls = arcpy.GetParameterAsText(2)

#INTERSECT
#arcpy.Intersect_analysis (inFC, "outFC", "ALL", "","")
arcpy.PairwiseIntersect_analysis(inFC, "outFC", "ALL", "", "")

dissolveFields = ["AREASYMBOL", "MUSYM", "MLRARSYM"]
#Dissolve Features
#arcpy.Dissolve_management ("outFC", "outFCDISSOLVE", dissolveFields)
arcpy.PairwiseDissolve_analysis("outFC", "outFCDISSOLVE", dissolveFields)

#Add Field
arcpy.AddField_management(
    "outFCDISSOLVE",
    "ACRES",
    "DOUBLE",
)

#Calculate Field
arcpy.CalculateField_management(
    "outFCDISSOLVE",
    "ACRES",
    '!Shape.area@ACRES!',
    "PYTHON_9.3",
)
            arcpy.AddGeometryAttributes_management(fc, "CENTROID")
            arcpy.AddGeometryAttributes_management(fc, "CENTROID")
            arcpy.CalculateGeometryAttributes_management(fc, centroid_list)
            print("Centroid X and Centroid Y Fields added and calculated for %s"%(fc))
        else:
            print("%s not in %s"%(fc, updated_fc_list))
# ##----------------------Pairwise dissolve--------------------------
    arcpy.env.workspace = "B:/GIS_Projects/SP_Wildfire/Reprocessing/Workspace/Fire_Occ.gdb"
    arcpy.env.parallelProcessingFactor = "100%"
    dissolve_output = ['F_O_AK_Dissolve', 'F_O_HI_Dissolve', 'F_O_US_Dissolve']
    dissolve_fields = ["CENTROID_X", "CENTROID_Y"]
    for fc in arcpy.ListFeatureClasses():
        print(fc)
        if fc == union_list[0]: ## Alaska
            print("Starting pairwise dissolve on %s using CENTROID_X and CENTROID_Y as dissolve fields"%(fc))
            arcpy.PairwiseDissolve_analysis(fc, dissolve_output[0], dissolve_fields, [["FID_F_O_AK_Prj", "COUNT"]], "MULTI_PART")
            print("Pairwise dissolve completed for %s"%(fc))
        elif fc == union_list[1]: ## Hawaii
            print("Starting pairwise dissolve on %s using CENTROID_X and CENTROID_Y as dissolve fields"%(fc))
            arcpy.PairwiseDissolve_analysis(fc, dissolve_output[1], dissolve_fields, [["FID_F_O_HI_Prj", "COUNT"]], "MULTI_PART")
            print("Pairwise dissolve completed for %s"%(fc))
        elif fc == union_list[2]: ## Lower 48
            print("Starting pairwise dissolve on %s using CENTROID_X and CENTROID_Y as dissolve fields"%(fc))
            arcpy.PairwiseDissolve_analysis(fc, dissolve_output[2], dissolve_fields, [["FID_F_O_US_Prj", "COUNT"]], "MULTI_PART")
            print("Pairwise dissolve completed for %s"%(fc))
        else:
            print("%s is not in union_list"%(fc))
    print("All Pairwise dissolve operations completed.")
##---------------------------Rasterize the dissolve outputs----------------------------------
    ## Start with Alaska. Set snap raster to alaska MFRI
    arcpy.env.workspace = "B:/GIS_Projects/SP_Wildfire/Reprocessing/Workspace/Fire_Occ.gdb"
Exemplo n.º 8
0
        arcpy.AddMessage("Dissolving Features")

        dissolveFeatureClass = perennialFeatureClass + "_dissolved"

        if sys.version_info[0] < 3:
            arcpy.Dissolve_management(
                perennialFeatureClass, dissolveFeatureClass, [
                    "UnitID", "GRANK_FIRE", "SNAME_FIRE", "CNAME_FIRE",
                    "SOURCEFIRE", "BUFFT_FIRE", "BUFFM_FIRE", "CMNT_FIRE",
                    "INST_FIRE", "BUFF_DIST"
                ], "", "SINGLE_PART")
        else:
            arcpy.PairwiseDissolve_analysis(
                perennialFeatureClass, dissolveFeatureClass, [
                    "UnitID", "GRANK_FIRE", "SNAME_FIRE", "CNAME_FIRE",
                    "SOURCEFIRE", "BUFFT_FIRE", "BUFFM_FIRE", "CMNT_FIRE",
                    "INST_FIRE", "BUFF_DIST"
                ])

        arcpy.AddMessage("Repairing Dissolved Geometry ......")
        arcpy.RepairGeometry_management(dissolveFeatureClass)
        arcpy.AddMessage("Dissolve and Repair complete")
        arcpy.AddMessage(
            " ____________________________________________________________________"
        )

        interimfc = outputProjGDB + "\\" + item + "_geocomplete"

        arcpy.CopyFeatures_management(dissolveFeatureClass, interimfc)

except arcpy.ExecuteError:
#Union update soils and original soils
arcpy.Union_analysis(inFC, "union_compare_data", "ALL")

#Make Feature Layer from Union soils
arcpy.MakeFeatureLayer_management("union_compare_data", "union_compare_data_lyr")

#Select Layer By Attribute NEW_SELECTION "MUSYM" <> "MUSYM_1"
arcpy.SelectLayerByAttribute_management("union_compare_data_lyr", "NEW_SELECTION", ' "MUSYM" <> "MUSYM_1" ')

#Copy Features
arcpy.CopyFeatures_management ("union_compare_data_lyr", "outFC")

dissolveFields = ["AREASYMBOL", "MUSYM", "MUSYM_1"]
#Dissolve Features
arcpy.PairwiseDissolve_analysis ("outFC", "COMPARE", dissolveFields)


#Delete Features
arcpy.Delete_management("union_compare_data")
arcpy.Delete_management("outFC")

#Add Field

arcpy.AddField_management("COMPARE", "ACRES", "DOUBLE", )

#Calculate Field

arcpy.CalculateField_management("COMPARE", "ACRES", '!Shape.area@ACRES!', "PYTHON_9.3", )

Exemplo n.º 10
0
        arcpy.FeatureClassToGeodatabase_conversion(merge_fc, final_no_wksp)

        arcpy.Rename_management(final_no_fc_old, final_no_fc)

        arcpy.AddMessage("Export to non-distributable GDB complete")

        arcpy.AddMessage("Dissolving " + tes + " Features")

        dissolveFeatureClass = final_no_fc + "_dissolved"

        if sys.version_info[0] < 3:
            arcpy.Dissolve_management(final_no_fc, dissolveFeatureClass,
                                      ["UnitID", "GRANK_FIRE"], "",
                                      "SINGLE_PART")
        else:
            arcpy.PairwiseDissolve_analysis(final_no_fc, dissolveFeatureClass,
                                            ["UnitID", "GRANK_FIRE"])

        arcpy.AddMessage("Repairing Dissolved Geometry ......")
        arcpy.RepairGeometry_management(dissolveFeatureClass)
        arcpy.AddMessage("Dissolve and Repair complete")

        arcpy.AddMessage(
            'Exporting dissolved feature class with only UnitID and GRANK_FIRE '
            'fields to final distributable Geodatabase')

        final_fc_old = final_wksp + "\\" + "FireRetardantEIS_" + tes + "_NoDistribution_dissolved"
        final_fc = final_wksp + "\\" + "FireRetardantEIS_" + tes

        arcpy.FeatureClassToGeodatabase_conversion(dissolveFeatureClass,
                                                   final_wksp)