1

I have a point shapefile that contains all my field collected data, lat/long and all the field data collected during the season. The one thing not imported was the name of the Lakes these points fell on. I have a polygon data set that has the name of the lake. What I want to accomplish without creating another data set is to have the Lake name populated for each point that falls within the lake. Some of my lakes do not have names so some will have blank records if that makes a difference. I was trying to accomplish this with python code that I found around the net trying to accomplish the same thing. I tried importing it into the ArcGIS addin assistant that lets you create buttons with python code running them. Here is the code I have so far that is not working. I click the button and nothing happens.

  import arcpy
  import pythonaddins

  class Transfer(object):
"""Implementation for AIS_Transfer_addin.tool (Button)"""
def __init__(self):
    self.enabled = True
    self.checked = False
def onClick(self):
    pythonaddins.MessageBox ('Attributes have been Transfered!', 'Message', 0)
    arcpy.env.overwriteOutput = True
    arcpy.MakeFeatureLayer_management('E:\Violations\AIS_Registry\MISIN_Source_Data_All_20181120.shp','lyr_Source')
    arcpy.MakeFeatureLayer_management('E:\Violations\AIS_Registry\Michigan_Lakes_All_v3.shp','lyr_lakes')

    rows = arcpy.SearchCursor(lyr_lakes)
    for row in rows:
        arcpy.SelectLayerByAttribute_management('lyr_lakes', 'NEW_SELECTION', '\'FID\' = ' + str(row.getValue('FID')))
        arcpy.SelectLayerByLocation_management('lyr_source', INTERSECT, 'lyr_lakes', '', 'NEW_SELECTION')
        arcpy.CalculateField_management('lyr_source', 'Lake_Name', "'[0]'".format(str(row.getValue('Label'))), 'PYTHON_9.3', '')
    print 'Finished processing' + str(row.getValue('Label')) 
2

The make feature layer paths are not correct, currently the "\" are being interpreted as an escape character. Try one of these options instead:

arcpy.MakeFeatureLayer_management('E:/Violations/AIS_Registry/MISIN_Source_Data_All_20181120.shp','lyr_Source')
arcpy.MakeFeatureLayer_management('E:/Violations/AIS_Registry/Michigan_Lakes_All_v3.shp','lyr_lakes')

or

arcpy.MakeFeatureLayer_management('E:\\Violations\\AIS_Registry\\MISIN_Source_Data_All_20181120.shp','lyr_Source')
arcpy.MakeFeatureLayer_management('E:\\Violations\\AIS_Registry\\Michigan_Lakes_All_v3.shp','lyr_lakes')

or

arcpy.MakeFeatureLayer_management(r'E:\Violations\AIS_Registry\MISIN_Source_Data_All_20181120.shp','lyr_Source')
arcpy.MakeFeatureLayer_management(r'E:\Violations\AIS_Registry\Michigan_Lakes_All_v3.shp','lyr_lakes')
  • Ok that fixed the layer issue, however the second part of the script isn't working either it looks like. Wonder if its not correct.? – Jeremy Jones Nov 26 '18 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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