This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os.path import dirname, join, realpath | |
| import arcpy | |
| import ConfigParser ## note that in Python 3.x, name will change to configparser | |
| #------------------------------------------------------------------------------- | |
| # Function to write each section with its keys & values | |
| #------------------------------------------------------------------------------- | |
| def write_config(keys, values, config, section): | |
| config.add_section(section) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| arcpy.env.overwriteOutput = True | |
| snapPoints = arcpy.GetParameterAsText(0) | |
| roadLines = arcpy.GetParameterAsText(1) | |
| outFc = arcpy.GetParameterAsText(2) | |
| searchDistance = arcpy.GetParameterAsText(3) | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # concatenate parsed address fields without extra spaces | |
| import arcpy | |
| featureClass = "c:\\myfakepath\\data.gdb\\fc" | |
| # create an expression to find records where the STREETNO field is not blank | |
| # this indicates an address to be concatenated | |
| expression = "STREETNO IS NOT NULL" | |
| # create a list of the fields to be concatenated | |
| # (the last field in the list is the field to be concatenated in to) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| # input feature class and field name to check for duplicates | |
| inputFC = r"c:\mygeodatabase.gdb\myfeatureclass" | |
| myField = "myField" | |
| # create new, empty lists for duplicate values and unique values | |
| dupeList = [] | |
| uniqueList = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| # get parameters | |
| fc = "c:/geodatabase.gdb/featureclass" ## feature class | |
| field = "field" ## name of field to truncate | |
| newLength = 100 ## new length: whatever is needed | |
| # create new name, length, expression to truncate existing data | |
| newField = field + "tmp" | |
| newLengthSlice = newLength - 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fc = "c:/path/geodatabase.gdb/featureclass" | |
| # restrict returned fields by wildcard | |
| fieldList = arcpy.ListFields(fc,"OWN*") | |
| # restrict returned fields by field type | |
| fieldList = arcpy.ListFields(fc,"","String") | |
| # exclude required fields such as Shape and OID | |
| # (https://blogs.esri.com/esri/arcgis/2012/08/30/field-mapping-and-python-scripting) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| srcFC = "c:/path/Geodatabase.gdb/srcFc" | |
| destFC = "c:/path/Geodatabase.gdb/destFc" | |
| # get field lists from each feature class, restricting to "String" feature types | |
| srcFields = arcpy.ListFields(srcFC,"","String") | |
| destFields = arcpy.ListFields(destFC,"","String") | |
| # create empty dictionaries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| featureClass = "c:/path/Geodatabase.gdb/fc" | |
| # Get a list of field objects from a feature class | |
| fcFields = arcpy.ListFields(featureClass) | |
| # Print the field names, types and lengths using string formatting | |
| for field in fcFields: | |
| print("{0}: type = {1} length = {2}".format(field.name, field.type, field.length)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| source ="path/to/featureclass" | |
| srcFlds = arcpy.ListFields(source) | |
| for field in srcFlds: | |
| print("{0} type = {1} length = {2}".format(field.name, field.type, field.length)) |