Select to view content in your preferred language

Order of features after Copy/Export from memory workspace to FGDB

552
4
11-24-2024 06:01 PM
FelixPertziger
Regular Contributor

I am using ArcGIS Pro 3.4. I did this:

arcpy.management.FeatureVerticesToPoints("R2P",r"memory\POINTS","ALL")

arcpy.management.CopyFeatures("POINTS",r"...\GDB.gdb\POINTS_GDB")

Picture shows parent polygon (R2P) and 2 pairs of points labelled by $feature.OBJECTID:

FelixPertziger_0-1732499423377.png

 

As one can see copying features has broke their original physical order. In reality 47k points out of 54k are randomly reshuffled.

Is this intended behavior? 

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

I suspect so, since they include a ORIG_FID field in the output data.

If you need to maintain the order you can use

FeatureClassToNumPyArray—ArcGIS Pro | Documentation

with "explode_to_points" as True, 

Then 

NumPyArrayToFeatureClass—ArcGIS Pro | Documentation

Perhaps instead of the ORIG_FID field, you would like a "retain_original_order" option in the FeatureVerticesToPoints tool


... sort of retired...
0 Kudos
FelixPertziger
Regular Contributor

Hi Dan,

thanks for you reply, see my comments below

0 Kudos
DanPatterson
MVP Esteemed Contributor

I suspect CopyFeatures is optimizing the layout of the points when it does the copy.  I haven't looked into it in detail. Things like

Are the copied points sorted in some fashion?  (by x, then y? peano sort?)

Are duplicate points removed? (only possible if polylines/polygons are used that have shared edges, duplicate start/end points for polygons,  etc)

Duplicating OBJECTID is always a good idea since it belongs to the geodatabase and not the featureclass.

Tools provide the options for the widest use-case.  Arcpy allows fine-tuning for specific cases, and even those have their limits.  For instance FeatureClassToNumpy and its relatives do a good job but not a perfect one (for example, it is hard to work with multipart shapes)

You have a workaround.  I simply suggest other options should the existing tool not work in your particular situation.


... sort of retired...
0 Kudos
FelixPertziger
Regular Contributor

You are talking about arcpy, let's assume I have no clue about it and have no desire to learn.

My issue is not with FeatureVerticesToPoints tool. It produces nicely ordered points with first being first vertex of geometry etc.

My issue is with Copy Features tool. Moreover if I use Data-Export Features  (instead of Copy Features), there is no OBJECTID in a list of SORT fields available. There is a good reason why it is not in a list, - it is a default. And, yes Data-Export Features creates similar mess, which I can avoid by populating new long integer field with OBJECTID and use it as sorting order...

This is annoying oddity, which caused my 2 years old script to fail and I've wasted 3 hours debugging it.

0 Kudos