About

ArcGIS Python code recipes is a place for users to learn from and download Python code for use in GIS workflows. The code is authored and tested by the ArcGIS Python development team and can be used to help jump start the development of your GIS applications.

11 thoughts on “About

  1. Is there a script to perform a spatial join without creating a new feature class, but updates field(s) in the target feature?

    • spatial join writes a new feature class. Typical workflow for updating fields is using AddJoin then CalculateField tools.

  2. Glad to have found this site. I have been searching endlessly for a py script that will write out the OID + x + y for each feature in a polyline feature class / shapefile but I cannot locate anywhere. I know it would or should be a short script. Can you help?

  3. Pingback: feature class to csv | ArcPy Café

  4. I have just found this site so I’m a newbie. I was wondering if there was a contents page for the different scripts available for download? I seem to be having some trouble finding anything.

    Thanks,
    Donna

    • the content is mostly embedded within the posts on this blog. There is not a “download all scripts” page. Though that is an interesting idea.

  5. We’ve been trying to get the https://arcpy.wordpress.com/tag/football/ script to work, but have not been successful to get the output files to fill. They output files create but are empty. Can someone help us???!!!!
    Here is our script:

    #Function 1
    arcpy.CreateFileGDB_management(“C:\\Users\\carmodyco\\Desktop\\Python\\Carmody_Final”, “final.gdb”)
    def build_football_field(final,footballfield): # function called build_football_field (output_gdb, output_feature_class):
    print(‘Creating football field.’)
    football_field_fields = (‘Polygon’, ‘Packers’) # creating the object (‘SHAPE@’, ‘TEAM’)
    fc =os.path.join(“final.gdb”,”footballfield”) # fc = joining the paths of final.gdb and footballfield (output gdb, outputfeatureclass)
    if not arcpy.Exists(os.path.join(“final.gdb”, “footballfield”)): #checking to see if path exists
    arcpy.CreateFeatureclass_management(“final.gdb”, “footballfield”, “POLYGON”, “#”,”DISABLED”,”DISABLED”, arcpy.SpatialReference(3857)) #creates a polygon feature class in final.gdb with spatial reference of WGS 1984 Web Mercator
    arcpy.AddField_management(fc, football_field_fields[1], “TEXT”,field_length=20) #adds a new field to the table

    cursor = arcpy.da.InsertCursor(fc, football_field_fields) #inserting a row into the table (in_table, field_names)

    field = [(0, 533.3), #vertices of the field
    (1000, 533.3),
    (1000, 0),
    (0, 0)]
    cursor.insertRow([field,””]) #inserting row

    home_endzone = [(-100, 533.3), #vertices of the home endzone
    (0, 533.3),
    (0, 0),
    (-100, 0)]
    cursor.insertRow([home_endzone, “Packers”]) #inserting row for home_endzone called Packers

    away_endzone = [(1000, 533.3), #vertices of away_endzone
    (1100, 533.3),
    (1100, 0),
    (1000, 0)]
    cursor.insertRow([away_endzone, “Bears”]) #inserting row for away_endzone called Bears

    #need to call the function
    field1 = build_football_field(“C:\\Users\\carmodyco\\Desktop\\Python\\Carmody_Final\\final.gdb”, “C:\\Users\\carmodyco\\Desktop\\Python\\Carmody_Final\\final.gdb\\footballfield”)

    #Function 2:

    def build_yard_lines(final,yardlines): #function called build_yard_lines (output_gdb, output_feature_class):
    print(‘Creating yard markers.’)
    football_line_fields = (‘POLYLINE’, ‘MARKER’) # creating an object (shape@, marker)
    fc = os.path.join(“final.gdb”, “yardlines”) # joining paths of yardlines and final.gdb(ouput_gdb, output_feature_class)
    if not arcpy.Exists(os.path.join(“final.gdb”, “yardlines”)): #checking to see if path exists
    arcpy.CreateFeatureclass_management(“final.gdb”, “yardlines”, “POLYLINE”, “#”, “DISABLED”,”DISABLED”, arcpy.SpatialReference(3857))
    #creates a polyline feature class in final.gdb with spatial reference of WGS 1984 Web Mercator
    arcpy.AddField_management(fc, football_line_fields[1], “TEXT”,field_length=10) #adding new field to the table

    cursor = arcpy.da.InsertCursor(fc, football_line_fields) #inserting a row into the table (in_table, field_names)
    markers = [10, 20, 30, 40, 50, 60, 70, 80, 90] #creating markers
    for marker in markers:
    line_1 = [(marker * 10, 533.3 / 2), (marker * 10, 0)]
    line_2 = [(marker * 10, 533.3 / 2), (marker * 10, 533.3)]
    if marker > 50:
    cursor.insertRow([line_1, str(100 – marker)])
    cursor.insertRow([line_2, str(100 – marker)])
    else:
    cursor.insertRow([line_1, str(marker)])
    cursor.insertRow([line_2, str(marker)])

    lines = build_yard_lines(“C:\\Users\\carmodyco\\Desktop\\Python\\Carmody_Final\\final.gdb”,”C:\\Users\\carmodyco\\Desktop\\Python\\Carmody_Final\\final.gdb\\yardlines”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s