Select to view content in your preferred language

NumPyArrayToFeatureClass gives RuntimeError: create table

2517
8
Jump to solution
02-26-2019 01:26 AM
GrzegorzJeleniewicz
Occasional Contributor

I've tried to change polygon feautre  to point by using tools:

FeatureClassToNumPyArray
NumPyArrayToFeatureClass.
My code as below:
import arcpy
import numpy as np
in_file='C:/ios/OneDrive/siatki_obliczeniowe/siatki.gdb/siatka_005'
a = arcpy.da.FeatureClassToNumPyArray(in_file, ["*"], explode_to_points=False)
out_file='C:/ios/OneDrive/siatki_obliczeniowe/siatki.gdb/xxxx3'

arcpy.da.NumPyArrayToFeatureClass(a, out_file,["shape"])

I got an error:

Traceback (most recent call last):
  File "C:/ios/OneDrive/python/feature_to_point.py", line 7, in <module>
    arcpy.da.NumPyArrayToFeatureClass(a, out_file,["shape"])
RuntimeError: create table


I had changed out_file to shp file and it works but it is not solution for me. I would like to be able write to .gdb.
Any idea how to solve this problem?
0 Kudos
1 Solution
8 Replies
DanPatterson_Retired
MVP Emeritus

your geometry field... what was it named? and what was it in the array?

you indicate it was ['shape']? or ['Shape@'] or 'SHAPE@' or some other variant

use

a.dtype‍

and get the exact case and spelling of the geometry field.

Also you will need to set

...explode_to_points=True)  # in order to get points, ‍

you can't set explode_to_points=False, unless you want the centroid of the original polygon

Thirdly, if the output featureclass name exists, it will fail

GrzegorzJeleniewicz
Occasional Contributor

Thank you for your answer.

my geomtery field is ['Shape']. I've cheked it with a.dtype and got result:

[('OBJECTID', '<i4'), ('Shape', '<f8', (2,)), ('Shape_Length', '<f8'), ('Shape_Area', '<f8'), ('miasto', '<U50')]

I've changed small 's' for capital 'S', but it didn't help

Yes, I want the centroid of the original polygon, so explode_to_points=False is ok for me.

The output featureclass name is set to new each run.

0 Kudos
DanPatterson_Retired
MVP Emeritus

hmmm if you only want the centroid coordinate, you should avoid using the true shape, but use one of the alternates and specify your field names explictly

FeatureClassToNumPyArray—Data Access module | ArcGIS Desktop

you can easily parse the fields rather than using "*" which is ok in some situations, but the shape field should be parsed into x and y coordinates usually

flds = ['OID@', 'SHAPE@X', 'SHAPE@Y']

other_flds = [i.name for i in arcpy.ListFields(fc) if i.type not in ('OID', 'Geometry')]

flds.extend(other_flds)

flds

['OID@', 'SHAPE@X', 'SHAPE@Y', 'ID', 'Norm', 'Rank1', 'Text01', 'Text02', 'Xs', 'Ys',
 'Int_short', 'Float_fld', 'Grid_code', 'Rank_shp', 'PolyID', 'Grid_Count',
 'Diff_from_mean', 'x']
GrzegorzJeleniewicz
Occasional Contributor

I changed my code following your instructions:

import arcpy
import numpy as np
in_file='C:/ios/OneDrive/siatki_obliczeniowe/siatki.gdb/strefy_miejskie_siatka_01'
flds = ['OID@', 'SHAPE@X', 'SHAPE@Y']
other_flds = [i.name for i in arcpy.ListFields(in_file) if i.type not in ('OID', 'Geometry')]
flds.extend(other_flds)
a = arcpy.da.FeatureClassToNumPyArray(in_file, flds, explode_to_points=False)
out_file='C:/ios/OneDrive/siatki_obliczeniowe/siatki.gdb/axxxyz9'
print (a.dtype)
arcpy.da.NumPyArrayToFeatureClass(a, out_file,['SHAPE@X', 'SHAPE@Y'])

Unfortunately I got error again:

Traceback (most recent call last):
  File "C:/ios/OneDrive/python/feature_to_point.py", line 10, in <module>
    arcpy.da.NumPyArrayToFeatureClass(a, out_file,['SHAPE@X', 'SHAPE@Y'])
RuntimeError: create table

The most annoying  fact is that if I change the 'out_file ' to shp file instead of feature class in geodatabase (.gdb) it works (with both code versions). For sure there is a problem with saving output to geodatabase (.gdb). I have no clue why.

 
0 Kudos
DanPatterson_Retired
MVP Emeritus

Just noticed you are using python 2.7... may be the issue since I have no problem using the process with either points exploded or not exploded using python 3

0 Kudos
GrzegorzJeleniewicz
Occasional Contributor

I've got already the solution and posted link to it above.

0 Kudos
DanPatterson_Retired
MVP Emeritus

for future reference

all_flds = [f.name for f in arcpy.ListFields(fc, "*")]

editable_flds = [f.name for f in arcpy.ListFields(fc, "*") if f.editable]

all_flds

['OBJECTID', 'Shape', 'Grid_codes', 'F_', 'Shape_Length', 'Shape_Area', 'Rand_0',
 'Rand_1', 'Shape_Length_1', 'Shape_Area_1']

editable_flds

['Shape', 'Grid_codes', 'F_', 'Rand_0', 'Rand_1']

OBJECTID, and Shape info can be accessed through their @ property, other variants of Shape aren't editable and removing them from the list of candidates is a safe bet... at least for a file gdb