Hi
I'm using arcmap 10.2 and have been trying in vain to get the
numpyArrayToFeatureClass tool to work in a python script. It generates a shapefile
but the output I get only ever has an index column - no other columns are
output.
When I use the code example here ArcGIS Help (10.2, 10.2.1, and 10.2.2) I get exactly the same problem. Can you please
give me any indication where I am going wrong?
Thanks
Alastair
Can you post your code
Hi
Note that I’m starting with a pandas data frame (df) and converting it using “to_records” (although I have tried several methods like 'df.as_matrix()';
turbinesNPArray = df.to_records()
dt = turbinesNPArray.dtype
#(Note this returns:
#[('index', '<i8'), ('TurbineID', '<f8'), ('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('HubH', '<f8'), ('RotorD', '<f8'), ('WGS84Lat', '<f8'), ('WGS84Long', '<f8'), ('OFFSETA', '<f8'), ('OFFSETB', '<f8')]
#type turbinesNPArray:<class 'numpy.core.records.recarray'>
outShapeFile = r"%s\%s.shp" %(rootPath + "Outputs", "outLayout_temp")
arcpy.da.NumPyArrayToFeatureClass(turbinesNPArray, outShapeFile, ("TurbineID","X","Y","Z","HubH","RotorD","WGS84Lat","WGS84Long","OFFSETA", "OFFSETB"), self.spRef)
I suspect that you are not correctly setting up the nparray:
turbinesNPArray = df.to_records()
Without knowing your fields info, I don't see you fully qualifying the fields in your conversion from Pandas DataFrame to NumPy Array. You can try the following but I have no real way to test:
turbinesNPArray = numpy.array(df.to_records(), numpy.dtype([('index', '<i8'), ('TurbineID', '<f8'), ('X', '<f8'), ('Y', '<f8'), ('Z', '<f8'), ('HubH', '<f8'), ('RotorD', '<f8'), ('WGS84Lat', '<f8'), ('WGS84Long', '<f8'), ('OFFSETA', '<f8'), ('OFFSETB', '<f8')]))
Hi Alastair,
This code works fine for me. Please, use it and tell us what you get.
import arcpy
import numpy
outFC = "E:/temp/testShape.shp"
array = numpy.array([(1, 'testText1', (471316.3835861763, 5000448.782036674)),
(2, 'testText2', (470402.49348005146, 5000049.216449278))],
numpy.dtype([('idfield',numpy.int32),('textField','<U10'),('XY', '<f8', 2)]))
arcpy.da.NumPyArrayToFeatureClass(array, outFC, ['XY'])
Regards
Dani
Hi
Well a shape file gets created but only has an index column - no other fields - see below.
idfield |
1 |
2 |
Thanks
Dani...line 7 is truncated
Not sure what you mean about line 7?
I get;
Traceback (most recent call last):
File "<module1>", line 23, in <module>
RuntimeError: create table