How do I retain the values and field names in the resulting shapefile's attribute table after using NumPyArrayToFeatureClass?
I'm starting out with a 2d array named npGrid and I'm making it into a structured array with column names in order to run NumPyArrayToFeatureClass. I read the following post to guide me this far: arcpy.NumPyArrayToFeatureClass exception: "TypeError: narray.fields require"
import arcpy, os import numpy as np out_fc = os.path.join(os.getcwd(), "test.shp") sr = arcpy.SpatialReference(4326) npGrid = np.array([[40.10, 35.3, .001], [40.2, 35.25, .002], [40.8, 34.9, .003], [40.75, 35.75, .004]]) x = npGrid[:,0] y = npGrid[:,1] tprobs = npGrid[:,2] struct = np.rec.fromarrays([x,y,tprobs], formats=['f8','f8','f8'], names=["X", "Y", "TPROBS"]) feature = arcpy.da.NumPyArrayToFeatureClass(struct, out_fc, ['X', 'Y', 'TPROBS'], sr) print([f.name for f in arcpy.ListFields(out_fc)])
The resulting shapefile is missing all of the field names and values:
Output: [u'FID', u'Shape', u'Id']
edit after changing the code to the following, the attribute table in the output shapefile was populated with the tprob value:
feature = arcpy.da.NumPyArrayToFeatureClass(struct, out_fc, ['X', 'Y'], sr)