Arcpy XYTableToPoint creating empty feature class

423
8
08-20-2024 02:18 PM
Scosh
by
Emerging Contributor

Using XY Table to Point with python creates an empty feature class. I use the exact same data and settings in ArcPro and it works fine.

 

Things I've checked: this is the correct coordinate system and the fields are in fact populated by valid coordinates.

 

I think this worked fine before I upgraded to 3.3.1, but I'm not 100% sure on that.

 

import arcpy


lines = r'C:\Users\...\workspace.gdb\lines'
info = arcpy.da.Describe(lines)
s = info['spatialReference']
results = arcpy.management.XYTableToPoint(in_table = lines,
out_feature_class = r'memory\test_results',
x_field = 'start_x',
y_field = 'start_y',
coordinate_system = s)

Scosh_0-1724188440544.png

 

8 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

right click on the ran instance of the tool under history and send its code to the Python Window compare that to your code and adapt accordingly if needed.

Question | Analyze | Visualize
Scosh
by
Emerging Contributor

I actually just figured it out. This took doesn't work with the feature class's path as the input. Every other tool I've used accepts the path, but not this one. And creating a feature layer from the path doesn't help either. 

I had to copy the data to a memory feature class first. That's very annoying.

0 Kudos
DanPatterson
MVP Esteemed Contributor
0 Kudos
Scosh
by
Emerging Contributor

That does not appear to help, at least not in Pro 3.3.1. 

The only thing that is helping is using arcpy.management.CopyFeatures to convert the gdb feature class path to a memory feature class.

 

Also, if you don't convert it BEFORE doing a selection, then you have to convert the selection results back to a gdb feature class and then back to a memory feature class. If you just take the selection results and make a feature layer or new memory feature class, the XYTabletoPoint tool won't work (empty output). The crazy thing is the input data appears to be the same no matter what. It still has the same number of features and correct attributes. There just seems to be something mysterious hidden in the input object that the XY tool doesn't like.

0 Kudos
DanPatterson
MVP Esteemed Contributor

how are you running the script?  a python window from within Pro? a Pro notebook with Pro open? a standalone script with Pro closed? 

a memory featureclass is a "view" of the data which may be why it works


... sort of retired...
0 Kudos
Scosh
by
Emerging Contributor

I've been running it as a standalone script from IDLE.

0 Kudos
DanPatterson
MVP Esteemed Contributor

It requires a table view as suggested in my previous post, IDLE isn't connected to Pro whereas the python window is


... sort of retired...
0 Kudos
Scosh
by
Emerging Contributor

I don't understand what you mean. I tried creating a table view in my script and it didn't help.

Are you saying that table views don't work in IDLE, or are you just saying IDLE isn't connected to Pro, because of my comment that I was using Pro 3.3.1? I only mentioned that because I thought ArcPy got updated whenever a new version of Pro came out.

0 Kudos