本文整理汇总了Python中arcpy.ListFields方法的典型用法代码示例。如果您正苦于以下问题:Python arcpy.ListFields方法的具体用法?Python arcpy.ListFields怎么用?Python arcpy.ListFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arcpy
的用法示例。
在下文中一共展示了arcpy.ListFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateMessages
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
try:
if parameters[0].altered:
field_names = []
fields = arcpy.ListFields(parameters[0].valueAsText)
for field in fields:
field_names.append(field.baseName.upper())
if not ("HYDROID" in field_names and "NEXTDOWNID" in field_names):
parameters[0].setErrorMessage("Input Drainage Line must contain HydroID and NextDownID.")
except Exception as e:
parameters[0].setErrorMessage(e.message)
if parameters[2].altered:
max_nbr = parameters[2].value
if (max_nbr < 0 or max_nbr > 12):
parameters[2].setErrorMessage("Input Maximum Number of Upstreams must be within [1, 12]")
return
示例2: testadd_fields_from_table
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def testadd_fields_from_table(self):
fc = os.path.join(self.testing_gdb, 'Illinois')
copy = fc + '_copy'
if arcpy.Exists(copy):
arcpy.Delete_management(copy)
arcpy.CopyFeatures_management(fc, copy)
flds = ['POP1990', 'POP2000']
tab = fc = os.path.join(self.testing_gdb, 'Illinois_county_info')
ap.add_fields_from_table(copy, tab, flds)
est = [f.name for f in arcpy.ListFields(copy)]
try:
arcpy.Delete_management(copy)
except: pass
for f in flds:
self.assertTrue(f in est)
pass
示例3: testjoin_using_dict
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def testjoin_using_dict(self):
if arcpy.Exists(r'in_memory\copy'):
arcpy.Delete_management(r'in_memory\copy')
fc = os.path.join(self.testing_gdb, 'Illinois')
copy = fc + '_copy'
if arcpy.Exists(copy):
arcpy.Delete_management(copy)
arcpy.CopyFeatures_management(fc, copy)
flds = ['POP1990', 'POP2000']
tab = fc = os.path.join(self.testing_gdb, 'Illinois_county_info')
ap.join_using_dict(copy, 'CNTY_FIPS', tab, 'CNTY_FIPS', flds)
est = [f.name for f in arcpy.ListFields(copy)]
try:
arcpy.Delete_management(copy)
except: pass
for f in flds:
self.assertTrue(f in est)
pass
示例4: updateMessages
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
try:
if parameters[0].altered:
field_names = []
fields = arcpy.ListFields(parameters[0].valueAsText)
for field in fields:
field_names.append(field.baseName.upper())
if not ("HYDROID" in field_names and "NEXTDOWNID" in field_names):
parameters[0].setErrorMessage("Input Drainage Line must contain HydroID and NextDownID.")
except Exception as e:
parameters[0].setErrorMessage(e.message)
return
示例5: updateMessages
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
try:
if parameters[0].altered:
field_names = []
fields = arcpy.ListFields(parameters[0].valueAsText)
for field in fields:
field_names.append(field.baseName.upper())
if not ("MUSK_KFAC" in field_names and "MUSK_K" in field_names and "MUSK_X" in field_names):
parameters[0].setErrorMessage("Input Drainage Line must contain Musk_kfac, Musk_k and Musk_x.")
except Exception as e:
parameters[0].setErrorMessage(e.message)
return
示例6: fc_to_features
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def fc_to_features(dataset):
"""
converts a dataset to a list of feature objects
Input:
dataset - path to table or feature class
Output:
list of feature objects
"""
if arcpyFound:
desc = arcpy.Describe(dataset)
fields = [field.name for field in arcpy.ListFields(dataset) if field.type not in ['Geometry']]
date_fields = [field.name for field in arcpy.ListFields(dataset) if field.type =='Date']
non_geom_fields = copy.deepcopy(fields)
features = []
if hasattr(desc, "shapeFieldName"):
fields.append("SHAPE@JSON")
del desc
with arcpy.da.SearchCursor(dataset, fields) as rows:
for row in rows:
row = list(row)
for df in date_fields:
if row[fields.index(df)] != None:
row[fields.index(df)] = int((_date_handler(row[fields.index(df)])))
template = {
"attributes" : dict(zip(non_geom_fields, row))
}
if "SHAPE@JSON" in fields:
template['geometry'] = \
json.loads(row[fields.index("SHAPE@JSON")])
features.append(
Feature(json_string=_unicode_convert(template))
)
del row
return features
return None
#----------------------------------------------------------------------
示例7: getDateFields
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def getDateFields(fc):
"""
Returns a list of fields that are of type DATE
Input:
fc - feature class or table path
Output:
List of date field names as strings
"""
if arcpyFound == False:
raise Exception("ArcPy is required to use this function")
return [field.name for field in arcpy.ListFields(fc, field_type="Date")]
#----------------------------------------------------------------------
示例8: combine_data
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def combine_data(fc_list, output_fc):
""" :param fc_list: array of featureclass paths as strings
:param output_fc: path to output dataset
Combine the downloaded datafiles into one
fastest approach is to use cursor
"""
if len(fc_list) == 1:
arcpy.Copy_management(fc_list[0], output_fc)
output_msg("Created {0}".format(output_fc))
else:
for fc in fc_list:
if fc_list.index(fc) == 0:
# append to first dataset. much faster
output_msg("Prepping yer first dataset {0}".format(fc))
if arcpy.Exists(output_fc):
output_msg("Avast! {0} exists, deleting...".format(output_fc), severity=1)
arcpy.Delete_management(output_fc)
arcpy.Copy_management(fc, output_fc) # create dataset to append to
output_msg("Created {0}".format(output_fc))
fieldlist = []
#fieldlist = ["SHAPE@"]
fields = arcpy.ListFields(output_fc)
for field in fields:
if field.name.lower() == u'shape':
fieldlist.insert(0, "SHAPE@") # add shape token to start
else:
fieldlist.append(field.name)
#fields = [field.name for field in arcpy.ListFields(output_fc) if field.name.lower() not in [u'shape']]
#fieldlist.extend(fields)
##arcpy.CopyFeatures_management(output_fc, fc) # duplicate first one so delete later doesn't fail
insert_rows = arcpy.da.InsertCursor(output_fc, fieldlist)
else:
search_rows = arcpy.da.SearchCursor(fc, fieldlist) # append to first dataset
for row in search_rows:
insert_rows.insertRow(row)
del row, search_rows
output_msg("Appended {0}...".format(fc))
del insert_rows
示例9: validate_schema_map
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def validate_schema_map(report_schema, reclass_map, report_date_field, report_ID_field):
try:
valid = True
fieldList = arcpy.ListFields(report_schema)
layer_fields = []
for field in fieldList:
layer_fields.append(field.name)
for fld in reclass_map:
if not fld['FieldName'] in layer_fields:
print "%s does not exist in %s" % (fld['FieldName'], report_schema)
valid = False
if report_date_field == '':
print "Warning: Report Date not set in %s" % (report_schema)
elif not report_date_field in layer_fields:
print "%s (Report Date Field) does not exist in %s" % (report_date_field, report_schema)
valid = False
if not report_ID_field in layer_fields:
print "%s (ID Field) does not exist in %s" % (report_ID_field, report_schema)
valid = False
if valid == False:
raise ReportToolsError({
"function": "validate_schema_map",
"line": 1454,
"filename": 'reporttools',
"synerror": "%s does not contain all the fields contained in the config" % report_schema
})
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise ReportToolsError({
"function": "validate_schema_map",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
})
except ReportToolsError, e:
raise e
示例10: fieldsToFieldArray
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def fieldsToFieldArray(featureclass):
"""fieldsToFieldArray(featureclass)
Converts fields to a list
featureclass(String):
The specified feature class or table whose fields will be returned.
"""
fieldList = None
try:
fieldList = arcpy.ListFields(featureclass)
returnFields = []
for field in fieldList:
returnFields.append(field.name)
return returnFields
except:
line, filename, synerror = trace()
raise ReportToolsError({
"function": "fieldsToFieldArray",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fieldList = None
del fieldList
gc.collect()
# ----------------------------------------------------------------------
示例11: names
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def names(x, filterer = None):
"""Return list of column names of a table.
Required:
x -- input table or table view
Optional:
filterer -- function, only fields where filterer returns True are listed
Example:
>>> names('c:\\foo\\bar.shp', lambda f: f.name.startswith('eggs'))
"""
flds = arcpy.ListFields(x)
if filterer is None: filterer = lambda a: True
return [f.name for f in flds if filterer(f)]
示例12: types
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def types(x, filterer = None):
"""Return list of column types of a table.
Required:
x -- input table or table view
Optional:
filterer -- function, only fields where filterer returns True are listed
Example:
>>> types('c:\\foo\\bar.shp', lambda f: f.name.startswith('eggs'))
"""
flds = arcpy.ListFields(x)
if filterer is None: filterer = lambda a: True
return [f.type for f in flds if filterer(f)]
示例13: rename_col
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def rename_col(tbl, col, newcol, alias = ''):
"""Rename column in table tbl and return the new name of the column.
This function first adds column newcol, re-calculates values of col into it,
and deletes column col.
Uses arcpy.ValidateFieldName to adjust newcol if not valid.
Raises ArcapiError if col is not found or if newcol already exists.
Required:
tbl -- table with the column to rename
col -- name of the column to rename
newcol -- new name of the column
Optional:
alias -- field alias for newcol, default is '' to use newcol for alias too
"""
if col != newcol:
d = arcpy.Describe(tbl)
dcp = d.catalogPath
flds = arcpy.ListFields(tbl)
fnames = [f.name.lower() for f in flds]
newcol = arcpy.ValidateFieldName(newcol, tbl) #os.path.dirname(dcp))
if col.lower() not in fnames:
raise ArcapiError("Field %s not found in %s." % (col, dcp))
if newcol.lower() in fnames:
raise ArcapiError("Field %s already exists in %s" % (newcol, dcp))
oldF = [f for f in flds if f.name.lower() == col.lower()][0]
if alias == "": alias = newcol
arcpy.AddField_management(tbl, newcol, oldF.type, oldF.precision, oldF.scale, oldF.length, alias, oldF.isNullable, oldF.required, oldF.domain)
arcpy.CalculateField_management(tbl, newcol, "!" + col + "!", "PYTHON_9.3")
arcpy.DeleteField_management(tbl, col)
return newcol
示例14: get_field_type
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def get_field_type(in_field, fc=''):
"""Converts esri field type returned from list fields or describe fields
to format for adding fields to tables.
Required:
in_field -- field name to find field type. If no feature class
is specified, the in_field paramter should be a describe of
a field.type
Optional:
fc -- feature class or table. If no feature class is specified,
the in_field paramter should be a describe of a field.type
Example
>>> # field type of 'String' needs to be 'TEXT' to be added to table
>>> # This is a text type field
>>> # now get esri field type
>>> print getFieldType(table, 'PARCEL_ID') #esri field.type return is 'String', we want 'TEXT'
TEXT
"""
if fc:
field = [f.type for f in arcpy.ListFields(fc) if f.name == in_field][0]
else:
field = in_field
if field in lut_field_types:
return lut_field_types[field]
else:
return None
示例15: match_field
# 需要导入模块: import arcpy [as 别名]
# 或者: from arcpy import ListFields [as 别名]
def match_field(table_or_list, pat, multi=False):
"""Return a list of field objects where name matches the specified pattern.
Required:
table_or_list -- input table or feature class or list of fields
pat -- pattern to match to field
Optional:
multi: if True, will return a list of all matches,
otherwise returns the first match
Example:
>>> match_field(r'C:\Temp\Counties.shp', 'county_*', True)
['COUNTY_CODE', 'COUNTY_FIPS']
"""
import fnmatch
if isinstance(table_or_list, list):
fields = table_or_list
else:
fields = [f.name for f in arcpy.ListFields(table_or_list)]
all_mats = []
for f in fields:
if fnmatch.fnmatch(f, pat):
if not multi:
return f
else:
all_mats.append(f)
return all_mats