0

I am trying to determine a method for conducting a spatial join on features from two separate feature datasets based on the first three letters of each input feature (A01_road == A01_gps).

import arcpy
import os

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'E:\GPS\GPS.gdb'

rds = r'E:\Pathways_GPS\Pathways.gdb\road_lines'
wlk_pts = r'E:\Pathways_GPS\Pathways.gdb\Walking_points'
output = r'E:\Pathways_GPS\Pathways.gdb\road_join'

#Spatial Join Variables 
join_operation = 'JOIN_ONE_TO_ONE'
join_type = 'KEEP_COMMON'
field_mapping = ''
match_option = 'WITHIN_A_DISTANCE'
search_radius = '15 meter'
name_suffix = "_400join"

arcpy.env.workspace = rds
road_list = arcpy.ListFeatureClasses()
for road in road_list:
    road_fc = road[:3]
    arcpy.env.workspace = wlk_pts
    walk_list = arcpy.ListFeatureClasses()
    for walk in walk_list:
        walk_fc=walk[:3]
        if road_fc == walk_fc:
            out_fc = (os.path.join(output,(join_fc [:3]+ name_suffix)))
            arcpy.SpatialJoin_analysis(target_fc,join_fc, out_fc, join_operation, join_type, '', match_option, search_radius,'')

closed as unclear what you're asking by Emil Brundage, Jochen Schwarze, whyzar, Mark Ireland, Dan C Oct 17 '18 at 16:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What's your question? – Emil Brundage Oct 16 '18 at 23:10
  • 1
    Where did you get stuck? – Kadir Şahbaz Oct 17 '18 at 0:03
  • for each A01_road, is there only one A01_gps? it might be easier to do it with a dictionary and update cursor. – AlexS1 Oct 17 '18 at 0:55
3
  • Because you have defined full path for output, you don't need arcpy.env.workspace for it.
  • I assume you want to join walk_points to road_lines.
  • You can define walk_list outside the loop, it's just string list.
import arcpy
import os

arcpy.env.overwriteOutput = True

#Spatial Join Variables 
join_operation = 'JOIN_ONE_TO_ONE'
join_type = 'KEEP_COMMON'
field_mapping = ''
match_option = 'WITHIN_A_DISTANCE'
search_radius = '15 meter'
name_suffix = "_400join"

# Feature datasets
rds = r'E:\Pathways_GPS\Pathways.gdb\road_lines'
wlk_pts = r'E:\Pathways_GPS\Pathways.gdb\Walking_points'
output = r'E:\Pathways_GPS\Pathways.gdb\road_join'

# FeatureClass lists
arcpy.env.workspace = rds
road_list = arcpy.ListFeatureClasses()  
arcpy.env.workspace = wlk_pts
walk_list = arcpy.ListFeatureClasses()

for road in road_list:
    road_fc = (os.path.join(rds, road))
    for walk in walk_list:
        if road[:3] == walk[:3]:            
            walk_fc = (os.path.join(wlk_pts, walk))
            out_fc  = (os.path.join(output, (road + walk[3:] + name_suffix)))
            arcpy.SpatialJoin_analysis(road_fc, walk_fc, out_fc, join_operation, join_type, '', match_option, search_radius, '')

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.