本文整理匯總了Python中arcpy.FieldMappings方法的典型用法代碼示例。如果您正苦於以下問題:Python arcpy.FieldMappings方法的具體用法?Python arcpy.FieldMappings怎麽用?Python arcpy.FieldMappings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類arcpy
的用法示例。
在下文中一共展示了arcpy.FieldMappings方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_field_map
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import FieldMappings [as 別名]
def generate_field_map(in_time_lapse_polys, fields_to_preserve):
'''Create a FieldMappings object to use in Spatial Join. For our application, we only want to preserve a few fields
for informational purposes. We expect all these field values to be the same, so use the "First" rule so the output
polygon will just keep the same value as the inputs. All other fields in the input data will not be transferred to
the output.
Params:
in_time_lapse_polys: Time lapse polygon feature class from which to retrieve the fields
fields_to_preserve: A list of field names we want to keep for the output.
'''
field_mappings = arcpy.FieldMappings()
for field in fields_to_preserve:
fmap = arcpy.FieldMap()
fmap.addInputField(in_time_lapse_polys, field)
fmap.mergeRule = "First"
field_mappings.addFieldMap(fmap)
return field_mappings
示例2: create_raw_cell_counts_fc
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import FieldMappings [as 別名]
def create_raw_cell_counts_fc(selected_time_lapse_polys, in_poly_raster_template, temp_spatial_join_fc, fmaps,
match_option):
'''Do a spatial join in order to count the number of time lapse polygons intersect each "cell" in the raster-like
polylgon template. We are effectively applying the template to a specific set of time lapse polygons, doing the
count, and creating the raw output. The result is a polygon feature class of raster-like cells with a field called
Join_Count that shows the number of input time lapse polygons that intersect the cell using the specified
match_option.
Params:
selected_time_lapse_polys: Set (or subset) of time lapse polygons to use
in_poly_raster_template: The raster-like polygon feature class produced from create_polygon_raster_template()
temp_spatial_join_fc: Path to a temporary output FC which we will overwrite each time this method is called and then
delete at the end of the tool during clean-up
fmaps: FieldMappings object indicating which fields to preserve
match_options: match_options parameter for the Spatial Join tool
'''
arcpy.analysis.SpatialJoin(
in_poly_raster_template,
selected_time_lapse_polys,
temp_spatial_join_fc,
"JOIN_ONE_TO_ONE", # Output keeps only one copy of each "cell" when multiple time lapse polys intersect it
"KEEP_COMMON", # Delete any "cells" that don't overlap the time lapse polys being considered
field_mapping=fmaps, # Preserve some fields from the original data
match_option=match_option
)
示例3: assignFieldsByIntersect
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import FieldMappings [as 別名]
def assignFieldsByIntersect(sourceFC, assignFC, fieldsToAssign, outputFC,report_areas_overlap):
tempWorkspace = arcpy.env.scratchGDB
assignFields = arcpy.ListFields(dataset=assignFC)
assignFieldsNames = [f.name for f in assignFields]
sourceFields = arcpy.ListFields(dataset=sourceFC)
sourceFieldNames = [f.name for f in sourceFields]
newFields = []
fms = arcpy.FieldMappings()
for fieldToAssign in fieldsToAssign:
if fieldToAssign not in assignFieldsNames:
raise ValueError("{0} does not exist in {1}".format(fieldToAssign,assignFC))
outputField = fieldToAssign
if fieldToAssign in sourceFieldNames + newFields:
outputField = Common.uniqueFieldName(fieldToAssign, sourceFieldNames + newFields)
newFields.append(outputField)
fm = arcpy.FieldMap()
fm.addInputField(assignFC, fieldToAssign)
type_name = fm.outputField
type_name.name = outputField
fm.outputField = type_name
fms.addFieldMap(fm)
fieldmappings = arcpy.FieldMappings()
#fieldmappings.addTable(assignFC)
#fieldmappings.removeAll()
fieldmappings.addTable(sourceFC)
for fm in fms.fieldMappings:
fieldmappings.addFieldMap(fm)
if report_areas_overlap:
join_operation = "JOIN_ONE_TO_MANY"
else:
join_operation = "JOIN_ONE_TO_ONE"
outputLayer = arcpy.SpatialJoin_analysis(target_features=sourceFC,
join_features=assignFC,
out_feature_class=outputFC,
join_operation=join_operation,
join_type="KEEP_COMMON",
field_mapping=fieldmappings,
match_option="HAVE_THEIR_CENTER_IN",
search_radius=None,
distance_field_name=None)[0]
return outputLayer
示例4: enable_copy_attachments
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import FieldMappings [as 別名]
def enable_copy_attachments(input_fc, output_fc):
# Check if the input feature class has attachments table
input_attachment_table = input_fc + '__ATTACH'
if not arcpy.Exists(input_attachment_table):
desc = arcpy.Describe(input_fc)
input_attachment_table = desc.Path.split('.')[0] + '.gdb\\' + desc.Name + '__ATTACH'
if not arcpy.Exists(input_attachment_table):
arcpy.AddMessage("Unable to locate the attachment table for the input feature class.")
else:
# Enable Attachments
arcpy.AddMessage("Enabling Attachments")
arcpy.EnableAttachments_management(output_fc)
arcpy.AddMessage("Enabled Attachments")
# Copy Attachments from Input feature class to Temp feature class.
arcpy.AddMessage("Copying Attachments..")
outputTable = output_fc + '__ATTACH'
try:
# Check if the input feature class was related to the attachment tables via the ObjectID field.
input_table_desc = arcpy.Describe(input_attachment_table)
field_rel_objectID = [field for field in input_table_desc.fields if field.name.lower() == 'rel_objectid']
# If the input attachment table has REL_OBJECTID field then remap GUID fields between input and output attachment table.
if field_rel_objectID:
field_rel_globalID = [field for field in input_table_desc.fields if field.type.lower() == 'guid']
if field_rel_globalID:
output_field = field_rel_globalID[0]
else:
arcpy.AddError("Can't copy attachments...")
output_table_field_mappings = arcpy.FieldMappings()
output_table_field_mappings.addTable(outputTable)
input_table_field_mappings = arcpy.FieldMappings()
input_table_field_mappings.addTable(input_attachment_table)
output_table_globalID = [field for field in output_table_field_mappings.fields if field.type.lower() == 'guid'][0]
field_index = output_table_field_mappings.findFieldMapIndex(output_table_globalID.name)
fmap = output_table_field_mappings.fieldMappings[field_index]
output_table_field_mappings.removeFieldMap(field_index)
fmap.addInputField(input_attachment_table,output_field.name)
output_table_field_mappings.addFieldMap(fmap)
for input_field_map in input_table_field_mappings.fieldMappings:
output_table_field_mappings.addFieldMap(input_field_map)
arcpy.Append_management(input_attachment_table, outputTable, 'NO_TEST', output_table_field_mappings)
else:
arcpy.Append_management(input_attachment_table, outputTable)
arcpy.AddMessage("Copied Attachments..")
except Exception as e:
arcpy.AddError(e)
示例5: GetFieldInfo
# 需要導入模塊: import arcpy [as 別名]
# 或者: from arcpy import FieldMappings [as 別名]
def GetFieldInfo(fc):
# Create and return FieldMapping object containing valid project record fields. Fields
# that are not part of project record feature class will not be appended to the project
# record fc.
try:
outFields = ['AREASYMBOL','MUSYM','PROJECT_NAME','STATUS','RECERT_NEEDED']
# Create required FieldMappings object and add the fc table as a
# FieldMap object
fms = arcpy.FieldMappings()
fms.addTable(fc)
# loop through each field in FieldMappings object
for fm in fms.fieldMappings:
# Field object containing the properties for the field (aliasName...)
outFld = fm.outputField
# Name of the field
fldName = outFld.name
# remove field from FieldMapping object if it is 'OID' or 'Geometry'
# or not in dFieldInfo dictionary (SSURGO schema)
if not fldName in outFields:
fms.removeFieldMap(fms.findFieldMapIndex(fldName))
for fldName in outFields:
newFM = fms.getFieldMap(fms.findFieldMapIndex(fldName))
fms.removeFieldMap(fms.findFieldMapIndex(fldName))
fms.addFieldMap(newFM)
return fms
except:
errorMsg()
fms = arcpy.FieldMappings()
return fms
## ===================================================================================