def create_vrz_LTE_by_state(self): vrz_parts = get_path.pathFinder(env=self.in_gdb_path).get_file_path_with_wildcard_from_gdb("*_70_*_p*_*") vrz_temp_lte_fc = [] for parts in vrz_parts: print(parts) vrz_temp_lte_fc.append(os.path.basename(parts)) arcpy.MakeFeatureLayer_management(parts, os.path.basename(parts), """"TECHNOLOGY"=83""") #merge the vrz lte parts arcpy.Merge_management(inputs=vrz_temp_lte_fc, output='in_memory/temp_merge') print(arcpy.GetMessages()) state_boundary_fc_list = get_path.pathFinder(env=self.in_gdb_2_path).get_path_for_all_feature_from_gdb() state_fips = get_path.pathFinder.make_fips_list() for state in state_fips: output = os.path.join(self.out_gdb, "June_2020_F477_70_Verizon_Wireless_LTE_{}".format(state)) state_fc = get_path.pathFinder.filter_List_of_featureclass_paths_with_wildcard(state_boundary_fc_list, wildcard="*_{}_*".format(state)) if len(state_fc) > 0: if not arcpy.Exists(output): arcpy.PairwiseIntersect_analysis(in_features=[state_fc[0],'in_memory/temp_merge'], out_feature_class=output) print(arcpy.GetMessages())
def intersect_block(self, wildcard, post_fix): fc_list = get_path.pathFinder(env=self.in_gdb_path).get_path_for_all_feature_from_gdb() block_list = get_path.pathFinder(env=self.in_gdb_2_path).get_file_path_with_wildcard_from_gdb(wildcard=wildcard) for fc in fc_list: print(fc) for block in block_list: print(block) output = os.path.join(self.out_gdb, os.path.basename(fc)+"{}".format(post_fix)) if not arcpy.Exists(output): arcpy.PairwiseIntersect_analysis(in_features=[block, fc],out_feature_class=output) print(arcpy.GetMessages())
def intersect_by_state_verizon(self): state_fc_list = get_path.pathFinder(env=self.in_gdb_2_path).get_path_for_all_feature_from_gdb() fc_list = get_path.pathFinder(env=self.in_gdb_path).get_file_path_with_wildcard_from_gdb(wildcard="*_70_*") for state in get_path.pathFinder.make_fips_list(): print(state) state_fc = get_path.pathFinder.filter_List_of_featureclass_paths_with_wildcard(state_fc_list, "*_{}_*".format(state)) if len(state_fc) != 0: for fc in fc_list: output = os.path.join(self.out_gdb, os.path.basename(fc) + "_" + state) if not arcpy.Exists(output): arcpy.PairwiseIntersect_analysis(in_features=[state_fc[0], fc], out_feature_class=output) print(arcpy.GetMessages(0))
def make_fhcs(self): block_list = get_path.pathFinder(env=self.in_gdb_2_path).get_path_for_all_feature_from_gdb() fhcs_list = get_path.pathFinder(env=self.in_gdb_path).get_path_for_all_feature_from_gdb() state_list = get_path.pathFinder.make_fips_list() for state in state_list: print(state) filter_fhcs_list = get_path.pathFinder.filter_List_of_featureclass_paths_with_wildcard(fhcs_list, wildcard="fhcs_{}_*".format(state)) filter_block_list = get_path.pathFinder.filter_List_of_featureclass_paths_with_wildcard(block_list, wildcard="*_{}_*".format(state)) if len(filter_fhcs_list)>0: for fc in filter_fhcs_list: print(fc) output = os.path.join(self.out_gdb, os.path.basename(fc)) if not arcpy.Exists(output): arcpy.PairwiseIntersect_analysis([filter_block_list[0], fc], out_feature_class=output) print(arcpy.GetMessages())
def intersect_coverage_service_area_fc(self, suffix="_"): fc_list = get_path.pathFinder(env=self.in_gdb_path).get_path_for_all_feature_from_gdb() service_area_list = get_path.pathFinder(env=os.path.join(self.base_input_folder, "_input_fhcs_by_block.gdb")).get_path_for_all_feature_from_gdb() for fc in fc_list: print(fc) name_dict = re.search( pattern=r'(\w.+)_(?P<pid>\d{1,3})_(?P<pname>\w.+)', string=fc).groupdict() wildcard_fhcs = get_path.pathFinder.filter_List_of_featureclass_paths_with_wildcard(path_link_list=service_area_list, wildcard="fhcs_*_{}_*".format(name_dict['pid'])) #todo:rename the wildcard for wfc in wildcard_fhcs: output = os.path.join(self.out_gdb, os.path.basename(wfc) + '_service_area_intersect{}'.format(suffix)) if not arcpy.Exists(output): arcpy.PairwiseIntersect_analysis(in_features=[fc, wfc], out_feature_class=output) print(arcpy.GetMessages())
else: arcpy.AddMessage( "Creating Geodatabase for Threatened Data Deliverables containing intersection data ...." ) arcpy.CreateFileGDB_management(newpath_threatened, threatened_gdb) arcpy.CreateFileGDB_management(newpath_threatened, fra_threatened_gdb) try: usfsOwnershipFeatureClass = r"C:\Users\jklaus\Documents\Python_Testing\fire_retardant\USFS_Ownership_LSRS\2017_USFS_Ownership_CAALB83.gdb\USFS_OwnershipLSRS_2017" intersectFeatureClass = outFeatClass + "_intersect" arcpy.AddMessage("Intersecting with USFS Ownership feature class .....") arcpy.AddMessage("Please be patient while this runs .....") # arcpy.Intersect_analysis([outFeatClass, usfsOwnershipFeatureClass], intersectFeatureClass) arcpy.PairwiseIntersect_analysis([outFeatClass, usfsOwnershipFeatureClass], intersectFeatureClass) # --------------Copying to Sensitive Geodatabase for interim deliverable step arcpy.MakeFeatureLayer_management(outFeatureClass, "lyr") arcpy.AddMessage("Selecting records based on Sensitive rank ....") arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", "GRANK_FIRE = 'Sensitive'") if layerType == "TESP": outlocation = newpath_sensitive + "\\\\" + fra_sensitive_gdb + "\\\\EDW_TESP_2017_OccurrenceAll_FoundPlants_ident_Sensitive" elif layerType == "Wildlife_Sites": outlocation = newpath_sensitive + "\\\\" + fra_sensitive_gdb + "\\\\EDW_WildlifeSites_2017_ident_Sensitive" elif layerType == "Wildlife_Observations": outlocation = newpath_sensitive + "\\\\" + fra_sensitive_gdb + "\\\\EDW_FishWildlife_Observation_2017_S_ident" elif layerType == "Critical_Habitat_Polygons":
def intersectFeatureClassesFromTrailsdb_returnName_v1(mainFeatureName, dataset_query, intersectFeatureName, database_version): start = time.time() # General Variables gdbVariables = trailsdb_or_tests(database_version) gdbFeaturesRoot = gdbVariables[2] """Intersect a feature Class with a Main Feature Class""" # Main feature variables mainFeature = gdbFeaturesRoot + mainFeatureName # Identify the main feature's name root and shorten it to avoid final name longer than arcsde's limit if mainFeatureName[-5:] == "admin": mainFeatureRoot = mainFeatureName[3:-6] else: mainFeatureRoot = mainFeatureName[3:-4] mainFeatureFields = arcpy.ListFields(mainFeature) intersectFeature = gdbFeaturesRoot + intersectFeatureName inFeatureDesc = arcpy.Describe(intersectFeature) featureShapeType = inFeatureDesc.shapeType intersectFeatureFields = arcpy.ListFields(intersectFeature) # Output variables # Identify the intersected feature's name root and shorten it to avoid final name longer than arcsde's limit if intersectFeatureName[-5:] == "admin": nameFeatureEnd = intersectFeatureName[-6:] endPos = -6 else: nameFeatureEnd = intersectFeatureName[-4:] endPos = -4 if intersectFeatureName[:3] == "fc_": intersectFeatureRoot = intersectFeatureName[3:endPos] if intersectFeatureName[:7] == "fc_act_": intersectFeatureRoot = intersectFeatureName[7:endPos] outFeatureName = "int_" + mainFeatureRoot + "_" + intersectFeatureRoot + nameFeatureEnd print(outFeatureName) outFeature = gdbPath_queries + dataset_query + "\\" + gdbName_queries + ".sde." + outFeatureName # output Fields fieldsToIgnoreOrDeleteMain = [ "objectid", "shape", "globalid", "created_user", "created_date", "last_edited_user", "last_edited_date" ] fieldsToIgnoreOrDeleteIntersect = [ "objectid", "shape", "globalid", "created_user", "created_date", "last_edited_user" ] outFeatureFields = [] outFeatureFieldsNewNames = {} outFeatureFieldsType = {} if featureShapeType == "Polyline": outFeatureFields.append("length") outFeatureFieldsType.update({"length": "FLOAT"}) outFeatureFieldsWithDomain = [] outFeatureFieldsDomains = {} outFeatureFieldsTable = {} # Add main feature's fields and intersect feature's fields to lists and dictionaries use to create output feature for field in mainFeatureFields: if not field.name in fieldsToIgnoreOrDeleteMain: if not field.name in outFeatureFields: outFeatureFields.append(field.name) outFeatureFieldsNewNames.update( {field.name: mainFeatureRoot[:5] + "_" + field.name}) outFeatureFieldsType.update({field.name: field.type}) for tableField in tablesJoinedFields: if tableField[0] == field.name: if not tableField[1] in outFeatureFields: outFeatureFields.append(tableField[1]) outFeatureFieldsType.update( {tableField[1]: "TEXT"}) outFeatureFieldsTable.update( {tableField[1]: tableField[0]}) if field.domain != "": outFeatureFieldsWithDomain.append(field.name) outFeatureFieldsDomains.update({field.name: field.domain}) for field in intersectFeatureFields: if not field.name in fieldsToIgnoreOrDeleteIntersect: if not field.name in outFeatureFields: outFeatureFields.append(field.name) outFeatureFieldsNewNames.update( {field.name: intersectFeatureRoot[:5] + "_" + field.name}) outFeatureFieldsType.update({field.name: field.type}) for tableField in tablesJoinedFields: if tableField[0] == field.name: if not tableField[1] in outFeatureFields: outFeatureFields.append(tableField[1]) outFeatureFieldsType.update( {tableField[1]: "TEXT"}) outFeatureFieldsTable.update( {tableField[1]: tableField[0]}) if field.domain != "": outFeatureFieldsWithDomain.append(field.name) outFeatureFieldsDomains.update({field.name: field.domain}) # Intersect feature if arcpy.Exists(outFeature): arcpy.Delete_management(outFeature) arcpy.PairwiseIntersect_analysis([mainFeature, intersectFeature], outFeature) for field in outFeatureFieldsWithDomain: fieldDomain = outFeatureFieldsDomains.get(field) arcpy.AssignDomainToField_management(outFeature, field, fieldDomain) for field in arcpy.ListFields(outFeature): if not field.name in outFeatureFields: try: arcpy.DeleteField_management(outFeature, field.name) except: continue if field.name in outFeatureFields: newName = outFeatureFieldsNewNames.get(field.name) try: arcpy.AlterField_management(outFeature, field.name, newName) except: continue stop = time.time() print("Time to make trailsdb gdb = %02d:%02d:%02d" % (int(stop - start) / 3600, int( ((stop - start) % 3600) / 60), int((stop - start) % 60))) return outFeatureName #intersectFeatureClassesFromTrailsdb_returnName_v1("fc_trail_code_pro", "fc_atv_pro", "trailsdb")
#split soils by MLRA with Acres #A. Stephens #09/18/2014 #03/21/2018 script updated to include Pairwise tools in ArcGIS Pro 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(
# usfsOwnershipFeatureClass = in_workspace + \ # "\\USFS_Ownership_LSRS\\2017_USFS_Ownership_CAALB83.gdb\\USFS_OwnershipLSRS_2017" intersectFeatureClass = bufferOutput + "_intersect" arcpy.AddMessage( "Intersecting with USFS Ownership feature class .....") arcpy.AddMessage("Please be patient while this runs .....") if sys.version_info[0] < 3: arcpy.Intersect_analysis([bufferOutput, usfsOwnershipFeatureClass], intersectFeatureClass) else: arcpy.PairwiseIntersect_analysis( [bufferOutput, usfsOwnershipFeatureClass], intersectFeatureClass) arcpy.AddMessage("Completed Intersection") arcpy.AddMessage( " ____________________________________________________________________" ) arcpy.AddMessage("Updating UnitID field from intersection") cur = arcpy.UpdateCursor(intersectFeatureClass) field = "UnitID_FS" # populating UnitID field with UnitID_FS field
# recalculate status_yr so that each XYco has the earliest status_yr that geometry had arcpy.CalculateField_management("all_wdpa_polybuffpnt_union_duplicates_flat","STATUS_YR","!MIN_status_yr!") # remove the field arcpy.DeleteField_management("all_wdpa_polybuffpnt_union_duplicates_flat","MIN_status_yr") # merge these site back into the unique geometries - creating a flat layer which has the whole WDPA schema populated still. ## If you want to do count analyses do it on the polybuffpnt, if you want to do spatial analyses, do it with this file. arcpy.Merge_management(["all_wdpa_polybuffpnt_union_duplicates_flat",r"in_memory\all_wdpa_polybuffpnt_union_unique"],r"in_memory\all_wdpa_polybuffpnt_union_flat") # repair the recombined layer arcpy.RepairGeometry_management(r"in_memory\all_wdpa_polybuffpnt_union_flat","DELETE_NULL","OGC") # intersect it with the basemap arcpy.PairwiseIntersect_analysis([r"in_memory\all_wdpa_polybuffpnt_union_flat",in_basemap_spat],r"in_memory\all_wdpa_polybuffpnt_union_flat_intersect") # repair it arcpy.RepairGeometry_management(r"in_memory\all_wdpa_polybuffpnt_union_flat_intersect","DELETE_NULL","OGC") # project it into mollweide, an equal area projection arcpy.Project_management(r"in_memory\all_wdpa_polybuffpnt_union_flat_intersect","all_wdpa_polybuffpnt_union_flat_intersect_project",in_mollweideprj) # repair it arcpy.RepairGeometry_management("all_wdpa_polybuffpnt_union_flat_intersect_project","DELETE_NULL","OGC") # add and calculate a new area field arcpy.AddGeometryAttributes_management("all_wdpa_polybuffpnt_union_flat_intersect_project","AREA_GEODESIC","","SQUARE_KILOMETERS",in_mollweideprj) # now we get into the creation of summary statistic tables # for the explanation and underlying rationale for these decisions please see accompanying metadata.