ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Aide
  • Sign Out
ArcGIS Desktop

ArcGIS Online

La plateforme cartographique de votre organisation

ArcGIS Desktop

Un SIG professionnel complet

ArcGIS Enterprise

SIG dans votre entreprise

ArcGIS Developers

Outils de création d'applications de localisation

ArcGIS Solutions

Modèles d'applications et de cartes gratuits pour votre secteur d'activité

ArcGIS Marketplace

Téléchargez des applications et des données pour votre organisation.

  • Documentation
  • Support
Esri
  • Se connecter
user
  • Mon profil
  • Déconnexion

ArcMap

  • Accueil
  • Commencer
  • Carte
  • Analyser
  • Gérer les données
  • Outils
  • Extensions

FieldMap

  • Résumé
  • Discussion
  • Syntaxe
  • Propriétés
  • Vue d’ensemble des méthodes
  • Méthodes
  • Exemple de code

Résumé

The FieldMap object provides a field definition and a list of input fields taken from a set of tables or feature classes.

Discussion

Les propriétés de l’objet FieldMap comprennent la position de départ et la position de fin d’une valeur de texte en entrée, de façon à ce qu’une valeur en sortie puisse être créée à l’aide d’une tranche d’une valeur en entrée. Si un objet FieldMap contient plusieurs champs en entrée provenant de la même table ou classe d'entités, chaque valeur d’enregistrement est fusionnée à l’aide de la propriété mergeRule. Il s’agit d’une méthode pratique pour concaténer des valeurs, comme un nom de rue contenu dans un champ et un type de voie contenu dans un autre champ, par exemple, Eureka et Street. La propriété joinDelimiter de FieldMap est utilisée si la valeur mergeRule Join est spécifiée. N’importe quel ensemble de caractères, comme un espace, peut être utilisé comme délimiteur. Dans l’exemple ci-dessus, ceci créerait la valeur Eureka Street.

L'objet FieldMappingsest une collection d'objets FieldMap et sert de valeur de paramètre pour les outils qui exécutent un appariement de champs, tels que l’outil Fusionner. La manière la plus simple de travailler avec ces objets est de créer tout d'abord un objet FieldMappings, puis d’initialiser ses objets FieldMap en ajoutant les classes ou tables d’entités en entrée devant être combinées. Une fois toutes les entrées fournies, l’objet FieldMappings contient un objet FieldMap, ou un champ en sortie, pour chaque nom de champ unique de toutes les entrées. Cette liste peut être modifiée en ajoutant de nouveaux champs, en modifiant les propriétés ou le contenu d’un champ en sortie, ou en supprimant tout champ en sortie non désiré.

Syntaxe

 FieldMap  ()

Propriétés

PropriétéExplicationType de données
inputFieldCount
(Lecture seule)

The number of defined input fields.

Integer
joinDelimiter
(Lecture/écriture)

A string value used to separate input values from the same table if the output field type is string and the mergeRule is Join.

String
mergeRule
(Lecture/écriture)

Defines how values from two or more fields from the same input table are merged into a single output value. Valid choices are as follows:

  • First —The first input value is used.
  • Last —The last input value is used.
  • Join —Merge the values using the delimiter value to separate the values (only valid if the output field type is text).
  • Min —The smallest input value is used (only valid if the output field type is numeric).
  • Max —The largest input value is used (only valid if the output field type is numeric).
  • Mean —The mean is calculated using the input values (only valid if the output field type is numeric).
  • Median —The median is calculated using the input values (only valid if the output field type is numeric).
  • Sum —The sum is calculated using the input values (only valid if the output field type is numeric).
  • StDev —The standard deviation is calculated using the input values (only valid if the output field type is numeric).
  • Count —The number of values included in statistical calculations. This counts each value except null values.
String
outputField
(Lecture/écriture)

The properties of the output field are either set or returned in a Field object.

Field

Vue d’ensemble des méthodes

MéthodeExplication
addInputField (table_dataset, field_name, {start_position}, {end_position})

Adds input field to the field map.

findInputFieldIndex (table_dataset, field_name)

Finds an input field from the field map.

getEndTextPosition (index)

Returns the end text position from the field map.

getInputFieldName (index)

Returns the name of an input field from the field map, based on the field's index position.

getInputTableName (index)

Returns the name of an input table from the field map, based on the table's index position.

getStartTextPosition (index)

Returns the start text position from the FieldMap object.

removeAll ()

Removes all values and creates an empty object.

removeInputField (index)

Removes an input field from the FieldMap object.

setEndTextPosition (index, end_position)

Sets end text position for the field map.

setStartTextPosition (index, start_position)

Sets the start text position from the field map.

Méthodes

addInputField (table_dataset, field_name, {start_position}, {end_position})
ParamètreExplicationType de données
table_dataset

The table added to the field map.

String
field_name

The input field name.

String
start_position

The start position of an input text value.

(La valeur par défaut est -1)

Integer
end_position

The end position of an input text value.

(La valeur par défaut est -1)

Integer
findInputFieldIndex (table_dataset, field_name)
ParamètreExplicationType de données
table_dataset

The table added to the field map.

