1

After days of solving errors and various issues I finally have code that runs in ArcMap... but the shapefile that shows up does not show any points on the map. I checked the attribute table and all fields are showing up there. Zoom to layer doesn't change anything.

Can anyone help me see why this is happening and how to fix it?

Here is the relevant code that I think is having an issue: EDIT: adding more code as requested The name variable is a dictionary from a read/loaded CSV.

# Create shapefile
arcpy.CreateFeatureclass_management(arcpy.env.workspace, outputClass, "POINT", "", "", "", coordsys)
# List variables
xCoord = []
yCoord = []
status = []
names = []
pid = 1
# Add fields to new shapefile
arcpy.AddField_management(outputClass, "Name", "TEXT")
arcpy.AddField_management(outputClass, "Status", "TEXT")

offenseField = ["ID", "Name", "Status", "SHAPE@"]
with arcpy.da.InsertCursor(outputClass, offenseField) as isCursor:
    for key, values in name.iteritems():
        xCoord.append(values[0][0])
        xCoord = filter(None, xCoord)
        xCoord = map(float, xCoord)
        yCoord.append(values[0][1])
        yCoord = filter(None, yCoord)
        yCoord = map(float, yCoord)
        status.append(values[0][2])
        names.append(key)
    for x, y, z, a in zip(xCoord, yCoord, names, status):
        newPoint = arcpy.point(x,y)
        arcpy.AddMessage("New point saved at {0}".format(newPoint))
        pid = pid + 1
        isCursor.insertRow([pid, z, a, newPoint])
  • Please show a bit more in your code snippet, specifically the line when you create the insert cursor you are using. – GeoSharp Dec 7 '16 at 17:43
  • Edited above to add on more code. – JackOfTales Dec 7 '16 at 17:51
  • Is this currently how you have your code indented? In you snippet the second loop is indented in a way that will cause issues – GeoSharp Dec 7 '16 at 17:57
  • 2
    What is offenseField set as? You're inserting 4 values for the row, but it looks like your cursor only has one field. Recommend using SHAPE@XY and setting newPoint = (x,y) . – Evan Dec 7 '16 at 20:27
  • 3
    SHAPE@ expects a geometry object so you would need to construct it with newPoint = arcpy.PointGeometry(arcpy.point(x,y)). For troubleshooting, have you tried printing the record you are trying to insert? newRow = [pid, z, a, newPoint] print(newRow) isCursor.insertRow(newRow) – Evan Dec 7 '16 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.