Sorting output fields in a spatial join?

705
7
05-10-2018 09:30 AM
TheodoreF
Occasional Contributor II

ArcGIS Pro

I'm spatially joining 2 features from a layer to another polygon later. How can I sort the joined attributes numerically/alphabetically?

ie.

                              Address                                                                  X_coordinate

Feature 1      1 Fake street                                                                        12345

Feature 2      1 Fake street, 2 Fake street                                             12345, 56789

Feature 3      3 Fake street, 1 Fake street, 2 Fake street                 34567, 12345, 56789

Note how Feature 3 has 3 addresses spatially joined to it, but the merged fields are in a strange order.

I think when a new join feature is found, it's attribute data is inserted randomly into the merged field order....

Tags (1)
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus

Or maybe added in a dictionary format.

One way to confirm would be to do this in ArcGIS PRO since it uses Python 3.6 and insertion order is not maintained in dictionaries (ie no random sorting)

0 Kudos
TheodoreF
Occasional Contributor II

But I did do it in Pro. Maybe it has sorted it by one of the fields and I haven't realised yet....

0 Kudos
DanPatterson_Retired
MVP Emeritus

seeing the table might provide clues

0 Kudos
TheodoreF
Occasional Contributor II

I've found out that the spatial join is sorting the outputs by OBJECTID

0 Kudos
TheodoreF
Occasional Contributor II

So what I'm doing here is:

Multi-ring buffering a site boudary polygon layer 50 times (50x1m buffer discs). Then each distance buffer disc is spatially joined to a Mine location point layer. I'm then able to export the joined layer to Excel and view the results in a table:

As you can see above, each row is a buffer disc of one property boundary. In the image, each red underlined Reference number represents a new mine being spatially joined to the buffers feature class.

Look at the DistanceFromSite field- between 1 and 4m from the site, no Mines are present.

At 5m away, a single Mine is found.

At 9m away, another mine is found and the attributes are added to the MineRef output field, delimited with a comma.

At 12m away another mine is found and the same happens.

Now when we get to 25m away form the site, another mine is found BUT the attributes for that mine are not added to the end of the output string in MineRef. Instead they're added at the beginning!

At 27m, the next found mine is added as the second entry in the string.

At 50m, a final, 6th mine is found. But again, it's added into the output string as the fourth entry (see red underlined Mine ref at the top of the image).

So in conclusion, I found that the MineRefs are being sorted by their OBJECTIDs. How can I sort it by order in which they were found/added to the spatial join output string?

(FYI I'm basically trying to recreate the Near Table tool, but without an Advanced license)

0 Kudos
DanPatterson_Retired
MVP Emeritus
0 Kudos
TheodoreF
Occasional Contributor II

Target layer is a polygon I'll download your tool anyway!

I've heard of SQL functions like ST_Azimuth and ST_Distance which meaure using the geometries of the polygon boundary agasint another feature. But I've no experience using SQL... yet...

0 Kudos