String
field_name

The field name.

String

Valeur renvoyée

Type de donnéesExplication
Integer

The index position of the field name.

getEndTextPosition (index)
ParamètreExplicationType de données
index

The index position.

Integer

Valeur renvoyée

Type de donnéesExplication
Integer

The end text position.

getInputFieldName (index)
ParamètreExplicationType de données
index

The index position.

Integer

Valeur renvoyée

Type de donnéesExplication
String

The input field name.

getInputTableName (index)
ParamètreExplicationType de données
index

The index position.

Integer

Valeur renvoyée

Type de donnéesExplication
String

The input table name.

getStartTextPosition (index)
ParamètreExplicationType de données
index

The index position.

Integer

Valeur renvoyée

Type de donnéesExplication
Integer

The start text position.

removeAll ()
removeInputField (index)
ParamètreExplicationType de données
index

The index position.

Integer
setEndTextPosition (index, end_position)
ParamètreExplicationType de données
index

The index position.

Integer
end_position

The end position of an input text value.

Integer
setStartTextPosition (index, start_position)
ParamètreExplicationType de données
index

The index position.

Integer
start_position

The start position of an input text value.

Integer

Exemple de code

FieldMap example

Les objets FieldMap sont souvent utilisés pour fusionner des jeux de données similaires dans un jeu de données les englobant tous. Dans cet exemple, la classe d'entités Arbres et le shapefile Plants.shp sont fusionnés pour former la classe d’entités nommée Végétation. Chacune des deux classes d'entités d’origine comporte deux attributs : Type et Diamètre. Ces deux attributs doivent être conservés dans la fusion.

import arcpy
# Set the workspace
arcpy.env.workspace = 'c:/base'
in_file1 = 'data.gdb/Trees'
in_file2 = 'Plants.shp'
output_file = 'data.gdb/Vegetation'
# Create the required FieldMap and FieldMappings objects
fm_type = arcpy.FieldMap()
fm_diam = arcpy.FieldMap()
fms = arcpy.FieldMappings()
# Get the field names of vegetation type and diameter for both original
# files
tree_type = "Tree_Type"
plant_type = "Plant_Type"
tree_diam = "Tree_Diameter"
plant_diam = "Diameter"
# Add fields to their corresponding FieldMap objects
fm_type.addInputField(in_file1, tree_type)
fm_type.addInputField(in_file2, plant_type)
fm_diam.addInputField(in_file1, tree_diam)
fm_diam.addInputField(in_file2, plant_diam)
# Set the output field properties for both FieldMap objects
type_name = fm_type.outputField
type_name.name = 'Veg_Type'
fm_type.outputField = type_name
diam_name = fm_diam.outputField
diam_name.name = 'Veg_Diam'
fm_diam.outputField = diam_name
# Add the FieldMap objects to the FieldMappings object
fms.addFieldMap(fm_type)
fms.addFieldMap(fm_diam)
# Merge the two feature classes
arcpy.Merge_management([in_file1, in_file2], output_file, fms)
FieldMap example 2

Cet exemple montre l’option consistant à utiliser des objets FieldMap pour fusionner des champs, à l’aide de l’outil FeatureClassToFeatureClass. Dans cet exemple, une classe d'entités contient des informations concernant le nombre d’accidents par intersection dans une ville. Les données de chaque année sont contenues dans un champ. L’utilisateur veut connaître le nombre moyen d’accidents pour chaque intersection, sans modifier la table existante.

import arcpy
# Set the workspace arcpy.env.workspace = 'c:/base/data.gdb'
in_file = 'AccidentData' out_file = 'AverageAccidents'
# Create the necessary FieldMap and FieldMappings objects fm = arcpy.FieldMap() fm1 = arcpy.FieldMap() fms = arcpy.FieldMappings()
# Each field with accident data begins with 'Yr' (from Yr2007 to Yr2012). # The next step loops through each of the fields beginning with 'Yr', # and adds them to the FieldMap Object for field in arcpy.ListFields(in_file, 'Yr*'):
    fm.addInputField(in_file, field.name)
# Set the merge rule to find the mean value of all fields in the
# FieldMap object fm.mergeRule = 'Mean'
# Set properties of the output name. f_name = fm.outputField f_name.name = 'AvgAccidents' f_name.aliasName = 'AvgAccidents' fm.outputField = f_name
# Add the intersection field to the second FieldMap object fm1.addInputField(in_file, "Intersection")
# Add both FieldMaps to the FieldMappings Object fms.addFieldMap(fm) fms.addFieldMap(fm1)
# Create the output feature class, using the FieldMappings object arcpy.FeatureClassToFeatureClass_conversion(    in_file, arcpy.env.workspace, out_file, field_mapping=fms)

Rubriques connexes

  • Apparier les champs en entrée aux champs en sortie
  • FieldMappings

ArcGIS Desktop

  • Accueil
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

A propos d'Esri

  • A propos de la société
  • Carrières
  • Blog d’Esri
  • Conférence des utilisateurs
  • Sommet des développeurs
Esri
Donnez-nous votre avis.
Copyright © 2021 Esri. | Confidentialité | Légal