this code finds all the vertices of every census tract for the state of California and Colorado. The code runs, and creates a shapefile with all proper filled fields (totpop, XCoord,YCoord, area1 etc.). The problem now is that nothing is displaying when I add the shapefile on ArcMAP, however, when I open the attribute table, all the fields are filled.
fp = r"C:\Users\mr276170\Desktop\EXPLOSION!"
import os
import arcpy
import math
from arcpy.sa import *
from arcpy import env
env.workspace = fp
arcpy.env.overwriteOutput = True
#########
equal_shapeIN = fp + r'\CAandCO.shp'
out_shp = fp + r'\TheVertsAREAPOP.shp'
geometry_type = "POINT"
has_m = "DISABLED"
has_z = "DISABLED"
projection = arcpy.SpatialReference('USA Contiguous Albers Equal Area Conic USGS')
arcpy.Project_management(equal_shapeIN, out_shp, projection)
#########
arcpy.CopyFeatures_management(equal_shapeIN, out_shp)
arcpy.CreateFeatureclass_management(fp, 'TheVertsAREAPOP.shp',geometry_type, 'CAandCO.shp',has_m,has_z,projection)
dropFields = ["romney12", "obama12", "t_area", "totarea", "total_area"]
arcpy.DeleteField_management(out_shp,dropFields )
arcpy.DeleteRows_management(out_shp)
#########
fields = [('XCoord',"DOUBLE"), ("YCoord","DOUBLE"), ("area1","DOUBLE")]
for fields in fields:
arcpy.AddField_management(*(out_shp,) +fields)
with arcpy.da.UpdateCursor(equal_shapeIN,["OID@", "SHAPE@", "STATE_NAME", "NAME", "totpop", "POLY_ID", "OBJECTID", "STATE_FIPS", "CNTY_FIPS", "FIPS", "FIPSnum","FIPS_NUMER","SHAPE@AREA"]) as cursor:
#####add area
totalPOP = 0
for row in cursor:
print("Feature {}:".format(row[0]))
partnum = 0
for part in row[1]:
print("Part {}:".format(partnum))
for pnt in part:
if pnt:
Xcoord = ("{}".format(pnt.X))
Ycoord = ("{}".format(pnt.Y))
stateNAME = row[2]
countyname = row[3]
totalPOP = row[4]
idpoly = row[5]
idobject = row[6]
stateFIPS = row[7]
countyFIPS = row[8]
fips = row[9]
fipSnum = row[10]
fipsNumer = row[11]
totarea = row[12]
print Xcoord, Ycoord, stateNAME, countyname, totalPOP, idpoly, idobject, stateFIPS, countyFIPS, totarea
cursor1 = arcpy.da.InsertCursor(out_shp,["XCoord","YCoord","STATE_NAME", "NAME", "totpop", "POLY_ID", "OBJECTID", "STATE_FIPS", "CNTY_FIPS", "FIPS", "FIPSnum","FIPS_NUMER","area1"])
cursor1.insertRow([Xcoord,Ycoord,stateNAME,countyname,totalPOP, idpoly, idobject, stateFIPS, countyFIPS, fips, fipSnum, fipsNumer, totarea])
del cursor, cursor1
print "this works yo!"
del cursor
isn't necessary because thewith
does cleanup. Your UpdateCursor doesn't ever update. Please make sure your code samples are minimal -- see MCVE. – Vince Jun 5 '16 at 0:47