1

I am quite a beginner with programming in python and I am struggling with my code. I would like to create new points(trees) on my map using mouse click and afterwards add them to the existing attribute table. I managed to locate points with mouse click however they are not added to the table, it is always one row (even I added 10 points) and the columns(ID, tree, Lat and Long) are not there as well (only ID, Shape..). I tried to connect it directly to the existing data set but then when I locate a new tree all other trees are disappearing and attribute table is containing one row as well.

     def onMouseDownMap(self, x, y, button, shift):
         #adding points to the map
         mxd = arcpy.mapping.MapDocument ("CURRENT")
         sr = mxd.activeDataFrame.spatialReference
         pntFc = r"\\abc\home\xxx\Documents\moje dokumenty\xyz\arcgis\treepoints" #new polygon
         ofc=r"\\abc\home\xxx\Documents\moje dokumenty\xyz\arcgis\trees" #existing data set 
         fields=["OID@","Tree","Lat", "Long"]
         Lat="SHAPE@X"
         Long="SHAPE@Y"
         pt = arcpy.Point()
         pt.X = float(x)
         pt.Y = float(y)
         ptGeoms = [arcpy.Geometry ("POINT", pt, sr)]
         if not arcpy.Exists (pntFc):
              arcpy.CopyFeatures_management(ptGeoms, pntFc)
         else:
             with arcpy.da.InsertCursor (pntFc, fields) as iCurs: #create insert cursor
             #insert row
                for pt in ptGeoms:
                    row=iCurs.insertRow()
               arcpy.RefreshActiveView()
        print "Complete"

closed as unclear what you're asking by PolyGeo Dec 9 '17 at 21:36

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.

  • 1
    row=iCurs.insertRow() is not pushing anything into your cursor because it has no parameter values being supplied to it. Also, your indentation seems to be a little astray. Have you tried having your Python window open when you click the button so that you can see any error messages? – PolyGeo Aug 25 '17 at 8:30
  • Yes, I have python window open and it does not show any errors – Pauline89 Aug 25 '17 at 9:08
  • I think you must have an error in your program.arcpy.da.InsertCursor you should have a good look – SuperLph Aug 25 '17 at 11:29
  • No error at all...I have printed also the messages after all stages and they were printed so I guess all steps are made. – Pauline89 Aug 25 '17 at 12:51