Select to view content in your preferred language

One to Many Spatial Join not saving out the data properly

483
0
04-08-2019 04:17 AM
ronancorrigan
New Contributor

I'm reformatting this question as it seems I didn't do it right when I asked first time round. here is my problem.

if I run a one to many spatial analysis between a polygon and point feature class using arcmap, the result gives me the upper number of what I need (459 results), where as if I attempt to do it through arcpy, I get the lower number, as the one to many doesn't work (55 results)

I've tried everything I can think of, and I need this to work through arcpy as I'm doing it as a tool for another team where the guys using it has very poor understanding of arcmap and so do his team. below is the code I use. I have also attached the same code from exporting the arcmap function as code. so for the first code you see is the python snippet of what I have done in arcmap. I display XY data of a dbf table and do the below

arcpy.SpatialJoin_analysis(target_features="templayer", join_features="temptab Events", out_feature_class="H:/ArcGIS/Default.gdb/templayer_SpatialJoin12", join_operation="JOIN_ONE_TO_MANY", join_type="KEEP_ALL", field_mapping=(long string of code for the field attributes), match_option="INTERSECT", search_radius="", distance_field_name="")

the above gives me what I want

whereas my code below;

import arcpy, csv, openpyxl, os, xlrd, datetime from arcpy import env env.workspace = r"C:\Users\myname\Desktop\Yanko's tool" arcpy.env.overwriteOutput = True gdb = r"C:\Users\ronan.corrigan\Desktop\Yanko's tool\Yankos.gdb" today = datetime.datetime.today().strftime('%y%m%d') temptab = r"C:\Users\ronan.corrigan\Desktop\Yanko's tool\Yankos.gdb\temptab" arcpy.MakeXYEventLayer_management(temptab, "XCoord", "YCoord", "{}\templayer2".format(gdb)) r esult2 = "{}\templayer2".format(gdb) layer = r"C:\Users\ronan.corrigan\Desktop\Yanko's tool\Yanko's Duplicate tool\Example_Polygons.shp" arcpy.FeatureClassToFeatureClass_conversion(layer, gdb, "templayer") result = r"C:\Users\ronan.corrigan\Desktop\Yanko's tool\Yankos.gdb\templayer" arcpy.SpatialJoin_analysis(result, result2, r"{}\YankosTool{}".format(gdb, today), "JOIN_ONE_TO_MANY", "KEEP_ALL")

doesn't give me the full 459 (I copy and paste out the result1 because its a reference layer I need for all of them, the above is a slightly simplified version, but rest assured that the input to arcmap that is "temptab" is exactly the same as the make xy event layer "result 2" in my code and both the temp layers are the same).

I tried copying and pasting the first block and changing the parameters to match what's needed, but I still only get the 55. like below

arcpy.SpatialJoin_analysis(input1, input2, out_feature_class="C:/Users/ronan.corrigan/Desktop/Yanko's tool/Yankos.gdb/testing2", join_operation="JOIN_ONE_TO_MANY", join_type="KEEP_ALL", field_mapping= long string of code for the field attributes)', match_option="INTERSECT", search_radius="", distance_field_name="")

where input 1 and input 2 are just the inputs ive referenced as result 1 and result 2 before. but again I just keep getting 55 instead of the 459, which doing it through arcmap gives me. if I try doing it so that result 1 and result 2 are switched I just end up with points, buts it's polygons I need

can anyone see what's going wrong here, or maybe encountered this issue before?

0 Kudos
0 Replies